Commit Graph

343 Commits

Author SHA1 Message Date
Kishan Sagathiya
c0b8301525 Fix #854: 404 on deleting a pin that isn't part of pinset (#854)
With this commit
- If cid in `DELETE /pins/{cid}` isn't part of the pinset, it would
return 404
- If path in `DELETE /pins/{keyType}/{path}` resolves to a cid that
isn't part of the pinset, it would return 404
2019-07-29 13:26:53 +02:00
Hector Sanjuan
7a78620017
Fix #853: Make a more orderly shutdown of rest api libp2p host (#855)
Cancelling its context before closing the listeners and de-registering
protocols is ground for panics on libp2p.
2019-07-26 17:32:11 +02:00
Hector Sanjuan
7c636061bd
Improve pin/unpin method signatures (#843)
* Improve pin/unpin method signatures:

These changes the following Cluster Go API methods:

* -> Cluster.Pin(ctx, cid, options) (pin, error)
* -> Cluster.Unpin(ctx, cid) (pin, error)
* -> Cluster.PinPath(ctx, path, opts) (pin,error)

Pin and Unpin now return the pinned object.

The signature of the methods now matches that of the API Client, is clearer as
to what options the user can set and is aligned with PinPath, UnpinPath, which
returned pin methods.

The REST API now returns the Pinned/Unpinned object rather than 204-Accepted.

This was necessary for a cleaner pin/update approach, which I'm working on in
another branch.

Most of the changes here are updating tests to the new signatures

* Adapt load-balancing client to new Pin/Unpin signatures

* cluster.go: Fix typo

Co-Authored-By: Kishan Sagathiya <kishansagathiya@gmail.com>

* cluster.go: Fix typo

Co-Authored-By: Kishan Sagathiya <kishansagathiya@gmail.com>
2019-07-22 15:39:11 +02:00
Kishan Sagathiya
b6ba67804f Fix #448: rest api client: Load balancing client implementations
This adds a LoadBalancing rest client implementation which is initialized with a set of client configurations and can use two strategies: failover and roundrobin (more strategies can be added by implementing the LBStrategy interface).
2019-07-19 15:17:51 +02:00
Kishan Mohanbhai Sagathiya
586253a2ce JSON Config object key should match JSON tags
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
2019-07-15 17:47:35 +05:30
Protocol Labs
4c8738f585 Fix #765 Added needed gx references 2019-07-04 13:57:52 +01:00
Hector Sanjuan
b804e61ef0 Update deps along with go-libp2p-core refactor
Lots of rewrites in imports...
2019-06-14 13:10:45 +02:00
Adrian Lanzafame
5a61d5bef8
add IPFSPinStatusFromString benchmark
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-06-05 11:48:39 +10:00
Michael Muré
5515bdd7d7
Fix: api: replace two regex with strings.HasPrefix()
Those regex were compiled with each call to the function. As it's
called by PinLs, this resulted in a significant amount of memory used,
500MB in my case after a single call.

License: MIT
Signed-off-by: Michael Muré <batolettre@gmail.com>
2019-06-04 20:13:35 +02:00
Hector Sanjuan
99be078548 Fix: ipfsproxy: fix test failing with empty multiaddresses
This is a recent change in the multiaddress library to disallow
empty addresses.
2019-05-27 14:27:23 +02:00
Hector Sanjuan
196aa23f34 Fix #787: Connectivity fixes
Currently, unless doing Join() (--bootstrap), we do not connect to any peers on startup.

We however loaded up the peerstore file and Raft will automatically connect
older peers to figure out who is the leader etc. DHT bootstrap, after Raft
was working, did the rest.

For CRDTs we need to connect to people on a normal boot as otherwise, unless
bootstrapping, this does not happen, even if the peerstore contains known peers.

This introduces a number of changes:

* Move peerstore file management back inside the Cluster component, which was
already in charge of saving the peerstore file.
* We keep saving all "known addresses" but we load them with a non permanent
TTL, so that there will be clean up of peers we're not connected to for long.
* "Bootstrap" (connect) to a small number of peers during Cluster component creation.
* Bootstrap the DHT asap after this, so that other cluster components can
initialize with a working peer discovery mechanism.
* CRDT Trust() method will now:
  * Protect the trusted Peer ID in the conn manager
  * Give top priority in the PeerManager to that Peer (see below)
  * Mark addresses as permanent in the Peerstore

The PeerManager now attaches priorities to peers when importing them and is
able to order them according to that priority. The result is that peers with
high priority are saved first in the peerstore file. When we load the peerstore
file, the first entries in it are given the highest priority.

This means that during startup we will connect to "trusted peers" first
(because they have been tagged with priority in the previous run and saved at
the top of the list). Once connected to a small number of peers, we let the
DHT bootstrap process in the background do the rest and discover the network.

All this makes the peerstore file a "bootstrap" list for CRDTs and we will attempt
to connect to peers on that list until some of those connections succeed.
2019-05-27 14:27:23 +02:00
Hector Sanjuan
c59873e076 update deps 2019-05-21 11:34:33 +02:00
Hector Sanjuan
d51c2a0377 Merge branch 'master' into feat/monitor-ring 2019-05-16 15:46:30 +02:00
Hector Sanjuan
a86c7cae2b rpc auth: handle some auth errors gracefully
particuarly we will ignore authorization errors for some broadcasts and somply
not include those responses in the assembled one.
2019-05-09 21:23:49 +02:00
Hector Sanjuan
949e6f2364 RPC auth: Support Trusted Peers in CRDT consensus component.
TrustedPeers are specified in the configuration. Additional peers
can be added at runtime with Trust/Distrust functions.

Unfortunately we cannot use consensus.PeerAdd as a way to trust a peer as
cluster.PeerAdd+Join can be called by any peer and this calls
consensus.PeerAdd.

The result is consensus.PeerAdd doing a lot in Raft while consensus.Trust does
nothing, while in CRDTs consensus.Trust does something but consensus.PeerAdd
does nothing. But this is more or less consistent.
2019-05-09 19:48:40 +02:00
Adrian Lanzafame
e69f440523
add String method for Pin type
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-05-07 18:50:03 +10:00
Adrian Lanzafame
ff6e559744
add String method for GlobalPinInfo type
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-05-07 12:04:59 +10:00
Hector Sanjuan
3d49ac26a5 Feat: Split components into RPC Services
I had thought of this for a very long time but there were no compelling
reasons to do it. Specifying RPC endpoint permissions becomes however
significantly nicer if each Component is a different RPC Service. This also
fixes some naming issues like having to prefix methods with the component name
to separate them from methods named in the same way in some other component
(Pin and IPFSPin).
2019-05-04 21:36:10 +01:00
Hector Sanjuan
036e3da7f1 Proxy pin/update: Respond with BadRequest when arguments missing 2019-05-02 10:32:13 +01:00
Hector Sanjuan
da24114ae0 Proxy: hijack pin/update
The IPFS pin/update endpoint takes two arguments and usually
unpins the first and pins the second. It is a bit more efficient
to do it in a single operation than two separate ones.

This will make the proxy endpoint hijack pin/update requests.

First, the FROM pin is fetched from the state. If present, we
set the options (replication factors, actual allocations) from
that pin to the new one. Then we pin the TO item and proceed
to unpin the FROM item when `unpin` is not false.

We need to support path resolving, just like IPFS, therefore
it was necessary to expose IPFSResolve() via RPC.
2019-04-29 16:36:40 +02:00
Hector Sanjuan
2144f4bd42 Types: make UserAllocations []peer.ID instead of string
It seems we forgot to convert this after peer.IDs became serializable. This
fixes it.
2019-04-29 16:24:38 +02:00
Kishan Mohanbhai Sagathiya
fa8d5c973c Invalid filter should throw BadRequest
- for GET `/allocations` and GET `/pins` an invalid filter now result
in BadRequest
- Added tests for the same
2019-04-24 21:54:12 +05:30
Kishan Mohanbhai Sagathiya
b2796b951a Default allocations filter should be all
Currently `curl -X GET http://localhost:9094/allocations` results in an
empty array, because no filter is provided. Solution to this would be
either 1) to consider filter as all if no filter is provided by the user
or 2) to make the `filter` parameter mandatory and reply with BadRequest
if no filter is provided

This commit makes the default filter as all
2019-04-24 20:24:08 +05:30
Adrian Lanzafame
ebcf40cf7d
rename TS to ReceivedAt
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-04-18 16:09:18 +10:00
Hector Sanjuan
7711ab8cfd
Replace underlying slice with ring.Ring in metrics window
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-04-18 16:09:18 +10:00
Hector Sanjuan
acbd7fda60 Consensus: add new "crdt" consensus component
This adds a new "crdt" consensus component using go-ds-crdt.

This implies several refactors to fully make cluster consensus-component
independent:

* Delete mapstate and fully adopt dsstate (after people have migrated).
* Return errors from state methods rather than ignoring them.
* Add a new "datastore" modules so that we can configure datastores in the
   main configuration like other components.
* Let the consensus components fully define the "state.State". Thus, they do
not receive the state, they receive the storage where we put the state (a
go-datastore).
* Allow to customize how the monitor component obtains Peers() (the current
  peerset), including avoiding using the current peerset. At the moment the
  crdt consensus uses the monitoring component to define the current peerset.
  Therefore the monitor component cannot rely on the consensus component to
  produce a peerset.
* Re-factor/re-implementation of "ipfs-cluster-service state"
  operations. Includes the dissapearance of the "migrate" one.

The CRDT consensus component defines creates a crdt-datastore (with ipfs-lite)
and uses it to intitialize a dssate. Thus the crdt-store is elegantly
wrapped. Any modifications to the state get automatically replicated to other
peers. We store all the CRDT DAG blocks in the local datastore.

The consensus components only expose a ReadOnly state, as any modifications to
the shared state should happen through them.

DHT and PubSub facilities must now be created outside of Cluster and passed in
so they can be re-used by different components.
2019-04-17 19:14:26 +02:00
Hector Sanjuan
a25f4ecb10 Fix #743: Use lowercase "version" in json version object
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2019-04-10 11:15:56 +02:00
Hector Sanjuan
94a781ef21
Merge pull request #735 from jmank88/url-nocopy
support --nocopy when adding URLs
2019-03-27 15:18:08 +01:00
jmank88
76c798e313 support --nocopy when adding URLs 2019-03-26 10:22:37 -05:00
chenminjian
36d78e55c6 refact: remove duplicative package
License: MIT
Signed-off-by: chenminjian <727180553@qq.com>
2019-03-26 20:17:03 +08:00
Kishan Mohanbhai Sagathiya
be50543fef Omitempty IPFSID 2019-03-19 22:23:02 +05:30
Kishan Mohanbhai Sagathiya
99a7528d85 Make make check pass 2019-03-18 19:50:42 +05:30
Kishan Mohanbhai Sagathiya
660109c147 Merge branch 'master' into issue_715 2019-03-18 18:25:22 +05:30
Kishan Mohanbhai Sagathiya
226953dd26 Make IPFSID pointer
Make IPFSID pointer so that it can be made nil when empty
2019-03-18 18:24:56 +05:30
Kishan Mohanbhai Sagathiya
8a06936ccd Bug fix: input isn't valid multihash
Some command were failing with `input isn't valid multihash`, due to
empty peer.ID. This commit omit peer id from IPFSID when empty, thus
avoiding the error state
2019-03-14 18:28:36 +05:30
Alexey Novikov
a586548e62 fix #636: review nitpicks
License: MIT
Signed-off-by: Alexey Novikov <alexey@novikov.io>
2019-03-11 05:25:26 +00:00
Alexey Novikov
53d624e701 fix #636: mitingate long header attack
License: MIT
Signed-off-by: Alexey Novikov <alexey@novikov.io>
2019-03-10 21:16:26 +00:00
Hector Sanjuan
a9bd43575f types/AddedOutput: remove omitempty in cid 2019-03-07 11:30:08 +00:00
Hector Sanjuan
374ec59256 Fix tests 2019-03-06 19:29:41 +00:00
Hector Sanjuan
0008f69162 Types: make AddedOutput carry a cid.Cid
This was a leftover. For consisency, all CIDs coming out of the API
should have the canonical cid form ( { "/": "cid" } ), otherwise
we are inconsistent.
2019-03-06 18:48:25 +00:00
Kishan Mohanbhai Sagathiya
27a59991f6 Hide extract_headers_path, extract_headers_ttl
proxy: "extract_headers_path" and "extract_headers_ttl" should be
hidden options in the config
2019-03-06 17:55:06 +05:30
Hector Sanjuan
23db807b87 ipfsproxy: use PinPath to match IPFS behaviour
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2019-03-04 15:54:34 +00:00
Hector Sanjuan
6a37c5c7f8
Merge pull request #694 from alekswn/fix/645-BasicAuthTest
fix #645: Basic Authentication test in REST API
2019-03-03 23:21:48 +00:00
Alexey Novikov
d1c0729a5e fix #645: fix error messages
License: MIT
Signed-off-by: Alexey Novikov <alexey@novikov.io>
2019-03-02 14:08:53 +00:00
Alexey Novikov
b4cb46fc5b fix #645: golint
License: MIT
Signed-off-by: Alexey Novikov <alexey@novikov.io>
2019-03-02 08:35:09 +00:00
Alexey Novikov
d49bfff8c4 fix #645: Basic Authentication test in REST API
License: MIT
Signed-off-by: Alexey Novikov <alexey@novikov.io>
2019-03-02 07:28:40 +00:00
Hector Sanjuan
a7db3a9f9b Remove leftover debugging init() function
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2019-03-01 14:20:35 +00:00
Hector Sanjuan
ea85cf7805 Rename "test.Test*" to "test.*" (test.TestCid1 -> test.Cid1)
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2019-02-27 20:19:10 +00:00
Hector Sanjuan
9df6344a07 Avoid using string testing CIDs and use cid.Cids directly
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2019-02-27 20:09:31 +00:00
Hector Sanjuan
c4b18cd5f6 Address issues from self-review
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2019-02-27 18:43:29 +00:00