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

Abstract Sessions #6525

Open
Stebalien opened this issue Jul 16, 2019 · 0 comments
Open

Abstract Sessions #6525

Stebalien opened this issue Jul 16, 2019 · 0 comments
Labels
kind/enhancement A net-new feature or improvement to an existing feature

Comments

@Stebalien
Copy link
Member

Stebalien commented Jul 16, 2019

Currently, bitswap has a concept of "sessions" for related requests. However:

  1. 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.
  2. 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.
  3. 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!
@Stebalien Stebalien added the kind/enhancement A net-new feature or improvement to an existing feature label Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A net-new feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant