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
2c7761fa
Commit
2c7761fa
authored
Oct 27, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(bitswap) preserve ordering in bitswap message
parent
f758e76d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
message/message.go
message/message.go
+13
-12
No files found.
message/message.go
View file @
2c7761fa
...
...
@@ -27,14 +27,16 @@ type Exportable interface {
}
type
impl
struct
{
wantlist
map
[
u
.
Key
]
struct
{}
blocks
map
[
u
.
Key
]
blocks
.
Block
existsInWantlist
map
[
u
.
Key
]
struct
{}
// map to detect duplicates
wantlist
[]
u
.
Key
// slice to preserve ordering
blocks
map
[
u
.
Key
]
blocks
.
Block
// map to detect duplicates
}
func
New
()
BitSwapMessage
{
return
&
impl
{
wantlist
:
make
(
map
[
u
.
Key
]
struct
{}),
blocks
:
make
(
map
[
u
.
Key
]
blocks
.
Block
),
existsInWantlist
:
make
(
map
[
u
.
Key
]
struct
{}),
wantlist
:
make
([]
u
.
Key
,
0
),
}
}
...
...
@@ -50,16 +52,10 @@ func newMessageFromProto(pbm pb.Message) BitSwapMessage {
return
m
}
// TODO(brian): convert these into keys
func
(
m
*
impl
)
Wantlist
()
[]
u
.
Key
{
wl
:=
make
([]
u
.
Key
,
0
)
for
k
,
_
:=
range
m
.
wantlist
{
wl
=
append
(
wl
,
k
)
}
return
wl
return
m
.
wantlist
}
// TODO(brian): convert these into blocks
func
(
m
*
impl
)
Blocks
()
[]
blocks
.
Block
{
bs
:=
make
([]
blocks
.
Block
,
0
)
for
_
,
block
:=
range
m
.
blocks
{
...
...
@@ -69,7 +65,12 @@ func (m *impl) Blocks() []blocks.Block {
}
func
(
m
*
impl
)
AddWanted
(
k
u
.
Key
)
{
m
.
wantlist
[
k
]
=
struct
{}{}
_
,
exists
:=
m
.
existsInWantlist
[
k
]
if
exists
{
return
}
m
.
existsInWantlist
[
k
]
=
struct
{}{}
m
.
wantlist
=
append
(
m
.
wantlist
,
k
)
}
func
(
m
*
impl
)
AddBlock
(
b
blocks
.
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