mirror of https://github.com/status-im/nim-eth.git
Same error handling for rlpxAccept as for rlpxConnect
This commit is contained in:
parent
f8bdec88c9
commit
b44675eda5
|
@ -66,10 +66,8 @@ proc newEthereumNode*(keys: KeyPair,
|
|||
proc processIncoming(server: StreamServer,
|
||||
remote: StreamTransport): Future[void] {.async, gcsafe.} =
|
||||
var node = getUserData[EthereumNode](server)
|
||||
let peerfut = node.rlpxAccept(remote)
|
||||
yield peerfut
|
||||
if not peerfut.failed:
|
||||
let peer = peerfut.read()
|
||||
let peer = await node.rlpxAccept(remote)
|
||||
if not peer.isNil:
|
||||
trace "Connection established (incoming)", peer
|
||||
if node.peerPool != nil:
|
||||
node.peerPool.connectingNodes.excl(peer.remote)
|
||||
|
|
|
@ -1393,8 +1393,10 @@ proc rlpxConnect*(node: EthereumNode, remote: Node): Future[Peer] {.async.} =
|
|||
await postHelloSteps(result, response)
|
||||
ok = true
|
||||
except PeerDisconnected as e:
|
||||
if e.reason != TooManyPeers:
|
||||
debug "Unexpected disconnect during rlpxConnect", reason = e.reason
|
||||
if e.reason == AlreadyConnected or e.reason == TooManyPeers:
|
||||
trace "Disconnect during rlpxAccept", reason = e.reason
|
||||
else:
|
||||
debug "Unexpected disconnect during rlpxAccept", reason = e.reason
|
||||
except TransportIncompleteError:
|
||||
trace "Connection dropped in rlpxConnect", remote
|
||||
except UselessPeerError:
|
||||
|
@ -1405,12 +1407,10 @@ proc rlpxConnect*(node: EthereumNode, remote: Node): Future[Peer] {.async.} =
|
|||
debug "Rlp error in rlpxConnect"
|
||||
except TransportOsError:
|
||||
trace "TransportOsError", err = getCurrentExceptionMsg()
|
||||
except:
|
||||
error "Exception in rlpxConnect", remote,
|
||||
except CatchableError:
|
||||
error "Unexpected exception in rlpxConnect", remote,
|
||||
exc = getCurrentException().name,
|
||||
err = getCurrentExceptionMsg()
|
||||
result = nil
|
||||
raise
|
||||
|
||||
if not ok:
|
||||
if not isNil(result.transport):
|
||||
|
@ -1493,7 +1493,7 @@ proc rlpxAccept*(node: EthereumNode,
|
|||
await postHelloSteps(result, response)
|
||||
ok = true
|
||||
except PeerDisconnected as e:
|
||||
if e.reason == AlreadyConnected:
|
||||
if e.reason == AlreadyConnected or e.reason == TooManyPeers:
|
||||
trace "Disconnect during rlpxAccept", reason = e.reason
|
||||
else:
|
||||
debug "Unexpected disconnect during rlpxAccept", reason = e.reason
|
||||
|
@ -1501,16 +1501,21 @@ proc rlpxAccept*(node: EthereumNode,
|
|||
trace "Connection dropped in rlpxAccept", remote = result.remote
|
||||
except UselessPeerError:
|
||||
trace "Disconnecting useless peer", peer = result.remote
|
||||
except:
|
||||
error "Exception in rlpxAccept",
|
||||
err = getCurrentExceptionMsg(),
|
||||
stackTrace = getCurrentException().getStackTrace()
|
||||
except RlpTypeMismatch:
|
||||
# Some peers report capabilities with names longer than 3 chars. We ignore
|
||||
# those for now. Maybe we should allow this though.
|
||||
debug "Rlp error in rlpxAccept"
|
||||
except TransportOsError:
|
||||
trace "TransportOsError", err = getCurrentExceptionMsg()
|
||||
except CatchableError:
|
||||
error "Unexpected exception in rlpxAccept",
|
||||
exc = getCurrentException().name,
|
||||
err = getCurrentExceptionMsg()
|
||||
|
||||
if not ok:
|
||||
if not isNil(result.transport):
|
||||
result.transport.close()
|
||||
result = nil
|
||||
raise
|
||||
|
||||
when isMainModule:
|
||||
|
||||
|
|
Loading…
Reference in New Issue