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-unixfs
Commits
8450a8d4
Commit
8450a8d4
authored
9 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address comments from CR
parent
76e879c9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
11 deletions
+25
-11
exchange/bitswap/decision/engine.go
exchange/bitswap/decision/engine.go
+7
-0
exchange/bitswap/decision/peer_request_queue.go
exchange/bitswap/decision/peer_request_queue.go
+7
-6
exchange/bitswap/decision/peer_request_queue_test.go
exchange/bitswap/decision/peer_request_queue_test.go
+10
-5
exchange/bitswap/workers.go
exchange/bitswap/workers.go
+1
-0
No files found.
exchange/bitswap/decision/engine.go
View file @
8450a8d4
...
...
@@ -55,6 +55,9 @@ type Envelope struct {
Peer
peer
.
ID
// Message is the payload
Message
bsmsg
.
BitSwapMessage
// A callback to notify the decision queue that the task is complete
Sent
func
()
}
type
Engine
struct
{
...
...
@@ -132,6 +135,9 @@ func (e *Engine) nextEnvelope(ctx context.Context) (*Envelope, error) {
block
,
err
:=
e
.
bs
.
Get
(
nextTask
.
Entry
.
Key
)
if
err
!=
nil
{
// If we don't have the block, don't hold that against the peer
// make sure to update that the task has been 'completed'
nextTask
.
Done
()
continue
}
...
...
@@ -140,6 +146,7 @@ func (e *Engine) nextEnvelope(ctx context.Context) (*Envelope, error) {
return
&
Envelope
{
Peer
:
nextTask
.
Target
,
Message
:
m
,
Sent
:
nextTask
.
Done
,
},
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
exchange/bitswap/decision/peer_request_queue.go
View file @
8450a8d4
...
...
@@ -173,11 +173,11 @@ func wrapCmp(f func(a, b *peerRequestTask) bool) func(a, b pq.Elem) bool {
}
type
activePartner
struct
{
lk
sync
.
Mutex
// Active is the number of blocks this peer is currently being sent
// active must be locked around as it will be updated externally
active
int
activelk
sync
.
Mutex
active
int
// requests is the number of blocks this peer is currently requesting
// request need not be locked around as it will only be modified under
...
...
@@ -197,6 +197,7 @@ func partnerCompare(a, b pq.Elem) bool {
pb
:=
b
.
(
*
activePartner
)
// having no blocks in their wantlist means lowest priority
// having both of these checks ensures stability of the sort
if
pa
.
requests
==
0
{
return
false
}
...
...
@@ -208,19 +209,19 @@ func partnerCompare(a, b pq.Elem) bool {
// StartTask signals that a task was started for this partner
func
(
p
*
activePartner
)
StartTask
()
{
p
.
lk
.
Lock
()
p
.
active
lk
.
Lock
()
p
.
active
++
p
.
lk
.
Unlock
()
p
.
active
lk
.
Unlock
()
}
// TaskDone signals that a task was completed for this partner
func
(
p
*
activePartner
)
TaskDone
()
{
p
.
lk
.
Lock
()
p
.
active
lk
.
Lock
()
p
.
active
--
if
p
.
active
<
0
{
panic
(
"more tasks finished than started!"
)
}
p
.
lk
.
Unlock
()
p
.
active
lk
.
Unlock
()
}
// Index implements pq.Elem
...
...
This diff is collapsed.
Click to expand it.
exchange/bitswap/decision/peer_request_queue_test.go
View file @
8450a8d4
...
...
@@ -105,10 +105,15 @@ func TestPeerRepeats(t *testing.T) {
// Now, if one of the tasks gets finished, the next task off the queue should
// be for the same peer
tasks
[
0
]
.
Done
()
ntask
:=
prq
.
Pop
()
if
ntask
.
Target
!=
tasks
[
0
]
.
Target
{
t
.
Fatal
(
"Expected task from peer with lowest active count"
)
for
blockI
:=
0
;
blockI
<
4
;
blockI
++
{
for
i
:=
0
;
i
<
4
;
i
++
{
// its okay to mark the same task done multiple times here (JUST FOR TESTING)
tasks
[
i
]
.
Done
()
ntask
:=
prq
.
Pop
()
if
ntask
.
Target
!=
tasks
[
i
]
.
Target
{
t
.
Fatal
(
"Expected task from peer with lowest active count"
)
}
}
}
}
This diff is collapsed.
Click to expand it.
exchange/bitswap/workers.go
View file @
8450a8d4
...
...
@@ -51,6 +51,7 @@ func (bs *Bitswap) taskWorker(ctx context.Context) {
}
log
.
Event
(
ctx
,
"deliverBlocks"
,
envelope
.
Message
,
envelope
.
Peer
)
bs
.
send
(
ctx
,
envelope
.
Peer
,
envelope
.
Message
)
envelope
.
Sent
()
case
<-
ctx
.
Done
()
:
return
}
...
...
This diff is collapsed.
Click to expand it.
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