AddrManager: use addr manager with smarter TTLs
This addr manager should seriously help with the addrsplosion problem.
Juan Batiz-Benet committed
Feb 2, 2015 at 11:30 UTC
e908effb4ba608ea740e3fcd6a465721f44ce472
28 files changed
+184
-386
core/bootstrap.go
+1
-1
@@ -190,7 +190,7 @@ func bootstrapConnect(ctx context.Context,
190
defer log.EventBegin(ctx, "bootstrapDial", route.LocalPeer(), p.ID).Done()
191
log.Debugf("%s bootstrapping to %s", route.LocalPeer(), p.ID)
192
193
- ps.AddAddresses(p.ID, p.Addrs)
193
+ ps.AddAddrs(p.ID, p.Addrs, peer.PermanentAddrTTL)
194
err := route.Connect(ctx, p.ID)
195
if err != nil {
196
log.Event(ctx, "bootstrapDialFailed", p.ID)
core/commands/id.go
+1
-1
@@ -151,7 +151,7 @@ func printPeer(ps peer.Peerstore, p peer.ID) (interface{}, error) {
151
info.PublicKey = base64.StdEncoding.EncodeToString(pkb)
152
}
153
154
- for _, a := range ps.Addresses(p) {
154
+ for _, a := range ps.Addrs(p) {
155
info.Addresses = append(info.Addresses, a.String())
156
}
157
core/commands/ping.go
+3
-3
@@ -95,7 +95,7 @@ trip latency information.
95
}
96
97
if addr != nil {
98
- n.Peerstore.AddAddress(peerID, addr)
98
+ n.Peerstore.AddAddr(peerID, addr, peer.TempAddrTTL) // temporary
99
}
100
101
// Set up number of pings
@@ -120,7 +120,7 @@ func pingPeer(ctx context.Context, n *core.IpfsNode, pid peer.ID, numPings int)
120
go func() {
121
defer close(outChan)
122
123
- if len(n.Peerstore.Addresses(pid)) == 0 {
123
+ if len(n.Peerstore.Addrs(pid)) == 0 {
124
// Make sure we can find the node in question
125
outChan <- &PingResult{
126
Text: fmt.Sprintf("Looking up peer %s", pid.Pretty()),
@@ -132,7 +132,7 @@ func pingPeer(ctx context.Context, n *core.IpfsNode, pid peer.ID, numPings int)
132
outChan <- &PingResult{Text: fmt.Sprintf("Peer lookup error: %s", err)}
133
return
134
}
135
- n.Peerstore.AddPeerInfo(p)
135
+ n.Peerstore.AddAddrs(p.ID, p.Addrs, peer.TempAddrTTL)
136
}
137
138
outChan <- &PingResult{Text: fmt.Sprintf("PING %s.", pid.Pretty())}
core/commands/swarm.go
+1
-1
@@ -236,7 +236,7 @@ func peersWithAddresses(ps peer.Peerstore, addrs []string) (pids []peer.ID, err
236
237
for _, iaddr := range iaddrs {
238
pids = append(pids, iaddr.ID())
239
- ps.AddAddress(iaddr.ID(), iaddr.Multiaddr())
239
+ ps.AddAddr(iaddr.ID(), iaddr.Multiaddr(), peer.TempAddrTTL)
240
}
241
return pids, nil
242
}
core/core.go
+1
-5
@@ -476,16 +476,12 @@ func startListening(ctx context.Context, host p2phost.Host, cfg *config.Config)
476
return err
477
}
478
479
- // explicitly set these as our listen addrs.
480
- // (why not do it inside inet.NewNetwork? because this way we can
481
- // listen on addresses without necessarily advertising those publicly.)
479
+ // list out our addresses
480
addrs, err := host.Network().InterfaceListenAddresses()
481
if err != nil {
482
return debugerror.Wrap(err)
483
}
484
log.Infof("Swarm listening at: %s", addrs)
487
-
488
- host.Peerstore().AddAddresses(host.ID(), addrs)
485
return nil
486
}
487
exchange/bitswap/network/ipfs_impl.go
+15
-15
@@ -38,18 +38,24 @@ type impl struct {
38
receiver Receiver
39
}
40
41
-func (bsnet *impl) SendMessage(
42
- ctx context.Context,
43
- p peer.ID,
44
- outgoing bsmsg.BitSwapMessage) error {
41
+func (bsnet *impl) newStreamToPeer(ctx context.Context, p peer.ID) (inet.Stream, error) {
42
46
- // ensure we're connected
43
+ // first, make sure we're connected.
44
+ // if this fails, we cannot connect to given peer.
45
//TODO(jbenet) move this into host.NewStream?
46
if err := bsnet.host.Connect(ctx, peer.PeerInfo{ID: p}); err != nil {
49
- return err
47
+ return nil, err
48
}
49
52
- s, err := bsnet.host.NewStream(ProtocolBitswap, p)
50
+ return bsnet.host.NewStream(ProtocolBitswap, p)
51
+}
52
+
53
+func (bsnet *impl) SendMessage(
54
+ ctx context.Context,
55
+ p peer.ID,
56
+ outgoing bsmsg.BitSwapMessage) error {
57
+
58
+ s, err := bsnet.newStreamToPeer(ctx, p)
59
if err != nil {
60
return err
61
}
@@ -68,13 +74,7 @@ func (bsnet *impl) SendRequest(
74
p peer.ID,
75
outgoing bsmsg.BitSwapMessage) (bsmsg.BitSwapMessage, error) {
76
71
- // ensure we're connected
72
- //TODO(jbenet) move this into host.NewStream?
73
- if err := bsnet.host.Connect(ctx, peer.PeerInfo{ID: p}); err != nil {
74
- return nil, err
75
- }
76
-
77
- s, err := bsnet.host.NewStream(ProtocolBitswap, p)
77
+ s, err := bsnet.newStreamToPeer(ctx, p)
78
if err != nil {
79
return nil, err
80
}
@@ -123,7 +123,7 @@ func (bsnet *impl) FindProvidersAsync(ctx context.Context, k util.Key, max int)
123
if info.ID == bsnet.host.ID() {
124
continue // ignore self as provider
125
}
126
- bsnet.host.Peerstore().AddAddresses(info.ID, info.Addrs)
126
+ bsnet.host.Peerstore().AddAddrs(info.ID, info.Addrs, peer.TempAddrTTL)
127
select {
128
case <-ctx.Done():
129
return
p2p/host/basic/basic_host.go
+5
-1
@@ -144,7 +144,7 @@ func (h *BasicHost) NewStream(pid protocol.ID, p peer.ID) (inet.Stream, error) {
144
func (h *BasicHost) Connect(ctx context.Context, pi peer.PeerInfo) error {
145
146
// absorb addresses into peerstore
147
- h.Peerstore().AddPeerInfo(pi)
147
+ h.Peerstore().AddAddrs(pi.ID, pi.Addrs, peer.TempAddrTTL)
148
149
cs := h.Network().ConnsToPeer(pi.ID)
150
if len(cs) > 0 {
@@ -189,6 +189,10 @@ func (h *BasicHost) Addrs() []ma.Multiaddr {
189
log.Debug("error retrieving network interface addrs")
190
}
191
192
+ if h.ids != nil { // add external observed addresses
193
+ addrs = append(addrs, h.ids.OwnObservedAddrs()...)
194
+ }
195
+
196
if h.natmgr != nil { // natmgr is nil if we do not use nat option.
197
nat := h.natmgr.NAT()
198
if nat != nil { // nat is nil if not ready, or no nat is available.
p2p/net/mock/mock_link.go
+2
-2
@@ -33,8 +33,8 @@ func (l *link) newConnPair(dialer *peernet) (*conn, *conn) {
33
c.local = ln.peer
34
c.remote = rn.peer
35
36
- c.localAddr = ln.ps.Addresses(ln.peer)[0]
37
- c.remoteAddr = rn.ps.Addresses(rn.peer)[0]
36
+ c.localAddr = ln.ps.Addrs(ln.peer)[0]
37
+ c.remoteAddr = rn.ps.Addrs(rn.peer)[0]
38
39
c.localPrivKey = ln.ps.PrivKey(ln.peer)
40
c.remotePubKey = rn.ps.PubKey(rn.peer)
p2p/net/mock/mock_peernet.go
+3
-3
@@ -49,7 +49,7 @@ func newPeernet(ctx context.Context, m *mocknet, k ic.PrivKey,
49
50
// create our own entirely, so that peers knowledge doesn't get shared
51
ps := peer.NewPeerstore()
52
- ps.AddAddress(p, a)
52
+ ps.AddAddr(p, a, peer.PermanentAddrTTL)
53
ps.AddPrivKey(p, k)
54
ps.AddPubKey(p, k.GetPublic())
55
@@ -307,13 +307,13 @@ func (pn *peernet) BandwidthTotals() (in uint64, out uint64) {
307
308
// Listen tells the network to start listening on given multiaddrs.
309
func (pn *peernet) Listen(addrs ...ma.Multiaddr) error {
310
- pn.Peerstore().AddAddresses(pn.LocalPeer(), addrs)
310
+ pn.Peerstore().AddAddrs(pn.LocalPeer(), addrs, peer.PermanentAddrTTL)
311
return nil
312
}
313
314
// ListenAddresses returns a list of addresses at which this network listens.
315
func (pn *peernet) ListenAddresses() []ma.Multiaddr {
316
- return pn.Peerstore().Addresses(pn.LocalPeer())
316
+ return pn.Peerstore().Addrs(pn.LocalPeer())
317
}
318
319
// InterfaceListenAddresses returns a list of addresses at which this network
p2p/net/swarm/dial_test.go
+6
-6
@@ -48,7 +48,7 @@ func TestSimultDials(t *testing.T) {
48
connect := func(s *Swarm, dst peer.ID, addr ma.Multiaddr) {
49
// copy for other peer
50
log.Debugf("TestSimultOpen: connecting: %s --> %s (%s)", s.local, dst, addr)
51
- s.peers.AddAddress(dst, addr)
51
+ s.peers.AddAddr(dst, addr, peer.TempAddrTTL)
52
if _, err := s.Dial(ctx, dst); err != nil {
53
t.Fatal("error swarm dialing to peer", err)
54
}
@@ -125,7 +125,7 @@ func TestDialWait(t *testing.T) {
125
s2p, s2addr, s2l := newSilentPeer(t)
126
go acceptAndHang(s2l)
127
defer s2l.Close()
128
- s1.peers.AddAddress(s2p, s2addr)
128
+ s1.peers.AddAddr(s2p, s2addr, peer.PermanentAddrTTL)
129
130
before := time.Now()
131
if c, err := s1.Dial(ctx, s2p); err == nil {
@@ -171,13 +171,13 @@ func TestDialBackoff(t *testing.T) {
171
if err != nil {
172
t.Fatal(err)
173
}
174
- s1.peers.AddAddresses(s2.local, s2addrs)
174
+ s1.peers.AddAddrs(s2.local, s2addrs, peer.PermanentAddrTTL)
175
176
// dial to a non-existent peer.
177
s3p, s3addr, s3l := newSilentPeer(t)
178
go acceptAndHang(s3l)
179
defer s3l.Close()
180
- s1.peers.AddAddress(s3p, s3addr)
180
+ s1.peers.AddAddr(s3p, s3addr, peer.PermanentAddrTTL)
181
182
// in this test we will:
183
// 1) dial 10x to each node.
@@ -389,7 +389,7 @@ func TestDialBackoffClears(t *testing.T) {
389
defer s2l.Close()
390
391
// phase 1 -- dial to non-operational addresses
392
- s1.peers.AddAddress(s2.local, s2bad)
392
+ s1.peers.AddAddr(s2.local, s2bad, peer.PermanentAddrTTL)
393
394
before := time.Now()
395
if c, err := s1.Dial(ctx, s2.local); err == nil {
@@ -419,7 +419,7 @@ func TestDialBackoffClears(t *testing.T) {
419
if err != nil {
420
t.Fatal(err)
421
}
422
- s1.peers.AddAddresses(s2.local, ifaceAddrs1)
422
+ s1.peers.AddAddrs(s2.local, ifaceAddrs1, peer.PermanentAddrTTL)
423
424
before = time.Now()
425
if c, err := s1.Dial(ctx, s2.local); err != nil {
p2p/net/swarm/peers_test.go
+1
-1
@@ -19,7 +19,7 @@ func TestPeers(t *testing.T) {
19
20
connect := func(s *Swarm, dst peer.ID, addr ma.Multiaddr) {
21
// TODO: make a DialAddr func.
22
- s.peers.AddAddress(dst, addr)
22
+ s.peers.AddAddr(dst, addr, peer.PermanentAddrTTL)
23
// t.Logf("connections from %s", s.LocalPeer())
24
// for _, c := range s.ConnectionsToPeer(dst) {
25
// t.Logf("connection from %s to %s: %v", s.LocalPeer(), dst, c)
p2p/net/swarm/simul_test.go
+1
-1
@@ -25,7 +25,7 @@ func TestSimultOpen(t *testing.T) {
25
connect := func(s *Swarm, dst peer.ID, addr ma.Multiaddr) {
26
// copy for other peer
27
log.Debugf("TestSimultOpen: connecting: %s --> %s (%s)", s.local, dst, addr)
28
- s.peers.AddAddress(dst, addr)
28
+ s.peers.AddAddr(dst, addr, peer.PermanentAddrTTL)
29
if _, err := s.Dial(ctx, dst); err != nil {
30
t.Fatal("error swarm dialing to peer", err)
31
}
p2p/net/swarm/swarm_addr_test.go
+1
-1
@@ -110,7 +110,7 @@ func TestDialBadAddrs(t *testing.T) {
110
111
test := func(a ma.Multiaddr) {
112
p := testutil.RandPeerIDFatal(t)
113
- s.peers.AddAddress(p, a)
113
+ s.peers.AddAddr(p, a, peer.PermanentAddrTTL)
114
if _, err := s.Dial(ctx, p); err == nil {
115
t.Error("swarm should not dial: %s", m)
116
}
p2p/net/swarm/swarm_dial.go
+2
-2
@@ -289,14 +289,14 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
289
}
290
291
// get remote peer addrs
292
- remoteAddrs := s.peers.Addresses(p)
292
+ remoteAddrs := s.peers.Addrs(p)
293
// make sure we can use the addresses.
294
remoteAddrs = addrutil.FilterUsableAddrs(remoteAddrs)
295
// drop out any addrs that would just dial ourselves. use ListenAddresses
296
// as that is a more authoritative view than localAddrs.
297
ila, _ := s.InterfaceListenAddresses()
298
remoteAddrs = addrutil.Subtract(remoteAddrs, ila)
299
- remoteAddrs = addrutil.Subtract(remoteAddrs, s.peers.Addresses(s.local))
299
+ remoteAddrs = addrutil.Subtract(remoteAddrs, s.peers.Addrs(s.local))
300
log.Debugf("%s swarm dialing %s -- remote:%s local:%s", s.local, p, remoteAddrs, s.ListenAddresses())
301
if len(remoteAddrs) == 0 {
302
err := errors.New("peer has no addresses")
p2p/net/swarm/swarm_listen.go
+1
-1
@@ -53,7 +53,7 @@ func (s *Swarm) setupListener(maddr ma.Multiaddr) error {
53
// return err
54
// }
55
// for _, a := range resolved {
56
- // s.peers.AddAddress(s.local, a)
56
+ // s.peers.AddAddr(s.local, a)
57
// }
58
59
sk := s.peers.PrivKey(s.local)
p2p/net/swarm/swarm_test.go
+1
-1
@@ -75,7 +75,7 @@ func connectSwarms(t *testing.T, ctx context.Context, swarms []*Swarm) {
75
var wg sync.WaitGroup
76
connect := func(s *Swarm, dst peer.ID, addr ma.Multiaddr) {
77
// TODO: make a DialAddr func.
78
- s.peers.AddAddress(dst, addr)
78
+ s.peers.AddAddr(dst, addr, peer.PermanentAddrTTL)
79
if _, err := s.Dial(ctx, dst); err != nil {
80
t.Fatal("error swarm dialing to peer", err)
81
}
p2p/peer/addr_manager.go
renamed
+56
-20
@@ -1,16 +1,38 @@
1
-// package addr provides useful address utilities for p2p
2
-// applications. It buys into the multi-transport addressing
3
-// scheme Multiaddr, and uses it to build its own p2p addressing.
4
-// All Addrs must have an associated peer.ID.
5
-package addr
1
+package peer
2
3
import (
4
"sync"
5
"time"
6
7
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
8
+)
9
+
10
+const (
11
+
12
+ // TempAddrTTL is the ttl used for a short lived address
13
+ TempAddrTTL = time.Second * 10
14
+
15
+ // ProviderAddrTTL is the TTL of an address we've received from a provider.
16
+ // This is also a temporary address, but lasts longer. After this expires,
17
+ // the records we return will require an extra lookup.
18
+ ProviderAddrTTL = time.Minute * 10
19
13
- peer "github.com/jbenet/go-ipfs/p2p/peer"
20
+ // RecentlyConnectedAddrTTL is used when we recently connected to a peer.
21
+ // It means that we are reasonably certain of the peer's address.
22
+ RecentlyConnectedAddrTTL = time.Minute * 10
23
+
24
+ // OwnObservedAddrTTL is used for our own external addresses observed by peers.
25
+ OwnObservedAddrTTL = time.Minute * 20
26
+
27
+ // PermanentAddrTTL is the ttl for a "permanent address" (e.g. bootstrap nodes)
28
+ // if we haven't shipped you an update to ipfs in 356 days
29
+ // we probably arent running the same bootstrap nodes...
30
+ PermanentAddrTTL = time.Hour * 24 * 356
31
+
32
+ // ConnectedAddrTTL is the ttl used for the addresses of a peer to whom
33
+ // we're connected directly. This is basically permanent, as we will
34
+ // clear them + re-add under a TempAddrTTL after disconnecting.
35
+ ConnectedAddrTTL = PermanentAddrTTL
36
)
37
38
type expiringAddr struct {
@@ -24,30 +46,44 @@ func (e *expiringAddr) ExpiredBy(t time.Time) bool {
46
47
type addrSet map[string]expiringAddr
48
27
-// Manager manages addresses.
49
+// AddrManager manages addresses.
50
// The zero-value is ready to be used.
29
-type Manager struct {
51
+type AddrManager struct {
52
addrmu sync.Mutex // guards addrs
31
- addrs map[peer.ID]addrSet
53
+ addrs map[ID]addrSet
54
}
55
34
-// ensures the Manager is initialized.
56
+// ensures the AddrManager is initialized.
57
// So we can use the zero value.
36
-func (mgr *Manager) init() {
58
+func (mgr *AddrManager) init() {
59
+ if mgr.addrs == nil {
60
+ mgr.addrs = make(map[ID]addrSet)
61
+ }
62
+}
63
+
64
+func (mgr *AddrManager) Peers() []ID {
65
+ mgr.addrmu.Lock()
66
+ defer mgr.addrmu.Unlock()
67
if mgr.addrs == nil {
38
- mgr.addrs = make(map[peer.ID]addrSet)
68
+ return nil
69
+ }
70
+
71
+ pids := make([]ID, 0, len(mgr.addrs))
72
+ for pid := range mgr.addrs {
73
+ pids = append(pids, pid)
74
}
75
+ return pids
76
}
77
78
// AddAddr calls AddAddrs(p, []ma.Multiaddr{addr}, ttl)
43
-func (mgr *Manager) AddAddr(p peer.ID, addr ma.Multiaddr, ttl time.Duration) {
79
+func (mgr *AddrManager) AddAddr(p ID, addr ma.Multiaddr, ttl time.Duration) {
80
mgr.AddAddrs(p, []ma.Multiaddr{addr}, ttl)
81
}
82
47
-// AddAddrs gives Manager addresses to use, with a given ttl
83
+// AddAddrs gives AddrManager addresses to use, with a given ttl
84
// (time-to-live), after which the address is no longer valid.
85
// If the manager has a longer TTL, the operation is a no-op for that address
50
-func (mgr *Manager) AddAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duration) {
86
+func (mgr *AddrManager) AddAddrs(p ID, addrs []ma.Multiaddr, ttl time.Duration) {
87
mgr.addrmu.Lock()
88
defer mgr.addrmu.Unlock()
89
@@ -77,13 +113,13 @@ func (mgr *Manager) AddAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duration)
113
}
114
115
// SetAddr calls mgr.SetAddrs(p, addr, ttl)
80
-func (mgr *Manager) SetAddr(p peer.ID, addr ma.Multiaddr, ttl time.Duration) {
116
+func (mgr *AddrManager) SetAddr(p ID, addr ma.Multiaddr, ttl time.Duration) {
117
mgr.SetAddrs(p, []ma.Multiaddr{addr}, ttl)
118
}
119
120
// SetAddrs sets the ttl on addresses. This clears any TTL there previously.
121
// This is used when we receive the best estimate of the validity of an address.
86
-func (mgr *Manager) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duration) {
122
+func (mgr *AddrManager) SetAddrs(p ID, addrs []ma.Multiaddr, ttl time.Duration) {
123
mgr.addrmu.Lock()
124
defer mgr.addrmu.Unlock()
125
@@ -109,8 +145,8 @@ func (mgr *Manager) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duration)
145
}
146
}
147
112
-// Addresses returns all known (and valid) addresses for a given peer.
113
-func (mgr *Manager) Addrs(p peer.ID) []ma.Multiaddr {
148
+// Addresses returns all known (and valid) addresses for a given
149
+func (mgr *AddrManager) Addrs(p ID) []ma.Multiaddr {
150
mgr.addrmu.Lock()
151
defer mgr.addrmu.Unlock()
152
@@ -143,7 +179,7 @@ func (mgr *Manager) Addrs(p peer.ID) []ma.Multiaddr {
179
}
180
181
// ClearAddresses removes all previously stored addresses
146
-func (mgr *Manager) ClearAddrs(p peer.ID) {
182
+func (mgr *AddrManager) ClearAddrs(p ID) {
183
mgr.addrmu.Lock()
184
defer mgr.addrmu.Unlock()
185
mgr.init()
p2p/peer/addr_manager_test.go
renamed
+6
-8
@@ -1,16 +1,14 @@
1
-package addr
1
+package peer
2
3
import (
4
"testing"
5
"time"
6
7
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
8
-
9
- peer "github.com/jbenet/go-ipfs/p2p/peer"
8
)
9
12
-func IDS(t *testing.T, ids string) peer.ID {
13
- id, err := peer.IDB58Decode(ids)
10
+func IDS(t *testing.T, ids string) ID {
11
+ id, err := IDB58Decode(ids)
12
if err != nil {
13
t.Fatal(err)
14
}
@@ -71,7 +69,7 @@ func TestAddresses(t *testing.T) {
69
ma55 := MA(t, "/ip4/5.2.3.3/tcp/5555")
70
71
ttl := time.Hour
74
- m := Manager{}
72
+ m := AddrManager{}
73
m.AddAddr(id1, ma11, ttl)
74
75
m.AddAddrs(id2, []ma.Multiaddr{ma21, ma22}, ttl)
@@ -109,7 +107,7 @@ func TestAddressesExpire(t *testing.T) {
107
ma24 := MA(t, "/ip4/4.2.3.3/tcp/4444")
108
ma25 := MA(t, "/ip4/5.2.3.3/tcp/5555")
109
112
- m := Manager{}
110
+ m := AddrManager{}
111
m.AddAddr(id1, ma11, time.Hour)
112
m.AddAddr(id1, ma12, time.Hour)
113
m.AddAddr(id1, ma13, time.Hour)
@@ -164,7 +162,7 @@ func TestClearWorks(t *testing.T) {
162
ma24 := MA(t, "/ip4/4.2.3.3/tcp/4444")
163
ma25 := MA(t, "/ip4/5.2.3.3/tcp/5555")
164
167
- m := Manager{}
165
+ m := AddrManager{}
166
m.AddAddr(id1, ma11, time.Hour)
167
m.AddAddr(id1, ma12, time.Hour)
168
m.AddAddr(id1, ma13, time.Hour)
p2p/peer/peerstore.go
+23
-109
@@ -20,8 +20,8 @@ const (
20
// Peerstore provides a threadsafe store of Peer related
21
// information.
22
type Peerstore interface {
23
+ AddrBook
24
KeyBook
24
- AddressBook
25
Metrics
26
27
// Peers returns a list of all peer.IDs in this Peerstore
@@ -32,9 +32,6 @@ type Peerstore interface {
32
// that peer, useful to other services.
33
PeerInfo(ID) PeerInfo
34
35
- // AddPeerInfo absorbs the information listed in given PeerInfo.
36
- AddPeerInfo(PeerInfo)
37
-
35
// Get/Put is a simple registry for other peer-related key/value pairs.
36
// if we find something we use often, it should become its own set of
37
// methods. this is a last resort.
@@ -42,109 +39,30 @@ type Peerstore interface {
39
Put(id ID, key string, val interface{}) error
40
}
41
45
-// AddressBook tracks the addresses of Peers
46
-type AddressBook interface {
47
- Addresses(ID) []ma.Multiaddr // returns addresses for ID
48
- AddAddress(ID, ma.Multiaddr) // Adds given addr for ID
49
- AddAddresses(ID, []ma.Multiaddr) // Adds given addrs for ID
50
- SetAddresses(ID, []ma.Multiaddr) // Sets given addrs for ID (clears previously stored)
51
-}
42
+// AddrBook is an interface that fits the new AddrManager. I'm patching
43
+// it up in here to avoid changing a ton of the codebase.
44
+type AddrBook interface {
45
53
-type expiringAddr struct {
54
- Addr ma.Multiaddr
55
- TTL time.Time
56
-}
46
+ // AddAddr calls AddAddrs(p, []ma.Multiaddr{addr}, ttl)
47
+ AddAddr(p ID, addr ma.Multiaddr, ttl time.Duration)
48
58
-func (e *expiringAddr) Expired() bool {
59
- return time.Now().After(e.TTL)
60
-}
49
+ // AddAddrs gives AddrManager addresses to use, with a given ttl
50
+ // (time-to-live), after which the address is no longer valid.
51
+ // If the manager has a longer TTL, the operation is a no-op for that address
52
+ AddAddrs(p ID, addrs []ma.Multiaddr, ttl time.Duration)
53
62
-type addressMap map[string]expiringAddr
54
+ // SetAddr calls mgr.SetAddrs(p, addr, ttl)
55
+ SetAddr(p ID, addr ma.Multiaddr, ttl time.Duration)
56
64
-type addressbook struct {
65
- sync.RWMutex // guards all fields
57
+ // SetAddrs sets the ttl on addresses. This clears any TTL there previously.
58
+ // This is used when we receive the best estimate of the validity of an address.
59
+ SetAddrs(p ID, addrs []ma.Multiaddr, ttl time.Duration)
60
67
- addrs map[ID]addressMap
68
- ttl time.Duration // initial ttl
69
-}
61
+ // Addresses returns all known (and valid) addresses for a given
62
+ Addrs(p ID) []ma.Multiaddr
63
71
-func newAddressbook() *addressbook {
72
- return &addressbook{
73
- addrs: map[ID]addressMap{},
74
- ttl: AddressTTL,
75
- }
76
-}
77
-
78
-func (ab *addressbook) Peers() []ID {
79
- ab.RLock()
80
- ps := make([]ID, 0, len(ab.addrs))
81
- for p := range ab.addrs {
82
- ps = append(ps, p)
83
- }
84
- ab.RUnlock()
85
- return ps
86
-}
87
-
88
-func (ab *addressbook) Addresses(p ID) []ma.Multiaddr {
89
- ab.Lock()
90
- defer ab.Unlock()
91
-
92
- maddrs, found := ab.addrs[p]
93
- if !found {
94
- return nil
95
- }
96
-
97
- good := make([]ma.Multiaddr, 0, len(maddrs))
98
- var expired []string
99
- for s, m := range maddrs {
100
- if m.Expired() {
101
- expired = append(expired, s)
102
- } else {
103
- good = append(good, m.Addr)
104
- }
105
- }
106
-
107
- // clean up the expired ones.
108
- for _, s := range expired {
109
- delete(ab.addrs[p], s)
110
- }
111
- return good
112
-}
113
-
114
-func (ab *addressbook) AddAddress(p ID, m ma.Multiaddr) {
115
- ab.AddAddresses(p, []ma.Multiaddr{m})
116
-}
117
-
118
-func (ab *addressbook) AddAddresses(p ID, ms []ma.Multiaddr) {
119
- ab.Lock()
120
- defer ab.Unlock()
121
-
122
- amap, found := ab.addrs[p]
123
- if !found {
124
- amap = addressMap{}
125
- ab.addrs[p] = amap
126
- }
127
-
128
- ttl := time.Now().Add(ab.ttl)
129
- for _, m := range ms {
130
- // re-set all of them for new ttl.
131
- amap[m.String()] = expiringAddr{
132
- Addr: m,
133
- TTL: ttl,
134
- }
135
- }
136
-}
137
-
138
-func (ab *addressbook) SetAddresses(p ID, ms []ma.Multiaddr) {
139
- ab.Lock()
140
- defer ab.Unlock()
141
-
142
- amap := addressMap{}
143
- ttl := time.Now().Add(ab.ttl)
144
- for _, m := range ms {
145
- amap[m.String()] = expiringAddr{Addr: m, TTL: ttl}
146
- }
147
- ab.addrs[p] = amap // clear what was there before
64
+ // ClearAddresses removes all previously stored addresses
65
+ ClearAddrs(p ID)
66
}
67
68
// KeyBook tracks the Public keys of Peers.
@@ -231,8 +149,8 @@ func (kb *keybook) AddPrivKey(p ID, sk ic.PrivKey) error {
149
150
type peerstore struct {
151
keybook
234
- addressbook
152
metrics
153
+ AddrManager
154
155
// store other data, like versions
156
ds ds.ThreadSafeDatastore
@@ -242,8 +160,8 @@ type peerstore struct {
160
func NewPeerstore() Peerstore {
161
return &peerstore{
162
keybook: *newKeybook(),
245
- addressbook: *newAddressbook(),
163
metrics: *(NewMetrics()).(*metrics),
164
+ AddrManager: AddrManager{},
165
ds: dssync.MutexWrap(ds.NewMapDatastore()),
166
}
167
}
@@ -263,7 +181,7 @@ func (ps *peerstore) Peers() []ID {
181
for _, p := range ps.keybook.Peers() {
182
set[p] = struct{}{}
183
}
266
- for _, p := range ps.addressbook.Peers() {
184
+ for _, p := range ps.AddrManager.Peers() {
185
set[p] = struct{}{}
186
}
187
@@ -277,14 +195,10 @@ func (ps *peerstore) Peers() []ID {
195
func (ps *peerstore) PeerInfo(p ID) PeerInfo {
196
return PeerInfo{
197
ID: p,
280
- Addrs: ps.addressbook.Addresses(p),
198
+ Addrs: ps.AddrManager.Addrs(p),
199
}
200
}
201
284
-func (ps *peerstore) AddPeerInfo(pi PeerInfo) {
285
- ps.AddAddresses(pi.ID, pi.Addrs)
286
-}
287
-
202
func PeerInfos(ps Peerstore, peers []ID) []PeerInfo {
203
pi := make([]PeerInfo, len(peers))
204
for i, p := range peers {
p2p/peer/peerstore_test.go
deleted
-185
@@ -1,185 +0,0 @@
1
-package peer
2
-
3
-import (
4
- "testing"
5
- "time"
6
-
7
- ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
8
-)
9
-
10
-func IDS(t *testing.T, ids string) ID {
11
- id, err := IDB58Decode(ids)
12
- if err != nil {
13
- t.Fatal(err)
14
- }
15
- return id
16
-}
17
-
18
-func MA(t *testing.T, m string) ma.Multiaddr {
19
- maddr, err := ma.NewMultiaddr(m)
20
- if err != nil {
21
- t.Fatal(err)
22
- }
23
- return maddr
24
-}
25
-
26
-func TestAddresses(t *testing.T) {
27
-
28
- ps := NewPeerstore()
29
-
30
- id1 := IDS(t, "QmcNstKuwBBoVTpSCSDrwzjgrRcaYXK833Psuz2EMHwyQN")
31
- id2 := IDS(t, "QmRmPL3FDZKE3Qiwv1RosLdwdvbvg17b2hB39QPScgWKKZ")
32
- id3 := IDS(t, "QmPhi7vBsChP7sjRoZGgg7bcKqF6MmCcQwvRbDte8aJ6Kn")
33
- id4 := IDS(t, "QmPhi7vBsChP7sjRoZGgg7bcKqF6MmCcQwvRbDte8aJ5Kn")
34
- id5 := IDS(t, "QmPhi7vBsChP7sjRoZGgg7bcKqF6MmCcQwvRbDte8aJ5Km")
35
-
36
- ma11 := MA(t, "/ip4/1.2.3.1/tcp/1111")
37
- ma21 := MA(t, "/ip4/2.2.3.2/tcp/1111")
38
- ma22 := MA(t, "/ip4/2.2.3.2/tcp/2222")
39
- ma31 := MA(t, "/ip4/3.2.3.3/tcp/1111")
40
- ma32 := MA(t, "/ip4/3.2.3.3/tcp/2222")
41
- ma33 := MA(t, "/ip4/3.2.3.3/tcp/3333")
42
- ma41 := MA(t, "/ip4/4.2.3.3/tcp/1111")
43
- ma42 := MA(t, "/ip4/4.2.3.3/tcp/2222")
44
- ma43 := MA(t, "/ip4/4.2.3.3/tcp/3333")
45
- ma44 := MA(t, "/ip4/4.2.3.3/tcp/4444")
46
- ma51 := MA(t, "/ip4/5.2.3.3/tcp/1111")
47
- ma52 := MA(t, "/ip4/5.2.3.3/tcp/2222")
48
- ma53 := MA(t, "/ip4/5.2.3.3/tcp/3333")
49
- ma54 := MA(t, "/ip4/5.2.3.3/tcp/4444")
50
- ma55 := MA(t, "/ip4/5.2.3.3/tcp/5555")
51
-
52
- ps.AddAddress(id1, ma11)
53
- ps.AddAddresses(id2, []ma.Multiaddr{ma21, ma22})
54
- ps.AddAddresses(id2, []ma.Multiaddr{ma21, ma22}) // idempotency
55
- ps.AddAddress(id3, ma31)
56
- ps.AddAddress(id3, ma32)
57
- ps.AddAddress(id3, ma33)
58
- ps.AddAddress(id3, ma33) // idempotency
59
- ps.AddAddress(id3, ma33)
60
- ps.AddAddresses(id4, []ma.Multiaddr{ma41, ma42, ma43, ma44}) // multiple
61
- ps.AddAddresses(id5, []ma.Multiaddr{ma21, ma22}) // clearing
62
- ps.AddAddresses(id5, []ma.Multiaddr{ma41, ma42, ma43, ma44}) // clearing
63
- ps.SetAddresses(id5, []ma.Multiaddr{ma51, ma52, ma53, ma54, ma55}) // clearing
64
-
65
- test := func(exp, act []ma.Multiaddr) {
66
- if len(exp) != len(act) {
67
- t.Fatal("lengths not the same")
68
- }
69
-
70
- for _, a := range exp {
71
- found := false
72
-
73
- for _, b := range act {
74
- if a.Equal(b) {
75
- found = true
76
- break
77
- }
78
- }
79
-
80
- if !found {
81
- t.Fatal("expected address %s not found", a)
82
- }
83
- }
84
- }
85
-
86
- // test the Addresses return value
87
- test([]ma.Multiaddr{ma11}, ps.Addresses(id1))
88
- test([]ma.Multiaddr{ma21, ma22}, ps.Addresses(id2))
89
- test([]ma.Multiaddr{ma31, ma32, ma33}, ps.Addresses(id3))
90
- test([]ma.Multiaddr{ma41, ma42, ma43, ma44}, ps.Addresses(id4))
91
- test([]ma.Multiaddr{ma51, ma52, ma53, ma54, ma55}, ps.Addresses(id5))
92
-
93
- // test also the PeerInfo return
94
- test([]ma.Multiaddr{ma11}, ps.PeerInfo(id1).Addrs)
95
- test([]ma.Multiaddr{ma21, ma22}, ps.PeerInfo(id2).Addrs)
96
- test([]ma.Multiaddr{ma31, ma32, ma33}, ps.PeerInfo(id3).Addrs)
97
- test([]ma.Multiaddr{ma41, ma42, ma43, ma44}, ps.PeerInfo(id4).Addrs)
98
- test([]ma.Multiaddr{ma51, ma52, ma53, ma54, ma55}, ps.PeerInfo(id5).Addrs)
99
-}
100
-
101
-func TestAddressTTL(t *testing.T) {
102
-
103
- ps := NewPeerstore()
104
- id1 := IDS(t, "QmcNstKuwBBoVTpSCSDrwzjgrRcaYXK833Psuz2EMHwyQN")
105
- ma1 := MA(t, "/ip4/1.2.3.1/tcp/1111")
106
- ma2 := MA(t, "/ip4/2.2.3.2/tcp/2222")
107
- ma3 := MA(t, "/ip4/3.2.3.3/tcp/3333")
108
- ma4 := MA(t, "/ip4/4.2.3.3/tcp/4444")
109
- ma5 := MA(t, "/ip4/5.2.3.3/tcp/5555")
110
-
111
- ps.AddAddress(id1, ma1)
112
- ps.AddAddress(id1, ma2)
113
- ps.AddAddress(id1, ma3)
114
- ps.AddAddress(id1, ma4)
115
- ps.AddAddress(id1, ma5)
116
-
117
- test := func(exp, act []ma.Multiaddr) {
118
- if len(exp) != len(act) {
119
- t.Fatal("lengths not the same")
120
- }
121
-
122
- for _, a := range exp {
123
- found := false
124
-
125
- for _, b := range act {
126
- if a.Equal(b) {
127
- found = true
128
- break
129
- }
130
- }
131
-
132
- if !found {
133
- t.Fatal("expected address %s not found", a)
134
- }
135
- }
136
- }
137
-
138
- testTTL := func(ttle time.Duration, id ID, addr ma.Multiaddr) {
139
- ab := ps.(*peerstore).addressbook
140
- ttlat := ab.addrs[id][addr.String()].TTL
141
- ttla := ttlat.Sub(time.Now())
142
- if ttla > ttle {
143
- t.Error("ttl is greater than expected", ttle, ttla)
144
- }
145
- if ttla < (ttle / 2) {
146
- t.Error("ttl is smaller than expected", ttle/2, ttla)
147
- }
148
- }
149
-
150
- // should they are there
151
- ab := ps.(*peerstore).addressbook
152
- if len(ab.addrs[id1]) != 5 {
153
- t.Error("incorrect addr count", len(ab.addrs[id1]), ab.addrs[id1])
154
- }
155
-
156
- // test the Addresses return value
157
- test([]ma.Multiaddr{ma1, ma2, ma3, ma4, ma5}, ps.Addresses(id1))
158
- test([]ma.Multiaddr{ma1, ma2, ma3, ma4, ma5}, ps.PeerInfo(id1).Addrs)
159
-
160
- // check the addr TTL is a bit smaller than the init TTL
161
- testTTL(AddressTTL, id1, ma1)
162
- testTTL(AddressTTL, id1, ma2)
163
- testTTL(AddressTTL, id1, ma3)
164
- testTTL(AddressTTL, id1, ma4)
165
- testTTL(AddressTTL, id1, ma5)
166
-
167
- // change the TTL
168
- setTTL := func(id ID, addr ma.Multiaddr, ttl time.Time) {
169
- a := ab.addrs[id][addr.String()]
170
- a.TTL = ttl
171
- ab.addrs[id][addr.String()] = a
172
- }
173
- setTTL(id1, ma1, time.Now().Add(-1*time.Second))
174
- setTTL(id1, ma2, time.Now().Add(-1*time.Hour))
175
- setTTL(id1, ma3, time.Now().Add(-1*AddressTTL))
176
-
177
- // should no longer list those
178
- test([]ma.Multiaddr{ma4, ma5}, ps.Addresses(id1))
179
- test([]ma.Multiaddr{ma4, ma5}, ps.PeerInfo(id1).Addrs)
180
-
181
- // should no longer be there
182
- if len(ab.addrs[id1]) != 2 {
183
- t.Error("incorrect addr count", len(ab.addrs[id1]), ab.addrs[id1])
184
- }
185
-}
p2p/protocol/identify/id.go
+37
-2
@@ -11,6 +11,7 @@ import (
11
12
host "github.com/jbenet/go-ipfs/p2p/host"
13
inet "github.com/jbenet/go-ipfs/p2p/net"
14
+ peer "github.com/jbenet/go-ipfs/p2p/peer"
15
protocol "github.com/jbenet/go-ipfs/p2p/protocol"
16
pb "github.com/jbenet/go-ipfs/p2p/protocol/identify/pb"
17
config "github.com/jbenet/go-ipfs/repo/config"
@@ -49,6 +50,10 @@ type IDService struct {
50
// for wait purposes
51
currid map[inet.Conn]chan struct{}
52
currmu sync.RWMutex
53
+
54
+ // our own observed addresses.
55
+ // TODO: instead of expiring, remove these when we disconnect
56
+ addrs peer.AddrManager
57
}
58
59
func NewIDService(h host.Host) *IDService {
@@ -60,6 +65,11 @@ func NewIDService(h host.Host) *IDService {
65
return s
66
}
67
68
+// OwnObservedAddrs returns the addresses peers have reported we've dialed from
69
+func (ids *IDService) OwnObservedAddrs() []ma.Multiaddr {
70
+ return ids.addrs.Addrs(ids.Host.ID())
71
+}
72
+
73
func (ids *IDService) IdentifyConn(c inet.Conn) {
74
ids.currmu.Lock()
75
if wait, found := ids.currid[c]; found {
@@ -176,7 +186,7 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) {
186
187
// update our peerstore with the addresses. here, we SET the addresses, clearing old ones.
188
// We are receiving from the peer itself. this is current address ground truth.
179
- ids.Host.Peerstore().SetAddresses(p, lmaddrs)
189
+ ids.Host.Peerstore().SetAddrs(p, lmaddrs, peer.ConnectedAddrTTL)
190
log.Debugf("%s received listen addrs for %s: %s", c.LocalPeer(), c.RemotePeer(), lmaddrs)
191
192
// get protocol versions
@@ -235,7 +245,7 @@ func (ids *IDService) consumeObservedAddress(observed []byte, c inet.Conn) {
245
246
// ok! we have the observed version of one of our ListenAddresses!
247
log.Debugf("added own observed listen addr: %s --> %s", c.LocalMultiaddr(), maddr)
238
- ids.Host.Peerstore().AddAddress(ids.Host.ID(), maddr)
248
+ ids.addrs.AddAddr(ids.Host.ID(), maddr, peer.OwnObservedAddrTTL)
249
}
250
251
func addrInAddrs(a ma.Multiaddr, as []ma.Multiaddr) bool {
@@ -246,3 +256,28 @@ func addrInAddrs(a ma.Multiaddr, as []ma.Multiaddr) bool {
256
}
257
return false
258
}
259
+
260
+// netNotifiee defines methods to be used with the IpfsDHT
261
+type netNotifiee IDService
262
+
263
+func (nn *netNotifiee) IDService() *IDService {
264
+ return (*IDService)(nn)
265
+}
266
+
267
+func (nn *netNotifiee) Connected(n inet.Network, v inet.Conn) {
268
+ // TODO: deprecate the setConnHandler hook, and kick off
269
+ // identification here.
270
+}
271
+
272
+func (nn *netNotifiee) Disconnected(n inet.Network, v inet.Conn) {
273
+ // undo the setting of addresses to peer.ConnectedAddrTTL we did
274
+ ids := nn.IDService()
275
+ ps := ids.Host.Peerstore()
276
+ addrs := ps.Addrs(v.RemotePeer())
277
+ ps.SetAddrs(v.RemotePeer(), addrs, peer.RecentlyConnectedAddrTTL)
278
+}
279
+
280
+func (nn *netNotifiee) OpenedStream(n inet.Network, v inet.Stream) {}
281
+func (nn *netNotifiee) ClosedStream(n inet.Network, v inet.Stream) {}
282
+func (nn *netNotifiee) Listen(n inet.Network, a ma.Multiaddr) {}
283
+func (nn *netNotifiee) ListenClose(n inet.Network, a ma.Multiaddr) {}
p2p/protocol/identify/id_test.go
+3
-3
@@ -38,7 +38,7 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
38
39
// the IDService should be opened automatically, by the network.
40
// what we should see now is that both peers know about each others listen addresses.
41
- testKnowsAddrs(t, h1, h2p, h2.Peerstore().Addresses(h2p)) // has them
41
+ testKnowsAddrs(t, h1, h2p, h2.Peerstore().Addrs(h2p)) // has them
42
testHasProtocolVersions(t, h1, h2p)
43
44
// now, this wait we do have to do. it's the wait for the Listening side
@@ -50,12 +50,12 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
50
<-h2.IDService().IdentifyWait(c[0])
51
52
// and the protocol versions.
53
- testKnowsAddrs(t, h2, h1p, h1.Peerstore().Addresses(h1p)) // has them
53
+ testKnowsAddrs(t, h2, h1p, h1.Peerstore().Addrs(h1p)) // has them
54
testHasProtocolVersions(t, h2, h1p)
55
}
56
57
func testKnowsAddrs(t *testing.T, h host.Host, p peer.ID, expected []ma.Multiaddr) {
58
- actual := h.Peerstore().Addresses(p)
58
+ actual := h.Peerstore().Addrs(p)
59
60
if len(actual) != len(expected) {
61
t.Error("dont have the same addresses")
p2p/test/util/util.go
+3
-3
@@ -22,14 +22,14 @@ func GenSwarmNetwork(t *testing.T, ctx context.Context) *swarm.Network {
22
if err != nil {
23
t.Fatal(err)
24
}
25
- ps.AddAddresses(p.ID, n.ListenAddresses())
25
+ ps.AddAddrs(p.ID, n.ListenAddresses(), peer.PermanentAddrTTL)
26
return n
27
}
28
29
func DivulgeAddresses(a, b inet.Network) {
30
id := a.LocalPeer()
31
- addrs := a.Peerstore().Addresses(id)
32
- b.Peerstore().AddAddresses(id, addrs)
31
+ addrs := a.Peerstore().Addrs(id)
32
+ b.Peerstore().AddAddrs(id, addrs, peer.PermanentAddrTTL)
33
}
34
35
func GenHostSwarm(t *testing.T, ctx context.Context) *bhost.BasicHost {
routing/dht/dht_test.go
+7
-7
@@ -55,7 +55,7 @@ func setupDHTS(ctx context.Context, n int, t *testing.T) ([]ma.Multiaddr, []peer
55
for i := 0; i < n; i++ {
56
dhts[i] = setupDHT(ctx, t)
57
peers[i] = dhts[i].self
58
- addrs[i] = dhts[i].peerstore.Addresses(dhts[i].self)[0]
58
+ addrs[i] = dhts[i].peerstore.Addrs(dhts[i].self)[0]
59
}
60
61
return addrs, peers, dhts
@@ -64,12 +64,12 @@ func setupDHTS(ctx context.Context, n int, t *testing.T) ([]ma.Multiaddr, []peer
64
func connect(t *testing.T, ctx context.Context, a, b *IpfsDHT) {
65
66
idB := b.self
67
- addrB := b.peerstore.Addresses(idB)
67
+ addrB := b.peerstore.Addrs(idB)
68
if len(addrB) == 0 {
69
t.Fatal("peers setup incorrectly: no local address")
70
}
71
72
- a.peerstore.AddAddresses(idB, addrB)
72
+ a.peerstore.AddAddrs(idB, addrB, peer.TempAddrTTL)
73
if err := a.Connect(ctx, idB); err != nil {
74
t.Fatal(err)
75
}
@@ -754,20 +754,20 @@ func TestConnectCollision(t *testing.T) {
754
dhtA := setupDHT(ctx, t)
755
dhtB := setupDHT(ctx, t)
756
757
- addrA := dhtA.peerstore.Addresses(dhtA.self)[0]
758
- addrB := dhtB.peerstore.Addresses(dhtB.self)[0]
757
+ addrA := dhtA.peerstore.Addrs(dhtA.self)[0]
758
+ addrB := dhtB.peerstore.Addrs(dhtB.self)[0]
759
760
peerA := dhtA.self
761
peerB := dhtB.self
762
763
errs := make(chan error)
764
go func() {
765
- dhtA.peerstore.AddAddress(peerB, addrB)
765
+ dhtA.peerstore.AddAddr(peerB, addrB, peer.TempAddrTTL)
766
err := dhtA.Connect(ctx, peerB)
767
errs <- err
768
}()
769
go func() {
770
- dhtB.peerstore.AddAddress(peerA, addrA)
770
+ dhtB.peerstore.AddAddr(peerA, addrA, peer.TempAddrTTL)
771
err := dhtB.Connect(ctx, peerA)
772
errs <- err
773
}()
routing/dht/handlers.go
+1
-1
@@ -238,7 +238,7 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.M
238
log.Infof("received provider %s for %s (addrs: %s)", p, key, pi.Addrs)
239
if pi.ID != dht.self { // dont add own addrs.
240
// add the received addresses to our peerstore.
241
- dht.peerstore.AddPeerInfo(pi)
241
+ dht.peerstore.AddAddrs(pi.ID, pi.Addrs, peer.ProviderAddrTTL)
242
}
243
dht.providers.AddProvider(key, p)
244
}
routing/dht/lookup.go
+1
-1
@@ -100,7 +100,7 @@ func (dht *IpfsDHT) closerPeersSingle(ctx context.Context, key u.Key, p peer.ID)
100
for _, pbp := range pmes.GetCloserPeers() {
101
pid := peer.ID(pbp.GetId())
102
if pid != dht.self { // dont add self
103
- dht.peerstore.AddAddresses(pid, pbp.Addresses())
103
+ dht.peerstore.AddAddrs(pid, pbp.Addresses(), peer.TempAddrTTL)
104
out = append(out, pid)
105
}
106
}
routing/dht/query.go
+1
-1
@@ -253,7 +253,7 @@ func (r *dhtQueryRunner) queryPeer(cg ctxgroup.ContextGroup, p peer.ID) {
253
}
254
255
// add their addresses to the dialer's peerstore
256
- r.query.dht.peerstore.AddPeerInfo(next)
256
+ r.query.dht.peerstore.AddAddrs(next.ID, next.Addrs, peer.TempAddrTTL)
257
r.addPeerToQuery(cg.Context(), next.ID)
258
log.Debugf("PEERS CLOSER -- worker for: %v added %v (%v)", p, next.ID, next.Addrs)
259
}
routing/grandcentral/server.go
+1
-1
@@ -96,7 +96,7 @@ func (s *Server) handleMessage(
96
}
97
for _, maddr := range provider.Addresses() {
98
// FIXME do we actually want to store to peerstore
99
- s.peerstore.AddAddress(p, maddr)
99
+ s.peerstore.AddAddr(p, maddr, peer.TempAddrTTL)
100
}
101
}
102
var providers []dhtpb.Message_Peer