-
Notifications
You must be signed in to change notification settings - Fork 112
Bitswap Refactor #3: Extract sessions to package #30
Conversation
c320f0a
to
03f4615
Compare
5eb506e
to
604ae5e
Compare
03f4615
to
ac45ed0
Compare
- moved sessions out of main bitswap package - modified session manager to manage all sessions - moved get functions to their own package so sessions can directly BREAKING CHANGE: SessionsForBlock, while not used outside of Bitswap, has been removed, and was an exported function
604ae5e
to
40aa1fb
Compare
@Stebalien @whyrusleeping @michaelavila @eingenito @lanzafame @schomatis @parkan This is now the next part to review, if/when you have time. |
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.
This looks correct and is a nice improvement. I think there's some room to further decouple things but we can do that later without much difficulty.
LGTM modulo the odd loop in NewSession
.
session/session.go
Outdated
logging "github.com/ipfs/go-log" | ||
loggables "github.com/libp2p/go-libp2p-loggables" | ||
peer "github.com/libp2p/go-libp2p-peer" | ||
) | ||
|
||
const activeWantsLimit = 16 | ||
|
||
// SessionWantmanager is an interface that can be used to request blocks |
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.
nit: SessionWantManager.
type SessionWantManager interface { | ||
WantBlocks(ctx context.Context, ks []cid.Cid, peers []peer.ID, ses uint64) | ||
CancelWants(ctx context.Context, ks []cid.Cid, peers []peer.ID, ses uint64) | ||
} |
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.
Thought for a future direction (we can leave this as-is for now, I really like the architecture):
type WantManager interface {
AddWants(ctx context.Context, ks []cid.Cid, peers []peer.ID)
CancelWants(ctx context.Context, ks []cid.Cid, peers []peer.ID)
}
That is, we're currently:
- Constructing a session, passing in a session ID and a SessionWantManager.
- Expecting that SessionWantManager to pass the ID back for each request.
Instead, we could construct a thin helper type implementing the WantManager
interface that remembers the session ID.
But we can leave this for later, if ever.
sessionmanager/sessionmanager.go
Outdated
sm.sessLk.Lock() | ||
sm.sessions = append(sm.sessions, session) | ||
sm.sessLk.Unlock() | ||
go func() { | ||
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.
Any reason for the loop?
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.
oh, you're right. good catch. :)
remove for loop not needed, cleanup spelling
defer cancel() | ||
select { | ||
case <-sm.ctx.Done(): | ||
sm.removeSession(session) |
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.
Nit: duplicate code. We can replace this with:
defer cancel()
select {
case <-sm.ctx.Done():
case <-ctx.Done():
}
sm.removeSession(session)
(this has been up for long enough, feel free to merge when you're ready) |
Bitswap Refactor ipfs#3: Extract sessions to package This commit was moved from ipfs/go-bitswap@1e9b2c4
Goals
Modularize Bitswap in preparation for attempts to optimize bitswap further
child of #26
Implementation
BREAKING CHANGE: SessionsForBlock, while not used outside of Bitswap, has been removed, and was an exported function