From 37785aa370aa56870dddbfc69b4f83d72940b944 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Tue, 28 Nov 2023 13:05:29 -0700 Subject: [PATCH] correct peer id if invalid, or populate if not provided --- cmd/validate.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/cmd/validate.go b/cmd/validate.go index 7afdec0..ed27e7a 100644 --- a/cmd/validate.go +++ b/cmd/validate.go @@ -78,6 +78,14 @@ func validatePeers(peers string, limit int) { peer := peer go func() { defer wg.Done() + + peerAt := strings.Split(peer, "@") + skipIDValidation := false + if len(peerAt) == 1 { + peer = fmt.Sprintf("%s@%s", nodeKey.PubKey().Address(), peer) + skipIDValidation = true + } + netAddr, err := p2p.NewNetAddressString(peer) if err != nil { fmt.Printf("Invalid peer address: %s: %v\n", peer, err) @@ -103,12 +111,18 @@ func validatePeers(peers string, limit int) { // For outgoing conns, ensure connection key matches dialed key. connID := p2p.PubKeyToID(secretConn.RemotePubKey()) if connID != netAddr.ID { - fmt.Printf( - "conn.ID (%v) dialed ID (%v) mismatch: %s\n", - connID, - netAddr.ID, - peer, - ) + + addValid(fmt.Sprintf("%s@%s", connID, strings.Split(peer, "@")[1])) + + if !skipIDValidation { + fmt.Printf( + "conn.ID (%v) dialed ID (%v) mismatch: %s\n", + connID, + netAddr.ID, + peer, + ) + } + return }