webtorrent/bittorrent-dht

dht.get returns different sequence results each time

talarari opened this issue · 8 comments

i'm trying to put mutable data, update it and retrieve it (with get).
i'm incrementing the seq property every time i update the data.
but when i use dht.get to retrieve it, i get a different seq every time.

according to this: http://bittorrent.org/beps/bep_0044.html
there should be way to specify a min seq number in the get request, is this possible?

my goal is to be able to get the latest version of the item given the key hash only, how would you propose doing that?

@talarari Does this PR fix your issue? #158

My fix doesn't address this:

there should be way to specify a min seq number in the get request, is this possible?

Before seeing this issue, I had discovered that updating a mutable value sometimes didn't work because I was incrementing the sequence seq obtained from get, and get sometimes returned an outdated seq. Some debugging revealed the cause: get requests values from multiple nodes but when a new reply arrives the previous value is overwritten. The final value to arrive is the one ultimately returned by get and it sometimes is an obsolete value with an outdated seq. Basing the new seq on the outdated one results in the subsequent put only being accepted by a few outdated nodes. After fixing this by having get return the value corresponding to the greatest seq, updating always works for me.

It may be worthwhile to add the new feature you suggest, but perhaps my fix is adequate.

@feross
i think it will.
after upgrading to 7.5.2 i get the latest value.but it seems like this pull request is still not in, so that might be just luck

actually 7.5.2 still has this problem, getting old values and new randomly.

I should mention that I get consistently reliable results (with the fix) only when the DHT is persistent. My test program only does one update at a time, so I must restart it to make the next update. I load previously saved nodes with each invocation of the test program. I also persist the nodeId.

If I bootstrap the DHT with fresh nodes each time, get is unreliable. It often retrieves five or fewer values, and of these often several or even all are outdated. With the above approach, get often retrieves twenty or more values, with the majority up-to-date; it works every time I test it.

Cool, it sounds like @metamystical's PR is probably sufficient to fix this issue without offering a way to specific a seq number.

The continuing issues @metamystical and @talarari are still seeing may be due to #167. When I applied this patch and also #176 I found that problems like:

getting old values and new randomly.

are now gone.

Should be fixed in 8. If not please re-open.