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
221d5023
Commit
221d5023
authored
Apr 20, 2021
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: avoid returning typed nils
parent
2d73b1d6
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 @
221d5023
...
...
@@ -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 @
221d5023
...
...
@@ -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