Skip to content

Commit

Permalink
compiles i guess
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Aug 14, 2023
1 parent 34275d9 commit 779e15f
Show file tree
Hide file tree
Showing 28 changed files with 123 additions and 136 deletions.
2 changes: 1 addition & 1 deletion client/rpc/apifile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const forwardSeekLimit = 1 << 14 //16k

func (api *UnixfsAPI) Get(ctx context.Context, p path.Path) (files.Node, error) {
if p.Mutable() { // use resolved path in case we are dealing with IPNS / MFS
if p.Namespace().Mutable() { // use resolved path in case we are dealing with IPNS / MFS
var err error
p, err = api.core().ResolvePath(ctx, p)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (s *blockStat) Size() int {
return s.BSize
}

func (s *blockStat) Path() path.ResolvedPath {
func (s *blockStat) Path() path.ImmutablePath {
return path.NewIPLDPath(s.cid)
}

Expand Down
7 changes: 6 additions & 1 deletion client/rpc/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

iface "github.com/ipfs/boxo/coreiface"
caopts "github.com/ipfs/boxo/coreiface/options"
"github.com/ipfs/boxo/ipns"
"github.com/ipfs/boxo/path"
"github.com/libp2p/go-libp2p/core/peer"
)
Expand All @@ -24,7 +25,11 @@ func (k *keyOutput) Name() string {
}

func (k *keyOutput) Path() path.Path {
return path.NewIPNSPath(peer.ToCid(k.ID()))
p, err := path.NewPath("/ipns/" + ipns.NameFromPeer(k.pid).String())
if err != nil {
panic(err)
}
return p
}

func (k *keyOutput) ID() peer.ID {
Expand Down
10 changes: 5 additions & 5 deletions client/rpc/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (
return n, nil
}

func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.ObjectPutOption) (path.ResolvedPath, error) {
func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.ObjectPutOption) (path.ImmutablePath, error) {
options, err := caopts.ObjectPutOptions(opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -153,7 +153,7 @@ func (api *ObjectAPI) Stat(ctx context.Context, p path.Path) (*iface.ObjectStat,
}, nil
}

func (api *ObjectAPI) AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...caopts.ObjectAddLinkOption) (path.ResolvedPath, error) {
func (api *ObjectAPI) AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...caopts.ObjectAddLinkOption) (path.ImmutablePath, error) {
options, err := caopts.ObjectAddLinkOptions(opts...)
if err != nil {
return nil, err
Expand All @@ -175,7 +175,7 @@ func (api *ObjectAPI) AddLink(ctx context.Context, base path.Path, name string,
return path.NewIPFSPath(c), nil
}

func (api *ObjectAPI) RmLink(ctx context.Context, base path.Path, link string) (path.ResolvedPath, error) {
func (api *ObjectAPI) RmLink(ctx context.Context, base path.Path, link string) (path.ImmutablePath, error) {
var out objectOut
err := api.core().Request("object/patch/rm-link", base.String(), link).
Exec(ctx, &out)
Expand All @@ -191,7 +191,7 @@ func (api *ObjectAPI) RmLink(ctx context.Context, base path.Path, link string) (
return path.NewIPFSPath(c), nil
}

func (api *ObjectAPI) AppendData(ctx context.Context, p path.Path, r io.Reader) (path.ResolvedPath, error) {
func (api *ObjectAPI) AppendData(ctx context.Context, p path.Path, r io.Reader) (path.ImmutablePath, error) {
var out objectOut
err := api.core().Request("object/patch/append-data", p.String()).
FileBody(r).
Expand All @@ -208,7 +208,7 @@ func (api *ObjectAPI) AppendData(ctx context.Context, p path.Path, r io.Reader)
return path.NewIPFSPath(c), nil
}

func (api *ObjectAPI) SetData(ctx context.Context, p path.Path, r io.Reader) (path.ResolvedPath, error) {
func (api *ObjectAPI) SetData(ctx context.Context, p path.Path, r io.Reader) (path.ImmutablePath, error) {
var out objectOut
err := api.core().Request("object/patch/set-data", p.String()).
FileBody(r).
Expand Down
12 changes: 3 additions & 9 deletions client/rpc/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
ipld "github.com/ipfs/go-ipld-format"
)

func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.ResolvedPath, error) {
func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.ImmutablePath, error) {
var out struct {
Cid cid.Cid
RemPath string
Expand All @@ -27,18 +27,12 @@ func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.Resolved
return nil, err
}

// TODO:
ipath, err := path.NewPathFromSegments(p.Namespace().String(), out.Cid.String(), out.RemPath)
p, err = path.NewPathFromSegments(p.Namespace().String(), out.Cid.String(), out.RemPath)
if err != nil {
return nil, err
}

root, err := cid.Parse(ipfspath.Path(p.String()).Segments()[1])
if err != nil {
return nil, err
}

return path.NewResolvedPath(ipath, out.Cid, root, out.RemPath), nil
return path.NewImmutablePath(p)
}

func (api *HttpApi) ResolveNode(ctx context.Context, p path.Path) (ipld.Node, error) {
Expand Down
6 changes: 3 additions & 3 deletions client/rpc/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type pinRefKeyList struct {
}

type pin struct {
path path.ResolvedPath
path path.ImmutablePath
typ string
err error
}
Expand All @@ -33,7 +33,7 @@ func (p pin) Err() error {
return p.err
}

func (p pin) Path() path.ResolvedPath {
func (p pin) Path() path.ImmutablePath {
return p.path
}

Expand Down Expand Up @@ -182,7 +182,7 @@ type badNode struct {
cid cid.Cid
}

func (n badNode) Path() path.ResolvedPath {
func (n badNode) Path() path.ImmutablePath {
return path.NewIPLDPath(n.cid)
}

Expand Down
2 changes: 1 addition & 1 deletion client/rpc/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type addEvent struct {

type UnixfsAPI HttpApi

func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.UnixfsAddOption) (path.ResolvedPath, error) {
func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.UnixfsAddOption) (path.ImmutablePath, error) {
options, _, err := caopts.UnixfsAddOptions(opts...)
if err != nil {
return nil, err
Expand Down
9 changes: 7 additions & 2 deletions core/commands/pin/remotepin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"golang.org/x/sync/errgroup"

path "github.com/ipfs/boxo/coreiface/path"
path "github.com/ipfs/boxo/path"
pinclient "github.com/ipfs/boxo/pinning/remote/client"
cid "github.com/ipfs/go-cid"
cmds "github.com/ipfs/go-ipfs-cmds"
Expand Down Expand Up @@ -155,7 +155,12 @@ NOTE: a comma-separated notation is supported in CLI for convenience:
if err != nil {
return err
}
rp, err := api.ResolvePath(ctx, path.New(req.Arguments[0]))
p, err := path.NewPath(req.Arguments[0])
if err != nil {
return err
}

rp, err := api.ResolvePath(ctx, p)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions core/commands/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
cmdenv "github.com/ipfs/kubo/core/commands/cmdenv"

iface "github.com/ipfs/boxo/coreiface"
path "github.com/ipfs/boxo/coreiface/path"
merkledag "github.com/ipfs/boxo/ipld/merkledag"
path "github.com/ipfs/boxo/path"
cid "github.com/ipfs/go-cid"
cidenc "github.com/ipfs/go-cidutil/cidenc"
cmds "github.com/ipfs/go-ipfs-cmds"
Expand Down Expand Up @@ -171,7 +171,11 @@ Displays the hashes of all local objects. NOTE: This treats all local objects as
func objectsForPaths(ctx context.Context, n iface.CoreAPI, paths []string) ([]cid.Cid, error) {
roots := make([]cid.Cid, len(paths))
for i, sp := range paths {
o, err := n.ResolvePath(ctx, path.New(sp))
p, err := path.NewPath(sp)
if err != nil {
return nil, err
}
o, err := n.ResolvePath(ctx, p)
if err != nil {
return nil, err
}
Expand Down
33 changes: 7 additions & 26 deletions core/commands/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (

options "github.com/ipfs/boxo/coreiface/options"
nsopts "github.com/ipfs/boxo/coreiface/options/namesys"
path "github.com/ipfs/boxo/coreiface/path"
ipfspath "github.com/ipfs/boxo/path"
cidenc "github.com/ipfs/go-cidutil/cidenc"
path "github.com/ipfs/boxo/path"
cmds "github.com/ipfs/go-ipfs-cmds"
)

Expand Down Expand Up @@ -108,38 +106,21 @@ Resolve the value of an IPFS DAG path:
if err != nil && err != ns.ErrResolveRecursion {
return err
}
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: ipfspath.Path(p.String())})
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: p})
}

var enc cidenc.Encoder
switch {
case !cmdenv.CidBaseDefined(req) && !strings.HasPrefix(name, "/ipns/"):
// Not specified, check the path.
enc, err = cmdenv.CidEncoderFromPath(name)
if err == nil {
break
}
// Nope, fallback on the default.
fallthrough
default:
enc, err = cmdenv.GetCidEncoder(req)
if err != nil {
return err
}
p, err := path.NewPath(name)
if err != nil {
return err
}

// else, ipfs path or ipns with recursive flag
rp, err := api.ResolvePath(req.Context, path.New(name))
rp, err := api.ResolvePath(req.Context, p)
if err != nil {
return err
}

encoded := "/" + rp.Namespace() + "/" + enc.Encode(rp.Cid())
if remainder := rp.Remainder(); remainder != "" {
encoded += "/" + remainder
}

return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: ipfspath.Path(encoded)})
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: rp})
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, rp *ncmd.ResolvedPath) error {
Expand Down
7 changes: 4 additions & 3 deletions core/commands/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"errors"
"fmt"
"io"
"strings"
"time"

cmdenv "github.com/ipfs/kubo/core/commands/cmdenv"

iface "github.com/ipfs/boxo/coreiface"
"github.com/ipfs/boxo/coreiface/options"
dag "github.com/ipfs/boxo/ipld/merkledag"
path "github.com/ipfs/boxo/path"
cid "github.com/ipfs/go-cid"
cmds "github.com/ipfs/go-ipfs-cmds"
ipld "github.com/ipfs/go-ipld-format"
Expand Down Expand Up @@ -550,7 +550,7 @@ func printEvent(obj *routing.QueryEvent, out io.Writer, verbose bool, override p
}

func escapeDhtKey(s string) (string, error) {
parts := path.SplitList(s)
parts := strings.Split(s, "/")
if len(parts) != 3 ||
parts[0] != "" ||
!(parts[1] == "ipns" || parts[1] == "pk") {
Expand All @@ -561,5 +561,6 @@ func escapeDhtKey(s string) (string, error) {
if err != nil {
return "", err
}
return path.Join(append(parts[:2], string(k))), nil

return strings.Join(append(parts[:2], string(k)), "/"), nil
}
9 changes: 7 additions & 2 deletions core/commands/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/ipfs/kubo/core/commands/cmdenv"
tar "github.com/ipfs/kubo/tar"

path "github.com/ipfs/boxo/coreiface/path"
dag "github.com/ipfs/boxo/ipld/merkledag"
path "github.com/ipfs/boxo/path"
)

var TarCmd = &cmds.Command{
Expand Down Expand Up @@ -93,7 +93,12 @@ var tarCatCmd = &cmds.Command{
return err
}

root, err := api.ResolveNode(req.Context, path.New(req.Arguments[0]))
p, err := path.NewPath(req.Arguments[0])
if err != nil {
return err
}

root, err := api.ResolveNode(req.Context, p)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions core/coreapi/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

coreiface "github.com/ipfs/boxo/coreiface"
caopts "github.com/ipfs/boxo/coreiface/options"
path "github.com/ipfs/boxo/coreiface/path"
path "github.com/ipfs/boxo/path"
pin "github.com/ipfs/boxo/pinning/pinner"
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
Expand All @@ -22,7 +22,7 @@ import (
type BlockAPI CoreAPI

type BlockStat struct {
path path.Resolved
path path.ImmutablePath
size int
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func (api *BlockAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Bloc
}
}

return &BlockStat{path: path.IpldPath(b.Cid()), size: len(data)}, nil
return &BlockStat{path: path.NewIPLDPath(b.Cid()), size: len(data)}, nil
}

func (api *BlockAPI) Get(ctx context.Context, p path.Path) (io.Reader, error) {
Expand Down Expand Up @@ -143,7 +143,7 @@ func (api *BlockAPI) Stat(ctx context.Context, p path.Path) (coreiface.BlockStat
}

return &BlockStat{
path: path.IpldPath(b.Cid()),
path: path.NewIPLDPath(b.Cid()),
size: len(b.RawData()),
}, nil
}
Expand All @@ -152,7 +152,7 @@ func (bs *BlockStat) Size() int {
return bs.size
}

func (bs *BlockStat) Path() path.Resolved {
func (bs *BlockStat) Path() path.ImmutablePath {
return bs.path
}

Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
blockstore "github.com/ipfs/boxo/blockstore"
coreiface "github.com/ipfs/boxo/coreiface"
caopts "github.com/ipfs/boxo/coreiface/options"
path "github.com/ipfs/boxo/coreiface/path"
offline "github.com/ipfs/boxo/exchange/offline"
dag "github.com/ipfs/boxo/ipld/merkledag"
path "github.com/ipfs/boxo/path"
cid "github.com/ipfs/go-cid"
cidutil "github.com/ipfs/go-cidutil"
"github.com/ipfs/kubo/tracing"
Expand Down
10 changes: 7 additions & 3 deletions core/coreapi/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

coreiface "github.com/ipfs/boxo/coreiface"
caopts "github.com/ipfs/boxo/coreiface/options"
path "github.com/ipfs/boxo/coreiface/path"
ipfspath "github.com/ipfs/boxo/path"
"github.com/ipfs/boxo/ipns"
path "github.com/ipfs/boxo/path"
"github.com/ipfs/kubo/tracing"
crypto "github.com/libp2p/go-libp2p/core/crypto"
peer "github.com/libp2p/go-libp2p/core/peer"
Expand All @@ -32,7 +32,11 @@ func (k *key) Name() string {

// Path returns the path of the key.
func (k *key) Path() path.Path {
return path.New(ipfspath.Join([]string{"/ipns", coreiface.FormatKeyID(k.peerID)}))
p, err := path.NewPath("/ipns/" + ipns.NameFromPeer(k.peerID).String())
if err != nil {
panic(err)
}
return p
}

// ID returns key PeerID
Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
defer close(out)
for res := range resolver.ResolveAsync(ctx, name, options.ResolveOpts...) {
select {
case out <- coreiface.IpnsResult{Path: path.New(res.Path.String()), Err: res.Err}:
case out <- coreiface.IpnsResult{Path: res.Path, Err: res.Err}:
case <-ctx.Done():
return
}
Expand Down
Loading

0 comments on commit 779e15f

Please sign in to comment.