2018-08-23 12:12:55 +00:00
|
|
|
// Package client provides a Go Client for the IPFS Cluster API provided
|
|
|
|
// by the "api/rest" component. It supports both the HTTP(s) endpoint and
|
|
|
|
// the libp2p-http endpoint.
|
2017-12-05 20:44:22 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2017-12-08 14:38:30 +00:00
|
|
|
"fmt"
|
2018-12-19 20:19:47 +00:00
|
|
|
"net"
|
2017-12-05 20:44:22 +00:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2022-06-15 09:19:17 +00:00
|
|
|
"github.com/ipfs-cluster/ipfs-cluster/api"
|
2018-08-30 23:14:06 +00:00
|
|
|
|
2023-03-27 19:49:08 +00:00
|
|
|
files "github.com/ipfs/boxo/files"
|
2018-03-21 12:25:32 +00:00
|
|
|
shell "github.com/ipfs/go-ipfs-api"
|
2020-03-13 20:40:02 +00:00
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2022-09-06 14:57:17 +00:00
|
|
|
host "github.com/libp2p/go-libp2p/core/host"
|
|
|
|
peer "github.com/libp2p/go-libp2p/core/peer"
|
|
|
|
pnet "github.com/libp2p/go-libp2p/core/pnet"
|
2017-12-05 20:44:22 +00:00
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
2017-12-08 14:38:30 +00:00
|
|
|
madns "github.com/multiformats/go-multiaddr-dns"
|
2020-08-27 12:10:58 +00:00
|
|
|
manet "github.com/multiformats/go-multiaddr/net"
|
2018-06-27 04:03:15 +00:00
|
|
|
|
|
|
|
"go.opencensus.io/plugin/ochttp"
|
|
|
|
"go.opencensus.io/plugin/ochttp/propagation/tracecontext"
|
|
|
|
"go.opencensus.io/trace"
|
2017-12-05 20:44:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Configuration defaults
|
|
|
|
var (
|
2018-08-08 19:11:26 +00:00
|
|
|
DefaultTimeout = 0
|
2018-03-21 12:25:32 +00:00
|
|
|
DefaultAPIAddr = "/ip4/127.0.0.1/tcp/9094"
|
|
|
|
DefaultLogLevel = "info"
|
|
|
|
DefaultProxyPort = 9095
|
2018-08-08 19:11:26 +00:00
|
|
|
ResolveTimeout = 30 * time.Second
|
2018-08-10 13:10:16 +00:00
|
|
|
DefaultPort = 9094
|
2017-12-05 20:44:22 +00:00
|
|
|
)
|
|
|
|
|
2017-12-06 23:04:51 +00:00
|
|
|
var loggingFacility = "apiclient"
|
|
|
|
var logger = logging.Logger(loggingFacility)
|
2017-12-05 20:44:22 +00:00
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
// Client interface defines the interface to be used by API clients to
|
2018-06-27 04:03:15 +00:00
|
|
|
// interact with the ipfs-cluster-service. All methods take a
|
|
|
|
// context.Context as their first parameter, this allows for
|
2022-06-15 10:16:05 +00:00
|
|
|
// timing out and canceling of requests as well as recording
|
2018-06-27 04:03:15 +00:00
|
|
|
// metrics and tracing of requests through the API.
|
2018-08-30 23:14:06 +00:00
|
|
|
type Client interface {
|
|
|
|
// ID returns information about the cluster Peer.
|
2022-03-19 01:52:46 +00:00
|
|
|
ID(context.Context) (api.ID, error)
|
2018-08-30 23:14:06 +00:00
|
|
|
|
|
|
|
// Peers requests ID information for all cluster peers.
|
2022-03-23 00:27:57 +00:00
|
|
|
Peers(context.Context, chan<- api.ID) error
|
2018-08-30 23:14:06 +00:00
|
|
|
// PeerAdd adds a new peer to the cluster.
|
2022-03-19 01:52:46 +00:00
|
|
|
PeerAdd(ctx context.Context, pid peer.ID) (api.ID, error)
|
2018-08-30 23:14:06 +00:00
|
|
|
// PeerRm removes a current peer from the cluster
|
2018-06-27 04:03:15 +00:00
|
|
|
PeerRm(ctx context.Context, pid peer.ID) error
|
2018-08-30 23:14:06 +00:00
|
|
|
|
|
|
|
// Add imports files to the cluster from the given paths.
|
2022-03-19 01:52:46 +00:00
|
|
|
Add(ctx context.Context, paths []string, params api.AddParams, out chan<- api.AddedOutput) error
|
2018-08-30 23:14:06 +00:00
|
|
|
// AddMultiFile imports new files from a MultiFileReader.
|
2022-03-19 01:52:46 +00:00
|
|
|
AddMultiFile(ctx context.Context, multiFileR *files.MultiFileReader, params api.AddParams, out chan<- api.AddedOutput) error
|
2018-08-30 23:14:06 +00:00
|
|
|
|
|
|
|
// Pin tracks a Cid with the given replication factor and a name for
|
|
|
|
// human-friendliness.
|
2022-04-07 11:53:30 +00:00
|
|
|
Pin(ctx context.Context, ci api.Cid, opts api.PinOptions) (api.Pin, error)
|
2018-08-30 23:14:06 +00:00
|
|
|
// Unpin untracks a Cid from cluster.
|
2022-04-07 11:53:30 +00:00
|
|
|
Unpin(ctx context.Context, ci api.Cid) (api.Pin, error)
|
2018-08-30 23:14:06 +00:00
|
|
|
|
Add PinPath/UnpinPath support.
Squashed commit of the following:
commit 38cf569c6aed77c46ee4e0f8baa4d1a9daf8f03e
Merge: d125f69 aaada42
Author: Hector Sanjuan <hsanjuan@users.noreply.github.com>
Date: Wed Feb 20 11:02:00 2019 +0000
Merge pull request #634 from ipfs/issue_450
Support PinPath, UnpinPath (resolve before pinning)
commit aaada42054e1f1c7b2abb1270859d0de41a0e5d8
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 19 22:16:25 2019 +0530
formatResponse accepts api.Pin and not api.PinSerial
commit b5da4bea045865814cc422da71827b44ddd44b90
Merge: ba59036 cc8dd7e
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 19 21:36:46 2019 +0530
Merge branch 'master' into issue_450
commit ba5903649c1df1dba20f4d6f7e3573d6fe24921f
Merge: f002914 d59880c
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Feb 18 08:41:11 2019 +0530
Merge branch 'issue_450' of github.com:ipfs/ipfs-cluster into issue_450
commit f00291494c0c02621c2296cbb7ac71e4c23aa9ec
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Feb 18 08:31:39 2019 +0530
PinPath: more improvements
Added tracing for new methods
commit d59880c338eaa8214fe06b4f930a540793d78407
Merge: 0ca4c7c b4f0eb3
Author: Hector Sanjuan <hsanjuan@users.noreply.github.com>
Date: Wed Feb 13 15:22:49 2019 +0000
Merge branch 'master' into issue_450
commit 0ca4c7c3b0670ed9c8279f8274d36e3485c10030
Merge: d35017a ecef9ea
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 12 13:10:13 2019 +0530
Merge branch 'master' into issue_450
commit d35017a8de91ca9fc9a9a047c48c75134cee9f98
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 12 13:07:25 2019 +0530
PinPath: more improvements
- Worth having `PinOptions` as a separate field in the struct and
constructing the query in the test with ToQuery()
- sharness: "intialization" line can be placed outside the tests at
the top
commit 68e3b90417ffbad89d41a70ac81d85f9037f8848
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Sun Feb 10 21:43:50 2019 +0530
Using if-continue pattern instead of if-else
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 3c29799f3b85be328b27508332ab92049d8b82f3
Merge: 956790b 4324889
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Thu Feb 7 10:25:52 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 956790b381db9858e4194f983e898b07dc51ba66
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 21:11:20 2019 +0530
Removing resolved path
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 7191cc46cedfbec116a9746937e28881b50ca044
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 16:45:07 2019 +0530
Fix go vet
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit f8b3d5b63b1b7569e2a3e0d82894fd4491c246c4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 16:07:03 2019 +0530
Fixed linting error
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 23c57eb467755a1f21387a1615a7f34e97348053
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 09:20:41 2019 +0530
Fixed tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 0caedd94aefeb3b6649dedc214cb4b849ace2ea4
Merge: 17e555e 5a7ee1d
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 00:07:10 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 17e555e4a7c574413df90aac70c5cc29cab98f54
Author: Hector Sanjuan <code@hector.link>
Date: Tue Feb 5 16:58:50 2019 +0000
PinPath: address some feedback + improvements
* Changed client's Pin() API and PinPath to be consistent
* Added helper methods to turn PinPath to query and back
* Make code and tests build
* Use TestCidResolved everywhere
* Fix cluster.PinPath arguments
* Fix formatting of responses with --no-status
* Make tests readable and call Fatal when needed
* Use a pathTestCases variable
commit f0e7369c47c5ddadc8ed45df5fd2d4d9b2d42b38
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 5 18:34:26 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Addressed review comments as in
https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-198751932
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit a8b4f181d2d7afed32ee41331dfaab19fd66a173
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 29 22:41:27 2019 +0530
Fixing tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit e39b95ca19e4d75506f4f492678245ef13936a44
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 29 14:52:53 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- PinPath and UnpinPath should return api.Pin
- PinPath should accept pin options
- Removing duplicate logic for Resolve from cluster
- And many other review comments https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-195509504
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit d146075126320896665ba58d337a13789f68ea86
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 23 17:08:41 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
PinPath(in both rest and rpc) should return a serializable struct in the
form `{"\":"Q...cid..string..."}` (as used in "github.com/ipfs/go-cid"
to marshal and unmarshal)
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 1f4869568a8adb450275257154ea3a26d03a30f3
Merge: 7acfd28 a244af9
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 23 07:18:56 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 7acfd282732ddf2282a67d4f9d0170a494eb3ed4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 22 18:14:32 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- RPC must always use serializable structs
- In command, just use pin with path as cid is also a valid path
- Addressing many other small review comments as in
https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-192122534
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 36905041e1e3f0b204942030aab3ab7b5b9e4d62
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 16 09:36:42 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Extra logic for path checking should go into resolve so that it can be
properly reused
Added sharness tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 9116bda3534e77bb391d873051bb520a1b01a326
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 16 08:08:07 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
error strings should not be capitalized
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit ca7e61861374f456300a85ddc0374e594f74f963
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 15 23:40:25 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Tests
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 522fbcd899f01c01680375561a32a87464157c0a
Merge: f1a56ab f7bc468
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 15 10:40:54 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit f1a56ab925fb74c0c44273a4524afa4843cf757f
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Jan 14 20:58:17 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- IPFS Connector should act as a pure IPFS client, any extra logic
should go to cluster.go
- Use cid.Undef, instead of cid.Cid{}
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit c83b91054f6774f1f9d4930cfc3f1fa28236f57c
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Thu Jan 10 08:57:17 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- Separate handlers, methods and rpc apis for PinPath and UnpinPath from
Pin and Unpin
- Support ipld paths as well
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 719dff88129366ce3ccb5e04cb6f8082a0915c5c
Merge: 91ceb47 21170c4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 9 19:38:35 2019 +0530
Merge branch 'issue_450_old' into HEAD
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 91ceb4796259ca7ef2974ec43e6a278a12796b13
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 9 19:36:41 2019 +0530
Revert "WIP: Figure out why test does not impleme"
This reverts commit 28a3a3f25dce6f296c8cbef86221644c099a7e75.
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 28a3a3f25dce6f296c8cbef86221644c099a7e75
Author: cd10012 <ced361@nyu.edu>
Date: Tue Jul 24 23:23:10 2018 -0400
WIP: Figure out why test does not implement IPFSConnector interface...
License: MIT
Signed-off-by: cd10012 <ced361@nyu.edu>
commit 21170c48e77e69583db64544b08120a9baf40d8d
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 8 10:37:59 2019 +0530
Support PinPath, UnpinPath (resolve before pinning)
This commit adds API support for pinning using path
`POST /pins/<ipfs or ipns path>` and `DELETE /pins/<ipfs or ipns path>`
will resolve the path into a cid and perform perform pinning or
unpinning
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Co-authored-by: Hector Sanjuan <hector@protocol.ai>
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2019-02-20 11:07:50 +00:00
|
|
|
// PinPath resolves given path into a cid and performs the pin operation.
|
2022-03-19 01:52:46 +00:00
|
|
|
PinPath(ctx context.Context, path string, opts api.PinOptions) (api.Pin, error)
|
Add PinPath/UnpinPath support.
Squashed commit of the following:
commit 38cf569c6aed77c46ee4e0f8baa4d1a9daf8f03e
Merge: d125f69 aaada42
Author: Hector Sanjuan <hsanjuan@users.noreply.github.com>
Date: Wed Feb 20 11:02:00 2019 +0000
Merge pull request #634 from ipfs/issue_450
Support PinPath, UnpinPath (resolve before pinning)
commit aaada42054e1f1c7b2abb1270859d0de41a0e5d8
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 19 22:16:25 2019 +0530
formatResponse accepts api.Pin and not api.PinSerial
commit b5da4bea045865814cc422da71827b44ddd44b90
Merge: ba59036 cc8dd7e
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 19 21:36:46 2019 +0530
Merge branch 'master' into issue_450
commit ba5903649c1df1dba20f4d6f7e3573d6fe24921f
Merge: f002914 d59880c
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Feb 18 08:41:11 2019 +0530
Merge branch 'issue_450' of github.com:ipfs/ipfs-cluster into issue_450
commit f00291494c0c02621c2296cbb7ac71e4c23aa9ec
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Feb 18 08:31:39 2019 +0530
PinPath: more improvements
Added tracing for new methods
commit d59880c338eaa8214fe06b4f930a540793d78407
Merge: 0ca4c7c b4f0eb3
Author: Hector Sanjuan <hsanjuan@users.noreply.github.com>
Date: Wed Feb 13 15:22:49 2019 +0000
Merge branch 'master' into issue_450
commit 0ca4c7c3b0670ed9c8279f8274d36e3485c10030
Merge: d35017a ecef9ea
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 12 13:10:13 2019 +0530
Merge branch 'master' into issue_450
commit d35017a8de91ca9fc9a9a047c48c75134cee9f98
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 12 13:07:25 2019 +0530
PinPath: more improvements
- Worth having `PinOptions` as a separate field in the struct and
constructing the query in the test with ToQuery()
- sharness: "intialization" line can be placed outside the tests at
the top
commit 68e3b90417ffbad89d41a70ac81d85f9037f8848
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Sun Feb 10 21:43:50 2019 +0530
Using if-continue pattern instead of if-else
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 3c29799f3b85be328b27508332ab92049d8b82f3
Merge: 956790b 4324889
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Thu Feb 7 10:25:52 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 956790b381db9858e4194f983e898b07dc51ba66
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 21:11:20 2019 +0530
Removing resolved path
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 7191cc46cedfbec116a9746937e28881b50ca044
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 16:45:07 2019 +0530
Fix go vet
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit f8b3d5b63b1b7569e2a3e0d82894fd4491c246c4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 16:07:03 2019 +0530
Fixed linting error
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 23c57eb467755a1f21387a1615a7f34e97348053
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 09:20:41 2019 +0530
Fixed tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 0caedd94aefeb3b6649dedc214cb4b849ace2ea4
Merge: 17e555e 5a7ee1d
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 00:07:10 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 17e555e4a7c574413df90aac70c5cc29cab98f54
Author: Hector Sanjuan <code@hector.link>
Date: Tue Feb 5 16:58:50 2019 +0000
PinPath: address some feedback + improvements
* Changed client's Pin() API and PinPath to be consistent
* Added helper methods to turn PinPath to query and back
* Make code and tests build
* Use TestCidResolved everywhere
* Fix cluster.PinPath arguments
* Fix formatting of responses with --no-status
* Make tests readable and call Fatal when needed
* Use a pathTestCases variable
commit f0e7369c47c5ddadc8ed45df5fd2d4d9b2d42b38
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 5 18:34:26 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Addressed review comments as in
https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-198751932
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit a8b4f181d2d7afed32ee41331dfaab19fd66a173
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 29 22:41:27 2019 +0530
Fixing tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit e39b95ca19e4d75506f4f492678245ef13936a44
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 29 14:52:53 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- PinPath and UnpinPath should return api.Pin
- PinPath should accept pin options
- Removing duplicate logic for Resolve from cluster
- And many other review comments https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-195509504
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit d146075126320896665ba58d337a13789f68ea86
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 23 17:08:41 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
PinPath(in both rest and rpc) should return a serializable struct in the
form `{"\":"Q...cid..string..."}` (as used in "github.com/ipfs/go-cid"
to marshal and unmarshal)
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 1f4869568a8adb450275257154ea3a26d03a30f3
Merge: 7acfd28 a244af9
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 23 07:18:56 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 7acfd282732ddf2282a67d4f9d0170a494eb3ed4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 22 18:14:32 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- RPC must always use serializable structs
- In command, just use pin with path as cid is also a valid path
- Addressing many other small review comments as in
https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-192122534
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 36905041e1e3f0b204942030aab3ab7b5b9e4d62
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 16 09:36:42 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Extra logic for path checking should go into resolve so that it can be
properly reused
Added sharness tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 9116bda3534e77bb391d873051bb520a1b01a326
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 16 08:08:07 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
error strings should not be capitalized
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit ca7e61861374f456300a85ddc0374e594f74f963
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 15 23:40:25 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Tests
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 522fbcd899f01c01680375561a32a87464157c0a
Merge: f1a56ab f7bc468
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 15 10:40:54 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit f1a56ab925fb74c0c44273a4524afa4843cf757f
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Jan 14 20:58:17 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- IPFS Connector should act as a pure IPFS client, any extra logic
should go to cluster.go
- Use cid.Undef, instead of cid.Cid{}
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit c83b91054f6774f1f9d4930cfc3f1fa28236f57c
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Thu Jan 10 08:57:17 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- Separate handlers, methods and rpc apis for PinPath and UnpinPath from
Pin and Unpin
- Support ipld paths as well
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 719dff88129366ce3ccb5e04cb6f8082a0915c5c
Merge: 91ceb47 21170c4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 9 19:38:35 2019 +0530
Merge branch 'issue_450_old' into HEAD
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 91ceb4796259ca7ef2974ec43e6a278a12796b13
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 9 19:36:41 2019 +0530
Revert "WIP: Figure out why test does not impleme"
This reverts commit 28a3a3f25dce6f296c8cbef86221644c099a7e75.
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 28a3a3f25dce6f296c8cbef86221644c099a7e75
Author: cd10012 <ced361@nyu.edu>
Date: Tue Jul 24 23:23:10 2018 -0400
WIP: Figure out why test does not implement IPFSConnector interface...
License: MIT
Signed-off-by: cd10012 <ced361@nyu.edu>
commit 21170c48e77e69583db64544b08120a9baf40d8d
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 8 10:37:59 2019 +0530
Support PinPath, UnpinPath (resolve before pinning)
This commit adds API support for pinning using path
`POST /pins/<ipfs or ipns path>` and `DELETE /pins/<ipfs or ipns path>`
will resolve the path into a cid and perform perform pinning or
unpinning
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Co-authored-by: Hector Sanjuan <hector@protocol.ai>
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2019-02-20 11:07:50 +00:00
|
|
|
// UnpinPath resolves given path into a cid and performs the unpin operation.
|
|
|
|
// It returns api.Pin of the given cid before it is unpinned.
|
2022-03-19 01:52:46 +00:00
|
|
|
UnpinPath(ctx context.Context, path string) (api.Pin, error)
|
Add PinPath/UnpinPath support.
Squashed commit of the following:
commit 38cf569c6aed77c46ee4e0f8baa4d1a9daf8f03e
Merge: d125f69 aaada42
Author: Hector Sanjuan <hsanjuan@users.noreply.github.com>
Date: Wed Feb 20 11:02:00 2019 +0000
Merge pull request #634 from ipfs/issue_450
Support PinPath, UnpinPath (resolve before pinning)
commit aaada42054e1f1c7b2abb1270859d0de41a0e5d8
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 19 22:16:25 2019 +0530
formatResponse accepts api.Pin and not api.PinSerial
commit b5da4bea045865814cc422da71827b44ddd44b90
Merge: ba59036 cc8dd7e
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 19 21:36:46 2019 +0530
Merge branch 'master' into issue_450
commit ba5903649c1df1dba20f4d6f7e3573d6fe24921f
Merge: f002914 d59880c
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Feb 18 08:41:11 2019 +0530
Merge branch 'issue_450' of github.com:ipfs/ipfs-cluster into issue_450
commit f00291494c0c02621c2296cbb7ac71e4c23aa9ec
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Feb 18 08:31:39 2019 +0530
PinPath: more improvements
Added tracing for new methods
commit d59880c338eaa8214fe06b4f930a540793d78407
Merge: 0ca4c7c b4f0eb3
Author: Hector Sanjuan <hsanjuan@users.noreply.github.com>
Date: Wed Feb 13 15:22:49 2019 +0000
Merge branch 'master' into issue_450
commit 0ca4c7c3b0670ed9c8279f8274d36e3485c10030
Merge: d35017a ecef9ea
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 12 13:10:13 2019 +0530
Merge branch 'master' into issue_450
commit d35017a8de91ca9fc9a9a047c48c75134cee9f98
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 12 13:07:25 2019 +0530
PinPath: more improvements
- Worth having `PinOptions` as a separate field in the struct and
constructing the query in the test with ToQuery()
- sharness: "intialization" line can be placed outside the tests at
the top
commit 68e3b90417ffbad89d41a70ac81d85f9037f8848
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Sun Feb 10 21:43:50 2019 +0530
Using if-continue pattern instead of if-else
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 3c29799f3b85be328b27508332ab92049d8b82f3
Merge: 956790b 4324889
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Thu Feb 7 10:25:52 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 956790b381db9858e4194f983e898b07dc51ba66
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 21:11:20 2019 +0530
Removing resolved path
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 7191cc46cedfbec116a9746937e28881b50ca044
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 16:45:07 2019 +0530
Fix go vet
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit f8b3d5b63b1b7569e2a3e0d82894fd4491c246c4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 16:07:03 2019 +0530
Fixed linting error
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 23c57eb467755a1f21387a1615a7f34e97348053
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 09:20:41 2019 +0530
Fixed tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 0caedd94aefeb3b6649dedc214cb4b849ace2ea4
Merge: 17e555e 5a7ee1d
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 00:07:10 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 17e555e4a7c574413df90aac70c5cc29cab98f54
Author: Hector Sanjuan <code@hector.link>
Date: Tue Feb 5 16:58:50 2019 +0000
PinPath: address some feedback + improvements
* Changed client's Pin() API and PinPath to be consistent
* Added helper methods to turn PinPath to query and back
* Make code and tests build
* Use TestCidResolved everywhere
* Fix cluster.PinPath arguments
* Fix formatting of responses with --no-status
* Make tests readable and call Fatal when needed
* Use a pathTestCases variable
commit f0e7369c47c5ddadc8ed45df5fd2d4d9b2d42b38
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 5 18:34:26 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Addressed review comments as in
https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-198751932
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit a8b4f181d2d7afed32ee41331dfaab19fd66a173
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 29 22:41:27 2019 +0530
Fixing tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit e39b95ca19e4d75506f4f492678245ef13936a44
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 29 14:52:53 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- PinPath and UnpinPath should return api.Pin
- PinPath should accept pin options
- Removing duplicate logic for Resolve from cluster
- And many other review comments https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-195509504
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit d146075126320896665ba58d337a13789f68ea86
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 23 17:08:41 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
PinPath(in both rest and rpc) should return a serializable struct in the
form `{"\":"Q...cid..string..."}` (as used in "github.com/ipfs/go-cid"
to marshal and unmarshal)
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 1f4869568a8adb450275257154ea3a26d03a30f3
Merge: 7acfd28 a244af9
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 23 07:18:56 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 7acfd282732ddf2282a67d4f9d0170a494eb3ed4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 22 18:14:32 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- RPC must always use serializable structs
- In command, just use pin with path as cid is also a valid path
- Addressing many other small review comments as in
https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-192122534
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 36905041e1e3f0b204942030aab3ab7b5b9e4d62
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 16 09:36:42 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Extra logic for path checking should go into resolve so that it can be
properly reused
Added sharness tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 9116bda3534e77bb391d873051bb520a1b01a326
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 16 08:08:07 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
error strings should not be capitalized
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit ca7e61861374f456300a85ddc0374e594f74f963
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 15 23:40:25 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Tests
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 522fbcd899f01c01680375561a32a87464157c0a
Merge: f1a56ab f7bc468
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 15 10:40:54 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit f1a56ab925fb74c0c44273a4524afa4843cf757f
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Jan 14 20:58:17 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- IPFS Connector should act as a pure IPFS client, any extra logic
should go to cluster.go
- Use cid.Undef, instead of cid.Cid{}
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit c83b91054f6774f1f9d4930cfc3f1fa28236f57c
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Thu Jan 10 08:57:17 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- Separate handlers, methods and rpc apis for PinPath and UnpinPath from
Pin and Unpin
- Support ipld paths as well
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 719dff88129366ce3ccb5e04cb6f8082a0915c5c
Merge: 91ceb47 21170c4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 9 19:38:35 2019 +0530
Merge branch 'issue_450_old' into HEAD
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 91ceb4796259ca7ef2974ec43e6a278a12796b13
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 9 19:36:41 2019 +0530
Revert "WIP: Figure out why test does not impleme"
This reverts commit 28a3a3f25dce6f296c8cbef86221644c099a7e75.
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 28a3a3f25dce6f296c8cbef86221644c099a7e75
Author: cd10012 <ced361@nyu.edu>
Date: Tue Jul 24 23:23:10 2018 -0400
WIP: Figure out why test does not implement IPFSConnector interface...
License: MIT
Signed-off-by: cd10012 <ced361@nyu.edu>
commit 21170c48e77e69583db64544b08120a9baf40d8d
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 8 10:37:59 2019 +0530
Support PinPath, UnpinPath (resolve before pinning)
This commit adds API support for pinning using path
`POST /pins/<ipfs or ipns path>` and `DELETE /pins/<ipfs or ipns path>`
will resolve the path into a cid and perform perform pinning or
unpinning
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Co-authored-by: Hector Sanjuan <hector@protocol.ai>
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2019-02-20 11:07:50 +00:00
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
// Allocations returns the consensus state listing all tracked items
|
|
|
|
// and the peers that should be pinning them.
|
2022-03-19 01:52:46 +00:00
|
|
|
Allocations(ctx context.Context, filter api.PinType, out chan<- api.Pin) error
|
2018-08-30 23:14:06 +00:00
|
|
|
// Allocation returns the current allocations for a given Cid.
|
2022-04-07 11:53:30 +00:00
|
|
|
Allocation(ctx context.Context, ci api.Cid) (api.Pin, error)
|
2018-08-30 23:14:06 +00:00
|
|
|
|
|
|
|
// Status returns the current ipfs state for a given Cid. If local is true,
|
|
|
|
// the information affects only the current peer, otherwise the information
|
|
|
|
// is fetched from all cluster peers.
|
2022-04-07 11:53:30 +00:00
|
|
|
Status(ctx context.Context, ci api.Cid, local bool) (api.GlobalPinInfo, error)
|
2022-03-01 12:13:52 +00:00
|
|
|
// StatusCids status information for the requested CIDs.
|
2022-04-07 11:53:30 +00:00
|
|
|
StatusCids(ctx context.Context, cids []api.Cid, local bool, out chan<- api.GlobalPinInfo) error
|
2018-08-30 23:14:06 +00:00
|
|
|
// StatusAll gathers Status() for all tracked items.
|
2022-03-22 09:56:16 +00:00
|
|
|
StatusAll(ctx context.Context, filter api.TrackerStatus, local bool, out chan<- api.GlobalPinInfo) error
|
2018-08-30 23:14:06 +00:00
|
|
|
|
|
|
|
// Recover retriggers pin or unpin ipfs operations for a Cid in error
|
|
|
|
// state. If local is true, the operation is limited to the current
|
|
|
|
// peer, otherwise it happens on every cluster peer.
|
2022-04-07 11:53:30 +00:00
|
|
|
Recover(ctx context.Context, ci api.Cid, local bool) (api.GlobalPinInfo, error)
|
2018-08-30 23:14:06 +00:00
|
|
|
// RecoverAll triggers Recover() operations on all tracked items. If
|
|
|
|
// local is true, the operation is limited to the current peer.
|
|
|
|
// Otherwise, it happens everywhere.
|
2022-03-22 09:56:16 +00:00
|
|
|
RecoverAll(ctx context.Context, local bool, out chan<- api.GlobalPinInfo) error
|
2018-08-30 23:14:06 +00:00
|
|
|
|
2021-01-13 21:09:21 +00:00
|
|
|
// Alerts returns information health events in the cluster (expired
|
|
|
|
// metrics etc.).
|
2022-03-19 01:52:46 +00:00
|
|
|
Alerts(ctx context.Context) ([]api.Alert, error)
|
2019-12-12 18:51:28 +00:00
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
// Version returns the ipfs-cluster peer's version.
|
2022-03-19 01:52:46 +00:00
|
|
|
Version(context.Context) (api.Version, error)
|
2018-08-30 23:14:06 +00:00
|
|
|
|
2018-10-01 18:09:26 +00:00
|
|
|
// IPFS returns an instance of go-ipfs-api's Shell, pointing to a
|
|
|
|
// Cluster's IPFS proxy endpoint.
|
2018-06-27 04:03:15 +00:00
|
|
|
IPFS(context.Context) *shell.Shell
|
2018-10-01 18:09:26 +00:00
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
// GetConnectGraph returns an ipfs-cluster connection graph.
|
2022-03-19 01:52:46 +00:00
|
|
|
GetConnectGraph(context.Context) (api.ConnectGraph, error)
|
2018-10-07 16:32:46 +00:00
|
|
|
|
2018-10-21 06:34:50 +00:00
|
|
|
// Metrics returns a map with the latest metrics of matching name
|
2018-10-07 16:32:46 +00:00
|
|
|
// for the current cluster peers.
|
2022-03-19 01:52:46 +00:00
|
|
|
Metrics(ctx context.Context, name string) ([]api.Metric, error)
|
2019-10-22 05:40:32 +00:00
|
|
|
|
2019-10-24 14:37:26 +00:00
|
|
|
// MetricNames returns the list of metric types.
|
|
|
|
MetricNames(ctx context.Context) ([]string, error)
|
2019-11-07 17:35:42 +00:00
|
|
|
|
2019-10-22 05:40:32 +00:00
|
|
|
// RepoGC runs garbage collection on IPFS daemons of cluster peers and
|
|
|
|
// returns collected CIDs. If local is true, it would garbage collect
|
|
|
|
// only on contacted peer, otherwise on all peers' IPFS daemons.
|
2022-03-19 01:52:46 +00:00
|
|
|
RepoGC(ctx context.Context, local bool) (api.GlobalRepoGC, error)
|
2023-04-20 11:18:38 +00:00
|
|
|
|
|
|
|
// Health returns no content when everything is ok, and an error otherwise
|
|
|
|
Health(ctx context.Context) (error)
|
2018-08-30 23:14:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:44:22 +00:00
|
|
|
// Config allows to configure the parameters to connect
|
|
|
|
// to the ipfs-cluster REST API.
|
|
|
|
type Config struct {
|
2019-02-20 13:40:49 +00:00
|
|
|
// Enable SSL support. Only valid without APIAddr.
|
2017-12-05 20:44:22 +00:00
|
|
|
SSL bool
|
|
|
|
// Skip certificate verification (insecure)
|
|
|
|
NoVerifyCert bool
|
|
|
|
|
|
|
|
// Username and password for basic authentication
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
|
2017-12-08 14:38:30 +00:00
|
|
|
// The ipfs-cluster REST API endpoint in multiaddress form
|
2018-08-10 13:10:16 +00:00
|
|
|
// (takes precedence over host:port). It this address contains
|
|
|
|
// an /ipfs/, /p2p/ or /dnsaddr, the API will be contacted
|
|
|
|
// through a libp2p tunnel, thus getting encryption for
|
2018-08-13 08:28:25 +00:00
|
|
|
// free. Using the libp2p tunnel will ignore any configurations.
|
2017-12-05 20:44:22 +00:00
|
|
|
APIAddr ma.Multiaddr
|
|
|
|
|
2017-12-08 14:38:30 +00:00
|
|
|
// REST API endpoint host and port. Only valid without
|
2019-02-20 13:40:49 +00:00
|
|
|
// APIAddr.
|
2017-12-08 14:38:30 +00:00
|
|
|
Host string
|
|
|
|
Port string
|
|
|
|
|
2019-02-20 13:40:49 +00:00
|
|
|
// If APIAddr is provided, and the peer uses private networks (pnet),
|
|
|
|
// then we need to provide the key. If the peer is the cluster peer,
|
|
|
|
// this corresponds to the cluster secret.
|
2020-03-13 20:40:02 +00:00
|
|
|
ProtectorKey pnet.PSK
|
2018-03-15 13:44:18 +00:00
|
|
|
|
2018-03-21 12:25:32 +00:00
|
|
|
// ProxyAddr is used to obtain a go-ipfs-api Shell instance pointing
|
|
|
|
// to the ipfs proxy endpoint of ipfs-cluster. If empty, the location
|
2018-08-10 13:10:16 +00:00
|
|
|
// will be guessed from one of APIAddr/Host,
|
2018-03-21 12:25:32 +00:00
|
|
|
// and the port used will be ipfs-cluster's proxy default port (9095)
|
|
|
|
ProxyAddr ma.Multiaddr
|
|
|
|
|
2017-12-05 20:44:22 +00:00
|
|
|
// Define timeout for network operations
|
|
|
|
Timeout time.Duration
|
|
|
|
|
2017-12-07 10:27:37 +00:00
|
|
|
// Specifies if we attempt to re-use connections to the same
|
|
|
|
// hosts.
|
|
|
|
DisableKeepAlives bool
|
|
|
|
|
2017-12-06 23:04:51 +00:00
|
|
|
// LogLevel defines the verbosity of the logging facility
|
2017-12-05 20:44:22 +00:00
|
|
|
LogLevel string
|
|
|
|
}
|
|
|
|
|
2020-10-04 11:06:58 +00:00
|
|
|
// AsTemplateFor creates client configs from resolved multiaddresses
|
2021-01-13 21:09:21 +00:00
|
|
|
func (c *Config) AsTemplateFor(addrs []ma.Multiaddr) []*Config {
|
2020-10-04 11:06:58 +00:00
|
|
|
var cfgs []*Config
|
2020-10-08 17:14:03 +00:00
|
|
|
for _, addr := range addrs {
|
2020-10-04 11:06:58 +00:00
|
|
|
cfg := *c
|
2020-10-08 17:14:03 +00:00
|
|
|
cfg.APIAddr = addr
|
2020-10-04 11:06:58 +00:00
|
|
|
cfgs = append(cfgs, &cfg)
|
|
|
|
}
|
|
|
|
return cfgs
|
|
|
|
}
|
|
|
|
|
|
|
|
// AsTemplateForResolvedAddress creates client configs from a multiaddress
|
2020-10-08 17:14:03 +00:00
|
|
|
func (c *Config) AsTemplateForResolvedAddress(ctx context.Context, addr ma.Multiaddr) ([]*Config, error) {
|
|
|
|
resolvedAddrs, err := resolveAddr(ctx, addr)
|
2020-10-04 11:06:58 +00:00
|
|
|
if err != nil {
|
2020-10-08 17:14:03 +00:00
|
|
|
return nil, err
|
2020-10-04 11:06:58 +00:00
|
|
|
}
|
|
|
|
return c.AsTemplateFor(resolvedAddrs), nil
|
|
|
|
}
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
// DefaultClient provides methods to interact with the ipfs-cluster API. Use
|
|
|
|
// NewDefaultClient() to create one.
|
|
|
|
type defaultClient struct {
|
2017-12-05 20:44:22 +00:00
|
|
|
ctx context.Context
|
2020-04-14 17:58:00 +00:00
|
|
|
cancel context.CancelFunc
|
2017-12-05 20:44:22 +00:00
|
|
|
config *Config
|
2018-03-16 12:23:38 +00:00
|
|
|
transport *http.Transport
|
2018-03-15 13:44:18 +00:00
|
|
|
net string
|
|
|
|
hostname string
|
2017-12-07 10:27:37 +00:00
|
|
|
client *http.Client
|
2018-03-15 13:44:18 +00:00
|
|
|
p2p host.Host
|
2017-12-05 20:44:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
// NewDefaultClient initializes a client given a Config.
|
|
|
|
func NewDefaultClient(cfg *Config) (Client, error) {
|
2020-04-14 17:58:00 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
2018-08-30 23:14:06 +00:00
|
|
|
client := &defaultClient{
|
2018-03-15 13:44:18 +00:00
|
|
|
ctx: ctx,
|
2020-04-14 17:58:00 +00:00
|
|
|
cancel: cancel,
|
2018-03-15 13:44:18 +00:00
|
|
|
config: cfg,
|
|
|
|
}
|
|
|
|
|
2018-08-10 13:10:16 +00:00
|
|
|
if client.config.Port == "" {
|
|
|
|
client.config.Port = fmt.Sprintf("%d", DefaultPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
err := client.setupAPIAddr()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = client.resolveAPIAddr()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = client.setupHTTPClient()
|
2018-03-15 13:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-12-05 20:44:22 +00:00
|
|
|
|
2018-03-15 13:44:18 +00:00
|
|
|
err = client.setupHostname()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-03-21 12:25:32 +00:00
|
|
|
err = client.setupProxy()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-03-15 13:44:18 +00:00
|
|
|
if lvl := cfg.LogLevel; lvl != "" {
|
|
|
|
logging.SetLogLevel(loggingFacility, lvl)
|
2017-12-05 20:44:22 +00:00
|
|
|
} else {
|
2018-03-15 13:44:18 +00:00
|
|
|
logging.SetLogLevel(loggingFacility, DefaultLogLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
}
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
func (c *defaultClient) setupAPIAddr() error {
|
2018-12-19 20:15:37 +00:00
|
|
|
if c.config.APIAddr != nil {
|
|
|
|
return nil // already setup by user
|
|
|
|
}
|
|
|
|
|
2018-08-10 13:10:16 +00:00
|
|
|
var addr ma.Multiaddr
|
|
|
|
var err error
|
2018-12-19 20:19:47 +00:00
|
|
|
|
|
|
|
if c.config.Host == "" { //default
|
|
|
|
addr, err := ma.NewMultiaddr(DefaultAPIAddr)
|
2018-08-10 13:10:16 +00:00
|
|
|
c.config.APIAddr = addr
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-12-19 20:19:47 +00:00
|
|
|
var addrStr string
|
|
|
|
ip := net.ParseIP(c.config.Host)
|
|
|
|
switch {
|
|
|
|
case ip == nil:
|
|
|
|
addrStr = fmt.Sprintf("/dns4/%s/tcp/%s", c.config.Host, c.config.Port)
|
|
|
|
case ip.To4() != nil:
|
|
|
|
addrStr = fmt.Sprintf("/ip4/%s/tcp/%s", c.config.Host, c.config.Port)
|
|
|
|
default:
|
|
|
|
addrStr = fmt.Sprintf("/ip6/%s/tcp/%s", c.config.Host, c.config.Port)
|
|
|
|
}
|
|
|
|
|
|
|
|
addr, err = ma.NewMultiaddr(addrStr)
|
|
|
|
c.config.APIAddr = addr
|
|
|
|
return err
|
2018-08-10 13:10:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
func (c *defaultClient) resolveAPIAddr() error {
|
2018-12-19 20:15:37 +00:00
|
|
|
// Only resolve libp2p addresses. For HTTP addresses, we let
|
|
|
|
// the default client handle any resolving. We extract the hostname
|
|
|
|
// in setupHostname()
|
|
|
|
if !IsPeerAddress(c.config.APIAddr) {
|
|
|
|
return nil
|
|
|
|
}
|
2020-10-07 04:51:04 +00:00
|
|
|
resolved, err := resolveAddr(c.ctx, c.config.APIAddr)
|
2018-08-10 13:10:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.config.APIAddr = resolved[0]
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
func (c *defaultClient) setupHTTPClient() error {
|
2018-03-16 12:23:38 +00:00
|
|
|
var err error
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
switch {
|
2018-08-10 13:10:16 +00:00
|
|
|
case IsPeerAddress(c.config.APIAddr):
|
2018-03-16 12:23:38 +00:00
|
|
|
err = c.enableLibp2p()
|
2019-11-30 02:36:58 +00:00
|
|
|
case isUnixSocketAddress(c.config.APIAddr):
|
|
|
|
err = c.enableUnix()
|
2018-03-15 13:44:18 +00:00
|
|
|
case c.config.SSL:
|
2018-03-16 12:23:38 +00:00
|
|
|
err = c.enableTLS()
|
2018-03-15 13:44:18 +00:00
|
|
|
default:
|
2018-03-16 12:23:38 +00:00
|
|
|
c.defaultTransport()
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-12-05 20:44:22 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 13:44:18 +00:00
|
|
|
c.client = &http.Client{
|
2018-06-27 04:03:15 +00:00
|
|
|
Transport: &ochttp.Transport{
|
|
|
|
Base: c.transport,
|
|
|
|
Propagation: &tracecontext.HTTPFormat{},
|
|
|
|
StartOptions: trace.StartOptions{SpanKind: trace.SpanKindClient},
|
|
|
|
FormatSpanName: func(req *http.Request) string { return req.Host + ":" + req.URL.Path + ":" + req.Method },
|
|
|
|
NewClientTrace: ochttp.NewSpanAnnotatingClientTrace,
|
|
|
|
},
|
|
|
|
Timeout: c.config.Timeout,
|
2017-12-08 14:38:30 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-12-08 14:38:30 +00:00
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
func (c *defaultClient) setupHostname() error {
|
2018-08-10 13:10:16 +00:00
|
|
|
// Extract host:port form APIAddr or use Host:Port.
|
|
|
|
// For libp2p, hostname is set in enableLibp2p()
|
2019-11-30 02:36:58 +00:00
|
|
|
// For unix sockets, hostname set in enableUnix()
|
|
|
|
if IsPeerAddress(c.config.APIAddr) || isUnixSocketAddress(c.config.APIAddr) {
|
2018-12-19 20:15:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
_, hostname, err := manet.DialArgs(c.config.APIAddr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-12-05 20:44:22 +00:00
|
|
|
}
|
2019-11-30 02:36:58 +00:00
|
|
|
|
2018-12-19 20:15:37 +00:00
|
|
|
c.hostname = hostname
|
2018-03-15 13:44:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-03-21 12:25:32 +00:00
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
func (c *defaultClient) setupProxy() error {
|
2018-03-21 12:25:32 +00:00
|
|
|
if c.config.ProxyAddr != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
// Guess location from APIAddr
|
2018-03-21 12:25:32 +00:00
|
|
|
port, err := ma.NewMultiaddr(fmt.Sprintf("/tcp/%d", DefaultProxyPort))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-10 13:10:16 +00:00
|
|
|
c.config.ProxyAddr = ma.Split(c.config.APIAddr)[0].Encapsulate(port)
|
2018-03-21 12:25:32 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// IPFS returns an instance of go-ipfs-api's Shell, pointing to the
|
2018-10-01 18:09:26 +00:00
|
|
|
// configured ProxyAddr (or to the default Cluster's IPFS proxy port).
|
2018-03-21 12:25:32 +00:00
|
|
|
// It re-uses this Client's HTTP client, thus will be constrained by
|
|
|
|
// the same configurations affecting it (timeouts...).
|
2018-06-27 04:03:15 +00:00
|
|
|
func (c *defaultClient) IPFS(ctx context.Context) *shell.Shell {
|
2018-03-21 12:25:32 +00:00
|
|
|
return shell.NewShellWithClient(c.config.ProxyAddr.String(), c.client)
|
|
|
|
}
|
2018-08-10 13:10:16 +00:00
|
|
|
|
|
|
|
// IsPeerAddress detects if the given multiaddress identifies a libp2p peer,
|
|
|
|
// either because it has the /p2p/ protocol or because it uses /dnsaddr/
|
|
|
|
func IsPeerAddress(addr ma.Multiaddr) bool {
|
|
|
|
if addr == nil {
|
|
|
|
return false
|
|
|
|
}
|
2019-08-15 11:19:26 +00:00
|
|
|
pid, err := addr.ValueForProtocol(ma.P_P2P)
|
2020-04-14 17:58:00 +00:00
|
|
|
dnsaddr, err2 := addr.ValueForProtocol(ma.P_DNSADDR)
|
2018-08-10 13:10:16 +00:00
|
|
|
return (pid != "" && err == nil) || (dnsaddr != "" && err2 == nil)
|
|
|
|
}
|
2019-11-30 02:36:58 +00:00
|
|
|
|
|
|
|
// isUnixSocketAddress returns if the given address corresponds to a
|
|
|
|
// unix socket.
|
|
|
|
func isUnixSocketAddress(addr ma.Multiaddr) bool {
|
|
|
|
if addr == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
value, err := addr.ValueForProtocol(ma.P_UNIX)
|
|
|
|
return (value != "" && err == nil)
|
|
|
|
}
|
2020-10-04 11:06:58 +00:00
|
|
|
|
2020-10-07 04:51:04 +00:00
|
|
|
// resolve addr
|
|
|
|
func resolveAddr(ctx context.Context, addr ma.Multiaddr) ([]ma.Multiaddr, error) {
|
|
|
|
resolveCtx, cancel := context.WithTimeout(ctx, ResolveTimeout)
|
|
|
|
defer cancel()
|
|
|
|
resolved, err := madns.Resolve(resolveCtx, addr)
|
|
|
|
if err != nil {
|
2020-10-08 17:14:03 +00:00
|
|
|
return nil, err
|
2020-10-04 11:06:58 +00:00
|
|
|
}
|
2021-01-13 21:09:21 +00:00
|
|
|
|
2020-10-07 04:51:04 +00:00
|
|
|
if len(resolved) == 0 {
|
2020-10-08 17:14:03 +00:00
|
|
|
return nil, fmt.Errorf("resolving %s returned 0 results", addr)
|
2020-10-04 11:06:58 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 04:51:04 +00:00
|
|
|
return resolved, nil
|
2020-10-05 03:48:30 +00:00
|
|
|
}
|