mirror of https://github.com/status-im/nim-eth.git
Make use of peer.connectionState in whisper and blockchain sync + add note in docs
This commit is contained in:
parent
7459dffbca
commit
46255c31d1
|
@ -265,6 +265,10 @@ p2pProtocol les(version = 2):
|
|||
debug "peer disconnected", peer
|
||||
```
|
||||
|
||||
**Note:** Be aware that if currently one of the subprotocol `onPeerConnected`
|
||||
calls fails, the client will be disconnected as `UselessPeer` but no
|
||||
`onPeerDisconnect` calls are run.
|
||||
|
||||
### Checking the other peer's supported sub-protocols
|
||||
|
||||
Upon establishing a connection, RLPx will automatically negotiate the list of
|
||||
|
|
|
@ -171,7 +171,8 @@ proc obtainBlocksFromPeer(syncCtx: SyncContext, peer: Peer) {.async.} =
|
|||
# no need to exit here, because the context might still have blocks to fetch
|
||||
# from this peer
|
||||
|
||||
while (let workItemIdx = syncCtx.availableWorkItem(); workItemIdx != -1):
|
||||
while (let workItemIdx = syncCtx.availableWorkItem(); workItemIdx != -1 and
|
||||
peer.connectionState notin {Disconnecting, Disconnected}):
|
||||
template workItem: auto = syncCtx.workQueue[workItemIdx]
|
||||
workItem.state = Requested
|
||||
trace "Requesting block headers", start = workItem.startIndex, count = workItem.numBlocks, peer
|
||||
|
|
|
@ -704,7 +704,6 @@ type
|
|||
isLightNode*: bool
|
||||
trusted*: bool
|
||||
received: HashSet[Message]
|
||||
running: bool
|
||||
|
||||
WhisperNetwork = ref object
|
||||
queue*: Queue
|
||||
|
@ -768,10 +767,7 @@ p2pProtocol Whisper(version = whisperVersion,
|
|||
if not whisperNet.config.isLightNode:
|
||||
traceAsyncErrors peer.run()
|
||||
|
||||
debug "Whisper peer initialized"
|
||||
|
||||
onPeerDisconnected do (peer: Peer, reason: DisconnectionReason) {.gcsafe.}:
|
||||
peer.state.running = false
|
||||
debug "Whisper peer initialized", peer
|
||||
|
||||
proc status(peer: Peer,
|
||||
protocolVersion: uint,
|
||||
|
@ -890,12 +886,7 @@ proc processQueue(peer: Peer) =
|
|||
traceAsyncErrors peer.messages(envelopes)
|
||||
|
||||
proc run(peer: Peer) {.async.} =
|
||||
var
|
||||
whisperPeer = peer.state(Whisper)
|
||||
whisperNet = peer.networkState(Whisper)
|
||||
|
||||
whisperPeer.running = true
|
||||
while whisperPeer.running:
|
||||
while peer.connectionState notin {Disconnecting, Disconnected}:
|
||||
peer.processQueue()
|
||||
await sleepAsync(messageInterval)
|
||||
|
||||
|
|
Loading…
Reference in New Issue