Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-merkledag
Commits
deacce76
Commit
deacce76
authored
Feb 03, 2018
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comments
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
7c2d481e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
0 deletions
+8
-0
merkledag.go
merkledag.go
+1
-0
readonly.go
readonly.go
+4
-0
session.go
session.go
+3
-0
No files found.
merkledag.go
View file @
deacce76
...
@@ -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
)}
}
}
...
...
readonly.go
View file @
deacce76
...
@@ -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
,
...
...
session.go
View file @
deacce76
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment