truvorskameikin / udp-discovery-cpp

A small library to add local network discovery feature to your C++ programs with no dependencies
MIT License
60 stars 28 forks source link

PacketIndex is increased even when userdata didn't change #18

Open zapek opened 3 years ago

zapek commented 3 years ago

When a packet is received, packet_index is checked for increments to see if the userdata needs to be updated: https://github.com/truvorskameikin/udp-discovery-cpp/blob/63eda22d3f8a415324d99208011bc4f2b6583a7e/udp_discovery_peer.cpp#L351

But here: https://github.com/truvorskameikin/udp-discovery-cpp/blob/63eda22d3f8a415324d99208011bc4f2b6583a7e/udp_discovery_peer.cpp#L397

packet_index is incremented everytime a packet is sent, even if the userdata didn't change.

Shouldn't it be increased only if the userdata changed?

truvorskameikin commented 3 years ago

That is a good idea to not increment packet_index every send. And I think that it also can be renamed to something like snapshot_index. Now it should increase on every user_data change.