mirror of https://github.com/waku-org/nwaku.git
chore: update submodules (#987)
This commit is contained in:
parent
37325c8f48
commit
d5a04a2719
|
@ -19,7 +19,7 @@ suite "Peer Storage":
|
|||
peerKey = crypto.PrivateKey.random(ECDSA, rng[]).get()
|
||||
peer = PeerInfo.new(peerKey, @[peerLoc])
|
||||
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
|
||||
disconn = 999999
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 875d7d8e6ef0803ae1c331dbf76b1981b0caeb15
|
||||
Subproject commit b3548583fcc768d93654685e7ea55126c1752c29
|
|
@ -1 +1 @@
|
|||
Subproject commit 13503f3799aa7c746e17db0a4af38f8aec4115b8
|
||||
Subproject commit 36f3132d9a9346539d8b6969921990c82cb6db2f
|
|
@ -1 +1 @@
|
|||
Subproject commit 07039dd887c4e5b57367a16f4be3c18763be1d7b
|
||||
Subproject commit 2f040a5bfcef78f29b72016dfef98706a0f6dc9f
|
|
@ -1 +1 @@
|
|||
Subproject commit cdb1f213d073fd2ecbdaf35a866417657da9294c
|
||||
Subproject commit 412a691f5d29c93bee8f083d213ee8f2c6578bed
|
|
@ -1 +1 @@
|
|||
Subproject commit d260915a0c2111e64ac49b9f75083734c58e5f03
|
||||
Subproject commit 755b6dc92b1545d6c9eb242c551e8188e35ffe5d
|
|
@ -1 +1 @@
|
|||
Subproject commit 8927db93f6ca96abaacfea39f8ca50ce9d41bcdb
|
||||
Subproject commit 47b486b52f850d3534b8a1e778fcf9cf40ffe7f6
|
|
@ -63,7 +63,7 @@ proc dialPeer(pm: PeerManager, peerId: PeerID,
|
|||
debug "Dialing remote peer timed out"
|
||||
waku_peers_dials.inc(labelValues = ["timeout"])
|
||||
|
||||
pm.peerStore.connectionBook.set(peerId, CannotConnect)
|
||||
pm.peerStore.connectionBook[peerId] = CannotConnect
|
||||
if not pm.storage.isNil:
|
||||
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
|
||||
waku_peers_dials.inc(labelValues = ["failed"])
|
||||
|
||||
pm.peerStore.connectionBook.set(peerId, CannotConnect)
|
||||
pm.peerStore.connectionBook[peerId] = CannotConnect
|
||||
if not pm.storage.isNil:
|
||||
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), CannotConnect)
|
||||
|
||||
|
@ -89,11 +89,11 @@ proc loadFromStorage(pm: PeerManager) =
|
|||
# Do not manage self
|
||||
return
|
||||
|
||||
pm.peerStore.addressBook.set(peerId, storedInfo.addrs)
|
||||
pm.peerStore.protoBook.set(peerId, storedInfo.protos)
|
||||
pm.peerStore.keyBook.set(peerId, storedInfo.publicKey)
|
||||
pm.peerStore.connectionBook.set(peerId, NotConnected) # Reset connectedness state
|
||||
pm.peerStore.disconnectBook.set(peerId, disconnectTime)
|
||||
pm.peerStore.addressBook[peerId] = storedInfo.addrs
|
||||
pm.peerStore.protoBook[peerId] = storedInfo.protos
|
||||
pm.peerStore.keyBook[peerId] = storedInfo.publicKey
|
||||
pm.peerStore.connectionBook[peerId] = NotConnected # Reset connectedness state
|
||||
pm.peerStore.disconnectBook[peerId] = disconnectTime
|
||||
|
||||
let res = pm.storage.getAll(onData)
|
||||
if res.isErr:
|
||||
|
@ -109,12 +109,12 @@ proc loadFromStorage(pm: PeerManager) =
|
|||
proc onConnEvent(pm: PeerManager, peerId: PeerID, event: ConnEvent) {.async.} =
|
||||
case event.kind
|
||||
of ConnEventKind.Connected:
|
||||
pm.peerStore.connectionBook.set(peerId, Connected)
|
||||
pm.peerStore.connectionBook[peerId] = Connected
|
||||
if not pm.storage.isNil:
|
||||
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), Connected)
|
||||
return
|
||||
of ConnEventKind.Disconnected:
|
||||
pm.peerStore.connectionBook.set(peerId, CanConnect)
|
||||
pm.peerStore.connectionBook[peerId] = CanConnect
|
||||
if not pm.storage.isNil:
|
||||
pm.storage.insertOrReplace(peerId, pm.peerStore.get(peerId), CanConnect, getTime().toUnix)
|
||||
return
|
||||
|
@ -167,7 +167,7 @@ proc connectedness*(pm: PeerManager, peerId: PeerID): Connectedness =
|
|||
# Peer is not managed, therefore not connected
|
||||
return NotConnected
|
||||
else:
|
||||
pm.peerStore.connectionBook.get(peerId)
|
||||
pm.peerStore.connectionBook[peerId]
|
||||
|
||||
proc hasPeer*(pm: PeerManager, peerId: PeerID, proto: string): bool =
|
||||
# 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
|
||||
discard remotePeerInfo.peerId.extractPublicKey(publicKey)
|
||||
|
||||
pm.peerStore.keyBook.set(remotePeerInfo.peerId, publicKey)
|
||||
pm.peerStore.keyBook[remotePeerInfo.peerId] = publicKey
|
||||
|
||||
# ...associated protocols
|
||||
pm.peerStore.protoBook.add(remotePeerInfo.peerId, proto)
|
||||
|
@ -231,13 +231,13 @@ proc reconnectPeers*(pm: PeerManager,
|
|||
|
||||
for storedInfo in pm.peers(protocolMatcher):
|
||||
# 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
|
||||
continue
|
||||
|
||||
# Respect optional backoff period where applicable.
|
||||
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
|
||||
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
|
||||
return none(Connection)
|
||||
|
||||
let addrs = toSeq(pm.switch.peerStore.addressBook.get(peerId))
|
||||
let addrs = pm.switch.peerStore[AddressBook][peerId]
|
||||
if addrs.len == 0:
|
||||
return none(Connection)
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ type
|
|||
# Connected: actively connected to peer.
|
||||
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
|
||||
addressBook*: AddressBook
|
||||
|
@ -32,14 +32,38 @@ type
|
|||
StoredInfo* = object
|
||||
# Collates stored info about a peer
|
||||
peerId*: PeerID
|
||||
addrs*: HashSet[MultiAddress]
|
||||
protos*: HashSet[string]
|
||||
addrs*: seq[MultiAddress]
|
||||
protos*: seq[string]
|
||||
publicKey*: PublicKey
|
||||
|
||||
proc new*(T: type WakuPeerStore): WakuPeerStore =
|
||||
var p: WakuPeerStore
|
||||
new(p)
|
||||
return p
|
||||
let
|
||||
addressBook = AddressBook(book: initTable[PeerID, seq[MultiAddress]]())
|
||||
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 #
|
||||
|
@ -51,9 +75,9 @@ proc get*(peerStore: WakuPeerStore,
|
|||
|
||||
StoredInfo(
|
||||
peerId: peerId,
|
||||
addrs: peerStore.addressBook.get(peerId),
|
||||
protos: peerStore.protoBook.get(peerId),
|
||||
publicKey: peerStore.keyBook.get(peerId)
|
||||
addrs: peerStore.addressBook[peerId],
|
||||
protos: peerStore.protoBook[peerId],
|
||||
publicKey: peerStore.keyBook[peerId]
|
||||
)
|
||||
|
||||
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.getField(4, storedInfo.publicKey)
|
||||
|
||||
storedInfo.addrs = toHashSet(multiaddrSeq)
|
||||
storedInfo.protos = toHashSet(protoSeq)
|
||||
storedInfo.addrs = multiaddrSeq
|
||||
storedInfo.protos = protoSeq
|
||||
|
||||
ok(storedInfo)
|
||||
|
||||
|
|
|
@ -873,7 +873,7 @@ proc runDiscv5Loop(node: WakuNode) {.async.} =
|
|||
trace "Discovered peers", count=discoveredPeers.get().len()
|
||||
|
||||
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:
|
||||
debug "Connecting to newly discovered peers", count=newPeers.len()
|
||||
|
|
Loading…
Reference in New Issue