feat(bitswap/network) expose peerstore
Brian Tiger Chow committed
Dec 23, 2014 at 07:07 UTC
60f3a874c2dc88efbf7b1be51fffe4012fb8332f
3 files changed
+15
-3
exchange/bitswap/network/interface.go
+2
@@ -26,6 +26,8 @@ type BitSwapNetwork interface {
26
peer.ID,
27
bsmsg.BitSwapMessage) (incoming bsmsg.BitSwapMessage, err error)
28
29
+ Peerstore() peer.Peerstore
30
+
31
// SetDelegate registers the Reciver to handle messages received from the
32
// network.
33
SetDelegate(Receiver)
exchange/bitswap/network/ipfs_impl.go
+4
@@ -70,6 +70,10 @@ func (bsnet *impl) SetDelegate(r Receiver) {
70
bsnet.receiver = r
71
}
72
73
+func (bsnet *impl) Peerstore() peer.Peerstore {
74
+ return bsnet.Peerstore()
75
+}
76
+
77
// handleNewStream receives a new stream from the network.
78
func (bsnet *impl) handleNewStream(s inet.Stream) {
79
exchange/bitswap/testnet/network.go
+9
-3
@@ -47,8 +47,9 @@ type network struct {
47
48
func (n *network) Adapter(p peer.ID) bsnet.BitSwapNetwork {
49
client := &networkClient{
50
- local: p,
51
- network: n,
50
+ local: p,
51
+ network: n,
52
+ peerstore: peer.NewPeerstore(),
53
}
54
n.clients[p] = client
55
return client
@@ -148,7 +149,8 @@ func (n *network) SendRequest(
149
type networkClient struct {
150
local peer.ID
151
bsnet.Receiver
151
- network Network
152
+ network Network
153
+ peerstore peer.Peerstore
154
}
155
156
func (nc *networkClient) SendMessage(
@@ -176,3 +178,7 @@ func (nc *networkClient) DialPeer(ctx context.Context, p peer.ID) error {
178
func (nc *networkClient) SetDelegate(r bsnet.Receiver) {
179
nc.Receiver = r
180
}
181
+
182
+func (nc *networkClient) Peerstore() peer.Peerstore {
183
+ return nc.peerstore
184
+}