-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
kind/enhancementA net-new feature or improvement to an existing featureA net-new feature or improvement to an existing feature
Description
Currently, bitswap has a concept of "sessions" for related requests. However:
- Using usually means reconstructing the storage stack starting at the exchange. I.e., make the session, create a new blockservice, wrap it in a dagservice, etc.
- Sessions are hard to compose. We currently handle this by creating the session in the top-level command but it would be nice if commands could recursively "create" sessions kind of like a re-entrant mutex.
- Sessions are specific to the exchange, even when we have multiple components that should all logically be associated with the session.
Proposal: Extract the session concept from bitswap and stash the session handle in the context. Ideally, sessions would be generic peer/request trackers that track how useful each connected peer is over the course of the session.
Pros:
- We can share session information between subsystems.
- We can pre-seed these sessions with additional information (e.g. providers) from the request.
- Sessions become entirely implicit. We only need to care about them at the very top level where we decide that we're making an independent request.
Cons:
- Will take some refactoring. We can make a simple version that just stashes a shared ID in the context and then slowly move from there.
Basic Interface:
// Begin begins a new session if there are no sessions associated with the context.
func Begin(ctx context.Context) (context.Context, context.CancelFunc) {}
// Leave dissociates the context with the current session.
func Leave(ctx context.Context) (context.Context) {}
// Fork forks off a new session, inheriting the state of the current session.
// Ok, we can probably leave this till later...
func Fork(ctx context.Context) (context.Context, context.CancelFunc) {}
// GetSession returns the session associated with this context, if any.
func GetSession(ctx context.Context) Session {}
type Session interface {
func AddPeer(pi AddrInfo) // or maybe just a peer ID?
// Eventually, this will contain other peer-management methods.
}Usage:
ctx, cancel := session.Begin(ctx)
defer cancel()
block, err := myDag.Get(ctx, thing)
// look ma, no sessions!Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
kind/enhancementA net-new feature or improvement to an existing featureA net-new feature or improvement to an existing feature