From c6ede438635b4cd6d59d24b6f778b7ef6beca3d0 Mon Sep 17 00:00:00 2001 From: Shengwen Yu Date: Wed, 17 Apr 2019 17:13:41 -0700 Subject: [PATCH] feat: gateway change /ipfs, /ipns to /btfs, /btns --- cmd/btfs/daemon.go | 4 ++-- cmd/btfs/init.go | 4 ++-- core/commands/name/ipns.go | 4 ++-- core/commands/name/ipnsps.go | 6 +++--- core/commands/resolve.go | 2 +- core/commands/root.go | 28 ++++++++++++++-------------- core/coreapi/name.go | 4 ++-- core/coreapi/path.go | 2 +- core/corehttp/gateway_handler.go | 10 +++++----- core/corehttp/ipns_hostname.go | 2 +- core/pathresolver.go | 2 +- fuse/ipns/ipns_unix.go | 8 ++++---- namesys/publisher.go | 6 +++--- namesys/routing.go | 2 +- 14 files changed, 42 insertions(+), 42 deletions(-) diff --git a/cmd/btfs/daemon.go b/cmd/btfs/daemon.go index 00bf5dd4175..24e4a255c29 100644 --- a/cmd/btfs/daemon.go +++ b/cmd/btfs/daemon.go @@ -473,7 +473,7 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error unrestricted, _ := req.Options[unrestrictedApiAccessKwd].(bool) gatewayOpt := corehttp.GatewayOption(false, corehttp.WebUIPaths...) if unrestricted { - gatewayOpt = corehttp.GatewayOption(true, "/ipfs", "/ipns") + gatewayOpt = corehttp.GatewayOption(true, "/btfs", "/btns") } var opts = []corehttp.ServeOption{ @@ -594,7 +594,7 @@ func serveHTTPGateway(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, e var opts = []corehttp.ServeOption{ corehttp.MetricsCollectionOption("gateway"), corehttp.IPNSHostnameOption(), - corehttp.GatewayOption(writable, "/ipfs", "/ipns"), + corehttp.GatewayOption(writable, "/btfs", "/btns"), corehttp.VersionOption(), corehttp.CheckVersionOption(), corehttp.CommandsROOption(cmdctx), diff --git a/cmd/btfs/init.go b/cmd/btfs/init.go index 58ed82895de..c6f522df1ea 100644 --- a/cmd/btfs/init.go +++ b/cmd/btfs/init.go @@ -128,7 +128,7 @@ func initWithDefaults(out io.Writer, repoRoot string, profile string) error { } func doInit(out io.Writer, repoRoot string, empty bool, nBitsForKeypair int, confProfiles []string, conf *config.Config) error { - if _, err := fmt.Fprintf(out, "initializing IPFS node at %s\n", repoRoot); err != nil { + if _, err := fmt.Fprintf(out, "initializing BTFS node at %s\n", repoRoot); err != nil { return err } @@ -225,7 +225,7 @@ func addDefaultAssets(out io.Writer, repoRoot string) error { return err } - _, err = fmt.Fprintf(out, "\n\tipfs cat /ipfs/%s/readme\n\n", dkey) + _, err = fmt.Fprintf(out, "\n\tbtfs cat /btfs/%s/readme\n\n", dkey) return err } diff --git a/core/commands/name/ipns.go b/core/commands/name/ipns.go index 6557ca09e8e..31c189c4e12 100644 --- a/core/commands/name/ipns.go +++ b/core/commands/name/ipns.go @@ -125,8 +125,8 @@ Resolve the value of a dnslink: opts = append(opts, options.Name.ResolveOption(nsopts.DhtTimeout(d))) } - if !strings.HasPrefix(name, "/ipns/") { - name = "/ipns/" + name + if !strings.HasPrefix(name, "/btns/") { + name = "/btns/" + name } if !stream { diff --git a/core/commands/name/ipnsps.go b/core/commands/name/ipnsps.go index 1f3e1c53240..5ea5f5c0201 100644 --- a/core/commands/name/ipnsps.go +++ b/core/commands/name/ipnsps.go @@ -94,7 +94,7 @@ var ipnspsSubsCmd = &cmds.Command{ log.Errorf("ipns key not a valid peer ID: %s", err) continue } - paths = append(paths, "/ipns/"+peer.IDB58Encode(pid)) + paths = append(paths, "/btns/"+peer.IDB58Encode(pid)) } return cmds.EmitOnce(res, &stringList{paths}) @@ -120,13 +120,13 @@ var ipnspsCancelCmd = &cmds.Command{ } name := req.Arguments[0] - name = strings.TrimPrefix(name, "/ipns/") + name = strings.TrimPrefix(name, "/btns/") pid, err := peer.IDB58Decode(name) if err != nil { return cmdkit.Errorf(cmdkit.ErrClient, err.Error()) } - ok, err := n.PSRouter.Cancel("/ipns/" + string(pid)) + ok, err := n.PSRouter.Cancel("/btns/" + string(pid)) if err != nil { return err } diff --git a/core/commands/resolve.go b/core/commands/resolve.go index bc6f8850ad7..9199934cb2a 100644 --- a/core/commands/resolve.go +++ b/core/commands/resolve.go @@ -101,7 +101,7 @@ Resolve the value of an IPFS DAG path: } // the case when ipns is resolved step by step - if strings.HasPrefix(name, "/ipns/") && !recursive { + if strings.HasPrefix(name, "/btns/") && !recursive { rc, rcok := req.Options[resolveDhtRecordCountOptionName].(uint) dhtt, dhttok := req.Options[resolveDhtTimeoutOptionName].(string) ropts := []options.NameResolveOption{ diff --git a/core/commands/root.go b/core/commands/root.go index 6a7558dc5eb..cec08d58672 100644 --- a/core/commands/root.go +++ b/core/commands/root.go @@ -16,7 +16,7 @@ import ( var log = logging.Logger("core/commands") -var ErrNotOnline = errors.New("this command must be run in online mode. Try running 'ipfs daemon' first") +var ErrNotOnline = errors.New("this command must be run in online mode. Try running 'btfs daemon' first") const ( ConfigOption = "config" @@ -29,13 +29,13 @@ const ( var Root = &cmds.Command{ Helptext: cmdkit.HelpText{ Tagline: "Global p2p merkle-dag filesystem.", - Synopsis: "ipfs [--config= | -c] [--debug | -D] [--help] [-h] [--api=] [--offline] [--cid-base=] [--upgrade-cidv0-in-output] [--encoding= | --enc] [--timeout=] ...", + Synopsis: "btfs [--config= | -c] [--debug | -D] [--help] [-h] [--api=] [--offline] [--cid-base=] [--upgrade-cidv0-in-output] [--encoding= | --enc] [--timeout=] ...", Subcommands: ` BASIC COMMANDS - init Initialize ipfs local configuration - add Add a file to IPFS - cat Show IPFS object data - get Download IPFS objects + init Initialize btfs local configuration + add Add a file to BTFS + cat Show BTFS object data + get Download BTFS objects ls List links from an object refs List hashes of links from an object @@ -47,19 +47,19 @@ DATA STRUCTURE COMMANDS ADVANCED COMMANDS daemon Start a long-running daemon process - mount Mount an IPFS read-only mountpoint + mount Mount an BTFS read-only mountpoint resolve Resolve any type of name name Publish and resolve IPNS names key Create and list IPNS name keypairs dns Resolve DNS links pin Pin objects to local storage - repo Manipulate the IPFS repository + repo Manipulate the BTFS repository stats Various operational stats p2p Libp2p stream mounting filestore Manage the filestore (experimental) NETWORK COMMANDS - id Show info about IPFS peers + id Show info about BTFS peers bootstrap Add or remove bootstrap peers swarm Manage connections to the p2p network dht Query the DHT for values or peers @@ -68,19 +68,19 @@ NETWORK COMMANDS TOOL COMMANDS config Manage configuration - version Show ipfs version information + version Show btfs version information update Download and apply go-ipfs updates commands List all available commands cid Convert and discover properties of CIDs log Manage and show logs of running daemon -Use 'ipfs --help' to learn more about each command. +Use 'btfs --help' to learn more about each command. -ipfs uses a repository in the local file system. By default, the repo is -located at ~/.ipfs. To change the repo location, set the $IPFS_PATH +btfs uses a repository in the local file system. By default, the repo is +located at ~/.btfs. To change the repo location, set the $IPFS_PATH environment variable: - export IPFS_PATH=/path/to/ipfsrepo + export IPFS_PATH=/path/to/btfsrepo EXIT STATUS diff --git a/core/coreapi/name.go b/core/coreapi/name.go index 0b368ec540a..c62889c35b5 100644 --- a/core/coreapi/name.go +++ b/core/coreapi/name.go @@ -98,8 +98,8 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name resolver = namesys.NewNameSystem(api.routing, api.repo.Datastore(), 0) } - if !strings.HasPrefix(name, "/ipns/") { - name = "/ipns/" + name + if !strings.HasPrefix(name, "/btns/") { + name = "/btns/" + name } out := make(chan coreiface.IpnsResult) diff --git a/core/coreapi/path.go b/core/coreapi/path.go index 6302ec67fa5..04cf4cbeb08 100644 --- a/core/coreapi/path.go +++ b/core/coreapi/path.go @@ -48,7 +48,7 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p coreiface.Path) (coreifac var resolveOnce resolver.ResolveOnce switch ipath.Segments()[0] { - case "ipfs": + case "btfs": resolveOnce = uio.ResolveUnixfsOnce case "ipld": resolveOnce = resolver.ResolveSingle diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index a62aee4cdac..e9d7bacfe91 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -31,8 +31,8 @@ import ( ) const ( - ipfsPathPrefix = "/ipfs/" - ipnsPathPrefix = "/ipns/" + ipfsPathPrefix = "/btfs/" + ipnsPathPrefix = "/btns/" ) // gatewayHandler is a HTTP handler that serves IPFS objects (accessible by default at /ipfs/) @@ -156,16 +156,16 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr // Resolve path to the final DAG node for the ETag resolvedPath, err := i.api.ResolvePath(ctx, parsedPath) if err == coreiface.ErrOffline && !i.node.IsOnline { - webError(w, "ipfs resolve -r "+escapedURLPath, err, http.StatusServiceUnavailable) + webError(w, "btfs resolve -r "+escapedURLPath, err, http.StatusServiceUnavailable) return } else if err != nil { - webError(w, "ipfs resolve -r "+escapedURLPath, err, http.StatusNotFound) + webError(w, "btfs resolve -r "+escapedURLPath, err, http.StatusNotFound) return } dr, err := i.api.Unixfs().Get(ctx, resolvedPath) if err != nil { - webError(w, "ipfs cat "+escapedURLPath, err, http.StatusNotFound) + webError(w, "btfs cat "+escapedURLPath, err, http.StatusNotFound) return } diff --git a/core/corehttp/ipns_hostname.go b/core/corehttp/ipns_hostname.go index d5512779b35..775a6d4001c 100644 --- a/core/corehttp/ipns_hostname.go +++ b/core/corehttp/ipns_hostname.go @@ -25,7 +25,7 @@ func IPNSHostnameOption() ServeOption { host := strings.SplitN(r.Host, ":", 2)[0] if len(host) > 0 && isd.IsDomain(host) { - name := "/ipns/" + host + name := "/btns/" + host _, err := n.Namesys.Resolve(ctx, name, nsopts.Depth(1)) if err == nil || err == namesys.ErrResolveRecursion { r.Header.Set("X-Ipns-Original-Path", r.URL.Path) diff --git a/core/pathresolver.go b/core/pathresolver.go index 21c2a84be4c..0032c0c91d4 100644 --- a/core/pathresolver.go +++ b/core/pathresolver.go @@ -20,7 +20,7 @@ var ErrNoNamesys = errors.New( // ResolveIPNS resolves /ipns paths func ResolveIPNS(ctx context.Context, nsys namesys.NameSystem, p path.Path) (path.Path, error) { - if strings.HasPrefix(p.String(), "/ipns/") { + if strings.HasPrefix(p.String(), "/btns/") { evt := log.EventBegin(ctx, "resolveIpnsPath") defer evt.Done() // resolve ipns paths diff --git a/fuse/ipns/ipns_unix.go b/fuse/ipns/ipns_unix.go index d9f6c67404d..9c6935a5b2f 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -90,7 +90,7 @@ func ipnsPubFunc(ipfs *core.IpfsNode, k ci.PrivKey) mfs.PubFunc { } func loadRoot(ctx context.Context, rt *keyRoot, ipfs *core.IpfsNode, name string) (fs.Node, error) { - p, err := path.ParsePath("/ipns/" + name) + p, err := path.ParsePath("/btns/" + name) if err != nil { log.Errorf("mkpath %s: %s", name, err) return nil, err @@ -196,10 +196,10 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) { } // other links go through ipns resolution and are symlinked into the ipfs mountpoint - ipnsName := "/ipns/" + name + ipnsName := "/btns/" + name resolved, err := s.Ipfs.Namesys.Resolve(s.Ipfs.Context(), ipnsName) if err != nil { - log.Warningf("ipns: namesys resolve error: %s", err) + log.Warningf("btns: namesys resolve error: %s", err) return nil, fuse.ENOENT } @@ -210,7 +210,7 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) { } log.Error("Invalid path.Path: ", resolved) - return nil, errors.New("invalid path from ipns record") + return nil, errors.New("invalid path from btns record") } func (r *Root) Close() error { diff --git a/namesys/publisher.go b/namesys/publisher.go index e43858d02f6..a3b85998e7c 100644 --- a/namesys/publisher.go +++ b/namesys/publisher.go @@ -21,7 +21,7 @@ import ( base32 "github.com/whyrusleeping/base32" ) -const ipnsPrefix = "/ipns/" +const ipnsPrefix = "/btns/" const PublishPutValTimeout = time.Minute const DefaultRecordEOL = 24 * time.Hour @@ -52,7 +52,7 @@ func (p *IpnsPublisher) Publish(ctx context.Context, k ci.PrivKey, value path.Pa } func IpnsDsKey(id peer.ID) ds.Key { - return ds.NewKey("/ipns/" + base32.RawStdEncoding.EncodeToString([]byte(id))) + return ds.NewKey("/btns/" + base32.RawStdEncoding.EncodeToString([]byte(id))) } // PublishedNames returns the latest IPNS records published by this node and @@ -92,7 +92,7 @@ func (p *IpnsPublisher) ListPublished(ctx context.Context) (map[peer.ID]*pb.Ipns k := result.Key[len(ipnsPrefix):] pid, err := base32.RawStdEncoding.DecodeString(k) if err != nil { - log.Errorf("ipns ds key invalid: %s", result.Key) + log.Errorf("btns ds key invalid: %s", result.Key) continue } records[peer.ID(pid)] = e diff --git a/namesys/routing.go b/namesys/routing.go index e89dd9c9d4f..6d2c8c736cf 100644 --- a/namesys/routing.go +++ b/namesys/routing.go @@ -58,7 +58,7 @@ func (r *IpnsResolver) resolveOnceAsync(ctx context.Context, name string, option ctx, cancel = context.WithTimeout(ctx, options.DhtTimeout) } - name = strings.TrimPrefix(name, "/ipns/") + name = strings.TrimPrefix(name, "/btns/") pid, err := peer.IDB58Decode(name) if err != nil { log.Debugf("RoutingResolver: could not convert public key hash %s to peer ID: %s\n", name, err)