mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 09:59:13 +08:00
refactor(bitswap:msg) add, use getters
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user