Skip to content
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

netsync: Export opaque peer and require it in API. #3201

Merged
merged 3 commits into from
Oct 29, 2023

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Oct 26, 2023

Currently the sync manager maintains additional state per peer in an internal struct that wraps a base/common peer as well as a mapping keyed by that base/common peer. The internal wrapped peer is then queried each time it is needed. This leads to code that is harder to reason about and can fail to lookup the necessary state in some hard to hit corner cases.

With that in mind, this modifies the sync manager semantics to instead export the wrapped peer and require the caller to provide that wrapped peer in all of its APIs directly. The server then creates and stores the wrapped peer instance at connection time and passes it to the sync manager.

The end result is the code is easier to reason about and resolves the aforementioned hard to hit corner cases since it is no longer possible for the sync manager to ever have access to a peer without the associated extra state.

It also renames a the NewPeer and DonePeer methods to PeerConnected PeerDisconnected in separate commits, respectively, to more clearly denote their purpose.

@davecgh davecgh added this to the 1.9.0 milestone Oct 26, 2023
@davecgh davecgh changed the title netsync: Export opaque peer and required it in API. netsync: Export opaque peer and require it in API. Oct 26, 2023
This renames the NewPeer method to PeerConnected to more clearly denote
its purpose.  It also renames some of the internal plumbing to match.
This renames the DonePeer method to PeerDisconnected to more clearly
denote its purpose.  It also renames some of the internal plumbing to
match.
Currently the sync manager maintains additional state per peer in an
internal struct that wraps a base/common peer as well as a mapping keyed
by that base/common peer.  The internal wrapped peer is then queried
each time it is needed.  This leads to code that is harder to reason
about and can fail to lookup the necessary state in some hard to hit
corner cases.

With that in mind, this modifies the sync manager semantics to instead
export the wrapped peer and require the caller to provide that wrapped
peer in all of its APIs directly.  The server then creates and stores
the wrapped peer instance at connection time and passes it to the sync
manager.

The end result is the code is easier to reason about and resolves the
aforementioned hard to hit corner cases since it is no longer possible
for the sync manager to ever have access to a peer without the
associated extra state.
@davecgh davecgh merged commit 517091c into decred:master Oct 29, 2023
2 checks passed
@davecgh davecgh deleted the netsync_exported_peer branch October 29, 2023 00:10
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.

3 participants