2017-02-08 17:04:08 +00:00
|
|
|
// Package api holds declarations for types used in ipfs-cluster APIs to make
|
|
|
|
// them re-usable across differen tools. This include RPC API "Serial[izable]"
|
|
|
|
// versions for types. The Go API uses natives types, while RPC API,
|
2017-12-06 14:00:01 +00:00
|
|
|
// REST APIs etc use serializable types (i.e. json format). Conversion methods
|
2017-02-08 17:04:08 +00:00
|
|
|
// exists between types.
|
|
|
|
//
|
|
|
|
// Note that all conversion methods ignore any parsing errors. All values must
|
|
|
|
// be validated first before initializing any of the types defined here.
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2018-10-23 18:21:27 +00:00
|
|
|
"encoding/json"
|
2017-12-08 14:39:30 +00:00
|
|
|
"fmt"
|
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
|
|
|
"net/url"
|
2018-05-26 01:36:39 +00:00
|
|
|
"regexp"
|
2018-01-16 10:21:34 +00:00
|
|
|
"sort"
|
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
|
|
|
"strconv"
|
2018-01-16 10:21:34 +00:00
|
|
|
"strings"
|
2017-02-08 17:04:08 +00:00
|
|
|
"time"
|
|
|
|
|
2019-02-19 17:59:46 +00:00
|
|
|
pb "github.com/ipfs/ipfs-cluster/api/pb"
|
|
|
|
|
|
|
|
proto "github.com/gogo/protobuf/proto"
|
2017-02-08 17:04:08 +00:00
|
|
|
cid "github.com/ipfs/go-cid"
|
2017-12-07 22:59:24 +00:00
|
|
|
logging "github.com/ipfs/go-log"
|
2017-02-08 17:04:08 +00:00
|
|
|
peer "github.com/libp2p/go-libp2p-peer"
|
|
|
|
protocol "github.com/libp2p/go-libp2p-protocol"
|
2019-02-27 17:04:35 +00:00
|
|
|
multiaddr "github.com/multiformats/go-multiaddr"
|
2017-12-07 22:59:24 +00:00
|
|
|
|
|
|
|
// needed to parse /ws multiaddresses
|
|
|
|
_ "github.com/libp2p/go-ws-transport"
|
2018-03-16 12:37:32 +00:00
|
|
|
// needed to parse /dns* multiaddresses
|
2017-12-07 22:59:24 +00:00
|
|
|
_ "github.com/multiformats/go-multiaddr-dns"
|
2017-02-08 17:04:08 +00:00
|
|
|
)
|
|
|
|
|
2017-12-07 22:59:24 +00:00
|
|
|
var logger = logging.Logger("apitypes")
|
|
|
|
|
2019-01-07 18:45:07 +00:00
|
|
|
func init() {
|
|
|
|
// intialize trackerStatusString
|
|
|
|
stringTrackerStatus = make(map[string]TrackerStatus)
|
|
|
|
for k, v := range trackerStatusString {
|
|
|
|
stringTrackerStatus[v] = k
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-08 17:04:08 +00:00
|
|
|
// TrackerStatus values
|
|
|
|
const (
|
2019-01-07 18:45:07 +00:00
|
|
|
// IPFSStatus should never take this value.
|
|
|
|
// When used as a filter. It means "all".
|
|
|
|
TrackerStatusUndefined TrackerStatus = 0
|
2017-02-08 17:04:08 +00:00
|
|
|
// The cluster node is offline or not responding
|
2019-01-07 18:45:07 +00:00
|
|
|
TrackerStatusClusterError TrackerStatus = 1 << iota
|
2017-02-08 17:04:08 +00:00
|
|
|
// An error occurred pinning
|
|
|
|
TrackerStatusPinError
|
|
|
|
// An error occurred unpinning
|
|
|
|
TrackerStatusUnpinError
|
|
|
|
// The IPFS daemon has pinned the item
|
|
|
|
TrackerStatusPinned
|
|
|
|
// The IPFS daemon is currently pinning the item
|
|
|
|
TrackerStatusPinning
|
|
|
|
// The IPFS daemon is currently unpinning the item
|
|
|
|
TrackerStatusUnpinning
|
|
|
|
// The IPFS daemon is not pinning the item
|
|
|
|
TrackerStatusUnpinned
|
2018-04-18 04:53:41 +00:00
|
|
|
// The IPFS daemon is not pinning the item but it is being tracked
|
2017-02-13 15:46:53 +00:00
|
|
|
TrackerStatusRemote
|
2018-04-18 04:53:41 +00:00
|
|
|
// The item has been queued for pinning on the IPFS daemon
|
|
|
|
TrackerStatusPinQueued
|
|
|
|
// The item has been queued for unpinning on the IPFS daemon
|
|
|
|
TrackerStatusUnpinQueued
|
2018-03-18 19:29:02 +00:00
|
|
|
// The IPFS daemon is not pinning the item through this cid but it is
|
|
|
|
// tracked in a cluster dag
|
|
|
|
TrackerStatusSharded
|
2017-02-08 17:04:08 +00:00
|
|
|
)
|
|
|
|
|
2019-01-05 09:10:54 +00:00
|
|
|
// Composite TrackerStatus.
|
2019-01-04 17:57:26 +00:00
|
|
|
const (
|
|
|
|
TrackerStatusError = TrackerStatusClusterError | TrackerStatusPinError | TrackerStatusUnpinError
|
|
|
|
TrackerStatusQueued = TrackerStatusPinQueued | TrackerStatusUnpinQueued
|
|
|
|
)
|
|
|
|
|
2017-02-08 17:04:08 +00:00
|
|
|
// TrackerStatus represents the status of a tracked Cid in the PinTracker
|
|
|
|
type TrackerStatus int
|
|
|
|
|
|
|
|
var trackerStatusString = map[TrackerStatus]string{
|
2019-01-07 18:45:07 +00:00
|
|
|
TrackerStatusUndefined: "undefined",
|
2017-02-08 17:04:08 +00:00
|
|
|
TrackerStatusClusterError: "cluster_error",
|
|
|
|
TrackerStatusPinError: "pin_error",
|
|
|
|
TrackerStatusUnpinError: "unpin_error",
|
2019-01-04 17:57:26 +00:00
|
|
|
TrackerStatusError: "error",
|
2017-02-08 17:04:08 +00:00
|
|
|
TrackerStatusPinned: "pinned",
|
|
|
|
TrackerStatusPinning: "pinning",
|
|
|
|
TrackerStatusUnpinning: "unpinning",
|
|
|
|
TrackerStatusUnpinned: "unpinned",
|
2017-02-13 15:46:53 +00:00
|
|
|
TrackerStatusRemote: "remote",
|
2018-04-18 04:53:41 +00:00
|
|
|
TrackerStatusPinQueued: "pin_queued",
|
|
|
|
TrackerStatusUnpinQueued: "unpin_queued",
|
2019-01-04 17:57:26 +00:00
|
|
|
TrackerStatusQueued: "queued",
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 18:45:07 +00:00
|
|
|
// values autofilled in init()
|
|
|
|
var stringTrackerStatus map[string]TrackerStatus
|
|
|
|
|
2017-02-08 17:04:08 +00:00
|
|
|
// String converts a TrackerStatus into a readable string.
|
2019-01-07 18:45:07 +00:00
|
|
|
// If the given TrackerStatus is a filter (with several
|
|
|
|
// bits set), it will return a comma-separated list.
|
2017-02-08 17:04:08 +00:00
|
|
|
func (st TrackerStatus) String() string {
|
2019-01-07 18:45:07 +00:00
|
|
|
var values []string
|
|
|
|
|
|
|
|
// simple and known composite values
|
|
|
|
if v, ok := trackerStatusString[st]; ok {
|
|
|
|
return v
|
|
|
|
}
|
2017-02-08 17:04:08 +00:00
|
|
|
|
2019-01-07 18:45:07 +00:00
|
|
|
// other filters
|
|
|
|
for k, v := range trackerStatusString {
|
|
|
|
if st&k > 0 {
|
|
|
|
values = append(values, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Join(values, ",")
|
2019-01-05 09:10:54 +00:00
|
|
|
}
|
2019-01-04 17:57:26 +00:00
|
|
|
|
2019-01-05 09:10:54 +00:00
|
|
|
// Match returns true if the tracker status matches the given filter.
|
2019-01-07 18:45:07 +00:00
|
|
|
// For example TrackerStatusPinError will match TrackerStatusPinError
|
|
|
|
// and TrackerStatusError
|
2019-01-05 09:10:54 +00:00
|
|
|
func (st TrackerStatus) Match(filter TrackerStatus) bool {
|
2019-01-07 18:45:07 +00:00
|
|
|
return filter == 0 || st&filter > 0
|
2019-01-04 17:57:26 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
// MarshalJSON uses the string representation of TrackerStatus for JSON
|
|
|
|
// encoding.
|
|
|
|
func (st TrackerStatus) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(st.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON sets a tracker status from its JSON representation.
|
|
|
|
func (st *TrackerStatus) UnmarshalJSON(data []byte) error {
|
|
|
|
var v string
|
|
|
|
err := json.Unmarshal(data, &v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*st = TrackerStatusFromString(v)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-08 17:04:08 +00:00
|
|
|
// TrackerStatusFromString parses a string and returns the matching
|
2019-01-07 18:45:07 +00:00
|
|
|
// TrackerStatus value. The string can be a comma-separated list
|
|
|
|
// representing a TrackerStatus filter. Unknown status names are
|
|
|
|
// ignored.
|
2017-02-08 17:04:08 +00:00
|
|
|
func TrackerStatusFromString(str string) TrackerStatus {
|
2019-01-07 18:45:07 +00:00
|
|
|
values := strings.Split(strings.Replace(str, " ", "", -1), ",")
|
|
|
|
var status TrackerStatus
|
|
|
|
for _, v := range values {
|
|
|
|
st, ok := stringTrackerStatus[v]
|
|
|
|
if ok {
|
|
|
|
status |= st
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-07 18:45:07 +00:00
|
|
|
return status
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 18:45:07 +00:00
|
|
|
// TrackerStatusAll all known TrackerStatus values.
|
2019-01-05 09:10:54 +00:00
|
|
|
func TrackerStatusAll() []TrackerStatus {
|
2019-01-07 18:45:07 +00:00
|
|
|
var list []TrackerStatus
|
2019-01-05 09:10:54 +00:00
|
|
|
for k := range trackerStatusString {
|
2019-01-07 18:45:07 +00:00
|
|
|
if k != TrackerStatusUndefined {
|
|
|
|
list = append(list, k)
|
2018-12-26 05:45:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 18:45:07 +00:00
|
|
|
return list
|
2019-01-04 17:57:26 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 17:04:08 +00:00
|
|
|
// IPFSPinStatus values
|
2018-07-04 16:30:24 +00:00
|
|
|
// FIXME include maxdepth
|
2017-02-08 17:04:08 +00:00
|
|
|
const (
|
2018-06-01 15:27:21 +00:00
|
|
|
IPFSPinStatusBug IPFSPinStatus = iota
|
2017-02-08 17:04:08 +00:00
|
|
|
IPFSPinStatusError
|
|
|
|
IPFSPinStatusDirect
|
|
|
|
IPFSPinStatusRecursive
|
|
|
|
IPFSPinStatusIndirect
|
|
|
|
IPFSPinStatusUnpinned
|
|
|
|
)
|
|
|
|
|
|
|
|
// IPFSPinStatus represents the status of a pin in IPFS (direct, recursive etc.)
|
|
|
|
type IPFSPinStatus int
|
|
|
|
|
|
|
|
// IPFSPinStatusFromString parses a string and returns the matching
|
|
|
|
// IPFSPinStatus.
|
|
|
|
func IPFSPinStatusFromString(t string) IPFSPinStatus {
|
2018-07-04 16:30:24 +00:00
|
|
|
// Since indirect statuses are of the form "indirect through <cid>",
|
|
|
|
// use a regexp to match
|
2018-05-26 01:08:45 +00:00
|
|
|
var ind, _ = regexp.MatchString("^indirect", t)
|
2018-07-04 16:30:24 +00:00
|
|
|
var rec, _ = regexp.MatchString("^recursive", t)
|
2017-02-08 17:04:08 +00:00
|
|
|
switch {
|
2018-05-26 01:08:45 +00:00
|
|
|
case ind:
|
2017-02-08 17:04:08 +00:00
|
|
|
return IPFSPinStatusIndirect
|
2018-07-04 16:30:24 +00:00
|
|
|
case rec:
|
|
|
|
// FIXME: Maxdepth?
|
|
|
|
return IPFSPinStatusRecursive
|
2017-02-08 17:04:08 +00:00
|
|
|
case t == "direct":
|
|
|
|
return IPFSPinStatusDirect
|
|
|
|
default:
|
|
|
|
return IPFSPinStatusBug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-04 16:30:24 +00:00
|
|
|
// IsPinned returns true if the item is pinned as expected by the
|
|
|
|
// maxDepth parameter.
|
|
|
|
func (ips IPFSPinStatus) IsPinned(maxDepth int) bool {
|
|
|
|
switch {
|
|
|
|
case maxDepth < 0:
|
|
|
|
return ips == IPFSPinStatusRecursive
|
|
|
|
case maxDepth == 0:
|
|
|
|
return ips == IPFSPinStatusDirect
|
2018-08-06 12:31:45 +00:00
|
|
|
case maxDepth > 0:
|
|
|
|
// FIXME: when we know how ipfs returns partial pins.
|
2018-07-04 16:30:24 +00:00
|
|
|
return ips == IPFSPinStatusRecursive
|
|
|
|
}
|
|
|
|
return false
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-25 09:05:35 +00:00
|
|
|
// ToTrackerStatus converts the IPFSPinStatus value to the
|
|
|
|
// appropriate TrackerStatus value.
|
|
|
|
func (ips IPFSPinStatus) ToTrackerStatus() TrackerStatus {
|
|
|
|
return ipfsPinStatus2TrackerStatusMap[ips]
|
|
|
|
}
|
|
|
|
|
|
|
|
var ipfsPinStatus2TrackerStatusMap = map[IPFSPinStatus]TrackerStatus{
|
|
|
|
IPFSPinStatusDirect: TrackerStatusPinned,
|
|
|
|
IPFSPinStatusRecursive: TrackerStatusPinned,
|
|
|
|
IPFSPinStatusIndirect: TrackerStatusUnpinned,
|
|
|
|
IPFSPinStatusUnpinned: TrackerStatusUnpinned,
|
2019-01-07 18:45:07 +00:00
|
|
|
IPFSPinStatusBug: TrackerStatusUndefined,
|
2018-05-25 09:05:35 +00:00
|
|
|
IPFSPinStatusError: TrackerStatusClusterError, //TODO(ajl): check suitability
|
|
|
|
}
|
|
|
|
|
2017-02-08 17:04:08 +00:00
|
|
|
// GlobalPinInfo contains cluster-wide status information about a tracked Cid,
|
|
|
|
// indexed by cluster peer.
|
|
|
|
type GlobalPinInfo struct {
|
2019-02-27 18:43:29 +00:00
|
|
|
Cid cid.Cid `json:"cid" codec:"c"`
|
2019-02-27 17:04:35 +00:00
|
|
|
// https://github.com/golang/go/issues/28827
|
|
|
|
// Peer IDs are of string Kind(). We can't use peer IDs here
|
|
|
|
// as Go ignores TextMarshaler.
|
|
|
|
PeerMap map[string]*PinInfo `json:"peer_map" codec:"pm,omitempty"`
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-07 02:04:59 +00:00
|
|
|
// String returns the string representation of a GlobalPinInfo.
|
|
|
|
func (gpi *GlobalPinInfo) String() string {
|
|
|
|
str := fmt.Sprintf("Cid: %v\n", gpi.Cid.String())
|
|
|
|
str = str + "Peer:\n"
|
|
|
|
for _, p := range gpi.PeerMap {
|
|
|
|
str = str + fmt.Sprintf("\t%+v\n", p)
|
|
|
|
}
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
2017-11-30 00:53:31 +00:00
|
|
|
// PinInfo holds information about local pins.
|
2017-02-08 17:04:08 +00:00
|
|
|
type PinInfo struct {
|
2019-02-27 18:43:29 +00:00
|
|
|
Cid cid.Cid `json:"cid" codec:"c"`
|
2019-02-27 17:04:35 +00:00
|
|
|
Peer peer.ID `json:"peer" codec:"p,omitempty"`
|
|
|
|
PeerName string `json:"peername" codec:"pn,omitempty"`
|
|
|
|
Status TrackerStatus `json:"status" codec:"st,omitempty"`
|
|
|
|
TS time.Time `json:"timestamp" codec:"ts,omitempty"`
|
|
|
|
Error string `json:"error" codec:"e,omitempty"`
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Version holds version information
|
|
|
|
type Version struct {
|
2019-04-10 09:15:56 +00:00
|
|
|
Version string `json:"version" codec:"v"`
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 18:43:29 +00:00
|
|
|
// ConnectGraph holds information about the connectivity of the cluster To
|
|
|
|
// read, traverse the keys of ClusterLinks. Each such id is one of the peers
|
|
|
|
// of the "ClusterID" peer running the query. ClusterLinks[id] in turn lists
|
|
|
|
// the ids that peer "id" sees itself connected to. It is possible that id is
|
|
|
|
// a peer of ClusterID, but ClusterID can not reach id over rpc, in which case
|
|
|
|
// ClusterLinks[id] == [], as id's view of its connectivity can not be
|
|
|
|
// retrieved.
|
2017-10-13 21:12:46 +00:00
|
|
|
//
|
2019-02-27 18:43:29 +00:00
|
|
|
// Iff there was an error reading the IPFSID of the peer then id will not be a
|
|
|
|
// key of ClustertoIPFS or IPFSLinks. Finally iff id is a key of ClustertoIPFS
|
|
|
|
// then id will be a key of IPFSLinks. In the event of a SwarmPeers error
|
|
|
|
// IPFSLinks[id] == [].
|
2017-10-13 21:12:46 +00:00
|
|
|
type ConnectGraph struct {
|
2019-02-27 17:04:35 +00:00
|
|
|
ClusterID peer.ID
|
|
|
|
// ipfs to ipfs links
|
|
|
|
IPFSLinks map[string][]peer.ID `json:"ipfs_links" codec:"il,omitempty"`
|
|
|
|
// cluster to cluster links
|
|
|
|
ClusterLinks map[string][]peer.ID `json:"cluster_links" codec:"cl,omitempty"`
|
|
|
|
// cluster to ipfs links
|
|
|
|
ClustertoIPFS map[string]peer.ID `json:"cluster_to_ipfs" codec:"ci,omitempty"`
|
2017-10-13 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 18:43:29 +00:00
|
|
|
// Multiaddr is a concrete type to wrap a Multiaddress so that it knows how to
|
|
|
|
// serialize and deserialize itself.
|
2019-02-27 17:04:35 +00:00
|
|
|
type Multiaddr struct {
|
|
|
|
multiaddr.Multiaddr
|
2017-10-13 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 18:43:29 +00:00
|
|
|
// NewMultiaddr returns a cluster Multiaddr wrapper creating the
|
|
|
|
// multiaddr.Multiaddr with the given string.
|
2019-02-27 17:04:35 +00:00
|
|
|
func NewMultiaddr(mstr string) (Multiaddr, error) {
|
|
|
|
m, err := multiaddr.NewMultiaddr(mstr)
|
|
|
|
return Multiaddr{Multiaddr: m}, err
|
2017-10-13 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 18:43:29 +00:00
|
|
|
// NewMultiaddrWithValue returns a new cluster Multiaddr wrapper using the
|
|
|
|
// given multiaddr.Multiaddr.
|
2019-02-27 17:04:35 +00:00
|
|
|
func NewMultiaddrWithValue(ma multiaddr.Multiaddr) Multiaddr {
|
|
|
|
return Multiaddr{Multiaddr: ma}
|
2018-01-18 02:49:35 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 18:43:29 +00:00
|
|
|
// MarshalJSON returns a JSON-formatted multiaddress.
|
2019-02-27 17:04:35 +00:00
|
|
|
func (maddr Multiaddr) MarshalJSON() ([]byte, error) {
|
|
|
|
return maddr.Multiaddr.MarshalJSON()
|
2017-10-13 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 18:43:29 +00:00
|
|
|
// UnmarshalJSON parses a cluster Multiaddr from the JSON representation.
|
2019-02-27 17:04:35 +00:00
|
|
|
func (maddr *Multiaddr) UnmarshalJSON(data []byte) error {
|
|
|
|
maddr.Multiaddr, _ = multiaddr.NewMultiaddr("")
|
|
|
|
return maddr.Multiaddr.UnmarshalJSON(data)
|
2017-10-13 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 18:43:29 +00:00
|
|
|
// MarshalBinary returs the bytes of the wrapped multiaddress.
|
2019-02-27 17:04:35 +00:00
|
|
|
func (maddr Multiaddr) MarshalBinary() ([]byte, error) {
|
|
|
|
return maddr.Multiaddr.MarshalBinary()
|
|
|
|
}
|
2019-02-27 18:43:29 +00:00
|
|
|
|
|
|
|
// UnmarshalBinary casts some bytes as a multiaddress wraps it with
|
|
|
|
// the given cluster Multiaddr.
|
2019-02-27 17:04:35 +00:00
|
|
|
func (maddr *Multiaddr) UnmarshalBinary(data []byte) error {
|
|
|
|
datacopy := make([]byte, len(data)) // This is super important
|
|
|
|
copy(datacopy, data)
|
|
|
|
maddr.Multiaddr, _ = multiaddr.NewMultiaddr("")
|
|
|
|
return maddr.Multiaddr.UnmarshalBinary(datacopy)
|
2017-10-13 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 18:43:29 +00:00
|
|
|
// Value returns the wrapped multiaddr.Multiaddr.
|
2019-02-27 17:04:35 +00:00
|
|
|
func (maddr Multiaddr) Value() multiaddr.Multiaddr {
|
|
|
|
return maddr.Multiaddr
|
2017-10-13 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 17:04:08 +00:00
|
|
|
// ID holds information about the Cluster peer
|
|
|
|
type ID struct {
|
2019-02-27 17:04:35 +00:00
|
|
|
ID peer.ID `json:"id" codec:"i,omitempty"`
|
|
|
|
Addresses []Multiaddr `json:"addresses" codec:"a,omitempty"`
|
|
|
|
ClusterPeers []peer.ID `json:"cluster_peers" codec:"cp,omitempty"`
|
|
|
|
ClusterPeersAddresses []Multiaddr `json:"cluster_peers_addresses" codec:"cpa,omitempty"`
|
|
|
|
Version string `json:"version" codec:"v,omitempty"`
|
|
|
|
Commit string `json:"commit" codec:"c,omitempty"`
|
|
|
|
RPCProtocolVersion protocol.ID `json:"rpc_protocol_version" codec:"rv,omitempty"`
|
|
|
|
Error string `json:"error" codec:"e,omitempty"`
|
2019-03-19 16:53:02 +00:00
|
|
|
IPFS *IPFSID `json:"ipfs,omitempty" codec:"ip,omitempty"`
|
2019-02-27 17:04:35 +00:00
|
|
|
Peername string `json:"peername" codec:"pn,omitempty"`
|
2017-02-08 17:04:08 +00:00
|
|
|
//PublicKey crypto.PubKey
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
// IPFSID is used to store information about the underlying IPFS daemon
|
|
|
|
type IPFSID struct {
|
2019-03-14 12:58:36 +00:00
|
|
|
ID peer.ID `json:"id,omitempty" codec:"i,omitempty"`
|
2019-02-27 17:04:35 +00:00
|
|
|
Addresses []Multiaddr `json:"addresses" codec:"a,omitempty"`
|
|
|
|
Error string `json:"error" codec:"e,omitempty"`
|
2018-03-18 19:29:02 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 11:22:47 +00:00
|
|
|
// PinType specifies which sort of Pin object we are dealing with.
|
|
|
|
// In practice, the PinType decides how a Pin object is treated by the
|
|
|
|
// PinTracker.
|
|
|
|
// See descriptions above.
|
|
|
|
// A sharded Pin would look like:
|
|
|
|
//
|
|
|
|
// [ Meta ] (not pinned on IPFS, only present in cluster state)
|
|
|
|
// |
|
|
|
|
// v
|
|
|
|
// [ Cluster DAG ] (pinned everywhere in "direct")
|
|
|
|
// | .. |
|
|
|
|
// v v
|
|
|
|
// [Shard1] .. [ShardN] (allocated to peers and pinned with max-depth=1
|
|
|
|
// | | .. | | | .. |
|
|
|
|
// v v .. v v v .. v
|
|
|
|
// [][]..[] [][]..[] Blocks (indirectly pinned on ipfs, not tracked in cluster)
|
|
|
|
//
|
|
|
|
//
|
2018-08-10 12:39:44 +00:00
|
|
|
type PinType uint64
|
2018-08-06 09:12:57 +00:00
|
|
|
|
2018-07-04 16:30:24 +00:00
|
|
|
// PinType values. See PinType documentation for further explanation.
|
2018-03-18 19:29:02 +00:00
|
|
|
const (
|
2018-07-04 16:30:24 +00:00
|
|
|
// BadType type showing up anywhere indicates a bug
|
2018-08-09 11:22:47 +00:00
|
|
|
BadType PinType = 1 << iota
|
2018-07-23 13:56:46 +00:00
|
|
|
// DataType is a regular, non-sharded pin. It is pinned recursively.
|
|
|
|
// It has no associated reference.
|
2018-06-28 15:01:39 +00:00
|
|
|
DataType
|
2018-07-23 13:56:46 +00:00
|
|
|
// MetaType tracks the original CID of a sharded DAG. Its Reference
|
|
|
|
// points to the Cluster DAG CID.
|
2018-03-18 19:29:02 +00:00
|
|
|
MetaType
|
2018-08-09 11:22:47 +00:00
|
|
|
// ClusterDAGType pins carry the CID of the root node that points to
|
2018-07-04 16:30:24 +00:00
|
|
|
// all the shard-root-nodes of the shards in which a DAG has been
|
2018-07-23 13:56:46 +00:00
|
|
|
// divided. Its Reference carries the MetaType CID.
|
2018-07-04 16:30:24 +00:00
|
|
|
// ClusterDAGType pins are pinned directly everywhere.
|
|
|
|
ClusterDAGType
|
|
|
|
// ShardType pins carry the root CID of a shard, which points
|
|
|
|
// to individual blocks on the original DAG that the user is adding,
|
|
|
|
// which has been sharded.
|
2018-07-23 13:56:46 +00:00
|
|
|
// They carry a Reference to the previous shard.
|
2018-07-04 16:30:24 +00:00
|
|
|
// ShardTypes are pinned with MaxDepth=1 (root and
|
|
|
|
// direct children only).
|
2018-03-18 19:29:02 +00:00
|
|
|
ShardType
|
|
|
|
)
|
|
|
|
|
2018-08-09 11:22:47 +00:00
|
|
|
// AllType is a PinType used for filtering all pin types
|
|
|
|
const AllType PinType = DataType | MetaType | ClusterDAGType | ShardType
|
2018-03-18 19:29:02 +00:00
|
|
|
|
|
|
|
// PinTypeFromString is the inverse of String. It returns the PinType value
|
|
|
|
// corresponding to the input string
|
|
|
|
func PinTypeFromString(str string) PinType {
|
|
|
|
switch str {
|
|
|
|
case "pin":
|
|
|
|
return DataType
|
|
|
|
case "meta-pin":
|
|
|
|
return MetaType
|
|
|
|
case "clusterdag-pin":
|
2018-07-04 16:30:24 +00:00
|
|
|
return ClusterDAGType
|
2018-03-18 19:29:02 +00:00
|
|
|
case "shard-pin":
|
|
|
|
return ShardType
|
|
|
|
case "all":
|
|
|
|
return AllType
|
|
|
|
default:
|
2018-06-28 15:01:39 +00:00
|
|
|
return BadType
|
2018-03-18 19:29:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// String returns a printable value to identify the PinType
|
2018-08-10 12:39:44 +00:00
|
|
|
func (pT PinType) String() string {
|
|
|
|
switch pT {
|
2018-03-18 19:29:02 +00:00
|
|
|
case DataType:
|
|
|
|
return "pin"
|
|
|
|
case MetaType:
|
|
|
|
return "meta-pin"
|
2018-07-04 16:30:24 +00:00
|
|
|
case ClusterDAGType:
|
2018-03-18 19:29:02 +00:00
|
|
|
return "clusterdag-pin"
|
|
|
|
case ShardType:
|
|
|
|
return "shard-pin"
|
|
|
|
case AllType:
|
|
|
|
return "all"
|
|
|
|
default:
|
2018-08-10 12:39:44 +00:00
|
|
|
return "bad-type"
|
2018-03-18 19:29:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-20 12:49:30 +00:00
|
|
|
var pinOptionsMetaPrefix = "meta-"
|
|
|
|
|
2018-07-04 16:30:24 +00:00
|
|
|
// PinOptions wraps user-defined options for Pins
|
|
|
|
type PinOptions struct {
|
2019-02-19 17:59:46 +00:00
|
|
|
ReplicationFactorMin int `json:"replication_factor_min" codec:"rn,omitempty"`
|
|
|
|
ReplicationFactorMax int `json:"replication_factor_max" codec:"rx,omitempty"`
|
|
|
|
Name string `json:"name" codec:"n,omitempty"`
|
|
|
|
ShardSize uint64 `json:"shard_size" codec:"s,omitempty"`
|
2019-02-20 12:49:30 +00:00
|
|
|
UserAllocations []string `json:"user_allocations" codec:"ua,omitempty"`
|
2019-02-19 17:59:46 +00:00
|
|
|
Metadata map[string]string `json:"metadata" codec:"m,omitempty"`
|
2018-07-04 16:30:24 +00:00
|
|
|
}
|
|
|
|
|
2019-02-20 14:24:25 +00:00
|
|
|
// Equals returns true if two PinOption objects are equivalent. po and po2 may
|
|
|
|
// be nil.
|
2019-02-20 12:49:30 +00:00
|
|
|
func (po *PinOptions) Equals(po2 *PinOptions) bool {
|
2019-02-20 14:24:25 +00:00
|
|
|
if po == nil && po2 != nil || po2 == nil && po != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if po == po2 { // same as pin.Equals()
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-20 12:49:30 +00:00
|
|
|
if po.ReplicationFactorMax != po2.ReplicationFactorMax {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if po.ReplicationFactorMin != po2.ReplicationFactorMin {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if po.ShardSize != po2.ShardSize {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
lenAllocs1 := len(po.UserAllocations)
|
|
|
|
lenAllocs2 := len(po2.UserAllocations)
|
|
|
|
if lenAllocs1 != lenAllocs2 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-21 16:44:20 +00:00
|
|
|
// avoid side effects in the original objects
|
2019-02-20 12:49:30 +00:00
|
|
|
allocs1 := make([]string, lenAllocs1, lenAllocs1)
|
|
|
|
allocs2 := make([]string, lenAllocs2, lenAllocs2)
|
|
|
|
copy(allocs1, po.UserAllocations)
|
|
|
|
copy(allocs2, po2.UserAllocations)
|
|
|
|
sort.Strings(allocs1)
|
|
|
|
sort.Strings(allocs2)
|
|
|
|
if strings.Join(allocs1, ",") != strings.Join(allocs2, ",") {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range po.Metadata {
|
|
|
|
v2 := po2.Metadata[k]
|
|
|
|
if k != "" && v != v2 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// ToQuery returns the PinOption as query arguments.
|
|
|
|
func (po *PinOptions) ToQuery() string {
|
|
|
|
q := url.Values{}
|
|
|
|
q.Set("replication-min", fmt.Sprintf("%d", po.ReplicationFactorMin))
|
|
|
|
q.Set("replication-max", fmt.Sprintf("%d", po.ReplicationFactorMax))
|
|
|
|
q.Set("name", po.Name)
|
2019-02-20 12:49:30 +00:00
|
|
|
q.Set("shard-size", fmt.Sprintf("%d", po.ShardSize))
|
|
|
|
q.Set("user-allocations", strings.Join(po.UserAllocations, ","))
|
|
|
|
for k, v := range po.Metadata {
|
|
|
|
if k == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
q.Set(fmt.Sprintf("%s%s", pinOptionsMetaPrefix, k), v)
|
|
|
|
}
|
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
|
|
|
return q.Encode()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FromQuery is the inverse of ToQuery().
|
|
|
|
func (po *PinOptions) FromQuery(q url.Values) {
|
|
|
|
po.Name = q.Get("name")
|
|
|
|
rplStr := q.Get("replication")
|
|
|
|
rplStrMin := q.Get("replication-min")
|
|
|
|
rplStrMax := q.Get("replication-max")
|
|
|
|
if rplStr != "" { // override
|
|
|
|
rplStrMin = rplStr
|
|
|
|
rplStrMax = rplStr
|
|
|
|
}
|
|
|
|
if rpl, err := strconv.Atoi(rplStrMin); err == nil {
|
|
|
|
po.ReplicationFactorMin = rpl
|
|
|
|
}
|
|
|
|
if rpl, err := strconv.Atoi(rplStrMax); err == nil {
|
|
|
|
po.ReplicationFactorMax = rpl
|
|
|
|
}
|
2019-02-20 12:49:30 +00:00
|
|
|
|
|
|
|
if shsize, err := strconv.ParseUint(q.Get("shard-size"), 10, 64); err == nil {
|
|
|
|
po.ShardSize = shsize
|
|
|
|
}
|
|
|
|
|
|
|
|
if allocs := q.Get("user-allocations"); allocs != "" {
|
|
|
|
po.UserAllocations = strings.Split(allocs, ",")
|
|
|
|
}
|
|
|
|
|
|
|
|
po.Metadata = make(map[string]string)
|
|
|
|
for k := range q {
|
|
|
|
if !strings.HasPrefix(k, pinOptionsMetaPrefix) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
metaKey := strings.TrimPrefix(k, pinOptionsMetaPrefix)
|
|
|
|
if metaKey == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
po.Metadata[metaKey] = q.Get(k)
|
|
|
|
}
|
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-07-04 16:30:24 +00:00
|
|
|
// Pin carries all the information associated to a CID that is pinned
|
|
|
|
// in IPFS Cluster.
|
2017-03-08 15:57:27 +00:00
|
|
|
type Pin struct {
|
2018-07-04 16:30:24 +00:00
|
|
|
PinOptions
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
Cid cid.Cid `json:"cid" codec:"c"`
|
2018-07-04 16:30:24 +00:00
|
|
|
|
|
|
|
// See PinType comments
|
2019-02-27 17:04:35 +00:00
|
|
|
Type PinType `json:"type" codec:"t,omitempty"`
|
2018-07-04 16:30:24 +00:00
|
|
|
|
|
|
|
// The peers to which this pin is allocated
|
2019-02-27 17:04:35 +00:00
|
|
|
Allocations []peer.ID `json:"allocations" codec:"a,omitempty"`
|
2018-07-04 16:30:24 +00:00
|
|
|
|
|
|
|
// MaxDepth associated to this pin. -1 means
|
|
|
|
// recursive.
|
2019-02-27 17:04:35 +00:00
|
|
|
MaxDepth int `json:"max_depth" codec:"d,omitempty"`
|
2018-07-04 16:30:24 +00:00
|
|
|
|
2018-07-23 13:56:46 +00:00
|
|
|
// We carry a reference CID to this pin. For
|
|
|
|
// ClusterDAGs, it is the MetaPin CID. For the
|
|
|
|
// MetaPin it is the ClusterDAG CID. For Shards,
|
|
|
|
// it is the previous shard CID.
|
2019-02-27 17:04:35 +00:00
|
|
|
// When not needed the pointer is nil
|
|
|
|
Reference *cid.Cid `json:"reference" codec:"r,omitempty"`
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
|
|
|
|
2019-05-07 08:50:03 +00:00
|
|
|
// String is a string representation of a Pin.
|
|
|
|
func (pin *Pin) String() string {
|
|
|
|
var b strings.Builder
|
|
|
|
fmt.Fprintf(&b, "cid: %s\n", pin.Cid.String())
|
|
|
|
fmt.Fprintf(&b, "type: %s\n", pin.Type)
|
|
|
|
fmt.Fprintf(&b, "allocations: %v\n", pin.Allocations)
|
|
|
|
fmt.Fprintf(&b, "maxdepth: %d\n", pin.MaxDepth)
|
|
|
|
if pin.Reference != nil {
|
|
|
|
fmt.Fprintf(&b, "reference: %s\n", pin.Reference)
|
|
|
|
}
|
|
|
|
return b.String()
|
|
|
|
}
|
|
|
|
|
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 is a wrapper for holding pin options and path of the content.
|
|
|
|
type PinPath struct {
|
|
|
|
PinOptions
|
|
|
|
Path string `json:"path"`
|
|
|
|
}
|
|
|
|
|
2018-02-16 20:20:13 +00:00
|
|
|
// PinCid is a shortcut to create a Pin only with a Cid. Default is for pin to
|
2018-07-24 12:21:29 +00:00
|
|
|
// be recursive and the pin to be of DataType.
|
2019-02-27 17:04:35 +00:00
|
|
|
func PinCid(c cid.Cid) *Pin {
|
|
|
|
return &Pin{
|
2018-01-16 10:21:34 +00:00
|
|
|
Cid: c,
|
2018-03-18 19:29:02 +00:00
|
|
|
Type: DataType,
|
2018-01-16 10:21:34 +00:00
|
|
|
Allocations: []peer.ID{},
|
2018-07-04 16:30:24 +00:00
|
|
|
MaxDepth: -1,
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 12:21:29 +00:00
|
|
|
// PinWithOpts creates a new Pin calling PinCid(c) and then sets
|
|
|
|
// its PinOptions fields with the given options.
|
2019-02-27 17:04:35 +00:00
|
|
|
func PinWithOpts(c cid.Cid, opts PinOptions) *Pin {
|
2018-07-04 16:30:24 +00:00
|
|
|
p := PinCid(c)
|
2019-02-19 17:59:46 +00:00
|
|
|
p.PinOptions = opts
|
2018-07-04 16:30:24 +00:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2019-02-19 17:59:46 +00:00
|
|
|
func convertPinType(t PinType) pb.Pin_PinType {
|
|
|
|
var i pb.Pin_PinType
|
|
|
|
for t != 1 {
|
|
|
|
if t == 0 {
|
|
|
|
return pb.Pin_BadType
|
|
|
|
}
|
|
|
|
t = t >> 1
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProtoMarshal marshals this Pin using probobuf.
|
|
|
|
func (pin *Pin) ProtoMarshal() ([]byte, error) {
|
|
|
|
allocs := make([][]byte, len(pin.Allocations), len(pin.Allocations))
|
|
|
|
for i, pid := range pin.Allocations {
|
|
|
|
bs, err := pid.Marshal()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
allocs[i] = bs
|
|
|
|
}
|
|
|
|
|
2019-02-20 12:49:30 +00:00
|
|
|
opts := &pb.PinOptions{
|
2019-02-19 17:59:46 +00:00
|
|
|
ReplicationFactorMin: int32(pin.ReplicationFactorMin),
|
|
|
|
ReplicationFactorMax: int32(pin.ReplicationFactorMax),
|
|
|
|
Name: pin.Name,
|
|
|
|
ShardSize: pin.ShardSize,
|
2019-02-24 20:33:16 +00:00
|
|
|
// UserAllocations: pin.UserAllocations,
|
|
|
|
Metadata: pin.Metadata,
|
2019-02-19 17:59:46 +00:00
|
|
|
}
|
2019-02-20 12:49:30 +00:00
|
|
|
|
|
|
|
pbPin := &pb.Pin{
|
|
|
|
Cid: pin.Cid.Bytes(),
|
|
|
|
Type: convertPinType(pin.Type),
|
|
|
|
Allocations: allocs,
|
|
|
|
MaxDepth: int32(pin.MaxDepth),
|
|
|
|
Options: opts,
|
2019-02-19 17:59:46 +00:00
|
|
|
}
|
2019-02-27 17:04:35 +00:00
|
|
|
if ref := pin.Reference; ref != nil {
|
|
|
|
pbPin.Reference = ref.Bytes()
|
|
|
|
}
|
2019-02-19 17:59:46 +00:00
|
|
|
return proto.Marshal(pbPin)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProtoUnmarshal unmarshals this fields from protobuf-encoded bytes.
|
|
|
|
func (pin *Pin) ProtoUnmarshal(data []byte) error {
|
|
|
|
pbPin := pb.Pin{}
|
|
|
|
err := proto.Unmarshal(data, &pbPin)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ci, err := cid.Cast(pbPin.GetCid())
|
|
|
|
if err != nil {
|
|
|
|
pin.Cid = cid.Undef
|
|
|
|
} else {
|
|
|
|
pin.Cid = ci
|
|
|
|
}
|
|
|
|
|
|
|
|
pin.Type = 1 << uint64(pbPin.GetType())
|
|
|
|
|
|
|
|
pbAllocs := pbPin.GetAllocations()
|
|
|
|
lenAllocs := len(pbAllocs)
|
|
|
|
allocs := make([]peer.ID, lenAllocs, lenAllocs)
|
|
|
|
for i, pidb := range pbAllocs {
|
|
|
|
pid, err := peer.IDFromBytes(pidb)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
allocs[i] = pid
|
|
|
|
}
|
|
|
|
|
|
|
|
pin.Allocations = allocs
|
|
|
|
pin.MaxDepth = int(pbPin.GetMaxDepth())
|
|
|
|
ref, err := cid.Cast(pbPin.GetReference())
|
|
|
|
if err != nil {
|
2019-02-27 17:04:35 +00:00
|
|
|
pin.Reference = nil
|
2019-02-19 17:59:46 +00:00
|
|
|
|
|
|
|
} else {
|
2019-02-27 17:04:35 +00:00
|
|
|
pin.Reference = &ref
|
2019-02-19 17:59:46 +00:00
|
|
|
}
|
2019-02-20 12:49:30 +00:00
|
|
|
|
|
|
|
opts := pbPin.GetOptions()
|
|
|
|
pin.ReplicationFactorMin = int(opts.GetReplicationFactorMin())
|
|
|
|
pin.ReplicationFactorMax = int(opts.GetReplicationFactorMax())
|
|
|
|
pin.Name = opts.GetName()
|
|
|
|
pin.ShardSize = opts.GetShardSize()
|
2019-02-24 20:33:16 +00:00
|
|
|
// pin.UserAllocations = opts.GetUserAllocations()
|
2019-02-20 12:49:30 +00:00
|
|
|
pin.Metadata = opts.GetMetadata()
|
2019-02-19 17:59:46 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-01-16 10:21:34 +00:00
|
|
|
// Equals checks if two pins are the same (with the same allocations).
|
|
|
|
// If allocations are the same but in different order, they are still
|
|
|
|
// considered equivalent.
|
2019-02-20 14:24:25 +00:00
|
|
|
// pin or pin2 may be nil. If both are nil, Equals returns false.
|
2019-02-27 17:04:35 +00:00
|
|
|
func (pin *Pin) Equals(pin2 *Pin) bool {
|
|
|
|
if pin == nil && pin2 != nil || pin2 == nil && pin != nil {
|
|
|
|
return false
|
|
|
|
}
|
2018-01-16 10:21:34 +00:00
|
|
|
|
2019-02-20 14:24:25 +00:00
|
|
|
if pin == pin2 {
|
|
|
|
// ask @lanzafame why this is not true
|
|
|
|
// in any case, this is anomalous and we should
|
|
|
|
// not be using this with two nils.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
if !pin.Cid.Equals(pin2.Cid) {
|
2018-01-16 10:21:34 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
if pin.Name != pin2.Name {
|
2018-01-16 10:21:34 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
if pin.Type != pin2.Type {
|
2018-03-18 19:29:02 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
if pin.MaxDepth != pin2.MaxDepth {
|
2018-07-04 16:30:24 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-27 18:43:29 +00:00
|
|
|
if pin.Reference != nil && pin2.Reference == nil ||
|
|
|
|
pin.Reference == nil && pin2.Reference != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if pin.Reference != nil && pin2.Reference != nil &&
|
|
|
|
!pin.Reference.Equals(*pin2.Reference) {
|
2018-03-01 19:52:10 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
allocs1 := PeersToStrings(pin.Allocations)
|
|
|
|
sort.Strings(allocs1)
|
|
|
|
allocs2 := PeersToStrings(pin2.Allocations)
|
|
|
|
sort.Strings(allocs2)
|
2018-01-16 10:21:34 +00:00
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
if strings.Join(allocs1, ",") != strings.Join(allocs2, ",") {
|
2018-01-16 10:21:34 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-20 12:49:30 +00:00
|
|
|
return pin.PinOptions.Equals(&pin2.PinOptions)
|
2018-01-16 10:21:34 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 02:19:15 +00:00
|
|
|
// IsRemotePin determines whether a Pin's ReplicationFactor has
|
|
|
|
// been met, so as to either pin or unpin it from the peer.
|
2019-02-27 17:04:35 +00:00
|
|
|
func (pin *Pin) IsRemotePin(pid peer.ID) bool {
|
2018-08-14 13:18:16 +00:00
|
|
|
if pin.ReplicationFactorMax < 0 || pin.ReplicationFactorMin < 0 {
|
2018-06-07 02:19:15 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range pin.Allocations {
|
|
|
|
if p == pid {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-03-05 20:20:33 +00:00
|
|
|
// NodeWithMeta specifies a block of data and a set of optional metadata fields
|
|
|
|
// carrying information about the encoded ipld node
|
|
|
|
type NodeWithMeta struct {
|
2019-02-27 17:04:35 +00:00
|
|
|
Data []byte `codec:"d,omitempty"`
|
|
|
|
Cid cid.Cid `codec:"c, omitempty"`
|
|
|
|
CumSize uint64 `codec:"s,omitempty"` // Cumulative size
|
|
|
|
Format string `codec:"f,omitempty"`
|
2018-07-19 13:17:27 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 12:21:29 +00:00
|
|
|
// Size returns how big is the block. It is different from CumSize, which
|
|
|
|
// records the size of the underlying tree.
|
2018-07-19 13:17:27 +00:00
|
|
|
func (n *NodeWithMeta) Size() uint64 {
|
|
|
|
return uint64(len(n.Data))
|
2018-02-16 21:11:34 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 15:46:53 +00:00
|
|
|
// Metric transports information about a peer.ID. It is used to decide
|
|
|
|
// pin allocations by a PinAllocator. IPFS cluster is agnostic to
|
|
|
|
// the Value, which should be interpreted by the PinAllocator.
|
2019-03-21 01:51:03 +00:00
|
|
|
// The ReceivedAt value is a timestamp representing when a peer has received
|
2019-03-08 02:10:51 +00:00
|
|
|
// the metric value.
|
2017-02-13 15:46:53 +00:00
|
|
|
type Metric struct {
|
2019-03-21 01:51:03 +00:00
|
|
|
Name string `json:"name" codec:"n,omitempty"`
|
|
|
|
Peer peer.ID `json:"peer" codec:"p,omitempty"`
|
|
|
|
Value string `json:"value" codec:"v,omitempty"`
|
|
|
|
Expire int64 `json:"expire" codec:"e,omitempty"`
|
|
|
|
Valid bool `json:"valid" codec:"d,omitempty"`
|
|
|
|
ReceivedAt int64 `json:"received_at" codec:"t,omitempty"` // ReceivedAt contains a UnixNano timestamp
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
|
|
|
|
2018-05-07 06:50:03 +00:00
|
|
|
// SetTTL sets Metric to expire after the given time.Duration
|
|
|
|
func (m *Metric) SetTTL(d time.Duration) {
|
Issue #162: Rework configuration format
The following commit reimplements ipfs-cluster configuration under
the following premises:
* Each component is initialized with a configuration object
defined by its module
* Each component decides how the JSON representation of its
configuration looks like
* Each component parses and validates its own configuration
* Each component exposes its own defaults
* Component configurations are make the sections of a
central JSON configuration file (which replaces the current
JSON format)
* Component configurations implement a common interface
(config.ComponentConfig) with a set of common operations
* The central configuration file is managed by a
config.ConfigManager which:
* Registers ComponentConfigs
* Assigns the correspondent sections from the JSON file to each
component and delegates the parsing
* Delegates the JSON generation for each section
* Can be notified when the configuration is updated and must be
saved to disk
The new service.json would then look as follows:
```json
{
"cluster": {
"id": "QmTVW8NoRxC5wBhV7WtAYtRn7itipEESfozWN5KmXUQnk2",
"private_key": "<...>",
"secret": "00224102ae6aaf94f2606abf69a0e278251ecc1d64815b617ff19d6d2841f786",
"peers": [],
"bootstrap": [],
"leave_on_shutdown": false,
"listen_multiaddress": "/ip4/0.0.0.0/tcp/9096",
"state_sync_interval": "1m0s",
"ipfs_sync_interval": "2m10s",
"replication_factor": -1,
"monitor_ping_interval": "15s"
},
"consensus": {
"raft": {
"heartbeat_timeout": "1s",
"election_timeout": "1s",
"commit_timeout": "50ms",
"max_append_entries": 64,
"trailing_logs": 10240,
"snapshot_interval": "2m0s",
"snapshot_threshold": 8192,
"leader_lease_timeout": "500ms"
}
},
"api": {
"restapi": {
"listen_multiaddress": "/ip4/127.0.0.1/tcp/9094",
"read_timeout": "30s",
"read_header_timeout": "5s",
"write_timeout": "1m0s",
"idle_timeout": "2m0s"
}
},
"ipfs_connector": {
"ipfshttp": {
"proxy_listen_multiaddress": "/ip4/127.0.0.1/tcp/9095",
"node_multiaddress": "/ip4/127.0.0.1/tcp/5001",
"connect_swarms_delay": "7s",
"proxy_read_timeout": "10m0s",
"proxy_read_header_timeout": "5s",
"proxy_write_timeout": "10m0s",
"proxy_idle_timeout": "1m0s"
}
},
"monitor": {
"monbasic": {
"check_interval": "15s"
}
},
"informer": {
"disk": {
"metric_ttl": "30s",
"metric_type": "freespace"
},
"numpin": {
"metric_ttl": "10s"
}
}
}
```
This new format aims to be easily extensible per component. As such,
it already surfaces quite a few new options which were hardcoded
before.
Additionally, since Go API have changed, some redundant methods have been
removed and small refactoring has happened to take advantage of the new
way.
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-10-11 18:23:03 +00:00
|
|
|
exp := time.Now().Add(d)
|
2018-04-05 14:09:41 +00:00
|
|
|
m.Expire = exp.UnixNano()
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTTL returns the time left before the Metric expires
|
|
|
|
func (m *Metric) GetTTL() time.Duration {
|
2018-04-05 14:09:41 +00:00
|
|
|
expDate := time.Unix(0, m.Expire)
|
|
|
|
return expDate.Sub(time.Now())
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Expired returns if the Metric has expired
|
|
|
|
func (m *Metric) Expired() bool {
|
2018-04-05 14:09:41 +00:00
|
|
|
expDate := time.Unix(0, m.Expire)
|
|
|
|
return time.Now().After(expDate)
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Discard returns if the metric not valid or has expired
|
|
|
|
func (m *Metric) Discard() bool {
|
|
|
|
return !m.Valid || m.Expired()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Alert carries alerting information about a peer. WIP.
|
|
|
|
type Alert struct {
|
|
|
|
Peer peer.ID
|
|
|
|
MetricName string
|
|
|
|
}
|
2017-03-28 15:48:26 +00:00
|
|
|
|
|
|
|
// Error can be used by APIs to return errors.
|
|
|
|
type Error struct {
|
2019-02-27 17:04:35 +00:00
|
|
|
Code int `json:"code" codec:"o,omitempty"`
|
|
|
|
Message string `json:"message" codec:"m,omitempty"`
|
2017-03-28 15:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Error implements the error interface and returns the error's message.
|
2017-12-08 14:39:30 +00:00
|
|
|
func (e *Error) Error() string {
|
|
|
|
return fmt.Sprintf("%s (%d)", e.Message, e.Code)
|
2017-03-28 15:48:26 +00:00
|
|
|
}
|
2018-08-20 18:43:27 +00:00
|
|
|
|
|
|
|
// IPFSRepoStat wraps information about the IPFS repository.
|
|
|
|
type IPFSRepoStat struct {
|
2019-02-27 17:04:35 +00:00
|
|
|
RepoSize uint64 `codec:"r,omitempty"`
|
|
|
|
StorageMax uint64 `codec:"s, omitempty"`
|
2018-08-20 18:43:27 +00:00
|
|
|
}
|