本文整理汇总了Golang中github.com/ipfs/go-ipfs/blocks/key.B58KeyDecode函数的典型用法代码示例。如果您正苦于以下问题:Golang B58KeyDecode函数的具体用法?Golang B58KeyDecode怎么用?Golang B58KeyDecode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了B58KeyDecode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: escapeDhtKey
func escapeDhtKey(s string) (key.Key, error) {
parts := strings.Split(s, "/")
switch len(parts) {
case 1:
return key.B58KeyDecode(s), nil
case 3:
k := key.B58KeyDecode(parts[2])
return key.Key(strings.Join(append(parts[:2], string(k)), "/")), nil
default:
return "", errors.New("invalid key")
}
}
示例2: escapeDhtKey
func escapeDhtKey(s string) (key.Key, error) {
parts := path.SplitList(s)
switch len(parts) {
case 1:
return key.B58KeyDecode(s), nil
case 3:
k := key.B58KeyDecode(parts[2])
return key.Key(path.Join(append(parts[:2], k.String()))), nil
default:
return "", errors.New("invalid key")
}
}
示例3: 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
}
示例4: ResolveToKey
// ResolveToKey resolves a path to a key.
//
// It first checks if the path is already in the form of just a key (<key> or
// /ipfs/<key>) and returns immediately if so. Otherwise, it falls back onto
// Resolve to perform resolution of the dagnode being referenced.
func ResolveToKey(ctx context.Context, n *IpfsNode, p path.Path) (key.Key, error) {
// If the path is simply a key, parse and return it. Parsed paths are already
// normalized (read: prepended with /ipfs/ if needed), so segment[1] should
// always be the key.
if p.IsJustAKey() {
return key.B58KeyDecode(p.Segments()[1]), nil
}
// Fall back onto regular dagnode resolution. Retrieve the second-to-last
// segment of the path and resolve its link to the last segment.
head, tail, err := p.PopLastSegment()
if err != nil {
return key.Key(""), err
}
dagnode, err := Resolve(ctx, n, head)
if err != nil {
return key.Key(""), err
}
// Extract and return the key of the link to the target dag node.
link, err := dagnode.GetNodeLink(tail)
if err != nil {
return key.Key(""), err
}
return key.Key(link.Hash), nil
}
示例5: FromB58Slice
//FromB58Slice makes and returns Key from B58String slice
func FromB58Slice(ks []string) Key {
m := make(Key)
for _, kk := range ks {
k := key.B58KeyDecode(kk)
m.Add(k)
}
return m
}
示例6: nameResolve
//nameResolve resole name hash using IPNS.
func (p *Peer) nameResolve() (key.Key, error) {
log.Println("resolving", p.ID.Pretty())
pt, err := p.myself.ipfsNode.Namesys.Resolve(p.myself.ctx, "/ipns/"+p.ID.Pretty())
if log.If(err) {
return "", err
}
log.Println("resolved", pt)
seg := pt.Segments()
return key.B58KeyDecode(seg[len(seg)-1]), nil
}
示例7: 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)
}
示例8: DelBlock
// DelBlock deletes the block pointed to by `hash`.
func DelBlock(node *Node, hash gmh.Multihash) error {
nd, err := node.proc()
if err != nil {
log.Warningf("ipfs block-del: %v", err)
return err
}
k := key.B58KeyDecode(hash.B58String())
return nd.Blocks.DeleteBlock(k)
}
示例9: TestMetadata
func TestMetadata(t *testing.T) {
ctx := context.Background()
// Make some random node
ds := getDagserv(t)
data := make([]byte, 1000)
u.NewTimeSeededRand().Read(data)
r := bytes.NewReader(data)
nd, err := importer.BuildDagFromReader(ds, chunk.DefaultSplitter(r))
if err != nil {
t.Fatal(err)
}
k, err := nd.Key()
if err != nil {
t.Fatal(err)
}
m := new(ft.Metadata)
m.MimeType = "THIS IS A TEST"
// Such effort, many compromise
ipfsnode := &core.IpfsNode{DAG: ds}
mdk, err := AddMetadataTo(ipfsnode, k.B58String(), m)
if err != nil {
t.Fatal(err)
}
rec, err := Metadata(ipfsnode, mdk)
if err != nil {
t.Fatal(err)
}
if rec.MimeType != m.MimeType {
t.Fatalf("something went wrong in conversion: '%s' != '%s'", rec.MimeType, m.MimeType)
}
retnode, err := ds.Get(ctx, key.B58KeyDecode(mdk))
if err != nil {
t.Fatal(err)
}
ndr, err := uio.NewDagReader(ctx, retnode, ds)
if err != nil {
t.Fatal(err)
}
out, err := ioutil.ReadAll(ndr)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(out, data) {
t.Fatal("read incorrect data")
}
}
示例10: pin
func pin(n *core.IpfsNode, ctx context.Context, hash string) error {
hashkey := key.B58KeyDecode(hash)
node, err := n.DAG.Get(ctx, hashkey)
if err != nil {
return err
}
err = n.Pinning.Pin(ctx, node, false)
return err
}
示例11: addDefaultAssets
func addDefaultAssets(out io.Writer, repoRoot string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
r, err := fsrepo.Open(repoRoot)
if err != nil { // NB: repo is owned by the node
return err
}
nd, err := core.NewIPFSNode(ctx, core.Offline(r))
if err != nil {
return err
}
defer nd.Close()
dirb := uio.NewDirectory(nd.DAG)
// add every file in the assets pkg
for fname, file := range assets.Init_dir {
buf := bytes.NewBufferString(file)
s, err := coreunix.Add(nd, buf)
if err != nil {
return err
}
k := key.B58KeyDecode(s)
if err := dirb.AddChild(fname, k); err != nil {
return err
}
}
dir := dirb.GetNode()
dkey, err := nd.DAG.Add(dir)
if err != nil {
return err
}
if err := nd.Pinning.Pin(ctx, dir, true); err != nil {
return err
}
if err := nd.Pinning.Flush(); err != nil {
return err
}
if _, err = fmt.Fprintf(out, "to get started, enter:\n"); err != nil {
return err
}
_, err = fmt.Fprintf(out, "\n\tipfs cat /ipfs/%s/readme\n\n", dkey)
return err
}
示例12: Locate
// Locate finds the object pointed to by `hash`. It will wait
// for max `timeout` duration if it got less than `n` items in that time.
// If `n` is less than 0, all reachable peers that have `hash` will be returned.
// If `n` is 0, Locate will return immeditately.
// This operation requires online-mode.
func Locate(node *Node, hash gmh.Multihash, n int, t time.Duration) ([]*PeerInfo, error) {
if n == 0 {
return []*PeerInfo{}, nil
}
// Note: Do not use Maxint32. That makes ipfs allocate
// a whole lot of memory. Just assume that 100 is fine.
if n < 0 {
n = 100
}
if !node.IsOnline() {
return nil, ErrIsOffline
}
nd, err := node.proc()
if err != nil {
log.Warningf("ipfs dht: %v", err)
return nil, err
}
dht, ok := nd.Routing.(*ipdht.IpfsDHT)
if !ok {
return nil, commands.ErrNotDHT
}
ctx, cancel := context.WithTimeout(node.Context, t)
defer cancel()
k := key.B58KeyDecode(hash.B58String())
peers := dht.FindProvidersAsync(ctx, k, n)
infos := []*PeerInfo{}
for info := range peers {
// Converting equal struct into each other is my favourite thing.
peerInfo := &PeerInfo{
ID: info.ID.Pretty(),
PubKey: node.ipfsNode.Peerstore.PubKey(info.ID),
}
for _, addr := range info.Addrs {
peerInfo.Addrs = append(peerInfo.Addrs, ma.Cast(addr.Bytes()))
}
infos = append(infos, peerInfo)
}
return infos, nil
}
示例13: loadIndirPin
func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) {
var rcStore map[string]int
err := loadSet(d, k, &rcStore)
if err != nil {
return nil, err
}
refcnt := make(map[key.Key]int)
var keys []key.Key
for encK, v := range rcStore {
if v > 0 {
k := key.B58KeyDecode(encK)
keys = append(keys, k)
refcnt[k] = v
}
}
// log.Debugf("indirPin keys: %#v", keys)
return &indirectPin{blockset: set.SimpleSetFromKeys(keys), refCounts: refcnt}, nil
}
示例14: addLinkCaller
func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
if len(req.Arguments()) < 4 {
return "", fmt.Errorf("not enough arguments for add-link")
}
nd, err := req.InvocContext().GetNode()
if err != nil {
return "", err
}
path := req.Arguments()[2]
childk := key.B58KeyDecode(req.Arguments()[3])
create, _, err := req.Option("create").Bool()
if err != nil {
return "", err
}
var createfunc func() *dag.Node
if create {
createfunc = func() *dag.Node {
return &dag.Node{Data: ft.FolderPBData()}
}
}
e := dagutils.NewDagEditor(nd.DAG, root)
childnd, err := nd.DAG.Get(req.Context(), childk)
if err != nil {
return "", err
}
err = e.InsertNodeAtPath(req.Context(), path, childnd, createfunc)
if err != nil {
return "", err
}
nnode := e.GetNode()
return nnode.Key()
}
示例15: addLinkCaller
func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
if len(req.Arguments()) < 4 {
return "", fmt.Errorf("not enough arguments for add-link")
}
nd, err := req.InvocContext().GetNode()
if err != nil {
return "", err
}
path := req.Arguments()[2]
childk := key.B58KeyDecode(req.Arguments()[3])
parts := strings.Split(path, "/")
nnode, err := insertNodeAtPath(req.Context(), nd.DAG, root, parts, childk)
if err != nil {
return "", err
}
return nnode.Key()
}