Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client/rpc: migrate go-ipfs-http-client #9906

Merged
merged 130 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
2020815
Setup repo
magik6k Nov 6, 2018
6d85aff
Initial structure, path stuff
magik6k Nov 6, 2018
35c271e
wip notice in readme
magik6k Nov 6, 2018
6c927fd
Partial ipld node impl
magik6k Nov 6, 2018
1cd2ec0
Init gx
magik6k Dec 20, 2018
16e97bf
It builds
magik6k Dec 21, 2018
fe4c9fd
Skeleton for tests
magik6k Dec 30, 2018
e8da6e2
Block API
magik6k Jan 7, 2019
ab89e0a
Partial Unixfs.Add
magik6k Jan 7, 2019
cf74d39
Partial Key API, ApiAddr funcion
magik6k Jan 8, 2019
c236393
Connect test swarms, don't compress api calls
magik6k Jan 8, 2019
7861315
Wrap single files in Unixfs.Add
magik6k Jan 8, 2019
f638bae
implement .Name
magik6k Jan 8, 2019
1acf416
Implement .Unixfs.Ls()
magik6k Jan 8, 2019
a6636aa
Imprement partian Pin API
magik6k Jan 8, 2019
0f7c839
Import missing unixfs dep
magik6k Jan 8, 2019
af197cb
api.WithOption
magik6k Jan 8, 2019
6d9dea6
Implement Unixfs.Get()
magik6k Jan 8, 2019
00597e6
Dag.Put
magik6k Jan 9, 2019
101910f
Object.New
magik6k Jan 9, 2019
31a4c37
Fix Dag.Put
magik6k Jan 9, 2019
c213e26
Unixfs.Add progress events
magik6k Jan 9, 2019
266c2f9
Implement Key API
magik6k Jan 15, 2019
9d647d0
Implement Pin API
magik6k Jan 15, 2019
eaa1938
Implement Object API
magik6k Jan 15, 2019
ed9f2dd
Implement DHT Api
magik6k Jan 15, 2019
cae0ff2
Implement Swarm Api
magik6k Jan 15, 2019
c2e0872
Implement PubSub Api
magik6k Jan 15, 2019
9b24cf0
Use cids in DHT calls
magik6k Jan 15, 2019
b7e258c
Reimplement DAG as DAGService
magik6k Jan 21, 2019
c3f2970
block: Pin option
magik6k Feb 4, 2019
af2edd1
tests: enable filestore
magik6k Feb 4, 2019
75cf2be
apifile: Implement Seek
magik6k Feb 4, 2019
bb83ccb
response: read trailing error headers
magik6k Feb 4, 2019
88139dd
dag: Interface updates
magik6k Feb 4, 2019
93bfcf9
unixfs: updated ls
magik6k Feb 4, 2019
1bc854b
pin: handle Rm options
magik6k Feb 4, 2019
c543354
Check for redirects
magik6k Feb 6, 2019
ef5bf40
Update imports to use extracted interface
magik6k Feb 11, 2019
0813d80
Fix govet warning in Dag
magik6k Feb 12, 2019
abc30e3
Register iptb plugin once
magik6k Feb 12, 2019
9a6ee6f
Improve test node spawning
magik6k Feb 14, 2019
f7dd0c6
Improve apifile error messages
magik6k Feb 14, 2019
e1b14d7
Implement missing methods
magik6k Feb 14, 2019
42273ca
Don't use valid() pattern
magik6k Feb 14, 2019
93f6846
dag: remove unused waitgroup
magik6k Feb 14, 2019
cc964b4
Simplify Object.New, remove ipldnode.go
magik6k Feb 14, 2019
a23da82
swarm: attach peerid if needed
magik6k Feb 14, 2019
f005b8d
pin: verify: parse bad node cids early
magik6k Feb 18, 2019
4a6d36d
pubsub: handle ctx
magik6k Feb 18, 2019
7229dbb
don't read all and then throw away the buffer
magik6k Feb 18, 2019
b6ace8d
response: handle late errors
magik6k Feb 18, 2019
7be8d01
response: option to disable output draining
magik6k Feb 18, 2019
3088776
swarm: always append peer IDs
magik6k Feb 18, 2019
745bf92
gofmt
magik6k Feb 18, 2019
27aa13f
return errors from constructor methods
magik6k Feb 19, 2019
fc299e7
pin verify: use temporary struct
magik6k Feb 19, 2019
a058e7d
response: Document zero-result Decode behaviour
magik6k Feb 19, 2019
db1af49
use mime.ParseMediaType for Content-Type response parsing
magik6k Feb 19, 2019
f34788e
cleanup Swarm.Peers
magik6k Feb 19, 2019
aa4d6e1
Add some docs to constructors
magik6k Feb 19, 2019
f6a3a4f
gofmt
magik6k Feb 19, 2019
ad844e3
response: simplify Decode
magik6k Feb 20, 2019
19d91fb
response: pass close error in decode
magik6k Feb 20, 2019
cc9968d
request: fix Content-Disposition header in Send
magik6k Feb 21, 2019
47b8201
test: don't panic on errors in async node construction
magik6k Feb 21, 2019
4b30924
Merge pull request ipfs/go-ipfs-http-client#1 from ipfs/feat/implement
magik6k Feb 23, 2019
0e800c3
update interface-go-ipfs-core and handle breaking changes
Stebalien Mar 26, 2019
b22be85
Merge pull request ipfs/go-ipfs-http-client#10 from ipfs/feat/update-…
Stebalien Mar 29, 2019
e76ecd3
nit: return concrete types
Stebalien Mar 26, 2019
c6f704b
return an error when the API file isn't found
Stebalien Mar 26, 2019
40f40b5
fix golang-ci lint nits
Stebalien Mar 26, 2019
c791d73
avoid canceling multiple times
Stebalien Mar 26, 2019
0e790f4
Merge pull request ipfs/go-ipfs-http-client#9 from ipfs/fix/nits
Stebalien Mar 29, 2019
1c07bed
Export (*HttpApi).request to enable building custom requests
hinshun Apr 2, 2019
e2fdd5a
Merge pull request ipfs/go-ipfs-http-client#13 from hinshun/export-re…
Stebalien Apr 3, 2019
70158ed
feed through context
Stebalien Apr 4, 2019
3b02ea4
api: add authenticated transport, and direct connection
Apr 10, 2019
3b67615
gomod: update iface with path refactor
magik6k Apr 26, 2019
0fc826d
Merge pull request ipfs/go-ipfs-http-client#14 from ipfs/feat/add-con…
Stebalien Apr 27, 2019
ea34bcb
Merge pull request ipfs/go-ipfs-http-client#16 from ipfs/feat/update-…
Stebalien Apr 27, 2019
11a990c
api: expose headers via HttpApi, copy headers during request build
postables May 1, 2019
d8c286b
api: remove WithAuthorization, DirectAPI client, instantiate header map
postables May 1, 2019
89600e6
api: add wip api test
postables May 1, 2019
37ea6eb
Merge branch 'master' into client/auth
bonedaddy May 1, 2019
efe3b60
api: call NewURLApiWithClient from NewApiWithClient
postables May 1, 2019
fd5010b
api: cleanup header and NewURLApiWithClient test
postables May 1, 2019
daf1b72
api: fix failing test
postables May 2, 2019
8b9e189
remove unused transport.go file
postables May 2, 2019
fd9d62f
Merge pull request ipfs/go-ipfs-http-client#15 from RTradeLtd/client/…
magik6k May 2, 2019
8d953a7
Use interface for RequestBuilder
magik6k May 10, 2019
ee2dec1
Merge pull request ipfs/go-ipfs-http-client#18 from ipfs/feat/iface-r…
Stebalien May 10, 2019
1b81f2e
add extended error handling
Stebalien Jun 12, 2019
2612353
use error from go-ipfs-cmds
Stebalien Jun 13, 2019
2fabc8c
Merge pull request ipfs/go-ipfs-http-client#20 from ipfs/feat/errors
Stebalien Jun 13, 2019
9345cfa
update to consolidated libp2p interface package (#21)
godcong Jul 21, 2019
be8f802
fix path miss in windows/add a new api create function (#23)
godcong Aug 12, 2019
b6b2ae3
doc: mark this package experimental instead of WIP (#30)
Stebalien Aug 31, 2019
d48f8fc
file: implement ReadAt
Stebalien Sep 11, 2019
c71a840
Merge pull request ipfs/go-ipfs-http-client#31 from ipfs/feat/read-at
Stebalien Sep 12, 2019
8f93063
Update pin.go
joeltg Dec 7, 2019
d9004a9
IDB58Decode -> Decode
willscott May 3, 2020
861ff4a
Merge pull request ipfs/go-ipfs-http-client#97 from ipfs/fix/decode
willscott May 4, 2020
7ebef96
update contributing link
stensonb May 12, 2020
b867648
Merge pull request ipfs/go-ipfs-http-client#101 from stensonb/patch-1
Stebalien May 12, 2020
247cb05
Bump interface-go-ipfs-core version (#117)
petar Jul 31, 2020
ea2a356
fix staticcheck
marten-seemann May 16, 2021
3bb5bd2
Merge pull request ipfs/go-ipfs-http-client#143 from ipfs/fix-staticc…
marten-seemann May 17, 2021
5322cf8
feat: pubsub http rpc with multibase (#151)
lidel Nov 29, 2021
b52c80c
skip TestHttpApi on Windows
galargh Jan 14, 2022
ee92934
Merge pull request ipfs/go-ipfs-http-client#154 from ipfs/web3-bot/sync
galargh Jan 14, 2022
b85aa96
fix: make Block().* return correct ABI based ipld.ErrNotFound errors
Jorropo Mar 27, 2022
5a8e2b7
chore: rename abyfyIpldErrNotFound to parseIPLDErrNotFound
Jorropo Mar 30, 2022
a2a6076
fix: parseIPLDErrNotFound test
Jorropo Mar 31, 2022
ddd3664
feat: update the error parsing for go-ipld-format to v0.4.0
Jorropo Mar 31, 2022
775bcb7
feat: add blockstore: block not found matching too
Jorropo Mar 31, 2022
54f6e90
fix: change CID breaking logic when parsing ipld.ErrNotFound
Jorropo Apr 2, 2022
f2f2109
test: add a false case test to blockstore parsing
Jorropo Apr 2, 2022
60a548b
correctness: only match CIDs matching go-cid.Cid.String output
Jorropo Apr 5, 2022
ebb2807
Merge pull request ipfs/go-ipfs-http-client#156 from ipfs/fix/ipld-Er…
Jorropo Apr 5, 2022
fd20901
fix: interop with 'block put' from go-ipfs 0.13 (#158)
lidel Apr 21, 2022
1cdb9ad
fix: interop with go-ipfs 0.13 (#160)
lidel Jun 23, 2022
0fff1d5
stop using the deprecated io/ioutil package
web3-bot Sep 23, 2022
1193b29
chore: remove unused linter directives
galargh Oct 1, 2022
0c9c9b9
Merge pull request ipfs/go-ipfs-http-client#157 from ipfs/web3-bot/sync
galargh Oct 1, 2022
75b6f45
chore: bumps for Kubo 0.18 and Routing API with stub for Put
Jorropo Feb 6, 2023
5c21cf0
docs: adding example of connection and pinning to README (#173)
PedrobyJoao Mar 28, 2023
8bebfc0
chore: migrate from go-libipfs to boxo
Jorropo Apr 16, 2023
7d82623
fix: use https URI when multiaddress specifies tls (#177)
rossjones May 15, 2023
86d8e75
client/rpc: migrate go-ipfs-http-client
Jorropo May 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,39 +127,6 @@ jobs:
working-directory: go-ipfs-api
- run: cmd/ipfs/ipfs shutdown
if: always()
go-ipfs-http-client:
needs: [interop-prep]
runs-on: ubuntu-latest
timeout-minutes: 5
env:
TEST_DOCKER: 0
TEST_FUSE: 0
TEST_VERBOSE: 1
TRAVIS: 1
GIT_PAGER: cat
IPFS_CHECK_RCMGR_DEFAULTS: 1
defaults:
run:
shell: bash
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/download-artifact@v3
with:
name: kubo
path: cmd/ipfs
- run: chmod +x cmd/ipfs/ipfs
- uses: actions/checkout@v3
with:
repository: ipfs/go-ipfs-http-client
path: go-ipfs-http-client
- uses: protocol/cache-go-action@v1
with:
name: ${{ github.job }}
- run: echo '${{ github.workspace }}/cmd/ipfs' >> $GITHUB_PATH
- run: go test -count=1 -v ./...
working-directory: go-ipfs-http-client
ipfs-webui:
needs: [interop-prep]
runs-on: ${{ fromJSON(github.repository == 'ipfs/kubo' && '["self-hosted", "linux", "x64", "2xlarge"]' || '"ubuntu-latest"') }}
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ linters:

linters-settings:
stylecheck:
checks:
- all
- '-ST1003'
Copy link
Member

@hacdias hacdias May 31, 2023

Choose a reason for hiding this comment

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

I'm fine with skipping this for now to avoid breaking people migrating, but the rule is indeed correct: https://github.com/golang/go/wiki/CodeReviewComments#initialisms

dot-import-whitelist:
- github.com/ipfs/kubo/test/cli/testutils
44 changes: 44 additions & 0 deletions client/rpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# `httpapi`

> IPFS CoreAPI implementation using HTTP API

This packages implements [`coreiface.CoreAPI`](https://pkg.go.dev/github.com/ipfs/boxo/coreiface#CoreAPI) over the HTTP API.

## Documentation

https://pkg.go.dev/github.com/ipfs/kubo/client/rpc

### Example

Pin file on your local IPFS node based on its CID:

```go
package main

import (
"context"
"fmt"

ipfsClient "github.com/ipfs/kubo/client/rpc"
path "github.com/ipfs/boxo/coreiface/path"
)

func main() {
// "Connect" to local node
node, err := ipfsClient.NewLocalApi()
if err != nil {
fmt.Printf(err)
return
}
// Pin a given file by its CID
ctx := context.Background()
cid := "bafkreidtuosuw37f5xmn65b3ksdiikajy7pwjjslzj2lxxz2vc4wdy3zku"
p := path.New(cid)
err = node.Pin().Add(ctx, p)
if err != nil {
fmt.Printf(err)
return
}
return
}
```
215 changes: 215 additions & 0 deletions client/rpc/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
package httpapi

import (
"errors"
"fmt"
"net/http"
"os"
"path/filepath"
"strings"

iface "github.com/ipfs/boxo/coreiface"
caopts "github.com/ipfs/boxo/coreiface/options"
"github.com/mitchellh/go-homedir"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
)

const (
DefaultPathName = ".ipfs"
DefaultPathRoot = "~/" + DefaultPathName
DefaultApiFile = "api"
EnvDir = "IPFS_PATH"
)

// ErrApiNotFound if we fail to find a running daemon.
var ErrApiNotFound = errors.New("ipfs api address could not be found")

// HttpApi implements github.com/ipfs/interface-go-ipfs-core/CoreAPI using
// IPFS HTTP API.
//
// For interface docs see
// https://godoc.org/github.com/ipfs/interface-go-ipfs-core#CoreAPI
type HttpApi struct {
url string
httpcli http.Client
Headers http.Header
applyGlobal func(*requestBuilder)
}

// NewLocalApi tries to construct new HttpApi instance communicating with local
// IPFS daemon
//
// Daemon api address is pulled from the $IPFS_PATH/api file.
// If $IPFS_PATH env var is not present, it defaults to ~/.ipfs
func NewLocalApi() (*HttpApi, error) {
baseDir := os.Getenv(EnvDir)
if baseDir == "" {
baseDir = DefaultPathRoot
}

return NewPathApi(baseDir)
}

// NewPathApi constructs new HttpApi by pulling api address from specified
// ipfspath. Api file should be located at $ipfspath/api
func NewPathApi(ipfspath string) (*HttpApi, error) {
a, err := ApiAddr(ipfspath)
if err != nil {
if os.IsNotExist(err) {
err = ErrApiNotFound
}
return nil, err
}
return NewApi(a)
}

// ApiAddr reads api file in specified ipfs path
func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
baseDir, err := homedir.Expand(ipfspath)
if err != nil {
return nil, err
}

apiFile := filepath.Join(baseDir, DefaultApiFile)

api, err := os.ReadFile(apiFile)
if err != nil {
return nil, err
}

return ma.NewMultiaddr(strings.TrimSpace(string(api)))
}

// NewApi constructs HttpApi with specified endpoint
func NewApi(a ma.Multiaddr) (*HttpApi, error) {
c := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DisableKeepAlives: true,
},
}

return NewApiWithClient(a, c)
}

// NewApiWithClient constructs HttpApi with specified endpoint and custom http client
func NewApiWithClient(a ma.Multiaddr, c *http.Client) (*HttpApi, error) {
_, url, err := manet.DialArgs(a)
if err != nil {
return nil, err
}

if a, err := ma.NewMultiaddr(url); err == nil {
_, host, err := manet.DialArgs(a)
if err == nil {
url = host
}
}

proto := "http://"

// By default, DialArgs is going to provide details suitable for connecting
// a socket to, but not really suitable for making an informed choice of http
// protocol. For multiaddresses specifying tls and/or https we want to make
// a https request instead of a http request.
protocols := a.Protocols()
for _, p := range protocols {
if p.Code == ma.P_HTTPS || p.Code == ma.P_TLS {
proto = "https://"
break
}
}

return NewURLApiWithClient(proto+url, c)
}

func NewURLApiWithClient(url string, c *http.Client) (*HttpApi, error) {
api := &HttpApi{
url: url,
httpcli: *c,
Headers: make(map[string][]string),
applyGlobal: func(*requestBuilder) {},
}

// We don't support redirects.
api.httpcli.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
return fmt.Errorf("unexpected redirect")
}
return api, nil
}

func (api *HttpApi) WithOptions(opts ...caopts.ApiOption) (iface.CoreAPI, error) {
options, err := caopts.ApiOptions(opts...)
if err != nil {
return nil, err
}

subApi := *api
subApi.applyGlobal = func(req *requestBuilder) {
if options.Offline {
req.Option("offline", options.Offline)
}
}

return &subApi, nil
}

func (api *HttpApi) Request(command string, args ...string) RequestBuilder {
headers := make(map[string]string)
if api.Headers != nil {
for k := range api.Headers {
headers[k] = api.Headers.Get(k)
}
}
return &requestBuilder{
command: command,
args: args,
shell: api,
headers: headers,
}
}

func (api *HttpApi) Unixfs() iface.UnixfsAPI {
return (*UnixfsAPI)(api)
}

func (api *HttpApi) Block() iface.BlockAPI {
return (*BlockAPI)(api)
}

func (api *HttpApi) Dag() iface.APIDagService {
return (*HttpDagServ)(api)
}

func (api *HttpApi) Name() iface.NameAPI {
return (*NameAPI)(api)
}

func (api *HttpApi) Key() iface.KeyAPI {
return (*KeyAPI)(api)
}

func (api *HttpApi) Pin() iface.PinAPI {
return (*PinAPI)(api)
}

func (api *HttpApi) Object() iface.ObjectAPI {
return (*ObjectAPI)(api)
}

func (api *HttpApi) Dht() iface.DhtAPI {
return (*DhtAPI)(api)
}

func (api *HttpApi) Swarm() iface.SwarmAPI {
return (*SwarmAPI)(api)
}

func (api *HttpApi) PubSub() iface.PubSubAPI {
return (*PubsubAPI)(api)
}

func (api *HttpApi) Routing() iface.RoutingAPI {
return (*RoutingAPI)(api)
}
Loading