/ c-toxcore Publicforked from irungentoo/toxcore
forget DHT pubkey of offline friend after DHT timeout #615
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge.
According to my tests, this fixes #240. I expect it also fixes #237.
The problem was as follows: if a friend goes offline for long enough, we stop
searching for them on the DHT, but then if they come back with the same DHT key
(as will be the case if the network connection was interrupted but their client
wasn't restarted), prior to this patch we didn't initiate a new search.
The reason that it took two disconnections for this to cause a problem is that
we keep information on their ip address and tcp relays, and attempt to reuse
after a disconnect if there's still a DHT search ongoing. So if the first
disconnect lasted for at least 122s, the DHT search was deleted, but we could
still connect back using the old details once they reconnected; but then on a
subsequent disconnect, the old details wouldn't be used and nor would a DHT
search start up, so we'd never reconnect to the friend.
This PR zeroes out the friend's DHT PK when we delete them from the DHT, so the
next dhtpk packet we get from them will trigger us to add them back to the DHT
This change is