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-unixfs
Commits
b8bd2bc4
Commit
b8bd2bc4
authored
10 years ago
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(bitswap:msg) move to package
parent
282acb8f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
12 deletions
+13
-12
bitswap/bitswap.go
bitswap/bitswap.go
+5
-4
bitswap/message/message.go
bitswap/message/message.go
+2
-2
bitswap/message/message.pb.go
bitswap/message/message.pb.go
+1
-1
bitswap/message/message.proto
bitswap/message/message.proto
+1
-1
bitswap/message/message_test.go
bitswap/message/message_test.go
+4
-4
No files found.
bitswap/bitswap.go
View file @
b8bd2bc4
...
...
@@ -6,6 +6,7 @@ import (
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
bsmsg
"github.com/jbenet/go-ipfs/bitswap/message"
notifications
"github.com/jbenet/go-ipfs/bitswap/notifications"
blocks
"github.com/jbenet/go-ipfs/blocks"
swarm
"github.com/jbenet/go-ipfs/net/swarm"
...
...
@@ -119,7 +120,7 @@ func (bs *BitSwap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
blockChannel
:=
bs
.
notifications
.
Subscribe
(
ctx
,
k
)
message
:=
newMessage
()
message
:=
bsmsg
.
New
()
message
.
AppendWanted
(
k
)
bs
.
meschan
.
Outgoing
<-
message
.
ToSwarm
(
p
)
...
...
@@ -148,7 +149,7 @@ func (bs *BitSwap) HaveBlock(blk *blocks.Block) error {
}
func
(
bs
*
BitSwap
)
SendBlock
(
p
*
peer
.
Peer
,
b
*
blocks
.
Block
)
{
message
:=
newMessage
()
message
:=
bsmsg
.
New
()
message
.
AppendBlock
(
b
)
bs
.
meschan
.
Outgoing
<-
message
.
ToSwarm
(
p
)
}
...
...
@@ -157,7 +158,7 @@ func (bs *BitSwap) handleMessages() {
for
{
select
{
case
mes
:=
<-
bs
.
meschan
.
Incoming
:
bsmsg
,
err
:=
FromSwarm
(
*
mes
)
bsmsg
,
err
:=
bsmsg
.
FromSwarm
(
*
mes
)
if
err
!=
nil
{
u
.
PErr
(
"%v
\n
"
,
err
)
continue
...
...
@@ -250,7 +251,7 @@ func (bs *BitSwap) getLedger(p *peer.Peer) *Ledger {
}
func
(
bs
*
BitSwap
)
SendWantList
(
wl
KeySet
)
error
{
message
:=
newMessage
()
message
:=
bsmsg
.
New
()
for
k
,
_
:=
range
wl
{
message
.
AppendWanted
(
k
)
}
...
...
This diff is collapsed.
Click to expand it.
bitswap/message.go
→
bitswap/message
/message
.go
View file @
b8bd2bc4
package
bitswap
package
message
import
(
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
...
...
@@ -33,7 +33,7 @@ func newMessageFromProto(pb PBMessage) *message {
return
&
message
{
pb
:
pb
}
}
func
n
ew
Message
()
*
message
{
func
N
ew
()
*
message
{
return
new
(
message
)
}
...
...
This diff is collapsed.
Click to expand it.
bitswap/message.pb.go
→
bitswap/message
/message
.pb.go
View file @
b8bd2bc4
...
...
@@ -11,7 +11,7 @@ It is generated from these files:
It has these top-level messages:
PBMessage
*/
package
bitswap
package
message
import
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
import
math
"math"
...
...
This diff is collapsed.
Click to expand it.
bitswap/message.proto
→
bitswap/message
/message
.proto
View file @
b8bd2bc4
package
bitswap
;
package
message
;
message
PBMessage
{
repeated
string
wantlist
=
1
;
...
...
This diff is collapsed.
Click to expand it.
bitswap/message_test.go
→
bitswap/message
/message
_test.go
View file @
b8bd2bc4
package
bitswap
package
message
import
(
"bytes"
...
...
@@ -10,7 +10,7 @@ import (
func
TestAppendWanted
(
t
*
testing
.
T
)
{
const
str
=
"foo"
m
:=
n
ew
Message
()
m
:=
N
ew
()
m
.
AppendWanted
(
u
.
Key
(
str
))
if
!
contains
(
m
.
ToProto
()
.
GetWantlist
(),
str
)
{
...
...
@@ -37,7 +37,7 @@ func TestAppendBlock(t *testing.T) {
strs
=
append
(
strs
,
"Celeritas"
)
strs
=
append
(
strs
,
"Incendia"
)
m
:=
n
ew
Message
()
m
:=
N
ew
()
for
_
,
str
:=
range
strs
{
block
,
err
:=
blocks
.
NewBlock
([]
byte
(
str
))
if
err
!=
nil
{
...
...
@@ -57,7 +57,7 @@ func TestAppendBlock(t *testing.T) {
func
TestCopyProtoByValue
(
t
*
testing
.
T
)
{
const
str
=
"foo"
m
:=
n
ew
Message
()
m
:=
N
ew
()
protoBeforeAppend
:=
m
.
ToProto
()
m
.
AppendWanted
(
u
.
Key
(
str
))
if
contains
(
protoBeforeAppend
.
GetWantlist
(),
str
)
{
...
...
This diff is collapsed.
Click to expand it.
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