@@ -140,16 +140,6 @@ func (s *blockService) Allowlist() verifcid.Allowlist {
140140// directly.
141141// Sessions are lazily setup, this is cheap.
142142func NewSession (ctx context.Context , bs BlockService ) * Session {
143- ses := grabSessionFromContext (ctx , bs )
144- if ses != nil {
145- return ses
146- }
147-
148- return newSession (ctx , bs )
149- }
150-
151- // newSession is like [NewSession] but it does not attempt to reuse session from the existing context.
152- func newSession (ctx context.Context , bs BlockService ) * Session {
153143 return & Session {bs : bs , sesctx : ctx }
154144}
155145
@@ -232,10 +222,6 @@ func (s *blockService) AddBlocks(ctx context.Context, bs []blocks.Block) error {
232222// GetBlock retrieves a particular block from the service,
233223// Getting it from the datastore using the key (hash).
234224func (s * blockService ) GetBlock (ctx context.Context , c cid.Cid ) (blocks.Block , error ) {
235- if ses := grabSessionFromContext (ctx , s ); ses != nil {
236- return ses .GetBlock (ctx , c )
237- }
238-
239225 ctx , span := internal .StartSpan (ctx , "blockService.GetBlock" , trace .WithAttributes (attribute .Stringer ("CID" , c )))
240226 defer span .End ()
241227
@@ -295,10 +281,6 @@ func getBlock(ctx context.Context, c cid.Cid, bs BlockService, fetchFactory func
295281// the returned channel.
296282// NB: No guarantees are made about order.
297283func (s * blockService ) GetBlocks (ctx context.Context , ks []cid.Cid ) <- chan blocks.Block {
298- if ses := grabSessionFromContext (ctx , s ); ses != nil {
299- return ses .GetBlocks (ctx , ks )
300- }
301-
302284 ctx , span := internal .StartSpan (ctx , "blockService.GetBlocks" )
303285 defer span .End ()
304286
@@ -474,43 +456,6 @@ func (s *Session) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Blo
474456
475457var _ BlockGetter = (* Session )(nil )
476458
477- // ContextWithSession is a helper which creates a context with an embded session,
478- // future calls to [BlockGetter.GetBlock], [BlockGetter.GetBlocks] and [NewSession] with the same [BlockService]
479- // will be redirected to this same session instead.
480- // Sessions are lazily setup, this is cheap.
481- // It wont make a new session if one exists already in the context.
482- func ContextWithSession (ctx context.Context , bs BlockService ) context.Context {
483- if grabSessionFromContext (ctx , bs ) != nil {
484- return ctx
485- }
486- return EmbedSessionInContext (ctx , NewSession (ctx , bs ))
487- }
488-
489- // EmbedSessionInContext is like [ContextWithSession] but it allows to embed an existing session.
490- func EmbedSessionInContext (ctx context.Context , ses * Session ) context.Context {
491- // use ses.bs as a key, so if multiple blockservices use embeded sessions it gets dispatched to the matching blockservice.
492- return context .WithValue (ctx , ses .bs , ses )
493- }
494-
495- // grabSessionFromContext returns nil if the session was not found
496- // This is a private API on purposes, I dislike when consumers tradeoff compiletime typesafety with runtime typesafety,
497- // if this API is public it is too easy to forget to pass a [BlockService] or [Session] object around in your app.
498- // By having this private we allow consumers to follow the trace of where the blockservice is passed and used.
499- func grabSessionFromContext (ctx context.Context , bs BlockService ) * Session {
500- s := ctx .Value (bs )
501- if s == nil {
502- return nil
503- }
504-
505- ss , ok := s .(* Session )
506- if ! ok {
507- // idk what to do here, that kinda sucks, giveup
508- return nil
509- }
510-
511- return ss
512- }
513-
514459// grabAllowlistFromBlockservice never returns nil
515460func grabAllowlistFromBlockservice (bs BlockService ) verifcid.Allowlist {
516461 if bbs , ok := bs .(BoundedBlockService ); ok {
0 commit comments