@cryptotaxi247 / kubo / commits / d970f538e

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...)

Juan Batiz-Benet committed Dec 23, 2014 at 04:13 UTC d970f538e590f8b8ca3fe515efb0e7b0c0aa52aa
4 files changed +14 -11
exchange/bitswap/bitswap.go
+7 -5
@@ -176,14 +176,16 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.PeerInf
176 message.AddEntry(wanted.Key, wanted.Priority)
177 }
178 wg := sync.WaitGroup{}
179 - for peerToQuery := range peers {
180 - log.Event(ctx, "PeerToQuery", peerToQuery.ID)
179 + for pi := range peers {
180 + log.Debugf("bitswap.sendWantListTo: %s %s", pi.ID, pi.Addrs)
181 + log.Event(ctx, "PeerToQuery", pi.ID)
182 wg.Add(1)
182 - go func(p peer.ID) {
183 + go func(pi peer.PeerInfo) {
184 defer wg.Done()
185 + p := pi.ID
186
187 log.Event(ctx, "DialPeer", p)
186 - err := bs.sender.DialPeer(ctx, p)
188 + err := bs.sender.DialPeer(ctx, pi)
189 if err != nil {
190 log.Errorf("Error sender.DialPeer(%s): %s", p, err)
191 return
@@ -198,7 +200,7 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.PeerInf
200 // communication fails. May require slightly different API to
201 // get better guarantees. May need shared sequence numbers.
202 bs.engine.MessageSent(p, message)
201 - }(peerToQuery.ID)
203 + }(pi)
204 }
205 wg.Wait()
206 return nil
exchange/bitswap/network/interface.go
+1 -1
@@ -12,7 +12,7 @@ import (
12 type BitSwapNetwork interface {
13
14 // DialPeer ensures there is a connection to peer.
15 - DialPeer(context.Context, peer.ID) error
15 + DialPeer(context.Context, peer.PeerInfo) error
16
17 // SendMessage sends a BitSwap message to a peer.
18 SendMessage(
exchange/bitswap/network/ipfs_impl.go
+3 -2
@@ -53,8 +53,9 @@ func (bsnet *impl) handleNewStream(s inet.Stream) {
53
54 }
55
56 -func (bsnet *impl) DialPeer(ctx context.Context, p peer.ID) error {
57 - return bsnet.network.DialPeer(ctx, p)
56 +func (bsnet *impl) DialPeer(ctx context.Context, p peer.PeerInfo) error {
57 + bsnet.network.Peerstore().AddAddresses(p.ID, p.Addrs)
58 + return bsnet.network.DialPeer(ctx, p.ID)
59 }
60
61 func (bsnet *impl) SendMessage(
exchange/bitswap/testnet/network.go
+3 -3
@@ -165,10 +165,10 @@ func (nc *networkClient) SendRequest(
165 return nc.network.SendRequest(ctx, nc.local, to, message)
166 }
167
168 -func (nc *networkClient) DialPeer(ctx context.Context, p peer.ID) error {
168 +func (nc *networkClient) DialPeer(ctx context.Context, p peer.PeerInfo) error {
169 // no need to do anything because dialing isn't a thing in this test net.
170 - if !nc.network.HasPeer(p) {
171 - return fmt.Errorf("Peer not in network: %s", p)
170 + if !nc.network.HasPeer(p.ID) {
171 + return fmt.Errorf("Peer not in network: %s", p.ID)
172 }
173 return nil
174 }