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
a967e017
Commit
a967e017
authored
Oct 25, 2014
by
Emery Hemingway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert DAGService to an interface
parent
d08cbc10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
10 deletions
+22
-10
merkledag.go
merkledag.go
+22
-10
No files found.
merkledag.go
View file @
a967e017
...
...
@@ -62,7 +62,7 @@ func MakeLink(n *Node) (*Link, error) {
},
nil
}
func
(
l
*
Link
)
GetNode
(
serv
*
DAGService
)
(
*
Node
,
error
)
{
func
(
l
*
Link
)
GetNode
(
serv
DAGService
)
(
*
Node
,
error
)
{
if
l
.
Node
!=
nil
{
return
l
.
Node
,
nil
}
...
...
@@ -151,20 +151,32 @@ func (n *Node) Key() (u.Key, error) {
}
// DAGService is an IPFS Merkle DAG service.
type
DAGService
interface
{
Add
(
*
Node
)
(
u
.
Key
,
error
)
AddRecursive
(
*
Node
)
error
Get
(
u
.
Key
)
(
*
Node
,
error
)
Remove
(
*
Node
)
error
}
func
NewDAGService
(
bs
*
bserv
.
BlockService
)
DAGService
{
return
&
dagService
{
bs
}
}
// dagService is an IPFS Merkle DAG service.
// - the root is virtual (like a forest)
// - stores nodes' data in a BlockService
// TODO: should cache Nodes that are in memory, and be
// able to free some of them when vm pressure is high
type
DAG
Service
struct
{
type
dag
Service
struct
{
Blocks
*
bserv
.
BlockService
}
// Add adds a node to the
DAG
Service, storing the block in the BlockService
func
(
n
*
DAG
Service
)
Add
(
nd
*
Node
)
(
u
.
Key
,
error
)
{
// Add adds a node to the
dag
Service, storing the block in the BlockService
func
(
n
*
dag
Service
)
Add
(
nd
*
Node
)
(
u
.
Key
,
error
)
{
k
,
_
:=
nd
.
Key
()
log
.
Debug
(
"DagService Add [%s]"
,
k
)
if
n
==
nil
{
return
""
,
fmt
.
Errorf
(
"
DAG
Service is nil"
)
return
""
,
fmt
.
Errorf
(
"
dag
Service is nil"
)
}
d
,
err
:=
nd
.
Encoded
(
false
)
...
...
@@ -182,7 +194,7 @@ func (n *DAGService) Add(nd *Node) (u.Key, error) {
return
n
.
Blocks
.
AddBlock
(
b
)
}
func
(
n
*
DAG
Service
)
AddRecursive
(
nd
*
Node
)
error
{
func
(
n
*
dag
Service
)
AddRecursive
(
nd
*
Node
)
error
{
_
,
err
:=
n
.
Add
(
nd
)
if
err
!=
nil
{
log
.
Info
(
"AddRecursive Error: %s
\n
"
,
err
)
...
...
@@ -201,10 +213,10 @@ func (n *DAGService) AddRecursive(nd *Node) error {
return
nil
}
// Get retrieves a node from the
DAG
Service, fetching the block in the BlockService
func
(
n
*
DAG
Service
)
Get
(
k
u
.
Key
)
(
*
Node
,
error
)
{
// Get retrieves a node from the
dag
Service, fetching the block in the BlockService
func
(
n
*
dag
Service
)
Get
(
k
u
.
Key
)
(
*
Node
,
error
)
{
if
n
==
nil
{
return
nil
,
fmt
.
Errorf
(
"
DAG
Service is nil"
)
return
nil
,
fmt
.
Errorf
(
"
dag
Service is nil"
)
}
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
time
.
Second
*
5
)
...
...
@@ -216,7 +228,7 @@ func (n *DAGService) Get(k u.Key) (*Node, error) {
return
Decoded
(
b
.
Data
)
}
func
(
n
*
DAG
Service
)
Remove
(
nd
*
Node
)
error
{
func
(
n
*
dag
Service
)
Remove
(
nd
*
Node
)
error
{
for
_
,
l
:=
range
nd
.
Links
{
if
l
.
Node
!=
nil
{
n
.
Remove
(
l
.
Node
)
...
...
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