netsync: Embed peers vs separate peer states. #2541
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 a separate data structure which is keyed by the peer. This additional state is then queried each time it is needed. This leads to having to refer to the peer and the data associated with it via separate variables which makes the code harder to reason about than if it were all associated directly with the single peer variable.
Given that goal, this modifies the sync manager to introduce a new type named
syncMgrPeer
which embeds a regular peer from the peer package and adds additional information controlled by the sync manager. The mapping is still maintained as it was before, but each handler now looks up the new combined peer at the top and uses that single instance throughout the handler.The end result is the code is easier to reason about since there is no longer any question as to which state is being referred to as it all exists on the peer now.