@cryptotaxi247 / kubo / commits / 806b3c297

refac(bs:msg) msg.Wantlist() returns []u.Key

Brian Tiger Chow committed Sep 13, 2014 at 17:10 UTC 806b3c2977908e6cec868a98f285a4a37bc09840
2 files changed +11 -8
bitswap/bitswap.go
+4 -5
@@ -192,15 +192,14 @@ func (bs *BitSwap) handleMessages() {
192
193 // peerWantsBlock will check if we have the block in question,
194 // and then if we do, check the ledger for whether or not we should send it.
195 -func (bs *BitSwap) peerWantsBlock(p *peer.Peer, want string) {
196 - u.DOut("peer [%s] wants block [%s]\n", p.ID.Pretty(), u.Key(want).Pretty())
195 +func (bs *BitSwap) peerWantsBlock(p *peer.Peer, wanted u.Key) {
196 + u.DOut("peer [%s] wants block [%s]\n", p.ID.Pretty(), wanted.Pretty())
197 ledger := bs.getLedger(p)
198
199 - dsk := ds.NewKey(want)
200 - blk_i, err := bs.datastore.Get(dsk)
199 + blk_i, err := bs.datastore.Get(wanted.DatastoreKey())
200 if err != nil {
201 if err == ds.ErrNotFound {
203 - ledger.Wants(u.Key(want))
202 + ledger.Wants(wanted)
203 }
204 u.PErr("datastore get error: %v\n", err)
205 return
bitswap/message/message.go
+7 -3
@@ -14,7 +14,7 @@ import (
14 )
15
16 type BitSwapMessage interface {
17 - Wantlist() []string
17 + Wantlist() []u.Key
18 Blocks() []blocks.Block
19 AppendWanted(k u.Key)
20 AppendBlock(b *blocks.Block)
@@ -41,8 +41,12 @@ func New() *message {
41 }
42
43 // TODO(brian): convert these into keys
44 -func (m *message) Wantlist() []string {
45 - return m.pb.Wantlist
44 +func (m *message) Wantlist() []u.Key {
45 + wl := make([]u.Key, len(m.pb.Wantlist))
46 + for _, str := range m.pb.Wantlist {
47 + wl = append(wl, u.Key(str))
48 + }
49 + return wl
50 }
51
52 // TODO(brian): convert these into blocks