Skip to content

Possible Bug: AddPeer stores only IP as key, but GetPeers expects full NodeAddr binary #79

@adgsm

Description

@adgsm

Hi, thanks for maintaining this project!
While reading through the peer store code, I noticed what might be an inconsistency in how peers are added vs. retrieved. I’d like to confirm if my understanding is correct.

Flow I observed

AddPeer does the following:

  1. Uses string(na.IP) as the key
  2. Stores NodeAndTime{na, time.Now()} in the map

Meanwhile, GetPeers:

  • Iterates over the keys
  • Calls UnmarshalBinary([]byte(key)) on each key

Potential issue

  • AddPeer is only storing the IP address string as the key.
  • GetPeers appears to expect the key to be the full binary representation of a NodeAddr (i.e., IP + Port).

This means the port information is discarded on insert, but later expected during retrieval.

Suggested fix

Instead of using just the IP string, store the full binary representation of the NodeAddr as the key. For example:

// Use full binary representation (IP + Port) as key instead of just IP
binaryData, err := na.MarshalBinary()
if err != nil {
    panic(err) // Should never happen for valid NodeAddr
}
m[string(binaryData)] = NodeAndTime{na, time.Now()}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions