gluxon / wireguard-uapi-rs

MIT License
32 stars 10 forks source link

get: Make device peer vector a map #25

Open ernestask opened 2 years ago

ernestask commented 2 years ago

Currently, peers in a device are stored as a vector, which requires iterating to find a peer by its public key, so this commit changes it to be a hash map.

gluxon commented 2 years ago

I've had a bit of difficulty deciding whether the types returned from this library should be easy to use or reflective of the raw Netlink responses. Although a map is certainly more useful, the original intention was to mimic the raw response.

I think there's good arguments both ways. Is the primary advantage of returning a map directly to avoid a O(n) passthrough on the Vec<Peers> after the response is serialized? Or are there other advantages I'm forgetting?

ernestask commented 2 years ago

I guess you do have a point here, because my use case is holding a map of peers at runtime for constant-time access. Serialization and deserialization is more a happy accident. The peculiarity of largely reimplementing the data structures with one field having a different type (and, of course, the reimplemented serialization code) made me want to propose this.