Commit 3bac90de authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

AddrManager: use addr manager with smarter TTLs

This addr manager should seriously help with the addrsplosion
problem.
parent 50b768c8
......@@ -38,18 +38,24 @@ type impl struct {
receiver Receiver
}
func (bsnet *impl) SendMessage(
ctx context.Context,
p peer.ID,
outgoing bsmsg.BitSwapMessage) error {
func (bsnet *impl) newStreamToPeer(ctx context.Context, p peer.ID) (inet.Stream, error) {
// ensure we're connected
// first, make sure we're connected.
// if this fails, we cannot connect to given peer.
//TODO(jbenet) move this into host.NewStream?
if err := bsnet.host.Connect(ctx, peer.PeerInfo{ID: p}); err != nil {
return err
return nil, err
}
s, err := bsnet.host.NewStream(ProtocolBitswap, p)
return bsnet.host.NewStream(ProtocolBitswap, p)
}
func (bsnet *impl) SendMessage(
ctx context.Context,
p peer.ID,
outgoing bsmsg.BitSwapMessage) error {
s, err := bsnet.newStreamToPeer(ctx, p)
if err != nil {
return err
}
......@@ -68,13 +74,7 @@ func (bsnet *impl) SendRequest(
p peer.ID,
outgoing bsmsg.BitSwapMessage) (bsmsg.BitSwapMessage, error) {
// ensure we're connected
//TODO(jbenet) move this into host.NewStream?
if err := bsnet.host.Connect(ctx, peer.PeerInfo{ID: p}); err != nil {
return nil, err
}
s, err := bsnet.host.NewStream(ProtocolBitswap, p)
s, err := bsnet.newStreamToPeer(ctx, p)
if err != nil {
return nil, err
}
......@@ -123,7 +123,7 @@ func (bsnet *impl) FindProvidersAsync(ctx context.Context, k util.Key, max int)
if info.ID == bsnet.host.ID() {
continue // ignore self as provider
}
bsnet.host.Peerstore().AddAddresses(info.ID, info.Addrs)
bsnet.host.Peerstore().AddAddrs(info.ID, info.Addrs, peer.TempAddrTTL)
select {
case <-ctx.Done():
return
......
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