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