show peer info on connect (#1155)
This commit is contained in:
parent
8e648da399
commit
016cc22173
|
@ -654,13 +654,13 @@ proc handleOutgoingPeer*(peer: Peer): Future[bool] {.async.} =
|
||||||
let network = peer.network
|
let network = peer.network
|
||||||
|
|
||||||
proc onPeerClosed(udata: pointer) {.gcsafe.} =
|
proc onPeerClosed(udata: pointer) {.gcsafe.} =
|
||||||
debug "Peer (outgoing) lost", peer = $peer.info
|
debug "Peer (outgoing) lost", peer
|
||||||
libp2p_peers.set int64(len(network.peerPool))
|
libp2p_peers.set int64(len(network.peerPool))
|
||||||
|
|
||||||
let res = await network.peerPool.addOutgoingPeer(peer)
|
let res = await network.peerPool.addOutgoingPeer(peer)
|
||||||
if res:
|
if res:
|
||||||
peer.updateScore(NewPeerScore)
|
peer.updateScore(NewPeerScore)
|
||||||
debug "Peer (outgoing) has been added to PeerPool", peer = $peer.info
|
debug "Peer (outgoing) has been added to PeerPool", peer
|
||||||
peer.getFuture().addCallback(onPeerClosed)
|
peer.getFuture().addCallback(onPeerClosed)
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
|
@ -670,13 +670,13 @@ proc handleIncomingPeer*(peer: Peer): Future[bool] {.async.} =
|
||||||
let network = peer.network
|
let network = peer.network
|
||||||
|
|
||||||
proc onPeerClosed(udata: pointer) {.gcsafe.} =
|
proc onPeerClosed(udata: pointer) {.gcsafe.} =
|
||||||
debug "Peer (incoming) lost", peer = $peer.info
|
debug "Peer (incoming) lost", peer
|
||||||
libp2p_peers.set int64(len(network.peerPool))
|
libp2p_peers.set int64(len(network.peerPool))
|
||||||
|
|
||||||
let res = await network.peerPool.addIncomingPeer(peer)
|
let res = await network.peerPool.addIncomingPeer(peer)
|
||||||
if res:
|
if res:
|
||||||
peer.updateScore(NewPeerScore)
|
peer.updateScore(NewPeerScore)
|
||||||
debug "Peer (incoming) has been added to PeerPool", peer = $peer.info
|
debug "Peer (incoming) has been added to PeerPool", peer
|
||||||
peer.getFuture().addCallback(onPeerClosed)
|
peer.getFuture().addCallback(onPeerClosed)
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
|
@ -713,7 +713,7 @@ proc toPeerInfo(r: Option[enr.TypedRecord]): PeerInfo =
|
||||||
return r.get.toPeerInfo
|
return r.get.toPeerInfo
|
||||||
|
|
||||||
proc dialPeer*(node: Eth2Node, peerInfo: PeerInfo) {.async.} =
|
proc dialPeer*(node: Eth2Node, peerInfo: PeerInfo) {.async.} =
|
||||||
logScope: peer = $peerInfo
|
logScope: peer = peerInfo.id
|
||||||
|
|
||||||
debug "Connecting to discovered peer"
|
debug "Connecting to discovered peer"
|
||||||
await node.switch.connect(peerInfo)
|
await node.switch.connect(peerInfo)
|
||||||
|
@ -749,16 +749,16 @@ proc connectWorker(network: Eth2Node) {.async.} =
|
||||||
# will be stored in PeerPool.
|
# will be stored in PeerPool.
|
||||||
if fut.finished():
|
if fut.finished():
|
||||||
if fut.failed() and not(fut.cancelled()):
|
if fut.failed() and not(fut.cancelled()):
|
||||||
debug "Unable to establish connection with peer", peer = $pi,
|
debug "Unable to establish connection with peer", peer = pi.id,
|
||||||
errMsg = fut.readError().msg
|
errMsg = fut.readError().msg
|
||||||
inc libp2p_failed_dials
|
inc libp2p_failed_dials
|
||||||
network.addSeen(pi, SeenTableTimeDeadPeer)
|
network.addSeen(pi, SeenTableTimeDeadPeer)
|
||||||
continue
|
continue
|
||||||
debug "Connection to remote peer timed out", peer = $pi
|
debug "Connection to remote peer timed out", peer = pi.id
|
||||||
inc libp2p_timeout_dials
|
inc libp2p_timeout_dials
|
||||||
network.addSeen(pi, SeenTableTimeTimeout)
|
network.addSeen(pi, SeenTableTimeTimeout)
|
||||||
else:
|
else:
|
||||||
trace "Peer is already connected or already seen", peer = $pi,
|
trace "Peer is already connected or already seen", peer = pi.id,
|
||||||
peer_pool_has_peer = $r1, seen_table_has_peer = $r2,
|
peer_pool_has_peer = $r1, seen_table_has_peer = $r2,
|
||||||
seen_table_size = len(network.seenTable)
|
seen_table_size = len(network.seenTable)
|
||||||
|
|
||||||
|
|
|
@ -161,15 +161,6 @@ type
|
||||||
proc `==`*(a, b: ENRFieldPair): bool {.inline.} =
|
proc `==`*(a, b: ENRFieldPair): bool {.inline.} =
|
||||||
result = (a.eth2 == b.eth2)
|
result = (a.eth2 == b.eth2)
|
||||||
|
|
||||||
proc shortLog*(a: PeerInfo): string =
|
|
||||||
for ma in a.addrs:
|
|
||||||
if TCP.match(ma):
|
|
||||||
return $ma & "/" & $a.peerId
|
|
||||||
for ma in a.addrs:
|
|
||||||
if UDP.match(ma):
|
|
||||||
return $ma & "/" & $a.peerId
|
|
||||||
result = $a
|
|
||||||
|
|
||||||
proc hasTCP(a: PeerInfo): bool =
|
proc hasTCP(a: PeerInfo): bool =
|
||||||
for ma in a.addrs:
|
for ma in a.addrs:
|
||||||
if TCP.match(ma):
|
if TCP.match(ma):
|
||||||
|
@ -188,7 +179,7 @@ proc toNodeId(a: PeerID): Option[NodeId] =
|
||||||
chronicles.formatIt PeerInfo: it.shortLog
|
chronicles.formatIt PeerInfo: it.shortLog
|
||||||
chronicles.formatIt seq[PeerInfo]:
|
chronicles.formatIt seq[PeerInfo]:
|
||||||
var res = newSeq[string]()
|
var res = newSeq[string]()
|
||||||
for item in it.items(): res.add(item.shortLog())
|
for item in it.items(): res.add($item.shortLog())
|
||||||
"[" & res.join(", ") & "]"
|
"[" & res.join(", ") & "]"
|
||||||
|
|
||||||
func getTopics(forkDigest: ForkDigest,
|
func getTopics(forkDigest: ForkDigest,
|
||||||
|
|
|
@ -89,6 +89,8 @@ p2pProtocol BeaconSync(version = 1,
|
||||||
peerState = BeaconSyncPeerState):
|
peerState = BeaconSyncPeerState):
|
||||||
|
|
||||||
onPeerConnected do (peer: Peer) {.async.}:
|
onPeerConnected do (peer: Peer) {.async.}:
|
||||||
|
debug "Peer connected",
|
||||||
|
peer, peerInfo = shortLog(peer.info), wasDialed = peer.wasDialed
|
||||||
if peer.wasDialed:
|
if peer.wasDialed:
|
||||||
let
|
let
|
||||||
ourStatus = peer.networkState.getCurrentStatus()
|
ourStatus = peer.networkState.getCurrentStatus()
|
||||||
|
@ -100,7 +102,7 @@ p2pProtocol BeaconSync(version = 1,
|
||||||
await peer.handleStatus(peer.networkState,
|
await peer.handleStatus(peer.networkState,
|
||||||
ourStatus, theirStatus.get())
|
ourStatus, theirStatus.get())
|
||||||
else:
|
else:
|
||||||
warn "Status response not received in time", peer = peer
|
warn "Status response not received in time", peer
|
||||||
|
|
||||||
proc status(peer: Peer,
|
proc status(peer: Peer,
|
||||||
theirStatus: StatusMsg,
|
theirStatus: StatusMsg,
|
||||||
|
@ -169,7 +171,7 @@ p2pProtocol BeaconSync(version = 1,
|
||||||
proc goodbye(peer: Peer,
|
proc goodbye(peer: Peer,
|
||||||
reason: DisconnectionReason)
|
reason: DisconnectionReason)
|
||||||
{.async, libp2pProtocol("goodbye", 1).} =
|
{.async, libp2pProtocol("goodbye", 1).} =
|
||||||
debug "Received Goodbye message", reason
|
debug "Received Goodbye message", reason, peer
|
||||||
|
|
||||||
proc setStatusMsg(peer: Peer, statusMsg: StatusMsg) =
|
proc setStatusMsg(peer: Peer, statusMsg: StatusMsg) =
|
||||||
debug "Peer status", peer, statusMsg
|
debug "Peer status", peer, statusMsg
|
||||||
|
|
|
@ -249,7 +249,7 @@ proc goodbyeUserHandler(peer: Peer; reason: DisconnectionReason) {.async,
|
||||||
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
||||||
BeaconSyncProtocol))
|
BeaconSyncProtocol))
|
||||||
|
|
||||||
debug "Received Goodbye message", reason
|
debug "Received Goodbye message", reason, peer
|
||||||
|
|
||||||
template callUserHandler(MSG: type statusObj; peer: Peer; stream: Connection;
|
template callUserHandler(MSG: type statusObj; peer: Peer; stream: Connection;
|
||||||
noSnappy: bool; msg: StatusMsg): untyped =
|
noSnappy: bool; msg: StatusMsg): untyped =
|
||||||
|
@ -375,6 +375,8 @@ proc BeaconSyncPeerConnected(peer: Peer; stream: Connection) {.async, gcsafe.} =
|
||||||
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
||||||
BeaconSyncProtocol))
|
BeaconSyncProtocol))
|
||||||
|
|
||||||
|
debug "Peer connected", peer, peerInfo = shortLog(peer.info),
|
||||||
|
wasDialed = peer.wasDialed
|
||||||
if peer.wasDialed:
|
if peer.wasDialed:
|
||||||
let
|
let
|
||||||
ourStatus = peer.networkState.getCurrentStatus()
|
ourStatus = peer.networkState.getCurrentStatus()
|
||||||
|
@ -382,7 +384,7 @@ proc BeaconSyncPeerConnected(peer: Peer; stream: Connection) {.async, gcsafe.} =
|
||||||
if theirStatus.isOk:
|
if theirStatus.isOk:
|
||||||
await peer.handleStatus(peer.networkState, ourStatus, theirStatus.get())
|
await peer.handleStatus(peer.networkState, ourStatus, theirStatus.get())
|
||||||
else:
|
else:
|
||||||
warn "Status response not received in time", peer = peer
|
warn "Status response not received in time", peer
|
||||||
|
|
||||||
setEventHandlers(BeaconSyncProtocol, BeaconSyncPeerConnected, nil)
|
setEventHandlers(BeaconSyncProtocol, BeaconSyncPeerConnected, nil)
|
||||||
registerProtocol(BeaconSyncProtocol)
|
registerProtocol(BeaconSyncProtocol)
|
|
@ -1 +1 @@
|
||||||
Subproject commit 35ff99829e741c3fe0d50eb41800b8321cf6ea8a
|
Subproject commit 8d9e231a74c1afc76b6745e05020f8d4e33501e7
|
Loading…
Reference in New Issue