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
|
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
|
### Checking the other peer's supported sub-protocols
|
||||||
|
|
||||||
Upon establishing a connection, RLPx will automatically negotiate the list of
|
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
|
# no need to exit here, because the context might still have blocks to fetch
|
||||||
# from this peer
|
# 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]
|
template workItem: auto = syncCtx.workQueue[workItemIdx]
|
||||||
workItem.state = Requested
|
workItem.state = Requested
|
||||||
trace "Requesting block headers", start = workItem.startIndex, count = workItem.numBlocks, peer
|
trace "Requesting block headers", start = workItem.startIndex, count = workItem.numBlocks, peer
|
||||||
|
|
|
@ -704,7 +704,6 @@ type
|
||||||
isLightNode*: bool
|
isLightNode*: bool
|
||||||
trusted*: bool
|
trusted*: bool
|
||||||
received: HashSet[Message]
|
received: HashSet[Message]
|
||||||
running: bool
|
|
||||||
|
|
||||||
WhisperNetwork = ref object
|
WhisperNetwork = ref object
|
||||||
queue*: Queue
|
queue*: Queue
|
||||||
|
@ -768,10 +767,7 @@ p2pProtocol Whisper(version = whisperVersion,
|
||||||
if not whisperNet.config.isLightNode:
|
if not whisperNet.config.isLightNode:
|
||||||
traceAsyncErrors peer.run()
|
traceAsyncErrors peer.run()
|
||||||
|
|
||||||
debug "Whisper peer initialized"
|
debug "Whisper peer initialized", peer
|
||||||
|
|
||||||
onPeerDisconnected do (peer: Peer, reason: DisconnectionReason) {.gcsafe.}:
|
|
||||||
peer.state.running = false
|
|
||||||
|
|
||||||
proc status(peer: Peer,
|
proc status(peer: Peer,
|
||||||
protocolVersion: uint,
|
protocolVersion: uint,
|
||||||
|
@ -890,12 +886,7 @@ proc processQueue(peer: Peer) =
|
||||||
traceAsyncErrors peer.messages(envelopes)
|
traceAsyncErrors peer.messages(envelopes)
|
||||||
|
|
||||||
proc run(peer: Peer) {.async.} =
|
proc run(peer: Peer) {.async.} =
|
||||||
var
|
while peer.connectionState notin {Disconnecting, Disconnected}:
|
||||||
whisperPeer = peer.state(Whisper)
|
|
||||||
whisperNet = peer.networkState(Whisper)
|
|
||||||
|
|
||||||
whisperPeer.running = true
|
|
||||||
while whisperPeer.running:
|
|
||||||
peer.processQueue()
|
peer.processQueue()
|
||||||
await sleepAsync(messageInterval)
|
await sleepAsync(messageInterval)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue