mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-08 00:43:06 +00:00
chore: update submodules (#987)
This commit is contained in:
parent
77f80f53f7
commit
bc8ce89e91
@ -19,7 +19,7 @@ suite "Peer Storage":
|
|||||||
peerKey = crypto.PrivateKey.random(ECDSA, rng[]).get()
|
peerKey = crypto.PrivateKey.random(ECDSA, rng[]).get()
|
||||||
peer = PeerInfo.new(peerKey, @[peerLoc])
|
peer = PeerInfo.new(peerKey, @[peerLoc])
|
||||||
peerProto = "/waku/2/default-waku/codec"
|
peerProto = "/waku/2/default-waku/codec"
|
||||||
stored = StoredInfo(peerId: peer.peerId, addrs: toHashSet([peerLoc]), protos: toHashSet([peerProto]), publicKey: peerKey.getPublicKey().tryGet())
|
stored = StoredInfo(peerId: peer.peerId, addrs: @[peerLoc], protos: @[peerProto], publicKey: peerKey.getPublicKey().tryGet())
|
||||||
conn = Connectedness.CanConnect
|
conn = Connectedness.CanConnect
|
||||||
disconn = 999999
|
disconn = 999999
|
||||||
|
|
||||||
|
|||||||
2
vendor/nim-chronos
vendored
2
vendor/nim-chronos
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 875d7d8e6ef0803ae1c331dbf76b1981b0caeb15
|
Subproject commit b3548583fcc768d93654685e7ea55126c1752c29
|
||||||
2
vendor/nim-libp2p
vendored
2
vendor/nim-libp2p
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 13503f3799aa7c746e17db0a4af38f8aec4115b8
|
Subproject commit 36f3132d9a9346539d8b6969921990c82cb6db2f
|
||||||
2
vendor/nim-sqlite3-abi
vendored
2
vendor/nim-sqlite3-abi
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 07039dd887c4e5b57367a16f4be3c18763be1d7b
|
Subproject commit 2f040a5bfcef78f29b72016dfef98706a0f6dc9f
|
||||||
2
vendor/nim-stew
vendored
2
vendor/nim-stew
vendored
@ -1 +1 @@
|
|||||||
Subproject commit cdb1f213d073fd2ecbdaf35a866417657da9294c
|
Subproject commit 412a691f5d29c93bee8f083d213ee8f2c6578bed
|
||||||
2
vendor/nim-web3
vendored
2
vendor/nim-web3
vendored
@ -1 +1 @@
|
|||||||
Subproject commit d260915a0c2111e64ac49b9f75083734c58e5f03
|
Subproject commit 755b6dc92b1545d6c9eb242c551e8188e35ffe5d
|
||||||
2
vendor/nim-websock
vendored
2
vendor/nim-websock
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 8927db93f6ca96abaacfea39f8ca50ce9d41bcdb
|
Subproject commit 47b486b52f850d3534b8a1e778fcf9cf40ffe7f6
|
||||||
@ -63,7 +63,7 @@ proc dialPeer(pm: PeerManager, peerId: PeerID,
|
|||||||
debug "Dialing remote peer timed out"
|
debug "Dialing remote peer timed out"
|
||||||
waku_peers_dials.inc(labelValues = ["timeout"])
|
waku_peers_dials.inc(labelValues = ["timeout"])
|
||||||
|
|
||||||
pm.peerStore.connectionBook.set(peerId, CannotConnect)
|
pm.peerStore.connectionBook[peerId] = CannotConnect
|
||||||
if not pm.storage.isNil:
|
if not pm.storage.isNil:
|
||||||
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), CannotConnect)
|
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), CannotConnect)
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ proc dialPeer(pm: PeerManager, peerId: PeerID,
|
|||||||
debug "Dialing remote peer failed", msg = e.msg
|
debug "Dialing remote peer failed", msg = e.msg
|
||||||
waku_peers_dials.inc(labelValues = ["failed"])
|
waku_peers_dials.inc(labelValues = ["failed"])
|
||||||
|
|
||||||
pm.peerStore.connectionBook.set(peerId, CannotConnect)
|
pm.peerStore.connectionBook[peerId] = CannotConnect
|
||||||
if not pm.storage.isNil:
|
if not pm.storage.isNil:
|
||||||
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), CannotConnect)
|
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), CannotConnect)
|
||||||
|
|
||||||
@ -89,11 +89,11 @@ proc loadFromStorage(pm: PeerManager) =
|
|||||||
# Do not manage self
|
# Do not manage self
|
||||||
return
|
return
|
||||||
|
|
||||||
pm.peerStore.addressBook.set(peerId, storedInfo.addrs)
|
pm.peerStore.addressBook[peerId] = storedInfo.addrs
|
||||||
pm.peerStore.protoBook.set(peerId, storedInfo.protos)
|
pm.peerStore.protoBook[peerId] = storedInfo.protos
|
||||||
pm.peerStore.keyBook.set(peerId, storedInfo.publicKey)
|
pm.peerStore.keyBook[peerId] = storedInfo.publicKey
|
||||||
pm.peerStore.connectionBook.set(peerId, NotConnected) # Reset connectedness state
|
pm.peerStore.connectionBook[peerId] = NotConnected # Reset connectedness state
|
||||||
pm.peerStore.disconnectBook.set(peerId, disconnectTime)
|
pm.peerStore.disconnectBook[peerId] = disconnectTime
|
||||||
|
|
||||||
let res = pm.storage.getAll(onData)
|
let res = pm.storage.getAll(onData)
|
||||||
if res.isErr:
|
if res.isErr:
|
||||||
@ -109,12 +109,12 @@ proc loadFromStorage(pm: PeerManager) =
|
|||||||
proc onConnEvent(pm: PeerManager, peerId: PeerID, event: ConnEvent) {.async.} =
|
proc onConnEvent(pm: PeerManager, peerId: PeerID, event: ConnEvent) {.async.} =
|
||||||
case event.kind
|
case event.kind
|
||||||
of ConnEventKind.Connected:
|
of ConnEventKind.Connected:
|
||||||
pm.peerStore.connectionBook.set(peerId, Connected)
|
pm.peerStore.connectionBook[peerId] = Connected
|
||||||
if not pm.storage.isNil:
|
if not pm.storage.isNil:
|
||||||
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), Connected)
|
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), Connected)
|
||||||
return
|
return
|
||||||
of ConnEventKind.Disconnected:
|
of ConnEventKind.Disconnected:
|
||||||
pm.peerStore.connectionBook.set(peerId, CanConnect)
|
pm.peerStore.connectionBook[peerId] = CanConnect
|
||||||
if not pm.storage.isNil:
|
if not pm.storage.isNil:
|
||||||
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), CanConnect, getTime().toUnix)
|
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), CanConnect, getTime().toUnix)
|
||||||
return
|
return
|
||||||
@ -167,7 +167,7 @@ proc connectedness*(pm: PeerManager, peerId: PeerID): Connectedness =
|
|||||||
# Peer is not managed, therefore not connected
|
# Peer is not managed, therefore not connected
|
||||||
return NotConnected
|
return NotConnected
|
||||||
else:
|
else:
|
||||||
pm.peerStore.connectionBook.get(peerId)
|
pm.peerStore.connectionBook[peerId]
|
||||||
|
|
||||||
proc hasPeer*(pm: PeerManager, peerId: PeerID, proto: string): bool =
|
proc hasPeer*(pm: PeerManager, peerId: PeerID, proto: string): bool =
|
||||||
# Returns `true` if peer is included in manager for the specified protocol
|
# Returns `true` if peer is included in manager for the specified protocol
|
||||||
@ -199,7 +199,7 @@ proc addPeer*(pm: PeerManager, remotePeerInfo: RemotePeerInfo, proto: string) =
|
|||||||
var publicKey: PublicKey
|
var publicKey: PublicKey
|
||||||
discard remotePeerInfo.peerId.extractPublicKey(publicKey)
|
discard remotePeerInfo.peerId.extractPublicKey(publicKey)
|
||||||
|
|
||||||
pm.peerStore.keyBook.set(remotePeerInfo.peerId, publicKey)
|
pm.peerStore.keyBook[remotePeerInfo.peerId] = publicKey
|
||||||
|
|
||||||
# ...associated protocols
|
# ...associated protocols
|
||||||
pm.peerStore.protoBook.add(remotePeerInfo.peerId, proto)
|
pm.peerStore.protoBook.add(remotePeerInfo.peerId, proto)
|
||||||
@ -231,13 +231,13 @@ proc reconnectPeers*(pm: PeerManager,
|
|||||||
|
|
||||||
for storedInfo in pm.peers(protocolMatcher):
|
for storedInfo in pm.peers(protocolMatcher):
|
||||||
# Check if peer is reachable.
|
# Check if peer is reachable.
|
||||||
if pm.peerStore.connectionBook.get(storedInfo.peerId) == CannotConnect:
|
if pm.peerStore.connectionBook[storedInfo.peerId] == CannotConnect:
|
||||||
debug "Not reconnecting to unreachable peer", peerId=storedInfo.peerId
|
debug "Not reconnecting to unreachable peer", peerId=storedInfo.peerId
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Respect optional backoff period where applicable.
|
# Respect optional backoff period where applicable.
|
||||||
let
|
let
|
||||||
disconnectTime = Moment.init(pm.peerStore.disconnectBook.get(storedInfo.peerId), Second) # Convert
|
disconnectTime = Moment.init(pm.peerStore.disconnectBook[storedInfo.peerId], Second) # Convert
|
||||||
currentTime = Moment.init(getTime().toUnix, Second) # Current time comparable to persisted value
|
currentTime = Moment.init(getTime().toUnix, Second) # Current time comparable to persisted value
|
||||||
backoffTime = disconnectTime + backoff - currentTime # Consider time elapsed since last disconnect
|
backoffTime = disconnectTime + backoff - currentTime # Consider time elapsed since last disconnect
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ proc dialPeer*(pm: PeerManager, peerId: PeerID, proto: string, dialTimeout = def
|
|||||||
# Do not attempt to dial self
|
# Do not attempt to dial self
|
||||||
return none(Connection)
|
return none(Connection)
|
||||||
|
|
||||||
let addrs = toSeq(pm.switch.peerStore.addressBook.get(peerId))
|
let addrs = pm.switch.peerStore[AddressBook][peerId]
|
||||||
if addrs.len == 0:
|
if addrs.len == 0:
|
||||||
return none(Connection)
|
return none(Connection)
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,9 @@ type
|
|||||||
# Connected: actively connected to peer.
|
# Connected: actively connected to peer.
|
||||||
Connected
|
Connected
|
||||||
|
|
||||||
ConnectionBook* = object of PeerBook[Connectedness]
|
ConnectionBook* = ref object of PeerBook[Connectedness]
|
||||||
|
|
||||||
DisconnectBook* = object of PeerBook[int64] # Keeps track of when peers were disconnected in Unix timestamps
|
DisconnectBook* = ref object of PeerBook[int64] # Keeps track of when peers were disconnected in Unix timestamps
|
||||||
|
|
||||||
WakuPeerStore* = ref object
|
WakuPeerStore* = ref object
|
||||||
addressBook*: AddressBook
|
addressBook*: AddressBook
|
||||||
@ -32,14 +32,38 @@ type
|
|||||||
StoredInfo* = object
|
StoredInfo* = object
|
||||||
# Collates stored info about a peer
|
# Collates stored info about a peer
|
||||||
peerId*: PeerID
|
peerId*: PeerID
|
||||||
addrs*: HashSet[MultiAddress]
|
addrs*: seq[MultiAddress]
|
||||||
protos*: HashSet[string]
|
protos*: seq[string]
|
||||||
publicKey*: PublicKey
|
publicKey*: PublicKey
|
||||||
|
|
||||||
proc new*(T: type WakuPeerStore): WakuPeerStore =
|
proc new*(T: type WakuPeerStore): WakuPeerStore =
|
||||||
var p: WakuPeerStore
|
let
|
||||||
new(p)
|
addressBook = AddressBook(book: initTable[PeerID, seq[MultiAddress]]())
|
||||||
return p
|
protoBook = ProtoBook(book: initTable[PeerID, seq[string]]())
|
||||||
|
keyBook = KeyBook(book: initTable[PeerID, PublicKey]())
|
||||||
|
connectionBook = ConnectionBook(book: initTable[PeerID, Connectedness]())
|
||||||
|
disconnectBook = DisconnectBook(book: initTable[PeerID, int64]())
|
||||||
|
|
||||||
|
T(addressBook: addressBook,
|
||||||
|
protoBook: protoBook,
|
||||||
|
keyBook: keyBook,
|
||||||
|
connectionBook: connectionBook,
|
||||||
|
disconnectBook: disconnectBook)
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# Utility functions #
|
||||||
|
#####################
|
||||||
|
|
||||||
|
proc add*[T](peerBook: SeqPeerBook[T],
|
||||||
|
peerId: PeerId,
|
||||||
|
entry: T) =
|
||||||
|
## Add entry to a given peer. If the peer is not known,
|
||||||
|
## it will be set with the provided entry.
|
||||||
|
|
||||||
|
peerBook.book.mgetOrPut(peerId,
|
||||||
|
newSeq[T]()).add(entry)
|
||||||
|
|
||||||
|
# TODO: Notify clients?
|
||||||
|
|
||||||
##################
|
##################
|
||||||
# Peer Store API #
|
# Peer Store API #
|
||||||
@ -51,9 +75,9 @@ proc get*(peerStore: WakuPeerStore,
|
|||||||
|
|
||||||
StoredInfo(
|
StoredInfo(
|
||||||
peerId: peerId,
|
peerId: peerId,
|
||||||
addrs: peerStore.addressBook.get(peerId),
|
addrs: peerStore.addressBook[peerId],
|
||||||
protos: peerStore.protoBook.get(peerId),
|
protos: peerStore.protoBook[peerId],
|
||||||
publicKey: peerStore.keyBook.get(peerId)
|
publicKey: peerStore.keyBook[peerId]
|
||||||
)
|
)
|
||||||
|
|
||||||
proc peers*(peerStore: WakuPeerStore): seq[StoredInfo] =
|
proc peers*(peerStore: WakuPeerStore): seq[StoredInfo] =
|
||||||
|
|||||||
@ -33,8 +33,8 @@ proc init*(T: type StoredInfo, buffer: seq[byte]): ProtoResult[T] =
|
|||||||
discard ? pb.getRepeatedField(3, protoSeq)
|
discard ? pb.getRepeatedField(3, protoSeq)
|
||||||
discard ? pb.getField(4, storedInfo.publicKey)
|
discard ? pb.getField(4, storedInfo.publicKey)
|
||||||
|
|
||||||
storedInfo.addrs = toHashSet(multiaddrSeq)
|
storedInfo.addrs = multiaddrSeq
|
||||||
storedInfo.protos = toHashSet(protoSeq)
|
storedInfo.protos = protoSeq
|
||||||
|
|
||||||
ok(storedInfo)
|
ok(storedInfo)
|
||||||
|
|
||||||
|
|||||||
@ -873,7 +873,7 @@ proc runDiscv5Loop(node: WakuNode) {.async.} =
|
|||||||
trace "Discovered peers", count=discoveredPeers.get().len()
|
trace "Discovered peers", count=discoveredPeers.get().len()
|
||||||
|
|
||||||
let newPeers = discoveredPeers.get().filterIt(
|
let newPeers = discoveredPeers.get().filterIt(
|
||||||
not node.switch.peerStore.addressBook.contains(it.peerId))
|
not node.switch.peerStore[AddressBook].contains(it.peerId))
|
||||||
|
|
||||||
if newPeers.len > 0:
|
if newPeers.len > 0:
|
||||||
debug "Connecting to newly discovered peers", count=newPeers.len()
|
debug "Connecting to newly discovered peers", count=newPeers.len()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user