Skip to content

emit peer-synchronize when a peer's synchronize message is processed#847

Open
gmaclennan wants to merge 1 commit into
holepunchto:mainfrom
gmaclennan:add-peer-synchronize-event
Open

emit peer-synchronize when a peer's synchronize message is processed#847
gmaclennan wants to merge 1 commit into
holepunchto:mainfrom
gmaclennan:add-peer-synchronize-event

Conversation

@gmaclennan

Copy link
Copy Markdown
Contributor

peer-add is emitted before a peer has sent anything, so there is currently no way to observe when a peer's remote state (peer.remoteLength, peer.remoteFork, peer.remoteSynced) becomes known or changes.

This PR emits a peer-synchronize session event, mirroring peer-add/peer-remove, after a synchronize message has updated the peer's remote state fields. The emission is placed before the closeIfIdle() early-return so it also fires for sessions that immediately idle-close.

The first emission for a peer marks the completion of its handshake.

No behavior change; observability only.

Use case: CoMapeo tracks per-peer replication state (sync progress across a set of devices) and needs to know when a peer's length handshake has completed. We've previously been using core.update({ wait: true }) for this, which is wrong because it resolves immediately for writable cores, resolves for all waiters when any peer supplies an upgrade, and samples at most MAX_PEERS_UPGRADE peers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant