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
9cebc05a
Commit
9cebc05a
authored
Oct 27, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(bitswap/message) impl with map to ensure no duplicate blocks
comes at the cost of O(n) Blocks() method.
parent
824a185f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
message/message.go
message/message.go
+8
-4
No files found.
message/message.go
View file @
9cebc05a
...
...
@@ -26,15 +26,15 @@ type Exportable interface {
ToNet
(
p
peer
.
Peer
)
(
nm
.
NetMessage
,
error
)
}
// message wraps a proto message for convenience
type
impl
struct
{
wantlist
map
[
u
.
Key
]
struct
{}
blocks
[
]
blocks
.
Block
blocks
map
[
u
.
Key
]
blocks
.
Block
}
func
New
()
BitSwapMessage
{
return
&
impl
{
wantlist
:
make
(
map
[
u
.
Key
]
struct
{}),
blocks
:
make
(
map
[
u
.
Key
]
blocks
.
Block
),
}
}
...
...
@@ -61,7 +61,11 @@ func (m *impl) Wantlist() []u.Key {
// TODO(brian): convert these into blocks
func
(
m
*
impl
)
Blocks
()
[]
blocks
.
Block
{
return
m
.
blocks
bs
:=
make
([]
blocks
.
Block
,
0
)
for
_
,
block
:=
range
m
.
blocks
{
bs
=
append
(
bs
,
block
)
}
return
bs
}
func
(
m
*
impl
)
AddWanted
(
k
u
.
Key
)
{
...
...
@@ -69,7 +73,7 @@ func (m *impl) AddWanted(k u.Key) {
}
func
(
m
*
impl
)
AppendBlock
(
b
blocks
.
Block
)
{
m
.
blocks
=
append
(
m
.
blocks
,
b
)
m
.
blocks
[
b
.
Key
()]
=
b
}
func
FromNet
(
nmsg
netmsg
.
NetMessage
)
(
BitSwapMessage
,
error
)
{
...
...
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