Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gx: update go-libp2p-peerstore #261

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type IDService struct {
currid map[inet.Conn]chan struct{}
currmu sync.RWMutex

addrMu sync.Mutex

// our own observed addresses.
// TODO: instead of expiring, remove these when we disconnect
observedAddrs ObservedAddrSet
Expand Down Expand Up @@ -220,9 +222,17 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) {
lmaddrs = append(lmaddrs, c.RemoteMultiaddr())
}

// update our peerstore with the addresses. here, we SET the addresses, clearing old ones.
// We are receiving from the peer itself. this is current address ground truth.
ids.Host.Peerstore().SetAddrs(p, lmaddrs, pstore.ConnectedAddrTTL)
// Extend the TTLs on the known (probably) good addresses.
// Taking the lock ensures that we don't concurrently process a disconnect.
ids.addrMu.Lock()
switch ids.Host.Network().Connectedness(p) {
case inet.Connected:
ids.Host.Peerstore().AddAddrs(p, lmaddrs, pstore.ConnectedAddrTTL)
default:
ids.Host.Peerstore().AddAddrs(p, lmaddrs, pstore.RecentlyConnectedAddrTTL)
}
ids.addrMu.Unlock()

log.Debugf("%s received listen addrs for %s: %s", c.LocalPeer(), c.RemotePeer(), lmaddrs)

// get protocol versions
Expand Down Expand Up @@ -449,9 +459,14 @@ func (nn *netNotifiee) Connected(n inet.Network, v inet.Conn) {
func (nn *netNotifiee) Disconnected(n inet.Network, v inet.Conn) {
// undo the setting of addresses to peer.ConnectedAddrTTL we did
ids := nn.IDService()
ps := ids.Host.Peerstore()
addrs := ps.Addrs(v.RemotePeer())
ps.SetAddrs(v.RemotePeer(), addrs, pstore.RecentlyConnectedAddrTTL)
ids.addrMu.Lock()
defer ids.addrMu.Unlock()

if ids.Host.Network().Connectedness(v.RemotePeer()) != inet.Connected {
// Last disconnect.
ps := ids.Host.Peerstore()
ps.UpdateAddrs(v.RemotePeer(), pstore.ConnectedAddrTTL, pstore.RecentlyConnectedAddrTTL)
}
}

func (nn *netNotifiee) OpenedStream(n inet.Network, v inet.Stream) {}
Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@
},
{
"author": "whyrusleeping",
"hash": "QmYijbtjCxFEjSXaudaQAUz3LN5VKLssm8WCUsRoqzXmQR",
"hash": "QmQoXyRXtorcAtWwnud9HBod3vjPC8vTu1gJnsg9PLwuiT",
"name": "go-libp2p-peerstore",
"version": "1.4.10"
"version": "1.4.11"
},
{
"author": "whyrusleeping",
Expand Down Expand Up @@ -187,15 +187,15 @@
},
{
"author": "whyrusleeping",
"hash": "QmU4vCDZTPLDqSDKguWbHCiUe46mZUtmM2g2suBZ9NE8ko",
"hash": "Qmegn1aFLQmbCg4xurYgLug9TJ3rTVFjJ3L5fD3m9m4qMf",
"name": "go-libp2p-net",
"version": "2.0.3"
"version": "2.0.4"
},
{
"author": "whyrusleeping",
"hash": "QmaL2WYJGbWKqHoLujoi9GQ5jj4JVFrBqHUBWmEYzJPVWT",
"hash": "QmazrTQKkjFcajz55duY9eCePfjv1mVWH3xJbn5bu7qUXQ",
"name": "go-libp2p-metrics",
"version": "2.0.2"
"version": "2.0.3"
},
{
"author": "whyrusleeping",
Expand All @@ -205,15 +205,15 @@
},
{
"author": "whyrusleeping",
"hash": "QmP46LGWhzVZTMmt5akNNLfoV8qL4h5wTwmzQxLyDafggd",
"hash": "QmbEk4hyXjohArLiff8inoGsoywzfPD71SqD4qHZBiWQyr",
"name": "go-libp2p-host",
"version": "2.1.3"
"version": "2.1.4"
},
{
"author": "whyrusleeping",
"hash": "QmUhvp4VoQ9cKDVLqAxciEKdm8ymBx2Syx4C1Tv6SmSTPa",
"hash": "QmaNqYUXoM5x2gUVLKSdXBDBrw4maNydw1rpxbzPPuSQ8b",
"name": "go-libp2p-swarm",
"version": "2.1.2"
"version": "2.1.3"
},
{
"author": "whyrusleeping",
Expand All @@ -223,15 +223,15 @@
},
{
"author": "whyrusleeping",
"hash": "QmZTcPxK6VqrwY94JpKZPvEqAZ6tEr1rLrpcqJbbRZbg2V",
"hash": "QmR84wjmVyNUXQuL2s9rKr5QcL7CLUXjhQTFgosUh22UEZ",
"name": "go-libp2p-netutil",
"version": "0.3.6"
"version": "0.3.7"
},
{
"author": "whyrusleeping",
"hash": "QmYmhgAcvmDGXct1qBvc1kz9BxQSit1XBrTeiGZp2FvRyn",
"hash": "QmP4BoRH7qHbyVAjpXqZqXm3X2sMWokgACF9m5RXBWLDkq",
"name": "go-libp2p-blankhost",
"version": "0.2.3"
"version": "0.2.4"
},
{
"author": "whyrusleeping",
Expand Down Expand Up @@ -265,9 +265,9 @@
},
{
"author": "vyzo",
"hash": "QmVqNgx6RByRcnLVsr9spbo5ScomJyDZrb9Gz4XMWkYB7Z",
"hash": "QmPLBz772MAef586ooAEVqGjYsUiGQPUSJHcvWtD9BKhaF",
"name": "go-libp2p-circuit",
"version": "2.0.7"
"version": "2.0.8"
},
{
"author": "lgierth",
Expand All @@ -277,9 +277,9 @@
},
{
"author": "why",
"hash": "QmSAJm4QdTJ3EGF2cvgNcQyXTEbxqWSW1x4kCVV1aJQUQr",
"hash": "QmayGe6p6EJT8sbdmsh5eyVjp9u8KvFwkMacKwx2MDWzN8",
"name": "go-libp2p-interface-connmgr",
"version": "0.0.4"
"version": "0.0.5"
}
],
"gxVersion": "0.4.0",
Expand Down