Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
8b419c5d
Commit
8b419c5d
authored
Feb 02, 2015
by
Juan Batiz-Benet
Browse files
p2p/net/swarm: permute addrs in rate limited dials
so that we dont get stuck dialing bad addrs first always.
parent
51709847
Changes
1
Hide whitespace changes
Inline
Side-by-side
net/swarm/swarm_dial.go
View file @
8b419c5d
...
...
@@ -3,6 +3,7 @@ package swarm
import
(
"errors"
"fmt"
"math/rand"
"net"
"sync"
"time"
...
...
@@ -384,13 +385,16 @@ func (s *Swarm) dialAddrs(ctx context.Context, d *conn.Dialer, p peer.ID, remote
go
func
()
{
// rate limiting just in case. at most 10 addrs at once.
limiter
:=
ratelimit
.
NewRateLimiter
(
procctx
.
WithContext
(
ctx
),
10
)
for
_
,
addr
:=
range
remoteAddrs
{
// permute addrs so we try different sets first each time.
for
_
,
i
:=
range
rand
.
Perm
(
len
(
remoteAddrs
))
{
select
{
case
<-
foundConn
:
// if one of them succeeded already
break
default
:
}
workerAddr
:=
addr
// shadow variable to avoid race
workerAddr
:=
remoteAddrs
[
i
]
// shadow variable to avoid race
limiter
.
Go
(
func
(
worker
process
.
Process
)
{
dialSingleAddr
(
workerAddr
)
})
...
...
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