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,
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)

View File

@ -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: