Skip to content

Commit

Permalink
correct peer id if invalid, or populate if not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Nov 28, 2023
1 parent ad8ee26 commit 37785aa
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 37785aa

Please sign in to comment.