go-ipfs: github.com/ipfs/go-ipfs/core/commands/name Index | Files

package name

import "github.com/ipfs/go-ipfs/core/commands/name"

Index

Package Files

ipns.go ipnsps.go name.go publish.go

Variables

var IpnsCmd = &cmds.Command{
    Helptext: cmds.HelpText{
        Tagline:          "Resolve IPNS names.",
        ShortDescription: "" /* 245 byte string literal not displayed */,

        LongDescription: "" /* 744 byte string literal not displayed */,
    },

    Arguments: []cmds.Argument{
        cmds.StringArg("name", false, false, "The IPNS name to resolve. Defaults to your node's peerID."),
    },
    Options: []cmds.Option{
        cmds.BoolOption(recursiveOptionName, "r", "Resolve until the result is not an IPNS name.").WithDefault(true),
        cmds.BoolOption(nocacheOptionName, "n", "Do not use cached entries."),
        cmds.UintOption(dhtRecordCountOptionName, "dhtrc", "Number of records to request for DHT resolution."),
        cmds.StringOption(dhtTimeoutOptionName, "dhtt", "Max time to collect values during DHT resolution eg \"30s\". Pass 0 for no timeout."),
        cmds.BoolOption(streamOptionName, "s", "Stream entries as they are found."),
    },
    Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
        api, err := cmdenv.GetApi(env, req)
        if err != nil {
            return err
        }

        nocache, _ := req.Options["nocache"].(bool)

        var name string
        if len(req.Arguments) == 0 {
            self, err := api.Key().Self(req.Context)
            if err != nil {
                return err
            }
            name = self.ID().Pretty()
        } else {
            name = req.Arguments[0]
        }

        recursive, _ := req.Options[recursiveOptionName].(bool)
        rc, rcok := req.Options[dhtRecordCountOptionName].(int)
        dhtt, dhttok := req.Options[dhtTimeoutOptionName].(string)
        stream, _ := req.Options[streamOptionName].(bool)

        opts := []options.NameResolveOption{
            options.Name.Cache(!nocache),
        }

        if !recursive {
            opts = append(opts, options.Name.ResolveOption(nsopts.Depth(1)))
        }
        if rcok {
            opts = append(opts, options.Name.ResolveOption(nsopts.DhtRecordCount(uint(rc))))
        }
        if dhttok {
            d, err := time.ParseDuration(dhtt)
            if err != nil {
                return err
            }
            if d < 0 {
                return errors.New("DHT timeout value must be >= 0")
            }
            opts = append(opts, options.Name.ResolveOption(nsopts.DhtTimeout(d)))
        }

        if !strings.HasPrefix(name, "/ipns/") {
            name = "/ipns/" + name
        }

        if !stream {
            output, err := api.Name().Resolve(req.Context, name, opts...)
            if err != nil && (recursive || err != namesys.ErrResolveRecursion) {
                return err
            }

            return cmds.EmitOnce(res, &ResolvedPath{path.FromString(output.String())})
        }

        output, err := api.Name().Search(req.Context, name, opts...)
        if err != nil {
            return err
        }

        for v := range output {
            if v.Err != nil && (recursive || v.Err != namesys.ErrResolveRecursion) {
                return v.Err
            }
            if err := res.Emit(&ResolvedPath{path.FromString(v.Path.String())}); err != nil {
                return err
            }

        }

        return nil
    },
    Encoders: cmds.EncoderMap{
        cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, rp *ResolvedPath) error {
            _, err := fmt.Fprintln(w, rp.Path)
            return err
        }),
    },
    Type: ResolvedPath{},
}
var IpnsPubsubCmd = &cmds.Command{
    Helptext: cmds.HelpText{
        Tagline:          "IPNS pubsub management",
        ShortDescription: "" /* 144 byte string literal not displayed */,
    },
    Subcommands: map[string]*cmds.Command{
        "state":  ipnspsStateCmd,
        "subs":   ipnspsSubsCmd,
        "cancel": ipnspsCancelCmd,
    },
}

IpnsPubsubCmd is the subcommand that allows us to manage the IPNS pubsub system

var NameCmd = &cmds.Command{
    Helptext: cmds.HelpText{
        Tagline:          "Publish and resolve IPNS names.",
        ShortDescription: "" /* 245 byte string literal not displayed */,

        LongDescription: "" /* 1309 byte string literal not displayed */,
    },

    Subcommands: map[string]*cmds.Command{
        "publish": PublishCmd,
        "resolve": IpnsCmd,
        "pubsub":  IpnsPubsubCmd,
    },
}
var PublishCmd = &cmds.Command{
    Helptext: cmds.HelpText{
        Tagline:          "Publish IPNS names.",
        ShortDescription: "" /* 245 byte string literal not displayed */,

        LongDescription: "" /* 1258 byte string literal not displayed */,
    },

    Arguments: []cmds.Argument{
        cmds.StringArg(ipfsPathOptionName, true, false, "ipfs path of the object to be published.").EnableStdin(),
    },
    Options: []cmds.Option{
        cmds.BoolOption(resolveOptionName, "Check if the given path can be resolved before publishing.").WithDefault(true),
        cmds.StringOption(lifeTimeOptionName, "t",
            "" /* 193 byte string literal not displayed */,
        ).WithDefault("24h"),
        cmds.BoolOption(allowOfflineOptionName, "When offline, save the IPNS record to the the local datastore without broadcasting to the network instead of simply failing."),
        cmds.StringOption(ttlOptionName, "Time duration this record should be cached for. Uses the same syntax as the lifetime option. (caution: experimental)"),
        cmds.StringOption(keyOptionName, "k", "Name of the key to be used or a valid PeerID, as listed by 'ipfs key list -l'.").WithDefault("self"),
        cmds.BoolOption(quieterOptionName, "Q", "Write only final hash."),
    },
    Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
        api, err := cmdenv.GetApi(env, req)
        if err != nil {
            return err
        }

        allowOffline, _ := req.Options[allowOfflineOptionName].(bool)
        kname, _ := req.Options[keyOptionName].(string)

        validTimeOpt, _ := req.Options[lifeTimeOptionName].(string)
        validTime, err := time.ParseDuration(validTimeOpt)
        if err != nil {
            return fmt.Errorf("error parsing lifetime option: %s", err)
        }

        opts := []options.NamePublishOption{
            options.Name.AllowOffline(allowOffline),
            options.Name.Key(kname),
            options.Name.ValidTime(validTime),
        }

        if ttl, found := req.Options[ttlOptionName].(string); found {
            d, err := time.ParseDuration(ttl)
            if err != nil {
                return err
            }

            opts = append(opts, options.Name.TTL(d))
        }

        p := path.New(req.Arguments[0])

        if verifyExists, _ := req.Options[resolveOptionName].(bool); verifyExists {
            _, err := api.ResolveNode(req.Context, p)
            if err != nil {
                return err
            }
        }

        out, err := api.Name().Publish(req.Context, p, opts...)
        if err != nil {
            if err == iface.ErrOffline {
                err = errAllowOffline
            }
            return err
        }

        return cmds.EmitOnce(res, &IpnsEntry{
            Name:  out.Name(),
            Value: out.Value().String(),
        })
    },
    Encoders: cmds.EncoderMap{
        cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, ie *IpnsEntry) error {
            var err error
            quieter, _ := req.Options[quieterOptionName].(bool)
            if quieter {
                _, err = fmt.Fprintln(w, ie.Name)
            } else {
                _, err = fmt.Fprintf(w, "Published to %s: %s\n", ie.Name, ie.Value)
            }
            return err
        }),
    },
    Type: IpnsEntry{},
}

type IpnsEntry Uses

type IpnsEntry struct {
    Name  string
    Value string
}

type ResolvedPath Uses

type ResolvedPath struct {
    Path path.Path
}

Package name imports 16 packages (graph) and is imported by 7 packages. Updated 2019-07-13. Refresh now. Tools for package owners.