本文整理汇总了Golang中github.com/djbarber/ipfs-hack/core.IpfsNode.Context方法的典型用法代码示例。如果您正苦于以下问题:Golang IpfsNode.Context方法的具体用法?Golang IpfsNode.Context怎么用?Golang IpfsNode.Context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/djbarber/ipfs-hack/core.IpfsNode
的用法示例。
在下文中一共展示了IpfsNode.Context方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: InitializeKeyspace
// InitializeKeyspace sets the ipns record for the given key to
// point to an empty directory.
func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
emptyDir := &mdag.Node{Data: ft.FolderPBData()}
nodek, err := n.DAG.Add(emptyDir)
if err != nil {
return err
}
ctx, cancel := context.WithCancel(n.Context())
defer cancel()
err = n.Pinning.Pin(ctx, emptyDir, false)
if err != nil {
return err
}
err = n.Pinning.Flush()
if err != nil {
return err
}
pub := nsys.NewRoutingPublisher(n.Routing)
if err := pub.Publish(ctx, key, path.FromKey(nodek)); err != nil {
return err
}
return nil
}
示例3: Cat
func Cat(n *core.IpfsNode, pstr string) (*uio.DagReader, error) {
p := path.FromString(pstr)
dagNode, err := n.Resolver.ResolvePath(n.Context(), p)
if err != nil {
return nil, err
}
return uio.NewDagReader(n.Context(), dagNode, n.DAG)
}
示例4: Dial
func Dial(nd *core.IpfsNode, p peer.ID, protocol string) (net.Stream, error) {
ctx, cancel := context.WithTimeout(nd.Context(), time.Second*30)
defer cancel()
err := nd.PeerHost.Connect(ctx, peer.PeerInfo{ID: p})
if err != nil {
return nil, err
}
return nd.PeerHost.NewStream(pro.ID(protocol), p)
}
示例5: addNode
func addNode(n *core.IpfsNode, node *merkledag.Node) error {
if err := n.DAG.AddRecursive(node); err != nil { // add the file to the graph + local storage
return err
}
ctx, cancel := context.WithCancel(n.Context())
defer cancel()
err := n.Pinning.Pin(ctx, node, true) // ensure we keep it
return err
}
示例6: Metadata
func Metadata(n *core.IpfsNode, skey string) (*ft.Metadata, error) {
ukey := key.B58KeyDecode(skey)
nd, err := n.DAG.Get(n.Context(), ukey)
if err != nil {
return nil, err
}
return ft.MetadataFromBytes(nd.Data)
}
示例7: getPaths
func getPaths(t *testing.T, ipfs *core.IpfsNode, name string, n *dag.Node) []string {
if len(n.Links) == 0 {
return []string{name}
}
var out []string
for _, lnk := range n.Links {
child, err := lnk.GetNode(ipfs.Context(), ipfs.DAG)
if err != nil {
t.Fatal(err)
}
sub := getPaths(t, ipfs, path.Join(name, lnk.Name), child)
out = append(out, sub...)
}
return out
}
示例8: Listen
func Listen(nd *core.IpfsNode, protocol string) (*ipfsListener, error) {
ctx, cancel := context.WithCancel(nd.Context())
list := &ipfsListener{
proto: pro.ID(protocol),
conCh: make(chan net.Stream),
ctx: ctx,
cancel: cancel,
}
nd.PeerHost.SetStreamHandler(list.proto, func(s net.Stream) {
select {
case list.conCh <- s:
case <-ctx.Done():
s.Close()
}
})
return list, nil
}
示例9: Mount
// Mount mounts ipns at a given location, and returns a mount.Mount instance.
func Mount(ipfs *core.IpfsNode, ipnsmp, ipfsmp string) (mount.Mount, error) {
cfg, err := ipfs.Repo.Config()
if err != nil {
return nil, err
}
allow_other := cfg.Mounts.FuseAllowOther
if ipfs.IpnsFs == nil {
fs, err := ipnsfs.NewFilesystem(ipfs.Context(), ipfs.DAG, ipfs.Namesys, ipfs.Pinning, ipfs.PrivateKey)
if err != nil {
return nil, err
}
ipfs.IpnsFs = fs
}
fsys, err := NewFileSystem(ipfs, ipfs.PrivateKey, ipfsmp, ipnsmp)
if err != nil {
return nil, err
}
return mount.NewMount(ipfs.Process(), fsys, ipnsmp, allow_other)
}
示例10: addAssetList
func addAssetList(nd *core.IpfsNode, l []string) (*key.Key, error) {
dirb := uio.NewDirectory(nd.DAG)
for _, p := range l {
d, err := Asset(p)
if err != nil {
return nil, fmt.Errorf("assets: could load Asset '%s': %s", p, err)
}
s, err := coreunix.Add(nd, bytes.NewBuffer(d))
if err != nil {
return nil, fmt.Errorf("assets: could not Add '%s': %s", p, err)
}
fname := filepath.Base(p)
k := key.B58KeyDecode(s)
if err := dirb.AddChild(nd.Context(), fname, k); err != nil {
return nil, fmt.Errorf("assets: could not add '%s' as a child: %s", fname, err)
}
}
dir := dirb.GetNode()
dkey, err := nd.DAG.Add(dir)
if err != nil {
return nil, fmt.Errorf("assets: DAG.Add(dir) failed: %s", err)
}
if err := nd.Pinning.Pin(nd.Context(), dir, true); err != nil {
return nil, fmt.Errorf("assets: Pinning on init-docu failed: %s", err)
}
if err := nd.Pinning.Flush(); err != nil {
return nil, fmt.Errorf("assets: Pinning flush failed: %s", err)
}
return &dkey, nil
}