Commit deacce76 authored by Jeromy's avatar Jeromy

comments

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent 7c2d481e
...@@ -146,6 +146,7 @@ func (sg *sesGetter) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld. ...@@ -146,6 +146,7 @@ func (sg *sesGetter) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.
return getNodesFromBG(ctx, sg.bs, keys) return getNodesFromBG(ctx, sg.bs, keys)
} }
// Session returns a NodeGetter using a new session for block fetches.
func (ds *dagService) Session(ctx context.Context) ipld.NodeGetter { func (ds *dagService) Session(ctx context.Context) ipld.NodeGetter {
return &sesGetter{bserv.NewSession(ctx, ds.Blocks)} return &sesGetter{bserv.NewSession(ctx, ds.Blocks)}
} }
......
...@@ -6,8 +6,12 @@ import ( ...@@ -6,8 +6,12 @@ import (
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format" ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
) )
// ErrReadOnly is used when a read-only datastructure is written to.
var ErrReadOnly = fmt.Errorf("cannot write to readonly DAGService") var ErrReadOnly = fmt.Errorf("cannot write to readonly DAGService")
// NewReadOnlyDagService takes a NodeGetter, and returns a full DAGService
// implementation that returns ErrReadOnly when its 'write' methods are
// invoked.
func NewReadOnlyDagService(ng ipld.NodeGetter) ipld.DAGService { func NewReadOnlyDagService(ng ipld.NodeGetter) ipld.DAGService {
return &ComboService{ return &ComboService{
Read: ng, Read: ng,
......
...@@ -6,10 +6,13 @@ import ( ...@@ -6,10 +6,13 @@ import (
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format" ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
) )
// SessionMaker is an object that can generate a new fetching session.
type SessionMaker interface { type SessionMaker interface {
Session(context.Context) ipld.NodeGetter Session(context.Context) ipld.NodeGetter
} }
// NewSession returns a session backed NodeGetter if the given NodeGetter
// implements SessionMaker.
func NewSession(ctx context.Context, g ipld.NodeGetter) ipld.NodeGetter { func NewSession(ctx context.Context, g ipld.NodeGetter) ipld.NodeGetter {
if sm, ok := g.(SessionMaker); ok { if sm, ok := g.(SessionMaker); ok {
return sm.Session(ctx) return sm.Session(ctx)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment