-
-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Description
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:
- Uses
string(na.IP)as the key - Stores
NodeAndTime{na, time.Now()}in the map
Meanwhile, GetPeers:
- Iterates over the keys
- Calls
UnmarshalBinary([]byte(key))on each key
Potential issue
AddPeeris only storing the IP address string as the key.GetPeersappears to expect the key to be the full binary representation of aNodeAddr(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
Labels
No labels