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
66c94d77
Commit
66c94d77
authored
Dec 15, 2014
by
Brian Tiger Chow
Committed by
Juan Batiz-Benet
Dec 17, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
queue-like naming
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
7071ef57
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
strategy/ledgermanager.go
strategy/ledgermanager.go
+3
-3
strategy/tasklist.go
strategy/tasklist.go
+5
-5
No files found.
strategy/ledgermanager.go
View file @
66c94d77
...
...
@@ -45,7 +45,7 @@ func NewLedgerManager(bs bstore.Blockstore, ctx context.Context) *LedgerManager
func
(
lm
*
LedgerManager
)
taskWorker
()
{
for
{
nextTask
:=
lm
.
tasklist
.
GetNext
()
nextTask
:=
lm
.
tasklist
.
Pop
()
if
nextTask
==
nil
{
// No tasks in the list?
// Wait until there are!
...
...
@@ -107,7 +107,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
lm
.
tasklist
.
Cancel
(
e
.
Key
,
p
)
}
else
{
l
.
Wants
(
e
.
Key
,
e
.
Priority
)
lm
.
tasklist
.
Add
(
e
.
Key
,
e
.
Priority
,
p
)
lm
.
tasklist
.
Push
(
e
.
Key
,
e
.
Priority
,
p
)
// Signal task generation to restart (if stopped!)
select
{
...
...
@@ -122,7 +122,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
l
.
ReceivedBytes
(
len
(
block
.
Data
))
for
_
,
l
:=
range
lm
.
ledgerMap
{
if
l
.
WantListContains
(
block
.
Key
())
{
lm
.
tasklist
.
Add
(
block
.
Key
(),
1
,
l
.
Partner
)
lm
.
tasklist
.
Push
(
block
.
Key
(),
1
,
l
.
Partner
)
// Signal task generation to restart (if stopped!)
select
{
...
...
strategy/tasklist.go
View file @
66c94d77
...
...
@@ -25,9 +25,9 @@ type Task struct {
theirPriority
int
}
//
Add
currently adds a new task to the end of the list
//
Push
currently adds a new task to the end of the list
// TODO: make this into a priority queue
func
(
tl
*
TaskList
)
Add
(
block
u
.
Key
,
priority
int
,
to
peer
.
Peer
)
{
func
(
tl
*
TaskList
)
Push
(
block
u
.
Key
,
priority
int
,
to
peer
.
Peer
)
{
if
task
,
ok
:=
tl
.
taskmap
[
to
.
Key
()
+
block
];
ok
{
// TODO: when priority queue is implemented,
// rearrange this Task
...
...
@@ -43,9 +43,9 @@ func (tl *TaskList) Add(block u.Key, priority int, to peer.Peer) {
tl
.
taskmap
[
to
.
Key
()
+
block
]
=
task
}
//
GetNext
returns the next task to be performed by bitswap
//
the task is then
removed from the list
func
(
tl
*
TaskList
)
GetNext
()
*
Task
{
//
Pop
returns the next task to be performed by bitswap
the task is then
// removed from the list
func
(
tl
*
TaskList
)
Pop
()
*
Task
{
var
out
*
Task
for
len
(
tl
.
tasks
)
>
0
{
// TODO: instead of zero, use exponential distribution
...
...
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