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
36427bde
Commit
36427bde
authored
Apr 29, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try harder to not send duplicate blocks
parent
90fede8d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
decision/peer_request_queue.go
decision/peer_request_queue.go
+23
-5
workers.go
workers.go
+1
-1
No files found.
decision/peer_request_queue.go
View file @
36427bde
...
...
@@ -46,7 +46,7 @@ func (tl *prq) Push(entry wantlist.Entry, to peer.ID) {
defer
tl
.
lock
.
Unlock
()
partner
,
ok
:=
tl
.
partners
[
to
]
if
!
ok
{
partner
=
&
a
ctivePartner
{
taskQueue
:
pq
.
New
(
wrapCmp
(
V1
))}
partner
=
newA
ctivePartner
()
tl
.
pQueue
.
Push
(
partner
)
tl
.
partners
[
to
]
=
partner
}
...
...
@@ -57,12 +57,19 @@ func (tl *prq) Push(entry wantlist.Entry, to peer.ID) {
return
}
partner
.
activelk
.
Lock
()
defer
partner
.
activelk
.
Unlock
()
_
,
ok
=
partner
.
activeBlocks
[
entry
.
Key
]
if
ok
{
return
}
task
:=
&
peerRequestTask
{
Entry
:
entry
,
Target
:
to
,
created
:
time
.
Now
(),
Done
:
func
()
{
partner
.
TaskDone
()
partner
.
TaskDone
(
entry
.
Key
)
tl
.
lock
.
Lock
()
tl
.
pQueue
.
Update
(
partner
.
Index
())
tl
.
lock
.
Unlock
()
...
...
@@ -93,7 +100,7 @@ func (tl *prq) Pop() *peerRequestTask {
continue
// discarding tasks that have been removed
}
partner
.
StartTask
()
partner
.
StartTask
(
out
.
Entry
.
Key
)
partner
.
requests
--
break
// and return |out|
}
...
...
@@ -179,6 +186,8 @@ type activePartner struct {
activelk
sync
.
Mutex
active
int
activeBlocks
map
[
u
.
Key
]
struct
{}
// requests is the number of blocks this peer is currently requesting
// request need not be locked around as it will only be modified under
// the peerRequestQueue's locks
...
...
@@ -191,6 +200,13 @@ type activePartner struct {
taskQueue
pq
.
PQ
}
func
newActivePartner
()
*
activePartner
{
return
&
activePartner
{
taskQueue
:
pq
.
New
(
wrapCmp
(
V1
)),
activeBlocks
:
make
(
map
[
u
.
Key
]
struct
{}),
}
}
// partnerCompare implements pq.ElemComparator
func
partnerCompare
(
a
,
b
pq
.
Elem
)
bool
{
pa
:=
a
.
(
*
activePartner
)
...
...
@@ -208,15 +224,17 @@ func partnerCompare(a, b pq.Elem) bool {
}
// StartTask signals that a task was started for this partner
func
(
p
*
activePartner
)
StartTask
()
{
func
(
p
*
activePartner
)
StartTask
(
k
u
.
Key
)
{
p
.
activelk
.
Lock
()
p
.
activeBlocks
[
k
]
=
struct
{}{}
p
.
active
++
p
.
activelk
.
Unlock
()
}
// TaskDone signals that a task was completed for this partner
func
(
p
*
activePartner
)
TaskDone
()
{
func
(
p
*
activePartner
)
TaskDone
(
k
u
.
Key
)
{
p
.
activelk
.
Lock
()
delete
(
p
.
activeBlocks
,
k
)
p
.
active
--
if
p
.
active
<
0
{
panic
(
"more tasks finished than started!"
)
...
...
workers.go
View file @
36427bde
...
...
@@ -11,7 +11,7 @@ import (
u
"github.com/ipfs/go-ipfs/util"
)
var
TaskWorkerCount
=
16
var
TaskWorkerCount
=
8
func
init
()
{
twc
:=
os
.
Getenv
(
"IPFS_BITSWAP_TASK_WORKERS"
)
...
...
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