mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 05:14:14 +00:00
Slightly change the static peer manager lookup behaviour (#1484)
why: The peer manager runs concurrently to the discovery scheme. So the p2p peer observer will also present `peer` non-static entries. Previously, this peer manager throw an assert defect when this happened.
This commit is contained in:
parent
10ad7867e4
commit
fe04b50fef
@ -7,7 +7,10 @@
|
|||||||
# This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
# those terms.
|
# those terms.
|
||||||
|
|
||||||
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
|
std/[hashes, tables],
|
||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
eth/p2p,
|
eth/p2p,
|
||||||
@ -32,27 +35,33 @@ type
|
|||||||
pool: PeerPool
|
pool: PeerPool
|
||||||
maxRetryCount: int # zero == infinite
|
maxRetryCount: int # zero == infinite
|
||||||
retryInterval: int # in seconds
|
retryInterval: int # in seconds
|
||||||
reconnectStates: seq[ReconnectState]
|
reconnectStates: Table[Node,ReconnectState]
|
||||||
reconnectFut: Future[void]
|
reconnectFut: Future[void]
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "PeerManagerRef"
|
topics = "PeerManagerRef"
|
||||||
|
|
||||||
proc setConnected(pm: PeerManagerRef, peer: Peer, connected: bool) =
|
template noKeyError(info: static[string]; code: untyped) =
|
||||||
for n in pm.reconnectStates:
|
try:
|
||||||
if peer.remote.id == n.node.id:
|
code
|
||||||
n.connected = connected
|
except KeyError as e:
|
||||||
return
|
raiseAssert "Not possible (" & info & "): " & e.msg
|
||||||
|
|
||||||
doAssert(false, "unreachable code")
|
proc setConnected(pm: PeerManagerRef, peer: Peer, connected: bool) =
|
||||||
|
if pm.reconnectStates.hasKey(peer.remote):
|
||||||
|
noKeyError("setConnected"):
|
||||||
|
pm.reconnectStates[peer.remote].connected = connected
|
||||||
|
else:
|
||||||
|
# Peer was not registered a static, so ignore it
|
||||||
|
trace "Could not update non-static peer", peer, connected
|
||||||
|
|
||||||
proc needReconnect(pm: PeerManagerRef): bool =
|
proc needReconnect(pm: PeerManagerRef): bool =
|
||||||
for n in pm.reconnectStates:
|
for n in pm.reconnectStates.values:
|
||||||
if not n.connected:
|
if not n.connected:
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc reconnect(pm: PeerManagerRef) {.async, gcsafe.} =
|
proc reconnect(pm: PeerManagerRef) {.async, gcsafe.} =
|
||||||
for n in pm.reconnectStates:
|
for n in pm.reconnectStates.values:
|
||||||
if not n.connected and pm.state == Running:
|
if not n.connected and pm.state == Running:
|
||||||
if n.retryCount < pm.maxRetryCount or pm.maxRetryCount == 0:
|
if n.retryCount < pm.maxRetryCount or pm.maxRetryCount == 0:
|
||||||
trace "Reconnecting to", remote=n.node.node
|
trace "Reconnecting to", remote=n.node.node
|
||||||
@ -93,7 +102,7 @@ proc setupManager(pm: PeerManagerRef, enodes: openArray[ENode]) =
|
|||||||
retryCount: 0,
|
retryCount: 0,
|
||||||
connected: false
|
connected: false
|
||||||
)
|
)
|
||||||
pm.reconnectStates.add(state)
|
pm.reconnectStates[state.node] = state
|
||||||
|
|
||||||
proc new*(_: type PeerManagerRef,
|
proc new*(_: type PeerManagerRef,
|
||||||
pool: PeerPool,
|
pool: PeerPool,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user