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: Embed peers vs separate peer states. #2541

Merged
merged 1 commit into from Jan 7, 2021

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Jan 2, 2021

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.

@davecgh davecgh added this to the 1.7.0 milestone Jan 2, 2021
internal/netsync/manager.go Outdated Show resolved Hide resolved
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.
@davecgh davecgh merged commit 03fbb56 into decred:master Jan 7, 2021
@davecgh davecgh deleted the netsync_embed_peers branch January 7, 2021 23:15
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.

None yet

4 participants