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
1c0adc36
Unverified
Commit
1c0adc36
authored
Apr 02, 2020
by
Will
Committed by
GitHub
Apr 02, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #192 from libp2p/fix/simplify-backoff
chore: slightly simplify backoff logic
parents
6711d98c
aa270de0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
14 deletions
+4
-14
swarm_dial.go
swarm_dial.go
+4
-14
No files found.
swarm_dial.go
View file @
1c0adc36
...
...
@@ -131,15 +131,9 @@ func (db *DialBackoff) background(ctx context.Context) {
func
(
db
*
DialBackoff
)
Backoff
(
p
peer
.
ID
,
addr
ma
.
Multiaddr
)
(
backoff
bool
)
{
db
.
lock
.
Lock
()
defer
db
.
lock
.
Unlock
()
bp
,
found
:=
db
.
entries
[
p
]
if
found
{
ap
,
found
:=
bp
[
string
(
addr
.
Bytes
())]
if
found
&&
time
.
Now
()
.
Before
(
ap
.
until
)
{
return
true
}
}
return
false
ap
,
found
:=
db
.
entries
[
p
][
string
(
addr
.
Bytes
())]
return
found
&&
time
.
Now
()
.
Before
(
ap
.
until
)
}
// BackoffBase is the base amount of time to backoff (default: 5s).
...
...
@@ -167,12 +161,8 @@ func (db *DialBackoff) AddBackoff(p peer.ID, addr ma.Multiaddr) {
defer
db
.
lock
.
Unlock
()
bp
,
ok
:=
db
.
entries
[
p
]
if
!
ok
{
db
.
entries
[
p
]
=
make
(
map
[
string
]
*
backoffAddr
)
db
.
entries
[
p
][
saddr
]
=
&
backoffAddr
{
tries
:
1
,
until
:
time
.
Now
()
.
Add
(
BackoffBase
),
}
return
bp
=
make
(
map
[
string
]
*
backoffAddr
,
1
)
db
.
entries
[
p
]
=
bp
}
ba
,
ok
:=
bp
[
saddr
]
if
!
ok
{
...
...
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