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
9ed362ba
Commit
9ed362ba
authored
Jan 23, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dialer: handle dial cancel and/or completion before trying new addresses
parent
f056f38c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
8 deletions
+25
-8
swarm_dial.go
swarm_dial.go
+25
-8
No files found.
swarm_dial.go
View file @
9ed362ba
...
@@ -358,14 +358,34 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.
...
@@ -358,14 +358,34 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.
defer
s
.
limiter
.
clearAllPeerDials
(
p
)
defer
s
.
limiter
.
clearAllPeerDials
(
p
)
var
active
int
var
active
int
for
{
for
remoteAddrs
!=
nil
||
active
>
0
{
// Check for context cancellations and/or responses first.
select
{
case
<-
ctx
.
Done
()
:
if
exitErr
==
defaultDialFail
{
exitErr
=
ctx
.
Err
()
}
return
nil
,
exitErr
case
resp
:=
<-
respch
:
active
--
if
resp
.
Err
!=
nil
{
log
.
Infof
(
"got error on dial to %s: %s"
,
resp
.
Addr
,
resp
.
Err
)
// Errors are normal, lots of dials will fail
exitErr
=
resp
.
Err
}
else
if
resp
.
Conn
!=
nil
{
return
resp
.
Conn
,
nil
}
// We got a result, try again from the top.
continue
default
:
}
// Now, attempt to dial.
select
{
select
{
case
addr
,
ok
:=
<-
remoteAddrs
:
case
addr
,
ok
:=
<-
remoteAddrs
:
if
!
ok
{
if
!
ok
{
remoteAddrs
=
nil
remoteAddrs
=
nil
if
active
==
0
{
return
nil
,
exitErr
}
continue
continue
}
}
...
@@ -382,15 +402,12 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.
...
@@ -382,15 +402,12 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.
log
.
Infof
(
"got error on dial to %s: %s"
,
resp
.
Addr
,
resp
.
Err
)
log
.
Infof
(
"got error on dial to %s: %s"
,
resp
.
Addr
,
resp
.
Err
)
// Errors are normal, lots of dials will fail
// Errors are normal, lots of dials will fail
exitErr
=
resp
.
Err
exitErr
=
resp
.
Err
if
remoteAddrs
==
nil
&&
active
==
0
{
return
nil
,
exitErr
}
}
else
if
resp
.
Conn
!=
nil
{
}
else
if
resp
.
Conn
!=
nil
{
return
resp
.
Conn
,
nil
return
resp
.
Conn
,
nil
}
}
}
}
}
}
return
nil
,
exitErr
}
}
// limitedDial will start a dial to the given peer when
// limitedDial will start a dial to the given peer when
...
...
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