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
f6db5f77
Unverified
Commit
f6db5f77
authored
Mar 17, 2020
by
Steven Allen
Committed by
GitHub
Mar 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: micro-optimize priority (#304)
parent
a32feca5
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
16 additions
and
16 deletions
+16
-16
internal/decision/engine.go
internal/decision/engine.go
+3
-3
internal/decision/engine_test.go
internal/decision/engine_test.go
+2
-2
internal/decision/ledger.go
internal/decision/ledger.go
+1
-1
internal/messagequeue/messagequeue.go
internal/messagequeue/messagequeue.go
+2
-2
internal/testutil/testutil.go
internal/testutil/testutil.go
+1
-1
message/message.go
message/message.go
+4
-4
wantlist/wantlist.go
wantlist/wantlist.go
+3
-3
No files found.
internal/decision/engine.go
View file @
f6db5f77
...
...
@@ -596,7 +596,7 @@ func (e *Engine) MessageReceived(ctx context.Context, p peer.ID, m bsmsg.BitSwap
activeEntries
=
append
(
activeEntries
,
peertask
.
Task
{
Topic
:
c
,
Priority
:
entry
.
Priority
,
Priority
:
int
(
entry
.
Priority
)
,
Work
:
bsmsg
.
BlockPresenceSize
(
c
),
Data
:
&
taskData
{
BlockSize
:
0
,
...
...
@@ -624,7 +624,7 @@ func (e *Engine) MessageReceived(ctx context.Context, p peer.ID, m bsmsg.BitSwap
}
activeEntries
=
append
(
activeEntries
,
peertask
.
Task
{
Topic
:
c
,
Priority
:
entry
.
Priority
,
Priority
:
int
(
entry
.
Priority
)
,
Work
:
entrySize
,
Data
:
&
taskData
{
BlockSize
:
blockSize
,
...
...
@@ -692,7 +692,7 @@ func (e *Engine) ReceiveFrom(from peer.ID, blks []blocks.Block, haves []cid.Cid)
e
.
peerRequestQueue
.
PushTasks
(
l
.
Partner
,
peertask
.
Task
{
Topic
:
entry
.
Cid
,
Priority
:
entry
.
Priority
,
Priority
:
int
(
entry
.
Priority
)
,
Work
:
entrySize
,
Data
:
&
taskData
{
BlockSize
:
blockSize
,
...
...
internal/decision/engine_test.go
View file @
f6db5f77
...
...
@@ -1068,14 +1068,14 @@ func partnerWantBlocks(e *Engine, keys []string, partner peer.ID) {
add
:=
message
.
New
(
false
)
for
i
,
letter
:=
range
keys
{
block
:=
blocks
.
NewBlock
([]
byte
(
letter
))
add
.
AddEntry
(
block
.
Cid
(),
len
(
keys
)
-
i
,
pb
.
Message_Wantlist_Block
,
true
)
add
.
AddEntry
(
block
.
Cid
(),
int32
(
len
(
keys
)
-
i
)
,
pb
.
Message_Wantlist_Block
,
true
)
}
e
.
MessageReceived
(
context
.
Background
(),
partner
,
add
)
}
func
partnerWantBlocksHaves
(
e
*
Engine
,
keys
[]
string
,
wantHaves
[]
string
,
sendDontHave
bool
,
partner
peer
.
ID
)
{
add
:=
message
.
New
(
false
)
priority
:=
len
(
wantHaves
)
+
len
(
keys
)
priority
:=
int32
(
len
(
wantHaves
)
+
len
(
keys
)
)
for
_
,
letter
:=
range
wantHaves
{
block
:=
blocks
.
NewBlock
([]
byte
(
letter
))
add
.
AddEntry
(
block
.
Cid
(),
priority
,
pb
.
Message_Wantlist_Have
,
sendDontHave
)
...
...
internal/decision/ledger.go
View file @
f6db5f77
...
...
@@ -91,7 +91,7 @@ func (l *ledger) ReceivedBytes(n int) {
l
.
Accounting
.
BytesRecv
+=
uint64
(
n
)
}
func
(
l
*
ledger
)
Wants
(
k
cid
.
Cid
,
priority
int
,
wantType
pb
.
Message_Wantlist_WantType
)
{
func
(
l
*
ledger
)
Wants
(
k
cid
.
Cid
,
priority
int
32
,
wantType
pb
.
Message_Wantlist_WantType
)
{
log
.
Debugf
(
"peer %s wants %s"
,
l
.
Partner
,
k
)
l
.
wantList
.
Add
(
k
,
priority
,
wantType
)
}
...
...
internal/messagequeue/messagequeue.go
View file @
f6db5f77
...
...
@@ -68,7 +68,7 @@ type MessageQueue struct {
bcstWants
recallWantlist
peerWants
recallWantlist
cancels
*
cid
.
Set
priority
int
priority
int
32
// Dont touch any of these variables outside of run loop
sender
bsnet
.
MessageSender
...
...
@@ -95,7 +95,7 @@ func newRecallWantList() recallWantlist {
}
// Add want to both the pending list and the list of all wants
func
(
r
*
recallWantlist
)
Add
(
c
cid
.
Cid
,
priority
int
,
wtype
pb
.
Message_Wantlist_WantType
)
{
func
(
r
*
recallWantlist
)
Add
(
c
cid
.
Cid
,
priority
int
32
,
wtype
pb
.
Message_Wantlist_WantType
)
{
r
.
allWants
.
Add
(
c
,
priority
,
wtype
)
r
.
pending
.
Add
(
c
,
priority
,
wtype
)
}
...
...
internal/testutil/testutil.go
View file @
f6db5f77
...
...
@@ -13,7 +13,7 @@ import (
)
var
blockGenerator
=
blocksutil
.
NewBlockGenerator
()
var
prioritySeq
int
var
prioritySeq
int
32
// GenerateBlocksOfSize generates a series of blocks of the given byte size
func
GenerateBlocksOfSize
(
n
int
,
size
int64
)
[]
blocks
.
Block
{
...
...
message/message.go
View file @
f6db5f77
...
...
@@ -37,7 +37,7 @@ type BitSwapMessage interface {
PendingBytes
()
int32
// AddEntry adds an entry to the Wantlist.
AddEntry
(
key
cid
.
Cid
,
priority
int
,
wantType
pb
.
Message_Wantlist_WantType
,
sendDontHave
bool
)
int
AddEntry
(
key
cid
.
Cid
,
priority
int
32
,
wantType
pb
.
Message_Wantlist_WantType
,
sendDontHave
bool
)
int
// Cancel adds a CANCEL for the given CID to the message
// Returns the size of the CANCEL entry in the protobuf
...
...
@@ -124,7 +124,7 @@ func newMessageFromProto(pbm pb.Message) (BitSwapMessage, error) {
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"incorrectly formatted cid in wantlist: %s"
,
err
)
}
m
.
addEntry
(
c
,
int
(
e
.
Priority
)
,
e
.
Cancel
,
e
.
WantType
,
e
.
SendDontHave
)
m
.
addEntry
(
c
,
e
.
Priority
,
e
.
Cancel
,
e
.
WantType
,
e
.
SendDontHave
)
}
// deprecated
...
...
@@ -231,11 +231,11 @@ func (m *impl) Cancel(k cid.Cid) int {
return
m
.
addEntry
(
k
,
0
,
true
,
pb
.
Message_Wantlist_Block
,
false
)
}
func
(
m
*
impl
)
AddEntry
(
k
cid
.
Cid
,
priority
int
,
wantType
pb
.
Message_Wantlist_WantType
,
sendDontHave
bool
)
int
{
func
(
m
*
impl
)
AddEntry
(
k
cid
.
Cid
,
priority
int
32
,
wantType
pb
.
Message_Wantlist_WantType
,
sendDontHave
bool
)
int
{
return
m
.
addEntry
(
k
,
priority
,
false
,
wantType
,
sendDontHave
)
}
func
(
m
*
impl
)
addEntry
(
c
cid
.
Cid
,
priority
int
,
cancel
bool
,
wantType
pb
.
Message_Wantlist_WantType
,
sendDontHave
bool
)
int
{
func
(
m
*
impl
)
addEntry
(
c
cid
.
Cid
,
priority
int
32
,
cancel
bool
,
wantType
pb
.
Message_Wantlist_WantType
,
sendDontHave
bool
)
int
{
e
,
exists
:=
m
.
wantlist
[
c
]
if
exists
{
// Only change priority if want is of the same type
...
...
wantlist/wantlist.go
View file @
f6db5f77
...
...
@@ -18,12 +18,12 @@ type Wantlist struct {
// Entry is an entry in a want list, consisting of a cid and its priority
type
Entry
struct
{
Cid
cid
.
Cid
Priority
int
Priority
int
32
WantType
pb
.
Message_Wantlist_WantType
}
// NewRefEntry creates a new reference tracked wantlist entry.
func
NewRefEntry
(
c
cid
.
Cid
,
p
int
)
Entry
{
func
NewRefEntry
(
c
cid
.
Cid
,
p
int
32
)
Entry
{
return
Entry
{
Cid
:
c
,
Priority
:
p
,
...
...
@@ -50,7 +50,7 @@ func (w *Wantlist) Len() int {
}
// Add adds an entry in a wantlist from CID & Priority, if not already present.
func
(
w
*
Wantlist
)
Add
(
c
cid
.
Cid
,
priority
int
,
wantType
pb
.
Message_Wantlist_WantType
)
bool
{
func
(
w
*
Wantlist
)
Add
(
c
cid
.
Cid
,
priority
int
32
,
wantType
pb
.
Message_Wantlist_WantType
)
bool
{
e
,
ok
:=
w
.
set
[
c
]
// Adding want-have should not override want-block
...
...
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