Same error handling for rlpxAccept as for rlpxConnect

This commit is contained in:
kdeme 2019-06-11 14:38:02 +02:00
parent f8bdec88c9
commit b44675eda5
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
2 changed files with 19 additions and 16 deletions

View File

@ -66,10 +66,8 @@ proc newEthereumNode*(keys: KeyPair,
proc processIncoming(server: StreamServer, proc processIncoming(server: StreamServer,
remote: StreamTransport): Future[void] {.async, gcsafe.} = remote: StreamTransport): Future[void] {.async, gcsafe.} =
var node = getUserData[EthereumNode](server) var node = getUserData[EthereumNode](server)
let peerfut = node.rlpxAccept(remote) let peer = await node.rlpxAccept(remote)
yield peerfut if not peer.isNil:
if not peerfut.failed:
let peer = peerfut.read()
trace "Connection established (incoming)", peer trace "Connection established (incoming)", peer
if node.peerPool != nil: if node.peerPool != nil:
node.peerPool.connectingNodes.excl(peer.remote) node.peerPool.connectingNodes.excl(peer.remote)

View File

@ -1393,8 +1393,10 @@ proc rlpxConnect*(node: EthereumNode, remote: Node): Future[Peer] {.async.} =
await postHelloSteps(result, response) await postHelloSteps(result, response)
ok = true ok = true
except PeerDisconnected as e: except PeerDisconnected as e:
if e.reason != TooManyPeers: if e.reason == AlreadyConnected or e.reason == TooManyPeers:
debug "Unexpected disconnect during rlpxConnect", reason = e.reason trace "Disconnect during rlpxAccept", reason = e.reason
else:
debug "Unexpected disconnect during rlpxAccept", reason = e.reason
except TransportIncompleteError: except TransportIncompleteError:
trace "Connection dropped in rlpxConnect", remote trace "Connection dropped in rlpxConnect", remote
except UselessPeerError: except UselessPeerError:
@ -1405,12 +1407,10 @@ proc rlpxConnect*(node: EthereumNode, remote: Node): Future[Peer] {.async.} =
debug "Rlp error in rlpxConnect" debug "Rlp error in rlpxConnect"
except TransportOsError: except TransportOsError:
trace "TransportOsError", err = getCurrentExceptionMsg() trace "TransportOsError", err = getCurrentExceptionMsg()
except: except CatchableError:
error "Exception in rlpxConnect", remote, error "Unexpected exception in rlpxConnect", remote,
exc = getCurrentException().name, exc = getCurrentException().name,
err = getCurrentExceptionMsg() err = getCurrentExceptionMsg()
result = nil
raise
if not ok: if not ok:
if not isNil(result.transport): if not isNil(result.transport):
@ -1493,7 +1493,7 @@ proc rlpxAccept*(node: EthereumNode,
await postHelloSteps(result, response) await postHelloSteps(result, response)
ok = true ok = true
except PeerDisconnected as e: except PeerDisconnected as e:
if e.reason == AlreadyConnected: if e.reason == AlreadyConnected or e.reason == TooManyPeers:
trace "Disconnect during rlpxAccept", reason = e.reason trace "Disconnect during rlpxAccept", reason = e.reason
else: else:
debug "Unexpected disconnect during rlpxAccept", reason = e.reason debug "Unexpected disconnect during rlpxAccept", reason = e.reason
@ -1501,16 +1501,21 @@ proc rlpxAccept*(node: EthereumNode,
trace "Connection dropped in rlpxAccept", remote = result.remote trace "Connection dropped in rlpxAccept", remote = result.remote
except UselessPeerError: except UselessPeerError:
trace "Disconnecting useless peer", peer = result.remote trace "Disconnecting useless peer", peer = result.remote
except: except RlpTypeMismatch:
error "Exception in rlpxAccept", # Some peers report capabilities with names longer than 3 chars. We ignore
err = getCurrentExceptionMsg(), # those for now. Maybe we should allow this though.
stackTrace = getCurrentException().getStackTrace() 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 ok:
if not isNil(result.transport): if not isNil(result.transport):
result.transport.close() result.transport.close()
result = nil result = nil
raise
when isMainModule: when isMainModule: