@cryptotaxi247 / kubo / commits / a703e2d1f

comments

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Feb 3, 2018 at 14:45 UTC a703e2d1f2474ba5f82311ddb2a68d2668affed6
3 files changed +8
merkledag/merkledag.go
+1
@@ -146,6 +146,7 @@ func (sg *sesGetter) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.
146 return getNodesFromBG(ctx, sg.bs, keys)
147 }
148
149 +// Session returns a NodeGetter using a new session for block fetches.
150 func (ds *dagService) Session(ctx context.Context) ipld.NodeGetter {
151 return &sesGetter{bserv.NewSession(ctx, ds.Blocks)}
152 }
merkledag/readonly.go
+4
@@ -6,8 +6,12 @@ import (
6 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
7 )
8
9 +// ErrReadOnly is used when a read-only datastructure is written to.
10 var ErrReadOnly = fmt.Errorf("cannot write to readonly DAGService")
11
12 +// NewReadOnlyDagService takes a NodeGetter, and returns a full DAGService
13 +// implementation that returns ErrReadOnly when its 'write' methods are
14 +// invoked.
15 func NewReadOnlyDagService(ng ipld.NodeGetter) ipld.DAGService {
16 return &ComboService{
17 Read: ng,
merkledag/session.go
+3
@@ -6,10 +6,13 @@ import (
6 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
7 )
8
9 +// SessionMaker is an object that can generate a new fetching session.
10 type SessionMaker interface {
11 Session(context.Context) ipld.NodeGetter
12 }
13
14 +// NewSession returns a session backed NodeGetter if the given NodeGetter
15 +// implements SessionMaker.
16 func NewSession(ctx context.Context, g ipld.NodeGetter) ipld.NodeGetter {
17 if sm, ok := g.(SessionMaker); ok {
18 return sm.Session(ctx)