anacrolix / dht

dht is used by anacrolix/torrent, and is intended for use as a library in other projects both torrent related and otherwise
Mozilla Public License 2.0
309 stars 66 forks source link

Add NodeAddr equality and search methods #53

Closed yarikk closed 2 years ago

yarikk commented 2 years ago

Add NodeAddr.Equal() and CompactIPv[46]NodeAddrs.Index() methods.

Lifted from the PEX code in anacrolix/torrent.

@anacrolix

anacrolix commented 2 years ago

See https://github.com/anacrolix/dht/issues/33#issuecomment-989531282.

yarikk commented 2 years ago

See #33 (comment).

This one's not quite related to the topic of the marshaller change. This adds convenience methods for mutating the lists, making them suitable both for marshalling and for holding the data over many cycles and thus saving from extra alloc/copy overhead. We used to have (and use) the methods elsewhere; with this, they become a part of the API, covered with tests, and can be used in more applications if needed.