Skip to content

Commit

Permalink
feat: gateway change /ipfs, /ipns to /btfs, /btns
Browse files Browse the repository at this point in the history
  • Loading branch information
Shengwen Yu committed Apr 18, 2019
1 parent e1f6359 commit c6ede43
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions cmd/btfs/daemon.go
Expand Up @@ -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{
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions cmd/btfs/init.go
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions core/commands/name/ipns.go
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions core/commands/name/ipnsps.go
Expand Up @@ -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})
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/resolve.go
Expand Up @@ -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{
Expand Down
28 changes: 14 additions & 14 deletions core/commands/root.go
Expand Up @@ -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"
Expand All @@ -29,13 +29,13 @@ const (
var Root = &cmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Global p2p merkle-dag filesystem.",
Synopsis: "ipfs [--config=<config> | -c] [--debug | -D] [--help] [-h] [--api=<api>] [--offline] [--cid-base=<base>] [--upgrade-cidv0-in-output] [--encoding=<encoding> | --enc] [--timeout=<timeout>] <command> ...",
Synopsis: "btfs [--config=<config> | -c] [--debug | -D] [--help] [-h] [--api=<api>] [--offline] [--cid-base=<base>] [--upgrade-cidv0-in-output] [--encoding=<encoding> | --enc] [--timeout=<timeout>] <command> ...",
Subcommands: `
BASIC COMMANDS
init Initialize ipfs local configuration
add <path> Add a file to IPFS
cat <ref> Show IPFS object data
get <ref> Download IPFS objects
init Initialize btfs local configuration
add <path> Add a file to BTFS
cat <ref> Show BTFS object data
get <ref> Download BTFS objects
ls <ref> List links from an object
refs <ref> List hashes of links from an object
Expand All @@ -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
Expand All @@ -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 <command> --help' to learn more about each command.
Use 'btfs <command> --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
Expand Down
4 changes: 2 additions & 2 deletions core/coreapi/name.go
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/path.go
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions core/corehttp/gateway_handler.go
Expand Up @@ -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/<path>)
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion core/corehttp/ipns_hostname.go
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/pathresolver.go
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions fuse/ipns/ipns_unix.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions namesys/publisher.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion namesys/routing.go
Expand Up @@ -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)
Expand Down

2 comments on commit c6ede43

@GitCop
Copy link

@GitCop GitCop commented on c6ede43 Apr 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

We ask for a few features in the commit message for Open Source licensing hygiene and commit message clarity.
git commit --amend can often help you quickly improve the commit message.
Guidelines and a script are available to help in the long run.
Your feedback on GitCop is welcome on this issue.


This message was auto-generated by https://gitcop.com

@GitCop
Copy link

@GitCop GitCop commented on c6ede43 Apr 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

We ask for a few features in the commit message for Open Source licensing hygiene and commit message clarity.
git commit --amend can often help you quickly improve the commit message.
Guidelines and a script are available to help in the long run.
Your feedback on GitCop is welcome on this issue.


This message was auto-generated by https://gitcop.com

Please sign in to comment.