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
6db5ce44
Commit
6db5ce44
authored
Sep 06, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rework dagreader to have a dagservice for node resolution
parent
24257b36
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
4 deletions
+38
-4
dagreader.go
dagreader.go
+36
-4
merkledag.go
merkledag.go
+2
-0
No files found.
dagreader.go
View file @
6db5ce44
...
...
@@ -5,20 +5,22 @@ import (
"errors"
"io"
"code.google.com/p/goprotobuf/proto"
proto
"code.google.com/p/goprotobuf/proto"
u
"github.com/jbenet/go-ipfs/util"
)
var
ErrIsDir
=
errors
.
New
(
"this dag node is a directory."
)
// DagReader provides a way to easily read the data contained in a dag.
type
DagReader
struct
{
serv
*
DAGService
node
*
Node
position
int
buf
*
bytes
.
Buffer
thisData
[]
byte
}
func
NewDagReader
(
n
*
Node
)
(
io
.
Reader
,
error
)
{
func
NewDagReader
(
n
*
Node
,
serv
*
DAGService
)
(
io
.
Reader
,
error
)
{
pb
:=
new
(
PBData
)
err
:=
proto
.
Unmarshal
(
n
.
Data
,
pb
)
if
err
!=
nil
{
...
...
@@ -31,6 +33,7 @@ func NewDagReader(n *Node) (io.Reader, error) {
return
&
DagReader
{
node
:
n
,
thisData
:
pb
.
GetData
(),
serv
:
serv
,
},
nil
case
PBData_Raw
:
return
bytes
.
NewBuffer
(
pb
.
GetData
()),
nil
...
...
@@ -46,8 +49,11 @@ func (dr *DagReader) precalcNextBuf() error {
nxtLink
:=
dr
.
node
.
Links
[
dr
.
position
]
nxt
:=
nxtLink
.
Node
if
nxt
==
nil
{
//TODO: should use dagservice or something to get needed block
return
errors
.
New
(
"Link to nil node! Tree not fully expanded!"
)
nxtNode
,
err
:=
dr
.
serv
.
Get
(
u
.
Key
(
nxtLink
.
Hash
))
if
err
!=
nil
{
return
err
}
nxt
=
nxtNode
}
pb
:=
new
(
PBData
)
err
:=
proto
.
Unmarshal
(
nxt
.
Data
,
pb
)
...
...
@@ -96,3 +102,29 @@ func (dr *DagReader) Read(b []byte) (int, error) {
}
}
}
/*
func (dr *DagReader) Seek(offset int64, whence int) (int64, error) {
switch whence {
case os.SEEK_SET:
for i := 0; i < len(dr.node.Links); i++ {
nsize := dr.node.Links[i].Size - 8
if offset > nsize {
offset -= nsize
} else {
break
}
}
dr.position = i
err := dr.precalcNextBuf()
if err != nil {
return 0, err
}
case os.SEEK_CUR:
case os.SEEK_END:
default:
return 0, errors.New("invalid whence")
}
return 0, nil
}
*/
merkledag.go
View file @
6db5ce44
...
...
@@ -96,6 +96,8 @@ func (n *Node) Key() (u.Key, error) {
// 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
DAGService
struct
{
Blocks
*
bserv
.
BlockService
}
...
...
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