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-dms3
Commits
282acb8f
Commit
282acb8f
authored
Sep 12, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(bitswap:msg) add, use getters
parent
21639564
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
bitswap/bitswap.go
bitswap/bitswap.go
+6
-7
bitswap/message.go
bitswap/message.go
+12
-0
No files found.
bitswap/bitswap.go
View file @
282acb8f
...
...
@@ -4,7 +4,6 @@ import (
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
notifications
"github.com/jbenet/go-ipfs/bitswap/notifications"
...
...
@@ -158,14 +157,14 @@ func (bs *BitSwap) handleMessages() {
for
{
select
{
case
mes
:=
<-
bs
.
meschan
.
Incoming
:
pmes
:=
new
(
PBMessage
)
err
:=
proto
.
Unmarshal
(
mes
.
Data
,
pmes
)
bsmsg
,
err
:=
FromSwarm
(
*
mes
)
if
err
!=
nil
{
u
.
PErr
(
"%v
\n
"
,
err
)
continue
}
if
pmes
.
Blocks
!=
nil
{
for
_
,
blkData
:=
range
pmes
.
Blocks
{
if
bsmsg
.
Blocks
()
!=
nil
{
for
_
,
blkData
:=
range
bsmsg
.
Blocks
()
{
blk
,
err
:=
blocks
.
NewBlock
(
blkData
)
if
err
!=
nil
{
u
.
PErr
(
"%v
\n
"
,
err
)
...
...
@@ -175,8 +174,8 @@ func (bs *BitSwap) handleMessages() {
}
}
if
pmes
.
Wantlist
!=
nil
{
for
_
,
want
:=
range
pmes
.
Wantlist
{
if
bsmsg
.
Wantlist
()
!=
nil
{
for
_
,
want
:=
range
bsmsg
.
Wantlist
()
{
go
bs
.
peerWantsBlock
(
mes
.
Peer
,
want
)
}
}
...
...
bitswap/message.go
View file @
282acb8f
...
...
@@ -11,6 +11,8 @@ import (
)
type
BitSwapMessage
interface
{
Wantlist
()
[]
string
Blocks
()
[][]
byte
AppendWanted
(
k
u
.
Key
)
AppendBlock
(
b
*
blocks
.
Block
)
Exportable
...
...
@@ -35,6 +37,16 @@ func newMessage() *message {
return
new
(
message
)
}
// TODO(brian): convert these into keys
func
(
m
*
message
)
Wantlist
()
[]
string
{
return
m
.
pb
.
Wantlist
}
// TODO(brian): convert these into blocks
func
(
m
*
message
)
Blocks
()
[][]
byte
{
return
m
.
pb
.
Blocks
}
func
(
m
*
message
)
AppendWanted
(
k
u
.
Key
)
{
m
.
pb
.
Wantlist
=
append
(
m
.
pb
.
Wantlist
,
string
(
k
))
}
...
...
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