Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-swarm
Commits
a73c29ad
Unverified
Commit
a73c29ad
authored
Apr 22, 2021
by
Steven Allen
Committed by
GitHub
Apr 22, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #257 from libp2p/fix/typed-nil
fix: avoid returning typed nils
parents
2d73b1d6
221d5023
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
swarm_dial.go
swarm_dial.go
+6
-1
swarm_test.go
swarm_test.go
+13
-0
No files found.
swarm_dial.go
View file @
a73c29ad
...
...
@@ -226,7 +226,12 @@ func (s *Swarm) DialPeer(ctx context.Context, p peer.ID) (network.Conn, error) {
return
nil
,
&
DialError
{
Peer
:
p
,
Cause
:
ErrGaterDisallowedConnection
}
}
return
s
.
dialPeer
(
ctx
,
p
)
// Avoid typed nil issues.
c
,
err
:=
s
.
dialPeer
(
ctx
,
p
)
if
err
!=
nil
{
return
nil
,
err
}
return
c
,
nil
}
// internal dial method that returns an unwrapped conn
...
...
swarm_test.go
View file @
a73c29ad
...
...
@@ -412,6 +412,19 @@ func TestCloseWithOpenStreams(t *testing.T) {
}
}
func
TestTypedNilConn
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
s
:=
GenSwarm
(
t
,
ctx
)
defer
s
.
Close
()
// We can't dial ourselves.
c
,
err
:=
s
.
DialPeer
(
ctx
,
s
.
LocalPeer
())
require
.
Error
(
t
,
err
)
// If we fail to dial, the connection should be nil.
require
.
True
(
t
,
c
==
nil
)
}
func
TestPreventDialListenAddr
(
t
*
testing
.
T
)
{
s
:=
GenSwarm
(
t
,
context
.
Background
(),
OptDialOnly
)
if
err
:=
s
.
Listen
(
ma
.
StringCast
(
"/ip4/0.0.0.0/udp/0/quic"
));
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment