show peer info on connect (#1155)

This commit is contained in:
Jacek Sieka 2020-06-11 07:14:26 +02:00 committed by GitHub
parent 8e648da399
commit 016cc22173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 23 deletions

View File

@ -654,13 +654,13 @@ proc handleOutgoingPeer*(peer: Peer): Future[bool] {.async.} =
let network = peer.network
proc onPeerClosed(udata: pointer) {.gcsafe.} =
debug "Peer (outgoing) lost", peer = $peer.info
debug "Peer (outgoing) lost", peer
libp2p_peers.set int64(len(network.peerPool))
let res = await network.peerPool.addOutgoingPeer(peer)
if res:
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)
result = true
@ -670,13 +670,13 @@ proc handleIncomingPeer*(peer: Peer): Future[bool] {.async.} =
let network = peer.network
proc onPeerClosed(udata: pointer) {.gcsafe.} =
debug "Peer (incoming) lost", peer = $peer.info
debug "Peer (incoming) lost", peer
libp2p_peers.set int64(len(network.peerPool))
let res = await network.peerPool.addIncomingPeer(peer)
if res:
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)
result = true
@ -713,7 +713,7 @@ proc toPeerInfo(r: Option[enr.TypedRecord]): PeerInfo =
return r.get.toPeerInfo
proc dialPeer*(node: Eth2Node, peerInfo: PeerInfo) {.async.} =
logScope: peer = $peerInfo
logScope: peer = peerInfo.id
debug "Connecting to discovered peer"
await node.switch.connect(peerInfo)
@ -749,16 +749,16 @@ proc connectWorker(network: Eth2Node) {.async.} =
# will be stored in PeerPool.
if fut.finished():
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
inc libp2p_failed_dials
network.addSeen(pi, SeenTableTimeDeadPeer)
continue
debug "Connection to remote peer timed out", peer = $pi
debug "Connection to remote peer timed out", peer = pi.id
inc libp2p_timeout_dials
network.addSeen(pi, SeenTableTimeTimeout)
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,
seen_table_size = len(network.seenTable)

View File

@ -161,15 +161,6 @@ type
proc `==`*(a, b: ENRFieldPair): bool {.inline.} =
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 =
for ma in a.addrs:
if TCP.match(ma):
@ -188,7 +179,7 @@ proc toNodeId(a: PeerID): Option[NodeId] =
chronicles.formatIt PeerInfo: it.shortLog
chronicles.formatIt seq[PeerInfo]:
var res = newSeq[string]()
for item in it.items(): res.add(item.shortLog())
for item in it.items(): res.add($item.shortLog())
"[" & res.join(", ") & "]"
func getTopics(forkDigest: ForkDigest,

View File

@ -89,6 +89,8 @@ p2pProtocol BeaconSync(version = 1,
peerState = BeaconSyncPeerState):
onPeerConnected do (peer: Peer) {.async.}:
debug "Peer connected",
peer, peerInfo = shortLog(peer.info), wasDialed = peer.wasDialed
if peer.wasDialed:
let
ourStatus = peer.networkState.getCurrentStatus()
@ -100,7 +102,7 @@ p2pProtocol BeaconSync(version = 1,
await peer.handleStatus(peer.networkState,
ourStatus, theirStatus.get())
else:
warn "Status response not received in time", peer = peer
warn "Status response not received in time", peer
proc status(peer: Peer,
theirStatus: StatusMsg,
@ -169,7 +171,7 @@ p2pProtocol BeaconSync(version = 1,
proc goodbye(peer: Peer,
reason: DisconnectionReason)
{.async, libp2pProtocol("goodbye", 1).} =
debug "Received Goodbye message", reason
debug "Received Goodbye message", reason, peer
proc setStatusMsg(peer: Peer, statusMsg: StatusMsg) =
debug "Peer status", peer, statusMsg

View File

@ -249,7 +249,7 @@ proc goodbyeUserHandler(peer: Peer; reason: DisconnectionReason) {.async,
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
BeaconSyncProtocol))
debug "Received Goodbye message", reason
debug "Received Goodbye message", reason, peer
template callUserHandler(MSG: type statusObj; peer: Peer; stream: Connection;
noSnappy: bool; msg: StatusMsg): untyped =
@ -375,6 +375,8 @@ proc BeaconSyncPeerConnected(peer: Peer; stream: Connection) {.async, gcsafe.} =
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
BeaconSyncProtocol))
debug "Peer connected", peer, peerInfo = shortLog(peer.info),
wasDialed = peer.wasDialed
if peer.wasDialed:
let
ourStatus = peer.networkState.getCurrentStatus()
@ -382,7 +384,7 @@ proc BeaconSyncPeerConnected(peer: Peer; stream: Connection) {.async, gcsafe.} =
if theirStatus.isOk:
await peer.handleStatus(peer.networkState, ourStatus, theirStatus.get())
else:
warn "Status response not received in time", peer = peer
warn "Status response not received in time", peer
setEventHandlers(BeaconSyncProtocol, BeaconSyncPeerConnected, nil)
registerProtocol(BeaconSyncProtocol)

2
vendor/nim-libp2p vendored

@ -1 +1 @@
Subproject commit 35ff99829e741c3fe0d50eb41800b8321cf6ea8a
Subproject commit 8d9e231a74c1afc76b6745e05020f8d4e33501e7