mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 01:12:24 +08:00
refactor(bitswap:msg) move to package
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
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 newMessage() *message {
|
||||
func New() *message {
|
||||
return new(message)
|
||||
}
|
||||
|
@ -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"
|
@ -1,4 +1,4 @@
|
||||
package bitswap;
|
||||
package message;
|
||||
|
||||
message PBMessage {
|
||||
repeated string wantlist = 1;
|
@ -1,4 +1,4 @@
|
||||
package bitswap
|
||||
package message
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func TestAppendWanted(t *testing.T) {
|
||||
const str = "foo"
|
||||
m := newMessage()
|
||||
m := New()
|
||||
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 := newMessage()
|
||||
m := New()
|
||||
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 := newMessage()
|
||||
m := New()
|
||||
protoBeforeAppend := m.ToProto()
|
||||
m.AppendWanted(u.Key(str))
|
||||
if contains(protoBeforeAppend.GetWantlist(), str) {
|
Reference in New Issue
Block a user