From 806b3c2977908e6cec868a98f285a4a37bc09840 Mon Sep 17 00:00:00 2001
From: Brian Tiger Chow <brian.holderchow@gmail.com>
Date: Sat, 13 Sep 2014 17:10:12 -0700
Subject: [PATCH] refac(bs:msg) msg.Wantlist() returns []u.Key

---
 bitswap/bitswap.go         |  9 ++++-----
 bitswap/message/message.go | 10 +++++++---
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/bitswap/bitswap.go b/bitswap/bitswap.go
index 46fc727a..698cd99c 100644
--- a/bitswap/bitswap.go
+++ b/bitswap/bitswap.go
@@ -192,15 +192,14 @@ func (bs *BitSwap) handleMessages() {
 
 // peerWantsBlock will check if we have the block in question,
 // and then if we do, check the ledger for whether or not we should send it.
-func (bs *BitSwap) peerWantsBlock(p *peer.Peer, want string) {
-	u.DOut("peer [%s] wants block [%s]\n", p.ID.Pretty(), u.Key(want).Pretty())
+func (bs *BitSwap) peerWantsBlock(p *peer.Peer, wanted u.Key) {
+	u.DOut("peer [%s] wants block [%s]\n", p.ID.Pretty(), wanted.Pretty())
 	ledger := bs.getLedger(p)
 
-	dsk := ds.NewKey(want)
-	blk_i, err := bs.datastore.Get(dsk)
+	blk_i, err := bs.datastore.Get(wanted.DatastoreKey())
 	if err != nil {
 		if err == ds.ErrNotFound {
-			ledger.Wants(u.Key(want))
+			ledger.Wants(wanted)
 		}
 		u.PErr("datastore get error: %v\n", err)
 		return
diff --git a/bitswap/message/message.go b/bitswap/message/message.go
index ff07986f..f2e12edf 100644
--- a/bitswap/message/message.go
+++ b/bitswap/message/message.go
@@ -14,7 +14,7 @@ import (
 )
 
 type BitSwapMessage interface {
-	Wantlist() []string
+	Wantlist() []u.Key
 	Blocks() []blocks.Block
 	AppendWanted(k u.Key)
 	AppendBlock(b *blocks.Block)
@@ -41,8 +41,12 @@ func New() *message {
 }
 
 // TODO(brian): convert these into keys
-func (m *message) Wantlist() []string {
-	return m.pb.Wantlist
+func (m *message) Wantlist() []u.Key {
+	wl := make([]u.Key, len(m.pb.Wantlist))
+	for _, str := range m.pb.Wantlist {
+		wl = append(wl, u.Key(str))
+	}
+	return wl
 }
 
 // TODO(brian): convert these into blocks
-- 
GitLab