Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from ipfs/feat/update-paths
Browse files Browse the repository at this point in the history
Update interface - path changes
  • Loading branch information
Stebalien authored Apr 27, 2019
2 parents 0b1bf38 + e53361d commit 6062f4d
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 184 deletions.
1 change: 0 additions & 1 deletion .gx/lastpubver

This file was deleted.

4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ os:
language: go

go:
- 1.11.x
- 1.12.x

env:
global:
Expand All @@ -15,7 +15,6 @@ env:

# disable travis install
install:
- make deps
- go get -d github.com/ipfs/go-ipfs
- (cd $GOPATH/src/github.com/ipfs/go-ipfs; make install)

Expand All @@ -25,7 +24,6 @@ script:

cache:
directories:
- $GOPATH/src/gx
- $GOPATH/pkg/mod
- $HOME/.cache/go-build

Expand Down
20 changes: 4 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
all: deps
gx:
go get github.com/whyrusleeping/gx
go get github.com/whyrusleeping/gx-go
deps: gx
gx --verbose install --global
gx-go rewrite
test: deps
gx test -v -race -coverprofile=coverage.txt -covermode=atomic .
rw:
gx-go rewrite
rwundo:
gx-go rewrite --undo
publish: rwundo
gx publish
.PHONY: all gx deps test rw rwundo publish
test:
go test -v -race -coverprofile=coverage.txt -covermode=atomic .

.PHONY: test
7 changes: 2 additions & 5 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/path"
"github.com/ipfs/interface-go-ipfs-core/tests"
local "github.com/ipfs/iptb-plugins/local"
"github.com/ipfs/iptb/testbed"
Expand Down Expand Up @@ -171,11 +172,7 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
}

// empty node is pinned even with --empty-repo, we don't want that
emptyNode, err := iface.ParsePath("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn")
if err != nil {
errs <- err
return
}
emptyNode := path.New("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn")
if err := apis[i].Pin().Rm(ctx, emptyNode); err != nil {
errs <- err
return
Expand Down
16 changes: 8 additions & 8 deletions apifile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/ipfs/go-cid"
files "github.com/ipfs/go-ipfs-files"
unixfs "github.com/ipfs/go-unixfs"
iface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/path"
)

const forwardSeekLimit = 1 << 14 //16k

func (api *UnixfsAPI) Get(ctx context.Context, p iface.Path) (files.Node, error) {
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
var err error
p, err = api.core().ResolvePath(ctx, p)
Expand Down Expand Up @@ -48,7 +48,7 @@ type apiFile struct {
ctx context.Context
core *HttpApi
size int64
path iface.Path
path path.Path

r *Response
at int64
Expand Down Expand Up @@ -114,7 +114,7 @@ func (f *apiFile) Size() (int64, error) {
return f.size, nil
}

func (api *UnixfsAPI) getFile(ctx context.Context, p iface.Path, size int64) (files.Node, error) {
func (api *UnixfsAPI) getFile(ctx context.Context, p path.Path, size int64) (files.Node, error) {
f := &apiFile{
ctx: ctx,
core: api.core(),
Expand Down Expand Up @@ -177,13 +177,13 @@ func (it *apiIter) Next() bool {

switch it.cur.Type {
case unixfs.THAMTShard, unixfs.TMetadata, unixfs.TDirectory:
it.curFile, err = it.core.getDir(it.ctx, iface.IpfsPath(c), int64(it.cur.Size))
it.curFile, err = it.core.getDir(it.ctx, path.IpfsPath(c), int64(it.cur.Size))
if err != nil {
it.err = err
return false
}
case unixfs.TFile:
it.curFile, err = it.core.getFile(it.ctx, iface.IpfsPath(c), int64(it.cur.Size))
it.curFile, err = it.core.getFile(it.ctx, path.IpfsPath(c), int64(it.cur.Size))
if err != nil {
it.err = err
return false
Expand All @@ -203,7 +203,7 @@ type apiDir struct {
ctx context.Context
core *UnixfsAPI
size int64
path iface.Path
path path.Path

dec *json.Decoder
}
Expand All @@ -224,7 +224,7 @@ func (d *apiDir) Entries() files.DirIterator {
}
}

func (api *UnixfsAPI) getDir(ctx context.Context, p iface.Path, size int64) (files.Node, error) {
func (api *UnixfsAPI) getDir(ctx context.Context, p path.Path, size int64) (files.Node, error) {
resp, err := api.core().Request("ls", p.String()).
Option("resolve-size", true).
Option("stream", true).Send(ctx)
Expand Down
11 changes: 6 additions & 5 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ipfs/go-cid"
"github.com/ipfs/interface-go-ipfs-core"
caopts "github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/path"
mh "github.com/multiformats/go-multihash"
)

Expand All @@ -26,8 +27,8 @@ func (s *blockStat) Size() int {
return s.BSize
}

func (s *blockStat) Path() iface.ResolvedPath {
return iface.IpldPath(s.cid)
func (s *blockStat) Path() path.Resolved {
return path.IpldPath(s.cid)
}

func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockPutOption) (iface.BlockStat, error) {
Expand Down Expand Up @@ -60,7 +61,7 @@ func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockP
return &out, nil
}

func (api *BlockAPI) Get(ctx context.Context, p iface.Path) (io.Reader, error) {
func (api *BlockAPI) Get(ctx context.Context, p path.Path) (io.Reader, error) {
resp, err := api.core().Request("block/get", p.String()).Send(ctx)
if err != nil {
return nil, err
Expand All @@ -79,7 +80,7 @@ func (api *BlockAPI) Get(ctx context.Context, p iface.Path) (io.Reader, error) {
return b, nil
}

func (api *BlockAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.BlockRmOption) error {
func (api *BlockAPI) Rm(ctx context.Context, p path.Path, opts ...caopts.BlockRmOption) error {
options, err := caopts.BlockRmOptions(opts...)
if err != nil {
return err
Expand All @@ -105,7 +106,7 @@ func (api *BlockAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.BlockR
return nil
}

func (api *BlockAPI) Stat(ctx context.Context, p iface.Path) (iface.BlockStat, error) {
func (api *BlockAPI) Stat(ctx context.Context, p path.Path) (iface.BlockStat, error) {
var out blockStat
err := api.core().Request("block/stat", p.String()).Exec(ctx, &out)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
"github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-ipld-format"
"github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/path"
)

type httpNodeAdder HttpApi
type HttpDagServ httpNodeAdder
type pinningHttpNodeAdder httpNodeAdder

func (api *HttpDagServ) Get(ctx context.Context, c cid.Cid) (format.Node, error) {
r, err := api.core().Block().Get(ctx, iface.IpldPath(c))
r, err := api.core().Block().Get(ctx, path.IpldPath(c))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func (api *HttpDagServ) Pinning() format.NodeAdder {
}

func (api *HttpDagServ) Remove(ctx context.Context, c cid.Cid) error {
return api.core().Block().Rm(ctx, iface.IpldPath(c)) //TODO: should we force rm?
return api.core().Block().Rm(ctx, path.IpldPath(c)) //TODO: should we force rm?
}

func (api *HttpDagServ) RemoveMany(ctx context.Context, cids []cid.Cid) error {
Expand Down
6 changes: 3 additions & 3 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"encoding/json"

"github.com/ipfs/interface-go-ipfs-core"
caopts "github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/path"
"github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-peerstore"
notif "github.com/libp2p/go-libp2p-routing/notifications"
Expand Down Expand Up @@ -37,7 +37,7 @@ func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (peerstore.PeerInfo,
}
}

func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caopts.DhtFindProvidersOption) (<-chan peerstore.PeerInfo, error) {
func (api *DhtAPI) FindProviders(ctx context.Context, p path.Path, opts ...caopts.DhtFindProvidersOption) (<-chan peerstore.PeerInfo, error) {
options, err := caopts.DhtFindProvidersOptions(opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -93,7 +93,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
return res, nil
}

func (api *DhtAPI) Provide(ctx context.Context, p iface.Path, opts ...caopts.DhtProvideOption) error {
func (api *DhtAPI) Provide(ctx context.Context, p path.Path, opts ...caopts.DhtProvideOption) error {
options, err := caopts.DhtProvideOptions(opts...)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/ipfs/go-merkledag v0.0.3
github.com/ipfs/go-path v0.0.3
github.com/ipfs/go-unixfs v0.0.4
github.com/ipfs/interface-go-ipfs-core v0.0.6
github.com/ipfs/interface-go-ipfs-core v0.0.7
github.com/ipfs/iptb v1.4.0
github.com/ipfs/iptb-plugins v0.0.1
github.com/libp2p/go-libp2p-net v0.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
github.com/ipfs/interface-go-ipfs-core v0.0.6 h1:yf9D2cMLVgBMXHL+gs/HepDc/M7ZXQXYdoN0eXl7z9c=
github.com/ipfs/interface-go-ipfs-core v0.0.6/go.mod h1:VceUOYu+kPEy8Ev/gAhzXFTIfc/7xILKnL4fgZg8tZM=
github.com/ipfs/interface-go-ipfs-core v0.0.7 h1:KfPVykJTT2viS/NdIC7xUEmnS9jDufl3FXivatAxtZM=
github.com/ipfs/interface-go-ipfs-core v0.0.7/go.mod h1:VceUOYu+kPEy8Ev/gAhzXFTIfc/7xILKnL4fgZg8tZM=
github.com/ipfs/iptb v1.4.0 h1:YFYTrCkLMRwk/35IMyC6+yjoQSHTEcNcefBStLJzgvo=
github.com/ipfs/iptb v1.4.0/go.mod h1:1rzHpCYtNp87/+hTxG5TfCVn/yMY3dKnLn8tBiMfdmg=
github.com/ipfs/iptb-plugins v0.0.1 h1:aUHbQ4y8/lKIBX/FN0KXe3c4NldPLsq7VyW2CcFXbhE=
Expand Down
6 changes: 3 additions & 3 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ipfs/interface-go-ipfs-core"
caopts "github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/path"
"github.com/libp2p/go-libp2p-peer"
)

Expand All @@ -22,9 +23,8 @@ func (k *keyOutput) Name() string {
return k.JName
}

func (k *keyOutput) Path() iface.Path {
p, _ := iface.ParsePath("/ipns/" + k.Id)
return p
func (k *keyOutput) Path() path.Path {
return path.New("/ipns/" + k.Id)
}

func (k *keyOutput) ID() peer.ID {
Expand Down
17 changes: 9 additions & 8 deletions name.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ipfs/interface-go-ipfs-core"
caopts "github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/options/namesys"
"github.com/ipfs/interface-go-ipfs-core/path"
)

type NameAPI HttpApi
Expand All @@ -17,18 +18,18 @@ type ipnsEntry struct {
JName string `json:"Name"`
JValue string `json:"Value"`

path iface.Path
path path.Path
}

func (e *ipnsEntry) Name() string {
return e.JName
}

func (e *ipnsEntry) Value() iface.Path {
func (e *ipnsEntry) Value() path.Path {
return e.path
}

func (api *NameAPI) Publish(ctx context.Context, p iface.Path, opts ...caopts.NamePublishOption) (iface.IpnsEntry, error) {
func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.NamePublishOption) (iface.IpnsEntry, error) {
options, err := caopts.NamePublishOptions(opts...)
if err != nil {
return nil, err
Expand All @@ -48,8 +49,8 @@ func (api *NameAPI) Publish(ctx context.Context, p iface.Path, opts ...caopts.Na
if err := req.Exec(ctx, &out); err != nil {
return nil, err
}
out.path, err = iface.ParsePath(out.JValue)
return &out, err
out.path = path.New(out.JValue)
return &out, out.path.IsValid()
}

func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.NameResolveOption) (<-chan iface.IpnsResult, error) {
Expand Down Expand Up @@ -93,7 +94,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
}
var ires iface.IpnsResult
if err == nil {
ires.Path, err = iface.ParsePath(out.Path)
ires.Path = path.New(out.Path)
}

select {
Expand All @@ -109,7 +110,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
return res, nil
}

func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.NameResolveOption) (iface.Path, error) {
func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.NameResolveOption) (path.Path, error) {
options, err := caopts.NameResolveOptions(opts...)
if err != nil {
return nil, err
Expand All @@ -131,7 +132,7 @@ func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.Nam
return nil, err
}

return iface.ParsePath(out.Path)
return path.New(out.Path), nil
}

func (api *NameAPI) core() *HttpApi {
Expand Down
Loading

0 comments on commit 6062f4d

Please sign in to comment.