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
1b3d1588
Commit
1b3d1588
authored
Aug 26, 2016
by
Jeromy
Browse files
add listing method to backoff for eventual api access
parent
40a5c58c
Changes
1
Hide whitespace changes
Inline
Side-by-side
p2p/net/swarm/swarm_dial.go
View file @
1b3d1588
...
...
@@ -157,8 +157,8 @@ type dialbackoff struct {
}
type
backoffPeer
struct
{
t
ries
int
u
ntil
time
.
Time
T
ries
int
U
ntil
time
.
Time
}
func
(
db
*
dialbackoff
)
init
()
{
...
...
@@ -167,6 +167,17 @@ func (db *dialbackoff) init() {
}
}
func
(
db
*
dialbackoff
)
Listing
()
map
[
peer
.
ID
]
*
backoffPeer
{
db
.
lock
.
Lock
()
defer
db
.
lock
.
Unlock
()
out
:=
make
(
map
[
peer
.
ID
]
*
backoffPeer
)
for
k
,
v
:=
range
db
.
entries
{
p
:=
*
v
out
[
k
]
=
&
p
}
return
out
}
// Backoff returns whether the client should backoff from dialing
// peer p
func
(
db
*
dialbackoff
)
Backoff
(
p
peer
.
ID
)
(
backoff
bool
)
{
...
...
@@ -174,7 +185,7 @@ func (db *dialbackoff) Backoff(p peer.ID) (backoff bool) {
defer
db
.
lock
.
Unlock
()
db
.
init
()
bp
,
found
:=
db
.
entries
[
p
]
if
found
&&
time
.
Now
()
.
Before
(
bp
.
u
ntil
)
{
if
found
&&
time
.
Now
()
.
Before
(
bp
.
U
ntil
)
{
return
true
}
...
...
@@ -194,18 +205,18 @@ func (db *dialbackoff) AddBackoff(p peer.ID) {
bp
,
ok
:=
db
.
entries
[
p
]
if
!
ok
{
db
.
entries
[
p
]
=
&
backoffPeer
{
t
ries
:
1
,
u
ntil
:
time
.
Now
()
.
Add
(
baseBackoffTime
),
T
ries
:
1
,
U
ntil
:
time
.
Now
()
.
Add
(
baseBackoffTime
),
}
return
}
expTimeAdd
:=
time
.
Second
*
time
.
Duration
(
bp
.
t
ries
*
bp
.
t
ries
)
expTimeAdd
:=
time
.
Second
*
time
.
Duration
(
bp
.
T
ries
*
bp
.
T
ries
)
if
expTimeAdd
>
maxBackoffTime
{
expTimeAdd
=
maxBackoffTime
}
bp
.
u
ntil
=
time
.
Now
()
.
Add
(
baseBackoffTime
+
expTimeAdd
)
bp
.
t
ries
++
bp
.
U
ntil
=
time
.
Now
()
.
Add
(
baseBackoffTime
+
expTimeAdd
)
bp
.
T
ries
++
}
// Clear removes a backoff record. Clients should call this after a
...
...
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