mirror of
https://github.com/status-im/nim-libp2p.git
synced 2025-01-11 05:26:02 +00:00
Fix PeerStore missing remote endpoints of established connection. (#1226)
This commit is contained in:
parent
f591e692fc
commit
b7e0df127f
@ -63,6 +63,7 @@ type
|
|||||||
KeyBook* {.public.} = ref object of PeerBook[PublicKey]
|
KeyBook* {.public.} = ref object of PeerBook[PublicKey]
|
||||||
|
|
||||||
AgentBook* {.public.} = ref object of PeerBook[string]
|
AgentBook* {.public.} = ref object of PeerBook[string]
|
||||||
|
LastSeenBook* {.public.} = ref object of PeerBook[Opt[MultiAddress]]
|
||||||
ProtoVersionBook* {.public.} = ref object of PeerBook[string]
|
ProtoVersionBook* {.public.} = ref object of PeerBook[string]
|
||||||
SPRBook* {.public.} = ref object of PeerBook[Envelope]
|
SPRBook* {.public.} = ref object of PeerBook[Envelope]
|
||||||
|
|
||||||
@ -145,10 +146,16 @@ proc del*(peerStore: PeerStore, peerId: PeerId) {.public.} =
|
|||||||
for _, book in peerStore.books:
|
for _, book in peerStore.books:
|
||||||
book.deletor(peerId)
|
book.deletor(peerId)
|
||||||
|
|
||||||
proc updatePeerInfo*(peerStore: PeerStore, info: IdentifyInfo) =
|
proc updatePeerInfo*(
|
||||||
if info.addrs.len > 0:
|
peerStore: PeerStore,
|
||||||
|
info: IdentifyInfo,
|
||||||
|
observedAddr: Opt[MultiAddress] = Opt.none(MultiAddress),
|
||||||
|
) =
|
||||||
|
if len(info.addrs) > 0:
|
||||||
peerStore[AddressBook][info.peerId] = info.addrs
|
peerStore[AddressBook][info.peerId] = info.addrs
|
||||||
|
|
||||||
|
peerStore[LastSeenBook][info.peerId] = observedAddr
|
||||||
|
|
||||||
info.pubkey.withValue(pubkey):
|
info.pubkey.withValue(pubkey):
|
||||||
peerStore[KeyBook][info.peerId] = pubkey
|
peerStore[KeyBook][info.peerId] = pubkey
|
||||||
|
|
||||||
@ -200,7 +207,7 @@ proc identify*(peerStore: PeerStore, muxer: Muxer) {.async.} =
|
|||||||
knownAgent = shortAgent
|
knownAgent = shortAgent
|
||||||
muxer.connection.setShortAgent(knownAgent)
|
muxer.connection.setShortAgent(knownAgent)
|
||||||
|
|
||||||
peerStore.updatePeerInfo(info)
|
peerStore.updatePeerInfo(info, stream.observedAddr)
|
||||||
finally:
|
finally:
|
||||||
await stream.closeWithEOF()
|
await stream.closeWithEOF()
|
||||||
|
|
||||||
|
@ -842,6 +842,8 @@ suite "Switch":
|
|||||||
switch1.peerStore[AddressBook][switch2.peerInfo.peerId] == switch2.peerInfo.addrs
|
switch1.peerStore[AddressBook][switch2.peerInfo.peerId] == switch2.peerInfo.addrs
|
||||||
switch1.peerStore[ProtoBook][switch2.peerInfo.peerId] == switch2.peerInfo.protocols
|
switch1.peerStore[ProtoBook][switch2.peerInfo.peerId] == switch2.peerInfo.protocols
|
||||||
|
|
||||||
|
switch1.peerStore[LastSeenBook][switch2.peerInfo.peerId].isSome()
|
||||||
|
|
||||||
switch1.peerInfo.peerId notin switch2.peerStore[AddressBook]
|
switch1.peerInfo.peerId notin switch2.peerStore[AddressBook]
|
||||||
switch1.peerInfo.peerId notin switch2.peerStore[ProtoBook]
|
switch1.peerInfo.peerId notin switch2.peerStore[ProtoBook]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user