Skip to content

Commit

Permalink
Merge pull request #2 from strangelove-ventures/andrew/peer_id_correc…
Browse files Browse the repository at this point in the history
…tion

correct peer id if invalid, or populate if not provided
  • Loading branch information
agouin authored Nov 28, 2023
2 parents ad8ee26 + 37785aa commit 41417b3
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 41417b3

Please sign in to comment.