Commit c2186853 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

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...)
parent 17b4a863
......@@ -176,14 +176,16 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.PeerInf
message.AddEntry(wanted.Key, wanted.Priority)
}
wg := sync.WaitGroup{}
for peerToQuery := range peers {
log.Event(ctx, "PeerToQuery", peerToQuery.ID)
for pi := range peers {
log.Debugf("bitswap.sendWantListTo: %s %s", pi.ID, pi.Addrs)
log.Event(ctx, "PeerToQuery", pi.ID)
wg.Add(1)
go func(p peer.ID) {
go func(pi peer.PeerInfo) {
defer wg.Done()
p := pi.ID
log.Event(ctx, "DialPeer", p)
err := bs.sender.DialPeer(ctx, p)
err := bs.sender.DialPeer(ctx, pi)
if err != nil {
log.Errorf("Error sender.DialPeer(%s): %s", p, err)
return
......@@ -198,7 +200,7 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.PeerInf
// communication fails. May require slightly different API to
// get better guarantees. May need shared sequence numbers.
bs.engine.MessageSent(p, message)
}(peerToQuery.ID)
}(pi)
}
wg.Wait()
return nil
......
......@@ -12,7 +12,7 @@ import (
type BitSwapNetwork interface {
// 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(
......
......@@ -53,8 +53,9 @@ func (bsnet *impl) handleNewStream(s inet.Stream) {
}
func (bsnet *impl) DialPeer(ctx context.Context, p peer.ID) error {
return bsnet.network.DialPeer(ctx, p)
func (bsnet *impl) DialPeer(ctx context.Context, p peer.PeerInfo) error {
bsnet.network.Peerstore().AddAddresses(p.ID, p.Addrs)
return bsnet.network.DialPeer(ctx, p.ID)
}
func (bsnet *impl) SendMessage(
......
......@@ -165,10 +165,10 @@ func (nc *networkClient) SendRequest(
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.
if !nc.network.HasPeer(p) {
return fmt.Errorf("Peer not in network: %s", p)
if !nc.network.HasPeer(p.ID) {
return fmt.Errorf("Peer not in network: %s", p.ID)
}
return nil
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment