1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 09:34:03 +08:00

feat(bitswap/network) expose peerstore

This commit is contained in:
Brian Tiger Chow
2014-12-23 07:07:58 -05:00
committed by Juan Batiz-Benet
parent a225568ff6
commit 60f3a874c2
3 changed files with 15 additions and 3 deletions

View File

@ -26,6 +26,8 @@ type BitSwapNetwork interface {
peer.ID,
bsmsg.BitSwapMessage) (incoming bsmsg.BitSwapMessage, err error)
Peerstore() peer.Peerstore
// SetDelegate registers the Reciver to handle messages received from the
// network.
SetDelegate(Receiver)

View File

@ -70,6 +70,10 @@ func (bsnet *impl) SetDelegate(r Receiver) {
bsnet.receiver = r
}
func (bsnet *impl) Peerstore() peer.Peerstore {
return bsnet.Peerstore()
}
// handleNewStream receives a new stream from the network.
func (bsnet *impl) handleNewStream(s inet.Stream) {

View File

@ -47,8 +47,9 @@ type network struct {
func (n *network) Adapter(p peer.ID) bsnet.BitSwapNetwork {
client := &networkClient{
local: p,
network: n,
local: p,
network: n,
peerstore: peer.NewPeerstore(),
}
n.clients[p] = client
return client
@ -148,7 +149,8 @@ func (n *network) SendRequest(
type networkClient struct {
local peer.ID
bsnet.Receiver
network Network
network Network
peerstore peer.Peerstore
}
func (nc *networkClient) SendMessage(
@ -176,3 +178,7 @@ func (nc *networkClient) DialPeer(ctx context.Context, p peer.ID) error {
func (nc *networkClient) SetDelegate(r bsnet.Receiver) {
nc.Receiver = r
}
func (nc *networkClient) Peerstore() peer.Peerstore {
return nc.peerstore
}