-
Notifications
You must be signed in to change notification settings - Fork 112
Refactor: simplify session peer management #275
Conversation
@Stebalien |
@@ -164,44 +171,25 @@ func (s *Session) ID() uint64 { | |||
|
|||
// ReceiveFrom receives incoming blocks from the given peer. | |||
func (s *Session) ReceiveFrom(from peer.ID, ks []cid.Cid, haves []cid.Cid, dontHaves []cid.Cid) { | |||
// The SessionManager tells each Session about all keys that it may be | |||
// interested in. Here the Session filters the keys to the ones that this | |||
// particular Session is interested in. | |||
interestedRes := s.sim.FilterSessionInterested(s.id, ks, haves, dontHaves) | |||
ks = interestedRes[0] | |||
haves = interestedRes[1] | |||
dontHaves = interestedRes[2] | |||
// s.logReceiveFrom(from, ks, haves, dontHaves) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the isNewPeer
check below to be inside sessionPeerSender as it simplifies the logic there and consolidates changes to session peers in one place
// Update want potential | ||
s.sws.Update(from, ks, haves, dontHaves, isNewPeer) | ||
// Inform the session want sender that a message has been received | ||
s.sws.Update(from, ks, haves, dontHaves) | ||
|
||
if len(ks) == 0 { | ||
return | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the chunk of code below to be inside the run loop so we can get rid of locking
|
||
s.wm.BroadcastWantHaves(ctx, s.id, []cid.Cid{randomWant}) | ||
|
||
s.periodicSearchTimer.Reset(s.periodicSearchDelay.NextWaitTime()) | ||
} | ||
|
||
// findMorePeers attempts to find more peers for a session by searching for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I brought this function from inside of the SessionPeerManager to be in the Session instead, as it makes it easier to follow whats going on and simplifies the dependencies between Session, sessionWantSender and SessionPeerManager
@@ -12,7 +11,6 @@ import ( | |||
// sessionWants keeps track of which cids are waiting to be sent out, and which | |||
// peers are "live" - ie, we've sent a request but haven't received a block yet | |||
type sessionWants struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in sessionWants is basically just removing a bunch of locks that we no longer need as everything is inside the Session run loop now
Refactor: simplify session peer management This commit was moved from ipfs/go-bitswap@981dfb1
This refactor simplifies session peer management by