-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ACK feature #215
ACK feature #215
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation, tests, and a thin implementation. LveryGTM
I think this PR would best be redone to add an optional boolean ack field to HAVE messages in hypercore protocol instead of setting length=0 on HAVEs. This would be less hacky and would also allow for ACKs over ranges of sequences. |
Updated this patch to depend on hypercore-protocol/hypercore-protocol#37 so the CI ought to fail until that gets merged upstream. |
lib/replicate.js
Outdated
@@ -30,6 +30,7 @@ function replicate (feed, opts) { | |||
var peer = new Peer(feed, opts) | |||
peer.feed = feed | |||
peer.stream = stream.feed(feed.key, {peer: peer}) | |||
peer._replicateStream = stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is stored at peer.stream.stream already (could be named better yes)
7.6.0 |
This PR is based on #130 but adds:
'ack'
event on the replication stream instead of emitting events through the peer instance (only available by listening onfeed.on('peer-add', fn)
and the peer instance isn't an EventEmitter in mainline anyways)The original technique in the ACK PR mostly works but creates a bit of extra noise with false positives. This extra noise would probably not be too much of an issue in practice for many use cases because any ACK'd records would also be present on the remote machine (if the remote is being honest). But setting the length to 0 for ACKs avoids this noise. A better option might be to add a special type for ACK messages, but this patch works with that is currently available in hypercore-protocol.
There are some legacy cases for length=0 in HAVEs but the ACK cases are narrow and only reachable when ACK is enabled and a bitfield is not set on the HAVE, which the legacy branch seems to expect.
If this patch is accepted it would be good to document the convention it depends on, where a HAVE with length=0 and no bitfield is considered an ACK. This also means that ACKs are limited to acknowledging individual sequences, not whole ranges at a time (since the length field is set to zero). Negative values could be used, but at that point I think it would be better to have a dedicated ACK message type.