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