mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-02 20:32:58 +08:00
bitswap: network interface changed
Had to change the network interface from DialPeer(peer.ID) to DialPeer(peer.PeerInfo), so that addresses of a provider are handed to the network. @maybebtc and I are discussing whether this should go all the way down to the network, or whether the network _should always work_ with just an ID (which means the network needs to be able to resolve ID -> Addresses, using the routing system. This latter point might mean that "routing" might need to break down into subcomponents. It's a bit sketchy that the Network would become smarter than just dial/listen and I/O, but maybe there's a distinction between net.Network, and something like a peernet.Network that has routing built in...)
This commit is contained in:
@ -176,14 +176,16 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.PeerInf
|
|||||||
message.AddEntry(wanted.Key, wanted.Priority)
|
message.AddEntry(wanted.Key, wanted.Priority)
|
||||||
}
|
}
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
for peerToQuery := range peers {
|
for pi := range peers {
|
||||||
log.Event(ctx, "PeerToQuery", peerToQuery.ID)
|
log.Debugf("bitswap.sendWantListTo: %s %s", pi.ID, pi.Addrs)
|
||||||
|
log.Event(ctx, "PeerToQuery", pi.ID)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(p peer.ID) {
|
go func(pi peer.PeerInfo) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
p := pi.ID
|
||||||
|
|
||||||
log.Event(ctx, "DialPeer", p)
|
log.Event(ctx, "DialPeer", p)
|
||||||
err := bs.sender.DialPeer(ctx, p)
|
err := bs.sender.DialPeer(ctx, pi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error sender.DialPeer(%s): %s", p, err)
|
log.Errorf("Error sender.DialPeer(%s): %s", p, err)
|
||||||
return
|
return
|
||||||
@ -198,7 +200,7 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.PeerInf
|
|||||||
// communication fails. May require slightly different API to
|
// communication fails. May require slightly different API to
|
||||||
// get better guarantees. May need shared sequence numbers.
|
// get better guarantees. May need shared sequence numbers.
|
||||||
bs.engine.MessageSent(p, message)
|
bs.engine.MessageSent(p, message)
|
||||||
}(peerToQuery.ID)
|
}(pi)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return nil
|
return nil
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
type BitSwapNetwork interface {
|
type BitSwapNetwork interface {
|
||||||
|
|
||||||
// DialPeer ensures there is a connection to peer.
|
// DialPeer ensures there is a connection to peer.
|
||||||
DialPeer(context.Context, peer.ID) error
|
DialPeer(context.Context, peer.PeerInfo) error
|
||||||
|
|
||||||
// SendMessage sends a BitSwap message to a peer.
|
// SendMessage sends a BitSwap message to a peer.
|
||||||
SendMessage(
|
SendMessage(
|
||||||
|
@ -53,8 +53,9 @@ func (bsnet *impl) handleNewStream(s inet.Stream) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bsnet *impl) DialPeer(ctx context.Context, p peer.ID) error {
|
func (bsnet *impl) DialPeer(ctx context.Context, p peer.PeerInfo) error {
|
||||||
return bsnet.network.DialPeer(ctx, p)
|
bsnet.network.Peerstore().AddAddresses(p.ID, p.Addrs)
|
||||||
|
return bsnet.network.DialPeer(ctx, p.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bsnet *impl) SendMessage(
|
func (bsnet *impl) SendMessage(
|
||||||
|
@ -165,10 +165,10 @@ func (nc *networkClient) SendRequest(
|
|||||||
return nc.network.SendRequest(ctx, nc.local, to, message)
|
return nc.network.SendRequest(ctx, nc.local, to, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nc *networkClient) DialPeer(ctx context.Context, p peer.ID) error {
|
func (nc *networkClient) DialPeer(ctx context.Context, p peer.PeerInfo) error {
|
||||||
// no need to do anything because dialing isn't a thing in this test net.
|
// no need to do anything because dialing isn't a thing in this test net.
|
||||||
if !nc.network.HasPeer(p) {
|
if !nc.network.HasPeer(p.ID) {
|
||||||
return fmt.Errorf("Peer not in network: %s", p)
|
return fmt.Errorf("Peer not in network: %s", p.ID)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user