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
dms3
go-bitswap
Commits
2a00256b
Commit
2a00256b
authored
Jun 11, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nit(session): improve naming
parent
c783e018
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
50 deletions
+50
-50
session/session.go
session/session.go
+50
-50
No files found.
session/session.go
View file @
2a00256b
...
...
@@ -81,14 +81,14 @@ type Session struct {
interest
*
lru
.
Cache
pastWants
*
cidQueue
liveWants
map
[
cid
.
Cid
]
time
.
Time
t
ick
*
time
.
Timer
rebroadcast
*
time
.
Timer
idleT
ick
*
time
.
Timer
periodicSearchTimer
*
time
.
Timer
baseTickDelay
time
.
Duration
latTotal
time
.
Duration
fetchcnt
int
consecutiveTicks
int
prov
SearchDelay
time
.
Duration
rebroadcast
Delay
delay
.
D
initial
SearchDelay
time
.
Duration
periodicSearch
Delay
delay
.
D
// identifiers
notif
notifications
.
PubSub
uuid
logging
.
Loggable
...
...
@@ -102,8 +102,8 @@ func New(ctx context.Context,
wm
WantManager
,
pm
PeerManager
,
srs
RequestSplitter
,
prov
SearchDelay
time
.
Duration
,
rebroadcast
Delay
delay
.
D
)
*
Session
{
initial
SearchDelay
time
.
Duration
,
periodicSearch
Delay
delay
.
D
)
*
Session
{
s
:=
&
Session
{
liveWants
:
make
(
map
[
cid
.
Cid
]
time
.
Time
),
newReqs
:
make
(
chan
[]
cid
.
Cid
),
...
...
@@ -122,8 +122,8 @@ func New(ctx context.Context,
uuid
:
loggables
.
Uuid
(
"GetBlockRequest"
),
baseTickDelay
:
time
.
Millisecond
*
500
,
id
:
id
,
prov
SearchDelay
:
prov
SearchDelay
,
rebroadcastDelay
:
rebroadcast
Delay
,
initial
SearchDelay
:
initial
SearchDelay
,
periodicSearchDelay
:
periodicSearch
Delay
,
}
cache
,
_
:=
lru
.
New
(
2048
)
...
...
@@ -239,8 +239,8 @@ func (s *Session) SetBaseTickDelay(baseTickDelay time.Duration) {
// Session run loop -- everything function below here should not be called
// of this loop
func
(
s
*
Session
)
run
(
ctx
context
.
Context
)
{
s
.
t
ick
=
time
.
NewTimer
(
s
.
prov
SearchDelay
)
s
.
rebroadcast
=
time
.
NewTimer
(
s
.
rebroadcast
Delay
.
NextWaitTime
())
s
.
idleT
ick
=
time
.
NewTimer
(
s
.
initial
SearchDelay
)
s
.
periodicSearchTimer
=
time
.
NewTimer
(
s
.
periodicSearch
Delay
.
NextWaitTime
())
for
{
select
{
case
blk
:=
<-
s
.
incoming
:
...
...
@@ -253,10 +253,10 @@ func (s *Session) run(ctx context.Context) {
s
.
handleNewRequest
(
ctx
,
keys
)
case
keys
:=
<-
s
.
cancelKeys
:
s
.
handleCancel
(
keys
)
case
<-
s
.
t
ick
.
C
:
s
.
handleTick
(
ctx
)
case
<-
s
.
rebroadcast
.
C
:
s
.
handle
Rebroadcast
(
ctx
)
case
<-
s
.
idleT
ick
.
C
:
s
.
handle
Idle
Tick
(
ctx
)
case
<-
s
.
periodicSearchTimer
.
C
:
s
.
handle
PeriodicSearch
(
ctx
)
case
lwchk
:=
<-
s
.
interestReqs
:
lwchk
.
resp
<-
s
.
cidIsWanted
(
lwchk
.
c
)
case
resp
:=
<-
s
.
latencyReqs
:
...
...
@@ -271,7 +271,7 @@ func (s *Session) run(ctx context.Context) {
}
func
(
s
*
Session
)
handleIncomingBlock
(
ctx
context
.
Context
,
blk
blkRecv
)
{
s
.
t
ick
.
Stop
()
s
.
idleT
ick
.
Stop
()
if
blk
.
from
!=
""
{
s
.
pm
.
RecordPeerResponse
(
blk
.
from
,
blk
.
blk
.
Cid
())
...
...
@@ -279,7 +279,7 @@ func (s *Session) handleIncomingBlock(ctx context.Context, blk blkRecv) {
s
.
receiveBlock
(
ctx
,
blk
.
blk
)
s
.
resetTick
()
s
.
reset
Idle
Tick
()
}
func
(
s
*
Session
)
handleNewRequest
(
ctx
context
.
Context
,
keys
[]
cid
.
Cid
)
{
...
...
@@ -307,7 +307,7 @@ func (s *Session) handleCancel(keys []cid.Cid) {
}
}
func
(
s
*
Session
)
handleTick
(
ctx
context
.
Context
)
{
func
(
s
*
Session
)
handle
Idle
Tick
(
ctx
context
.
Context
)
{
live
:=
make
([]
cid
.
Cid
,
0
,
len
(
s
.
liveWants
))
now
:=
time
.
Now
()
...
...
@@ -321,18 +321,18 @@ func (s *Session) handleTick(ctx context.Context) {
s
.
wm
.
WantBlocks
(
ctx
,
live
,
nil
,
s
.
id
)
// do no find providers on consecutive ticks
// -- just rely on periodic
rebroadcast
// -- just rely on periodic
search widening
if
len
(
live
)
>
0
&&
(
s
.
consecutiveTicks
==
0
)
{
s
.
pm
.
FindMorePeers
(
ctx
,
live
[
0
])
}
s
.
resetTick
()
s
.
reset
Idle
Tick
()
if
len
(
s
.
liveWants
)
>
0
{
s
.
consecutiveTicks
++
}
}
func
(
s
*
Session
)
handle
Rebroadcast
(
ctx
context
.
Context
)
{
func
(
s
*
Session
)
handle
PeriodicSearch
(
ctx
context
.
Context
)
{
if
len
(
s
.
liveWants
)
==
0
{
return
...
...
@@ -342,7 +342,7 @@ func (s *Session) handleRebroadcast(ctx context.Context) {
// for new providers for blocks.
s
.
pm
.
FindMorePeers
(
ctx
,
s
.
randomLiveWant
())
s
.
rebroadcast
.
Reset
(
s
.
rebroadcast
Delay
.
NextWaitTime
())
s
.
periodicSearchTimer
.
Reset
(
s
.
periodicSearch
Delay
.
NextWaitTime
())
}
func
(
s
*
Session
)
randomLiveWant
()
cid
.
Cid
{
...
...
@@ -357,7 +357,7 @@ func (s *Session) randomLiveWant() cid.Cid {
return
cid
.
Cid
{}
}
func
(
s
*
Session
)
handleShutdown
()
{
s
.
t
ick
.
Stop
()
s
.
idleT
ick
.
Stop
()
s
.
notif
.
Shutdown
()
live
:=
make
([]
cid
.
Cid
,
0
,
len
(
s
.
liveWants
))
...
...
@@ -436,16 +436,16 @@ func (s *Session) averageLatency() time.Duration {
return
s
.
latTotal
/
time
.
Duration
(
s
.
fetchcnt
)
}
func
(
s
*
Session
)
resetTick
()
{
func
(
s
*
Session
)
reset
Idle
Tick
()
{
var
tickDelay
time
.
Duration
if
s
.
latTotal
==
0
{
tickDelay
=
s
.
prov
SearchDelay
tickDelay
=
s
.
initial
SearchDelay
}
else
{
avLat
:=
s
.
averageLatency
()
tickDelay
=
s
.
baseTickDelay
+
(
3
*
avLat
)
}
tickDelay
=
tickDelay
*
time
.
Duration
(
1
+
s
.
consecutiveTicks
)
s
.
t
ick
.
Reset
(
tickDelay
)
s
.
idleT
ick
.
Reset
(
tickDelay
)
}
func
(
s
*
Session
)
wantBudget
()
int
{
...
...
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