本文整理汇总了Golang中github.com/ipfs/go-ipfs/merkledag.Node类的典型用法代码示例。如果您正苦于以下问题:Golang Node类的具体用法?Golang Node怎么用?Golang Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: readHdr
func readHdr(n *merkledag.Node) (*pb.Set, []byte, error) {
hdrLenRaw, consumed := binary.Uvarint(n.Data())
if consumed <= 0 {
return nil, nil, errors.New("invalid Set header length")
}
buf := n.Data()[consumed:]
if hdrLenRaw > uint64(len(buf)) {
return nil, nil, errors.New("impossibly large Set header length")
}
// as hdrLenRaw was <= an int, we now know it fits in an int
hdrLen := int(hdrLenRaw)
var hdr pb.Set
if err := proto.Unmarshal(buf[:hdrLen], &hdr); err != nil {
return nil, nil, err
}
buf = buf[hdrLen:]
if v := hdr.GetVersion(); v != 1 {
return nil, nil, fmt.Errorf("unsupported Set version: %d", v)
}
if uint64(hdr.GetFanout()) > uint64(len(n.Links)) {
return nil, nil, errors.New("impossibly large Fanout")
}
return &hdr, buf, nil
}
开发者ID:yanghongkjxy,项目名称:go-ipfs,代码行数:25,代码来源:set.go
示例2: writeRefsSingle
func (rw *RefWriter) writeRefsSingle(n *dag.Node) (int, error) {
nkey, err := n.Key()
if err != nil {
return 0, err
}
if rw.skip(nkey) {
return 0, nil
}
count := 0
for _, l := range n.Links {
lk := key.Key(l.Hash)
if rw.skip(lk) {
continue
}
if err := rw.WriteEdge(nkey, lk, l.Name); err != nil {
return count, err
}
count++
}
return count, nil
}
开发者ID:Patagonicus,项目名称:go-ipfs,代码行数:25,代码来源:refs.go
示例3: NewDagReader
// NewDagReader creates a new reader object that reads the data represented by
// the given node, using the passed in DAGService for data retreival
func NewDagReader(ctx context.Context, n *mdag.Node, serv mdag.DAGService) (*DagReader, error) {
pb := new(ftpb.Data)
if err := proto.Unmarshal(n.Data(), pb); err != nil {
return nil, err
}
switch pb.GetType() {
case ftpb.Data_Directory:
// Dont allow reading directories
return nil, ErrIsDir
case ftpb.Data_Raw:
fallthrough
case ftpb.Data_File:
return NewDataFileReader(ctx, n, pb, serv), nil
case ftpb.Data_Metadata:
if len(n.Links) == 0 {
return nil, errors.New("incorrectly formatted metadata object")
}
child, err := n.Links[0].GetNode(ctx, serv)
if err != nil {
return nil, err
}
return NewDagReader(ctx, child, serv)
case ftpb.Data_Symlink:
return nil, ErrCantReadSymlinks
default:
return nil, ft.ErrUnrecognizedType
}
}
开发者ID:yanghongkjxy,项目名称:go-ipfs,代码行数:31,代码来源:dagreader.go
示例4: search
//search serches nearest and bigger than stamp and update all DAG after calling func f if needed.
func (t *Thread) search(root *merkledag.Node, stamp time.Time,
f func(bool, *merkledag.Node) (bool, error)) (*merkledag.Node, error) {
link, err := getLinkName(root)
if log.If(err) {
return nil, err
}
var eq bool
if link != nil {
eq = link.stamp.Equal(stamp)
}
if link == nil || (eq || link.stamp.Before(stamp)) {
updated, errr := f(eq, root)
log.If(errr)
if updated {
return root, errr
}
return nil, errr
}
n, err := t.self.GetLinkedNode(root, link.string())
if log.If(err) {
return nil, err
}
updated, err := t.search(n, stamp, f)
if err != nil {
return nil, err
}
if updated != nil {
root, err = root.UpdateNodeLink(link.string(), updated)
log.If(err)
return root, err
}
return nil, err
}
开发者ID:utamaro,项目名称:core,代码行数:34,代码来源:thread.go
示例5: randNode
func randNode() (*mdag.Node, key.Key) {
nd := new(mdag.Node)
nd.Data = make([]byte, 32)
util.NewTimeSeededRand().Read(nd.Data)
k, _ := nd.Key()
return nd, k
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:7,代码来源:pin_test.go
示例6: writeRefsRecursive
func (rw *RefWriter) writeRefsRecursive(n *dag.Node) (int, error) {
nkey, err := n.Key()
if err != nil {
return 0, err
}
var count int
for i, ng := range rw.DAG.GetDAG(rw.Ctx, n) {
lk := key.Key(n.Links[i].Hash)
if rw.skip(lk) {
continue
}
if err := rw.WriteEdge(nkey, lk, n.Links[i].Name); err != nil {
return count, err
}
nd, err := ng.Get(rw.Ctx)
if err != nil {
return count, err
}
c, err := rw.writeRefsRecursive(nd)
count += c
if err != nil {
return count, err
}
}
return count, nil
}
开发者ID:Patagonicus,项目名称:go-ipfs,代码行数:30,代码来源:refs.go
示例7: randNode
func randNode() (*merkledag.Node, key.Key) {
node := new(merkledag.Node)
node.Data = make([]byte, 32)
util.NewTimeSeededRand().Read(node.Data)
k, _ := node.Key()
return node, k
}
开发者ID:ccsblueboy,项目名称:go-ipfs,代码行数:7,代码来源:resolver_test.go
示例8: deserializeNode
// converts the Node object into a real dag.Node
func deserializeNode(node *Node, dataFieldEncoding string) (*dag.Node, error) {
dagnode := new(dag.Node)
switch dataFieldEncoding {
case "text":
dagnode.Data = []byte(node.Data)
case "base64":
dagnode.Data, _ = base64.StdEncoding.DecodeString(node.Data)
default:
return nil, fmt.Errorf("Unkown data field encoding")
}
dagnode.Links = make([]*dag.Link, len(node.Links))
for i, link := range node.Links {
hash, err := mh.FromB58String(link.Hash)
if err != nil {
return nil, err
}
dagnode.Links[i] = &dag.Link{
Name: link.Name,
Size: link.Size,
Hash: hash,
}
}
return dagnode, nil
}
开发者ID:kpcyrd,项目名称:go-ipfs,代码行数:27,代码来源:object.go
示例9: FromDAGNode
//FromDAGNode creates Records from links of merkledag n and retuns it.
//links must contain "Stamp" and "Thread"
func FromDAGNode(self *peer.Self, n *merkledag.Node, sign []byte) (*Record, error) {
r := &Record{
self: self,
Stamp: time.Unix(0, 0),
Sign: sign,
Contents: make(map[string][]byte),
}
var err error
r.Key, err = n.Key()
if log.If(err) {
return nil, err
}
for _, l := range n.Links {
nn, err := r.self.GetLinkedNode(n, l.Name)
if log.If(err) {
return nil, err
}
r.Contents[l.Name] = nn.Data
switch l.Name {
case "thread":
r.Thread = string(nn.Data)
case "stamp":
stamp := binary.BigEndian.Uint64(nn.Data)
r.Stamp = time.Unix(0, int64(stamp))
}
}
if err := r.check(false); log.If(err) {
return nil, err
}
return r, nil
}
开发者ID:utamaro,项目名称:core,代码行数:33,代码来源:record.go
示例10: AddMetadataTo
func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error) {
ukey := key.B58KeyDecode(skey)
nd, err := n.DAG.Get(n.Context(), ukey)
if err != nil {
return "", err
}
mdnode := new(dag.Node)
mdata, err := ft.BytesForMetadata(m)
if err != nil {
return "", err
}
mdnode.Data = mdata
if err := mdnode.AddNodeLinkClean("file", nd); err != nil {
return "", err
}
nk, err := n.DAG.Add(mdnode)
if err != nil {
return "", err
}
return nk.B58String(), nil
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:26,代码来源:metadata.go
示例11: Mkdir
func (d *Directory) Mkdir(name string) (*Directory, error) {
d.lock.Lock()
defer d.lock.Unlock()
fsn, err := d.childUnsync(name)
if err == nil {
switch fsn := fsn.(type) {
case *Directory:
return fsn, os.ErrExist
case *File:
return nil, os.ErrExist
default:
return nil, fmt.Errorf("unrecognized type: %#v", fsn)
}
}
ndir := new(dag.Node)
ndir.SetData(ft.FolderPBData())
_, err = d.dserv.Add(ndir)
if err != nil {
return nil, err
}
err = d.node.AddNodeLinkClean(name, ndir)
if err != nil {
return nil, err
}
dirobj := NewDirectory(d.ctx, name, ndir, d, d.dserv)
d.childDirs[name] = dirobj
return dirobj, nil
}
开发者ID:yanghongkjxy,项目名称:go-ipfs,代码行数:33,代码来源:dir.go
示例12: addNode
func (adder *Adder) addNode(node *dag.Node, path string) error {
// patch it into the root
if path == "" {
key, err := node.Key()
if err != nil {
return err
}
path = key.Pretty()
}
dir := gopath.Dir(path)
if dir != "." {
if err := mfs.Mkdir(adder.mr, dir, true, false); err != nil {
return err
}
}
if err := mfs.PutNode(adder.mr, path, node); err != nil {
return err
}
if !adder.Silent {
return outputDagnode(adder.out, path, node)
}
return nil
}
开发者ID:kalmi,项目名称:go-ipfs,代码行数:27,代码来源:add.go
示例13: printDag
func printDag(nd *mdag.Node, ds mdag.DAGService, indent int) {
pbd, err := ft.FromBytes(nd.Data())
if err != nil {
panic(err)
}
for i := 0; i < indent; i++ {
fmt.Print(" ")
}
fmt.Printf("{size = %d, type = %s, children = %d", pbd.GetFilesize(), pbd.GetType().String(), len(pbd.GetBlocksizes()))
if len(nd.Links) > 0 {
fmt.Println()
}
for _, lnk := range nd.Links {
child, err := lnk.GetNode(context.Background(), ds)
if err != nil {
panic(err)
}
printDag(child, ds, indent+1)
}
if len(nd.Links) > 0 {
for i := 0; i < indent; i++ {
fmt.Print(" ")
}
}
fmt.Println("}")
}
开发者ID:yiwang,项目名称:go-ipfs,代码行数:27,代码来源:dagmodifier_test.go
示例14: updateLink
func (t *Thread) updateLink(n *merkledag.Node, stamp time.Time) func(bool, *merkledag.Node) (bool, error) {
return func(exist bool, prev *merkledag.Node) (bool, error) {
if exist {
return false, nil
}
pren, err := getLinkName(prev)
if log.If(err) {
return false, err
}
if pren != nil {
log.Println(pren.stamp)
pn := pren.string()
raw, errr := prev.GetNodeLink(pn)
if log.If(errr) {
return false, errr
}
if errr := n.AddRawLink(pn, raw); log.If(errr) {
return false, errr
}
if errr := prev.RemoveNodeLink(pn); log.If(errr) {
return false, errr
}
}
name := &linkName{stamp: stamp}
log.Println(name.stamp)
if err := prev.AddNodeLink(name.string(), n); log.If(err) {
return false, err
}
log.If(err)
return true, err
}
}
开发者ID:utamaro,项目名称:core,代码行数:33,代码来源:thread.go
示例15: addLink
func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname string, childnd *dag.Node) (*dag.Node, error) {
if childname == "" {
return nil, errors.New("cannot create link with no name!")
}
// ensure that the node we are adding is in the dagservice
_, err := ds.Add(childnd)
if err != nil {
return nil, err
}
_ = ds.Remove(root)
// ensure no link with that name already exists
_ = root.RemoveNodeLink(childname) // ignore error, only option is ErrNotFound
if err := root.AddNodeLinkClean(childname, childnd); err != nil {
return nil, err
}
if _, err := ds.Add(root); err != nil {
return nil, err
}
return root, nil
}
开发者ID:yiwang,项目名称:go-ipfs,代码行数:25,代码来源:utils.go
示例16: NewDagModifier
func NewDagModifier(ctx context.Context, from *mdag.Node, serv mdag.DAGService, spl chunk.SplitterGen) (*DagModifier, error) {
return &DagModifier{
curNode: from.Copy(),
dagserv: serv,
splitter: spl,
ctx: ctx,
}, nil
}
开发者ID:musha68k,项目名称:go-ipfs,代码行数:8,代码来源:dagmodifier.go
示例17: nodeType
// nodeType returns the record node's type link value.
func nodeType(nd *dag.Node) ([]byte, error) {
tl, err := nd.GetNodeLink(linkType)
if err != nil {
return nil, fmt.Errorf("invalid record. failed to get link %s (%s)", linkType, err)
}
return tl.Hash, nil
}
开发者ID:ipfs,项目名称:go-iprs,代码行数:9,代码来源:coding.go
示例18: verifyTDagRec
// Recursive call for verifying the structure of a trickledag
func verifyTDagRec(nd *dag.Node, depth, direct, layerRepeat int, ds dag.DAGService) error {
if depth == 0 {
// zero depth dag is raw data block
if len(nd.Links) > 0 {
return errors.New("expected direct block")
}
pbn, err := ft.FromBytes(nd.Data())
if err != nil {
return err
}
if pbn.GetType() != ft.TRaw {
return errors.New("Expected raw block")
}
return nil
}
// Verify this is a branch node
pbn, err := ft.FromBytes(nd.Data())
if err != nil {
return err
}
if pbn.GetType() != ft.TFile {
return errors.New("expected file as branch node")
}
if len(pbn.Data) > 0 {
return errors.New("branch node should not have data")
}
for i := 0; i < len(nd.Links); i++ {
child, err := nd.Links[i].GetNode(context.TODO(), ds)
if err != nil {
return err
}
if i < direct {
// Direct blocks
err := verifyTDagRec(child, 0, direct, layerRepeat, ds)
if err != nil {
return err
}
} else {
// Recursive trickle dags
rdepth := ((i - direct) / layerRepeat) + 1
if rdepth >= depth && depth > 0 {
return errors.New("Child dag was too deep!")
}
err := verifyTDagRec(child, rdepth, direct, layerRepeat, ds)
if err != nil {
return err
}
}
}
return nil
}
开发者ID:yanghongkjxy,项目名称:go-ipfs,代码行数:59,代码来源:trickledag.go
示例19: pinIndirectRecurse
func (p *pinner) pinIndirectRecurse(ctx context.Context, node *mdag.Node) error {
k, err := node.Key()
if err != nil {
return err
}
p.indirPin.Increment(k)
return p.pinLinks(ctx, node)
}
开发者ID:noscripter,项目名称:go-ipfs,代码行数:9,代码来源:pin.go
示例20: NewDagModifier
func NewDagModifier(ctx context.Context, from *mdag.Node, serv mdag.DAGService, mp pin.ManualPinner, spl chunk.BlockSplitter) (*DagModifier, error) {
return &DagModifier{
curNode: from.Copy(),
dagserv: serv,
splitter: spl,
ctx: ctx,
mp: mp,
}, nil
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:9,代码来源:dagmodifier.go
注:本文中的github.com/ipfs/go-ipfs/merkledag.Node类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论