提交 282acb8f 作者: Brian Tiger Chow

refactor(bitswap:msg) add, use getters

上级 21639564
......@@ -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))
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论