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
6d1e10d2
Unverified
Commit
6d1e10d2
authored
Jun 12, 2019
by
Steven Allen
Committed by
GitHub
Jun 12, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #139 from ipfs/fix/nits
fix some naming nits and broadcast on search
parents
02895498
eb28a2e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
53 deletions
+54
-53
session/session.go
session/session.go
+54
-53
No files found.
session/session.go
View file @
6d1e10d2
...
...
@@ -77,18 +77,18 @@ type Session struct {
tickDelayReqs
chan
time
.
Duration
// do not touch outside run loop
tofetch
*
cidQueue
interest
*
lru
.
Cache
pastWants
*
cidQueue
liveWants
map
[
cid
.
Cid
]
time
.
Time
t
ick
*
time
.
Timer
rebroadcast
*
time
.
Timer
baseTickDelay
time
.
Duration
latTotal
time
.
Duration
fetchcnt
int
consecutiveTicks
int
prov
SearchDelay
time
.
Duration
rebroadcast
Delay
delay
.
D
tofetch
*
cidQueue
interest
*
lru
.
Cache
pastWants
*
cidQueue
liveWants
map
[
cid
.
Cid
]
time
.
Time
idleT
ick
*
time
.
Timer
periodicSearchTimer
*
time
.
Timer
baseTickDelay
time
.
Duration
latTotal
time
.
Duration
fetchcnt
int
consecutiveTicks
int
initial
SearchDelay
time
.
Duration
periodicSearch
Delay
delay
.
D
// identifiers
notif
notifications
.
PubSub
uuid
logging
.
Loggable
...
...
@@ -102,28 +102,28 @@ 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
),
cancelKeys
:
make
(
chan
[]
cid
.
Cid
),
tofetch
:
newCidQueue
(),
pastWants
:
newCidQueue
(),
interestReqs
:
make
(
chan
interestReq
),
latencyReqs
:
make
(
chan
chan
time
.
Duration
),
tickDelayReqs
:
make
(
chan
time
.
Duration
),
ctx
:
ctx
,
wm
:
wm
,
pm
:
pm
,
srs
:
srs
,
incoming
:
make
(
chan
blkRecv
),
notif
:
notifications
.
New
(),
uuid
:
loggables
.
Uuid
(
"GetBlockRequest"
),
baseTickDelay
:
time
.
Millisecond
*
500
,
id
:
id
,
prov
SearchDelay
:
prov
SearchDelay
,
rebroadcastDelay
:
rebroadcast
Delay
,
liveWants
:
make
(
map
[
cid
.
Cid
]
time
.
Time
),
newReqs
:
make
(
chan
[]
cid
.
Cid
),
cancelKeys
:
make
(
chan
[]
cid
.
Cid
),
tofetch
:
newCidQueue
(),
pastWants
:
newCidQueue
(),
interestReqs
:
make
(
chan
interestReq
),
latencyReqs
:
make
(
chan
chan
time
.
Duration
),
tickDelayReqs
:
make
(
chan
time
.
Duration
),
ctx
:
ctx
,
wm
:
wm
,
pm
:
pm
,
srs
:
srs
,
incoming
:
make
(
chan
blkRecv
),
notif
:
notifications
.
New
(),
uuid
:
loggables
.
Uuid
(
"GetBlockRequest"
),
baseTickDelay
:
time
.
Millisecond
*
500
,
id
:
id
,
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
.
rebroadcastDelay
.
Get
())
s
.
idleT
ick
=
time
.
NewTimer
(
s
.
initial
SearchDelay
)
s
.
periodicSearchTimer
=
time
.
NewTimer
(
s
.
periodicSearchDelay
.
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,28 +321,29 @@ 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
)
{
if
len
(
s
.
liveWants
)
==
0
{
func
(
s
*
Session
)
handle
PeriodicSearch
(
ctx
context
.
Context
)
{
randomWant
:=
s
.
randomLiveWant
()
if
!
randomWant
.
Defined
()
{
return
}
// TODO: come up with a better strategy for determining when to search
// for new providers for blocks.
s
.
pm
.
FindMorePeers
(
ctx
,
s
.
randomLiveWant
())
s
.
pm
.
FindMorePeers
(
ctx
,
randomWant
)
s
.
wm
.
WantBlocks
(
ctx
,
[]
cid
.
Cid
{
randomWant
},
nil
,
s
.
id
)
s
.
rebroadcast
.
Reset
(
s
.
rebroadcastDelay
.
Get
())
s
.
periodicSearchTimer
.
Reset
(
s
.
periodicSearchDelay
.
NextWaitTime
())
}
func
(
s
*
Session
)
randomLiveWant
()
cid
.
Cid
{
...
...
@@ -357,7 +358,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 +437,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