netsync: Export opaque peer and require it in API. #3201
Merged
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.
Suggestion cannot be applied right now. Please check back later.
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
andDonePeer
methods toPeerConnected
PeerDisconnected
in separate commits, respectively, to more clearly denote their purpose.