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
|
|
|
"bytes"
|
|
|
|
"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"
|
|
|
|
ma "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
|
|
|
}
|
|
|
|
|
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 {
|
2018-09-22 01:00:10 +00:00
|
|
|
Cid cid.Cid
|
2017-02-08 17:04:08 +00:00
|
|
|
PeerMap map[peer.ID]PinInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobalPinInfoSerial is the serializable version of GlobalPinInfo.
|
|
|
|
type GlobalPinInfoSerial struct {
|
|
|
|
Cid string `json:"cid"`
|
|
|
|
PeerMap map[string]PinInfoSerial `json:"peer_map"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToSerial converts a GlobalPinInfo to its serializable version.
|
|
|
|
func (gpi GlobalPinInfo) ToSerial() GlobalPinInfoSerial {
|
|
|
|
s := GlobalPinInfoSerial{}
|
2018-09-22 01:00:10 +00:00
|
|
|
if gpi.Cid.Defined() {
|
2017-12-07 22:59:24 +00:00
|
|
|
s.Cid = gpi.Cid.String()
|
|
|
|
}
|
2017-02-08 17:04:08 +00:00
|
|
|
s.PeerMap = make(map[string]PinInfoSerial)
|
|
|
|
for k, v := range gpi.PeerMap {
|
|
|
|
s.PeerMap[peer.IDB58Encode(k)] = v.ToSerial()
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToGlobalPinInfo converts a GlobalPinInfoSerial to its native version.
|
|
|
|
func (gpis GlobalPinInfoSerial) ToGlobalPinInfo() GlobalPinInfo {
|
2017-12-07 22:59:24 +00:00
|
|
|
c, err := cid.Decode(gpis.Cid)
|
|
|
|
if err != nil {
|
2018-03-28 17:16:49 +00:00
|
|
|
logger.Debug(gpis.Cid, err)
|
2017-12-07 22:59:24 +00:00
|
|
|
}
|
2017-02-08 17:04:08 +00:00
|
|
|
gpi := GlobalPinInfo{
|
|
|
|
Cid: c,
|
|
|
|
PeerMap: make(map[peer.ID]PinInfo),
|
|
|
|
}
|
|
|
|
for k, v := range gpis.PeerMap {
|
2017-12-07 22:59:24 +00:00
|
|
|
p, err := peer.IDB58Decode(k)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(k, err)
|
|
|
|
}
|
2017-02-08 17:04:08 +00:00
|
|
|
gpi.PeerMap[p] = v.ToPinInfo()
|
|
|
|
}
|
|
|
|
return gpi
|
|
|
|
}
|
|
|
|
|
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 {
|
2018-09-05 12:49:27 +00:00
|
|
|
Cid cid.Cid
|
|
|
|
Peer peer.ID
|
2018-09-21 17:28:55 +00:00
|
|
|
PeerName string
|
2018-09-05 12:49:27 +00:00
|
|
|
Status TrackerStatus
|
|
|
|
TS time.Time
|
|
|
|
Error string
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PinInfoSerial is a serializable version of PinInfo.
|
|
|
|
// information is marked as
|
|
|
|
type PinInfoSerial struct {
|
2018-09-05 12:49:27 +00:00
|
|
|
Cid string `json:"cid"`
|
|
|
|
Peer string `json:"peer"`
|
2018-09-21 17:28:55 +00:00
|
|
|
PeerName string `json:"peername"`
|
2018-09-05 12:49:27 +00:00
|
|
|
Status string `json:"status"`
|
|
|
|
TS string `json:"timestamp"`
|
|
|
|
Error string `json:"error"`
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToSerial converts a PinInfo to its serializable version.
|
|
|
|
func (pi PinInfo) ToSerial() PinInfoSerial {
|
2017-12-07 22:59:24 +00:00
|
|
|
c := ""
|
2018-09-22 01:00:10 +00:00
|
|
|
if pi.Cid.Defined() {
|
2017-12-07 22:59:24 +00:00
|
|
|
c = pi.Cid.String()
|
|
|
|
}
|
|
|
|
p := ""
|
|
|
|
if pi.Peer != "" {
|
|
|
|
p = peer.IDB58Encode(pi.Peer)
|
|
|
|
}
|
|
|
|
|
2017-02-08 17:04:08 +00:00
|
|
|
return PinInfoSerial{
|
2018-09-11 15:20:20 +00:00
|
|
|
Cid: c,
|
|
|
|
Peer: p,
|
2018-09-21 17:28:55 +00:00
|
|
|
PeerName: pi.PeerName,
|
2018-09-11 15:20:20 +00:00
|
|
|
Status: pi.Status.String(),
|
|
|
|
TS: pi.TS.UTC().Format(time.RFC3339),
|
|
|
|
Error: pi.Error,
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToPinInfo converts a PinInfoSerial to its native version.
|
|
|
|
func (pis PinInfoSerial) ToPinInfo() PinInfo {
|
2017-12-07 22:59:24 +00:00
|
|
|
c, err := cid.Decode(pis.Cid)
|
|
|
|
if err != nil {
|
2018-03-28 17:16:49 +00:00
|
|
|
logger.Debug(pis.Cid, err)
|
2017-12-07 22:59:24 +00:00
|
|
|
}
|
|
|
|
p, err := peer.IDB58Decode(pis.Peer)
|
|
|
|
if err != nil {
|
2018-03-28 17:16:49 +00:00
|
|
|
logger.Debug(pis.Peer, err)
|
2017-12-07 22:59:24 +00:00
|
|
|
}
|
|
|
|
ts, err := time.Parse(time.RFC3339, pis.TS)
|
|
|
|
if err != nil {
|
2018-03-28 17:16:49 +00:00
|
|
|
logger.Debug(pis.TS, err)
|
2017-12-07 22:59:24 +00:00
|
|
|
}
|
2017-02-08 17:04:08 +00:00
|
|
|
return PinInfo{
|
2018-09-11 15:20:20 +00:00
|
|
|
Cid: c,
|
|
|
|
Peer: p,
|
2018-09-21 17:28:55 +00:00
|
|
|
PeerName: pis.PeerName,
|
2018-09-11 15:20:20 +00:00
|
|
|
Status: TrackerStatusFromString(pis.Status),
|
|
|
|
TS: ts,
|
|
|
|
Error: pis.Error,
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version holds version information
|
|
|
|
type Version struct {
|
|
|
|
Version string `json:"Version"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IPFSID is used to store information about the underlying IPFS daemon
|
|
|
|
type IPFSID struct {
|
|
|
|
ID peer.ID
|
|
|
|
Addresses []ma.Multiaddr
|
|
|
|
Error string
|
|
|
|
}
|
|
|
|
|
|
|
|
// IPFSIDSerial is the serializable IPFSID for RPC requests
|
|
|
|
type IPFSIDSerial struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Addresses MultiaddrsSerial `json:"addresses"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToSerial converts IPFSID to a go serializable object
|
|
|
|
func (id *IPFSID) ToSerial() IPFSIDSerial {
|
2017-12-07 22:59:24 +00:00
|
|
|
p := ""
|
|
|
|
if id.ID != "" {
|
|
|
|
p = peer.IDB58Encode(id.ID)
|
|
|
|
}
|
|
|
|
|
2017-02-08 17:04:08 +00:00
|
|
|
return IPFSIDSerial{
|
2017-12-07 22:59:24 +00:00
|
|
|
ID: p,
|
2017-02-08 17:04:08 +00:00
|
|
|
Addresses: MultiaddrsToSerial(id.Addresses),
|
|
|
|
Error: id.Error,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToIPFSID converts an IPFSIDSerial to IPFSID
|
|
|
|
func (ids *IPFSIDSerial) ToIPFSID() IPFSID {
|
|
|
|
id := IPFSID{}
|
|
|
|
if pID, err := peer.IDB58Decode(ids.ID); err == nil {
|
|
|
|
id.ID = pID
|
|
|
|
}
|
|
|
|
id.Addresses = ids.Addresses.ToMultiaddrs()
|
|
|
|
id.Error = ids.Error
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
2017-10-13 21:12:46 +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.
|
|
|
|
//
|
|
|
|
// 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] == [].
|
|
|
|
type ConnectGraph struct {
|
|
|
|
ClusterID peer.ID
|
|
|
|
IPFSLinks map[peer.ID][]peer.ID // ipfs to ipfs links
|
|
|
|
ClusterLinks map[peer.ID][]peer.ID // cluster to cluster links
|
|
|
|
ClustertoIPFS map[peer.ID]peer.ID // cluster to ipfs links
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnectGraphSerial is the serializable ConnectGraph counterpart for RPC requests
|
|
|
|
type ConnectGraphSerial struct {
|
|
|
|
ClusterID string
|
|
|
|
IPFSLinks map[string][]string `json:"ipfs_links"`
|
|
|
|
ClusterLinks map[string][]string `json:"cluster_links"`
|
|
|
|
ClustertoIPFS map[string]string `json:"cluster_to_ipfs"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToSerial converts a ConnectGraph to its Go-serializable version
|
|
|
|
func (cg ConnectGraph) ToSerial() ConnectGraphSerial {
|
2018-01-18 02:49:35 +00:00
|
|
|
IPFSLinksSerial := serializeLinkMap(cg.IPFSLinks)
|
|
|
|
ClusterLinksSerial := serializeLinkMap(cg.ClusterLinks)
|
2017-10-13 21:12:46 +00:00
|
|
|
ClustertoIPFSSerial := make(map[string]string)
|
|
|
|
for k, v := range cg.ClustertoIPFS {
|
|
|
|
ClustertoIPFSSerial[peer.IDB58Encode(k)] = peer.IDB58Encode(v)
|
|
|
|
}
|
|
|
|
return ConnectGraphSerial{
|
|
|
|
ClusterID: peer.IDB58Encode(cg.ClusterID),
|
|
|
|
IPFSLinks: IPFSLinksSerial,
|
|
|
|
ClusterLinks: ClusterLinksSerial,
|
|
|
|
ClustertoIPFS: ClustertoIPFSSerial,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-18 02:49:35 +00:00
|
|
|
// ToConnectGraph converts a ConnectGraphSerial to a ConnectGraph
|
|
|
|
func (cgs ConnectGraphSerial) ToConnectGraph() ConnectGraph {
|
|
|
|
ClustertoIPFS := make(map[peer.ID]peer.ID)
|
|
|
|
for k, v := range cgs.ClustertoIPFS {
|
|
|
|
pid1, _ := peer.IDB58Decode(k)
|
|
|
|
pid2, _ := peer.IDB58Decode(v)
|
|
|
|
ClustertoIPFS[pid1] = pid2
|
|
|
|
}
|
|
|
|
pid, _ := peer.IDB58Decode(cgs.ClusterID)
|
|
|
|
return ConnectGraph{
|
|
|
|
ClusterID: pid,
|
|
|
|
IPFSLinks: deserializeLinkMap(cgs.IPFSLinks),
|
|
|
|
ClusterLinks: deserializeLinkMap(cgs.ClusterLinks),
|
|
|
|
ClustertoIPFS: ClustertoIPFS,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func serializeLinkMap(Links map[peer.ID][]peer.ID) map[string][]string {
|
2017-10-13 21:12:46 +00:00
|
|
|
LinksSerial := make(map[string][]string)
|
|
|
|
for k, v := range Links {
|
|
|
|
kS := peer.IDB58Encode(k)
|
|
|
|
LinksSerial[kS] = PeersToStrings(v)
|
|
|
|
}
|
|
|
|
return LinksSerial
|
|
|
|
}
|
|
|
|
|
2018-01-18 02:49:35 +00:00
|
|
|
func deserializeLinkMap(LinksSerial map[string][]string) map[peer.ID][]peer.ID {
|
|
|
|
Links := make(map[peer.ID][]peer.ID)
|
|
|
|
for k, v := range LinksSerial {
|
|
|
|
pid, _ := peer.IDB58Decode(k)
|
|
|
|
Links[pid] = StringsToPeers(v)
|
|
|
|
}
|
|
|
|
return Links
|
2017-10-13 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 02:49:35 +00:00
|
|
|
// SwarmPeers lists an ipfs daemon's peers
|
|
|
|
type SwarmPeers []peer.ID
|
|
|
|
|
2017-10-13 21:12:46 +00:00
|
|
|
// SwarmPeersSerial is the serialized form of SwarmPeers for RPC use
|
2018-01-18 02:49:35 +00:00
|
|
|
type SwarmPeersSerial []string
|
2017-10-13 21:12:46 +00:00
|
|
|
|
|
|
|
// ToSerial converts SwarmPeers to its Go-serializeable version
|
|
|
|
func (swarm SwarmPeers) ToSerial() SwarmPeersSerial {
|
2018-01-18 02:49:35 +00:00
|
|
|
return PeersToStrings(swarm)
|
2017-10-13 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToSwarmPeers converts a SwarmPeersSerial object to SwarmPeers.
|
|
|
|
func (swarmS SwarmPeersSerial) ToSwarmPeers() SwarmPeers {
|
2018-01-18 02:49:35 +00:00
|
|
|
return StringsToPeers(swarmS)
|
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 {
|
2017-11-10 15:09:45 +00:00
|
|
|
ID peer.ID
|
|
|
|
Addresses []ma.Multiaddr
|
|
|
|
ClusterPeers []peer.ID
|
|
|
|
ClusterPeersAddresses []ma.Multiaddr
|
|
|
|
Version string
|
|
|
|
Commit string
|
|
|
|
RPCProtocolVersion protocol.ID
|
|
|
|
Error string
|
|
|
|
IPFS IPFSID
|
2017-12-01 18:50:13 +00:00
|
|
|
Peername string
|
2017-02-08 17:04:08 +00:00
|
|
|
//PublicKey crypto.PubKey
|
|
|
|
}
|
|
|
|
|
|
|
|
// IDSerial is the serializable ID counterpart for RPC requests
|
|
|
|
type IDSerial struct {
|
2017-11-10 15:09:45 +00:00
|
|
|
ID string `json:"id"`
|
|
|
|
Addresses MultiaddrsSerial `json:"addresses"`
|
|
|
|
ClusterPeers []string `json:"cluster_peers"`
|
|
|
|
ClusterPeersAddresses MultiaddrsSerial `json:"cluster_peers_addresses"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
Commit string `json:"commit"`
|
|
|
|
RPCProtocolVersion string `json:"rpc_protocol_version"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
IPFS IPFSIDSerial `json:"ipfs"`
|
2017-12-01 18:50:13 +00:00
|
|
|
Peername string `json:"peername"`
|
2017-02-08 17:04:08 +00:00
|
|
|
//PublicKey []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToSerial converts an ID to its Go-serializable version
|
|
|
|
func (id ID) ToSerial() IDSerial {
|
|
|
|
//var pkey []byte
|
|
|
|
//if id.PublicKey != nil {
|
|
|
|
// pkey, _ = id.PublicKey.Bytes()
|
|
|
|
//}
|
|
|
|
|
2017-12-07 22:59:24 +00:00
|
|
|
p := ""
|
|
|
|
if id.ID != "" {
|
|
|
|
p = peer.IDB58Encode(id.ID)
|
2017-11-10 15:09:45 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 17:04:08 +00:00
|
|
|
return IDSerial{
|
2017-12-07 22:59:24 +00:00
|
|
|
ID: p,
|
2017-11-10 15:09:45 +00:00
|
|
|
Addresses: MultiaddrsToSerial(id.Addresses),
|
2017-12-07 22:59:24 +00:00
|
|
|
ClusterPeers: PeersToStrings(id.ClusterPeers),
|
2017-11-10 15:09:45 +00:00
|
|
|
ClusterPeersAddresses: MultiaddrsToSerial(id.ClusterPeersAddresses),
|
|
|
|
Version: id.Version,
|
|
|
|
Commit: id.Commit,
|
|
|
|
RPCProtocolVersion: string(id.RPCProtocolVersion),
|
|
|
|
Error: id.Error,
|
|
|
|
IPFS: id.IPFS.ToSerial(),
|
2017-12-01 18:50:13 +00:00
|
|
|
Peername: id.Peername,
|
2017-12-07 22:59:24 +00:00
|
|
|
//PublicKey: pkey,
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToID converts an IDSerial object to ID.
|
|
|
|
// It will ignore any errors when parsing the fields.
|
|
|
|
func (ids IDSerial) ToID() ID {
|
|
|
|
id := ID{}
|
2017-12-07 22:59:24 +00:00
|
|
|
p, err := peer.IDB58Decode(ids.ID)
|
|
|
|
if err != nil {
|
2018-03-28 17:16:49 +00:00
|
|
|
logger.Debug(ids.ID, err)
|
2017-12-07 22:59:24 +00:00
|
|
|
}
|
2017-02-08 17:04:08 +00:00
|
|
|
id.ID = p
|
|
|
|
|
|
|
|
//if pkey, err := crypto.UnmarshalPublicKey(ids.PublicKey); err == nil {
|
|
|
|
// id.PublicKey = pkey
|
|
|
|
//}
|
|
|
|
|
|
|
|
id.Addresses = ids.Addresses.ToMultiaddrs()
|
2017-12-07 22:59:24 +00:00
|
|
|
id.ClusterPeers = StringsToPeers(ids.ClusterPeers)
|
2017-11-10 15:09:45 +00:00
|
|
|
id.ClusterPeersAddresses = ids.ClusterPeersAddresses.ToMultiaddrs()
|
2017-02-08 17:04:08 +00:00
|
|
|
id.Version = ids.Version
|
|
|
|
id.Commit = ids.Commit
|
|
|
|
id.RPCProtocolVersion = protocol.ID(ids.RPCProtocolVersion)
|
|
|
|
id.Error = ids.Error
|
|
|
|
id.IPFS = ids.IPFS.ToIPFSID()
|
2017-12-01 18:50:13 +00:00
|
|
|
id.Peername = ids.Peername
|
2017-02-08 17:04:08 +00:00
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// MultiaddrSerial is a Multiaddress in a serializable form
|
|
|
|
type MultiaddrSerial string
|
|
|
|
|
|
|
|
// MultiaddrsSerial is an array of Multiaddresses in serializable form
|
|
|
|
type MultiaddrsSerial []MultiaddrSerial
|
|
|
|
|
|
|
|
// MultiaddrToSerial converts a Multiaddress to its serializable form
|
|
|
|
func MultiaddrToSerial(addr ma.Multiaddr) MultiaddrSerial {
|
2017-12-07 22:59:24 +00:00
|
|
|
if addr != nil {
|
|
|
|
return MultiaddrSerial(addr.String())
|
|
|
|
}
|
|
|
|
return ""
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToMultiaddr converts a serializable Multiaddress to its original type.
|
|
|
|
// All errors are ignored.
|
|
|
|
func (addrS MultiaddrSerial) ToMultiaddr() ma.Multiaddr {
|
2017-12-07 22:59:24 +00:00
|
|
|
str := string(addrS)
|
|
|
|
a, err := ma.NewMultiaddr(str)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(str, err)
|
|
|
|
}
|
2017-02-08 17:04:08 +00:00
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
// MultiaddrsToSerial converts a slice of Multiaddresses to its
|
|
|
|
// serializable form.
|
|
|
|
func MultiaddrsToSerial(addrs []ma.Multiaddr) MultiaddrsSerial {
|
|
|
|
addrsS := make([]MultiaddrSerial, len(addrs), len(addrs))
|
|
|
|
for i, a := range addrs {
|
2017-12-07 22:59:24 +00:00
|
|
|
if a != nil {
|
|
|
|
addrsS[i] = MultiaddrToSerial(a)
|
|
|
|
}
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
return addrsS
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToMultiaddrs converts MultiaddrsSerial back to a slice of Multiaddresses
|
|
|
|
func (addrsS MultiaddrsSerial) ToMultiaddrs() []ma.Multiaddr {
|
|
|
|
addrs := make([]ma.Multiaddr, len(addrsS), len(addrsS))
|
|
|
|
for i, addrS := range addrsS {
|
|
|
|
addrs[i] = addrS.ToMultiaddr()
|
|
|
|
}
|
|
|
|
return addrs
|
|
|
|
}
|
|
|
|
|
2018-03-18 19:29:02 +00:00
|
|
|
// CidsToStrings encodes cid.Cids to strings.
|
2018-09-22 01:00:10 +00:00
|
|
|
func CidsToStrings(cids []cid.Cid) []string {
|
2018-03-18 19:29:02 +00:00
|
|
|
strs := make([]string, len(cids))
|
|
|
|
for i, c := range cids {
|
|
|
|
strs[i] = c.String()
|
|
|
|
}
|
|
|
|
return strs
|
|
|
|
}
|
|
|
|
|
|
|
|
// StringsToCidSet decodes cid.Cids from strings.
|
|
|
|
func StringsToCidSet(strs []string) *cid.Set {
|
|
|
|
cids := cid.NewSet()
|
|
|
|
for _, str := range strs {
|
|
|
|
c, err := cid.Decode(str)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(str, err)
|
|
|
|
}
|
|
|
|
cids.Add(c)
|
|
|
|
}
|
|
|
|
return cids
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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"`
|
|
|
|
Metadata map[string]string `json:"metadata" codec:"m,omitempty"`
|
2018-07-04 16:30:24 +00:00
|
|
|
}
|
|
|
|
|
Add PinPath/UnpinPath support.
Squashed commit of the following:
commit 38cf569c6aed77c46ee4e0f8baa4d1a9daf8f03e
Merge: d125f69 aaada42
Author: Hector Sanjuan <hsanjuan@users.noreply.github.com>
Date: Wed Feb 20 11:02:00 2019 +0000
Merge pull request #634 from ipfs/issue_450
Support PinPath, UnpinPath (resolve before pinning)
commit aaada42054e1f1c7b2abb1270859d0de41a0e5d8
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 19 22:16:25 2019 +0530
formatResponse accepts api.Pin and not api.PinSerial
commit b5da4bea045865814cc422da71827b44ddd44b90
Merge: ba59036 cc8dd7e
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 19 21:36:46 2019 +0530
Merge branch 'master' into issue_450
commit ba5903649c1df1dba20f4d6f7e3573d6fe24921f
Merge: f002914 d59880c
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Feb 18 08:41:11 2019 +0530
Merge branch 'issue_450' of github.com:ipfs/ipfs-cluster into issue_450
commit f00291494c0c02621c2296cbb7ac71e4c23aa9ec
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Feb 18 08:31:39 2019 +0530
PinPath: more improvements
Added tracing for new methods
commit d59880c338eaa8214fe06b4f930a540793d78407
Merge: 0ca4c7c b4f0eb3
Author: Hector Sanjuan <hsanjuan@users.noreply.github.com>
Date: Wed Feb 13 15:22:49 2019 +0000
Merge branch 'master' into issue_450
commit 0ca4c7c3b0670ed9c8279f8274d36e3485c10030
Merge: d35017a ecef9ea
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 12 13:10:13 2019 +0530
Merge branch 'master' into issue_450
commit d35017a8de91ca9fc9a9a047c48c75134cee9f98
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 12 13:07:25 2019 +0530
PinPath: more improvements
- Worth having `PinOptions` as a separate field in the struct and
constructing the query in the test with ToQuery()
- sharness: "intialization" line can be placed outside the tests at
the top
commit 68e3b90417ffbad89d41a70ac81d85f9037f8848
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Sun Feb 10 21:43:50 2019 +0530
Using if-continue pattern instead of if-else
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 3c29799f3b85be328b27508332ab92049d8b82f3
Merge: 956790b 4324889
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Thu Feb 7 10:25:52 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 956790b381db9858e4194f983e898b07dc51ba66
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 21:11:20 2019 +0530
Removing resolved path
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 7191cc46cedfbec116a9746937e28881b50ca044
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 16:45:07 2019 +0530
Fix go vet
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit f8b3d5b63b1b7569e2a3e0d82894fd4491c246c4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 16:07:03 2019 +0530
Fixed linting error
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 23c57eb467755a1f21387a1615a7f34e97348053
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 09:20:41 2019 +0530
Fixed tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 0caedd94aefeb3b6649dedc214cb4b849ace2ea4
Merge: 17e555e 5a7ee1d
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 00:07:10 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 17e555e4a7c574413df90aac70c5cc29cab98f54
Author: Hector Sanjuan <code@hector.link>
Date: Tue Feb 5 16:58:50 2019 +0000
PinPath: address some feedback + improvements
* Changed client's Pin() API and PinPath to be consistent
* Added helper methods to turn PinPath to query and back
* Make code and tests build
* Use TestCidResolved everywhere
* Fix cluster.PinPath arguments
* Fix formatting of responses with --no-status
* Make tests readable and call Fatal when needed
* Use a pathTestCases variable
commit f0e7369c47c5ddadc8ed45df5fd2d4d9b2d42b38
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 5 18:34:26 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Addressed review comments as in
https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-198751932
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit a8b4f181d2d7afed32ee41331dfaab19fd66a173
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 29 22:41:27 2019 +0530
Fixing tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit e39b95ca19e4d75506f4f492678245ef13936a44
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 29 14:52:53 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- PinPath and UnpinPath should return api.Pin
- PinPath should accept pin options
- Removing duplicate logic for Resolve from cluster
- And many other review comments https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-195509504
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit d146075126320896665ba58d337a13789f68ea86
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 23 17:08:41 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
PinPath(in both rest and rpc) should return a serializable struct in the
form `{"\":"Q...cid..string..."}` (as used in "github.com/ipfs/go-cid"
to marshal and unmarshal)
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 1f4869568a8adb450275257154ea3a26d03a30f3
Merge: 7acfd28 a244af9
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 23 07:18:56 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 7acfd282732ddf2282a67d4f9d0170a494eb3ed4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 22 18:14:32 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- RPC must always use serializable structs
- In command, just use pin with path as cid is also a valid path
- Addressing many other small review comments as in
https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-192122534
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 36905041e1e3f0b204942030aab3ab7b5b9e4d62
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 16 09:36:42 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Extra logic for path checking should go into resolve so that it can be
properly reused
Added sharness tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 9116bda3534e77bb391d873051bb520a1b01a326
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 16 08:08:07 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
error strings should not be capitalized
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit ca7e61861374f456300a85ddc0374e594f74f963
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 15 23:40:25 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Tests
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 522fbcd899f01c01680375561a32a87464157c0a
Merge: f1a56ab f7bc468
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 15 10:40:54 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit f1a56ab925fb74c0c44273a4524afa4843cf757f
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Jan 14 20:58:17 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- IPFS Connector should act as a pure IPFS client, any extra logic
should go to cluster.go
- Use cid.Undef, instead of cid.Cid{}
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit c83b91054f6774f1f9d4930cfc3f1fa28236f57c
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Thu Jan 10 08:57:17 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- Separate handlers, methods and rpc apis for PinPath and UnpinPath from
Pin and Unpin
- Support ipld paths as well
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 719dff88129366ce3ccb5e04cb6f8082a0915c5c
Merge: 91ceb47 21170c4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 9 19:38:35 2019 +0530
Merge branch 'issue_450_old' into HEAD
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 91ceb4796259ca7ef2974ec43e6a278a12796b13
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 9 19:36:41 2019 +0530
Revert "WIP: Figure out why test does not impleme"
This reverts commit 28a3a3f25dce6f296c8cbef86221644c099a7e75.
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 28a3a3f25dce6f296c8cbef86221644c099a7e75
Author: cd10012 <ced361@nyu.edu>
Date: Tue Jul 24 23:23:10 2018 -0400
WIP: Figure out why test does not implement IPFSConnector interface...
License: MIT
Signed-off-by: cd10012 <ced361@nyu.edu>
commit 21170c48e77e69583db64544b08120a9baf40d8d
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 8 10:37:59 2019 +0530
Support PinPath, UnpinPath (resolve before pinning)
This commit adds API support for pinning using path
`POST /pins/<ipfs or ipns path>` and `DELETE /pins/<ipfs or ipns path>`
will resolve the path into a cid and perform perform pinning or
unpinning
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Co-authored-by: Hector Sanjuan <hector@protocol.ai>
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2019-02-20 11:07:50 +00:00
|
|
|
// 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)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2018-09-22 01:00:10 +00:00
|
|
|
Cid cid.Cid
|
2018-07-04 16:30:24 +00:00
|
|
|
|
|
|
|
// See PinType comments
|
|
|
|
Type PinType
|
|
|
|
|
|
|
|
// The peers to which this pin is allocated
|
|
|
|
Allocations []peer.ID
|
|
|
|
|
|
|
|
// MaxDepth associated to this pin. -1 means
|
|
|
|
// recursive.
|
|
|
|
MaxDepth int
|
|
|
|
|
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.
|
2018-09-22 01:00:10 +00:00
|
|
|
Reference cid.Cid
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
|
|
|
|
Add PinPath/UnpinPath support.
Squashed commit of the following:
commit 38cf569c6aed77c46ee4e0f8baa4d1a9daf8f03e
Merge: d125f69 aaada42
Author: Hector Sanjuan <hsanjuan@users.noreply.github.com>
Date: Wed Feb 20 11:02:00 2019 +0000
Merge pull request #634 from ipfs/issue_450
Support PinPath, UnpinPath (resolve before pinning)
commit aaada42054e1f1c7b2abb1270859d0de41a0e5d8
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 19 22:16:25 2019 +0530
formatResponse accepts api.Pin and not api.PinSerial
commit b5da4bea045865814cc422da71827b44ddd44b90
Merge: ba59036 cc8dd7e
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 19 21:36:46 2019 +0530
Merge branch 'master' into issue_450
commit ba5903649c1df1dba20f4d6f7e3573d6fe24921f
Merge: f002914 d59880c
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Feb 18 08:41:11 2019 +0530
Merge branch 'issue_450' of github.com:ipfs/ipfs-cluster into issue_450
commit f00291494c0c02621c2296cbb7ac71e4c23aa9ec
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Feb 18 08:31:39 2019 +0530
PinPath: more improvements
Added tracing for new methods
commit d59880c338eaa8214fe06b4f930a540793d78407
Merge: 0ca4c7c b4f0eb3
Author: Hector Sanjuan <hsanjuan@users.noreply.github.com>
Date: Wed Feb 13 15:22:49 2019 +0000
Merge branch 'master' into issue_450
commit 0ca4c7c3b0670ed9c8279f8274d36e3485c10030
Merge: d35017a ecef9ea
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 12 13:10:13 2019 +0530
Merge branch 'master' into issue_450
commit d35017a8de91ca9fc9a9a047c48c75134cee9f98
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 12 13:07:25 2019 +0530
PinPath: more improvements
- Worth having `PinOptions` as a separate field in the struct and
constructing the query in the test with ToQuery()
- sharness: "intialization" line can be placed outside the tests at
the top
commit 68e3b90417ffbad89d41a70ac81d85f9037f8848
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Sun Feb 10 21:43:50 2019 +0530
Using if-continue pattern instead of if-else
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 3c29799f3b85be328b27508332ab92049d8b82f3
Merge: 956790b 4324889
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Thu Feb 7 10:25:52 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 956790b381db9858e4194f983e898b07dc51ba66
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 21:11:20 2019 +0530
Removing resolved path
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 7191cc46cedfbec116a9746937e28881b50ca044
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 16:45:07 2019 +0530
Fix go vet
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit f8b3d5b63b1b7569e2a3e0d82894fd4491c246c4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 16:07:03 2019 +0530
Fixed linting error
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 23c57eb467755a1f21387a1615a7f34e97348053
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 09:20:41 2019 +0530
Fixed tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 0caedd94aefeb3b6649dedc214cb4b849ace2ea4
Merge: 17e555e 5a7ee1d
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Feb 6 00:07:10 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 17e555e4a7c574413df90aac70c5cc29cab98f54
Author: Hector Sanjuan <code@hector.link>
Date: Tue Feb 5 16:58:50 2019 +0000
PinPath: address some feedback + improvements
* Changed client's Pin() API and PinPath to be consistent
* Added helper methods to turn PinPath to query and back
* Make code and tests build
* Use TestCidResolved everywhere
* Fix cluster.PinPath arguments
* Fix formatting of responses with --no-status
* Make tests readable and call Fatal when needed
* Use a pathTestCases variable
commit f0e7369c47c5ddadc8ed45df5fd2d4d9b2d42b38
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Feb 5 18:34:26 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Addressed review comments as in
https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-198751932
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit a8b4f181d2d7afed32ee41331dfaab19fd66a173
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 29 22:41:27 2019 +0530
Fixing tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit e39b95ca19e4d75506f4f492678245ef13936a44
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 29 14:52:53 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- PinPath and UnpinPath should return api.Pin
- PinPath should accept pin options
- Removing duplicate logic for Resolve from cluster
- And many other review comments https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-195509504
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit d146075126320896665ba58d337a13789f68ea86
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 23 17:08:41 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
PinPath(in both rest and rpc) should return a serializable struct in the
form `{"\":"Q...cid..string..."}` (as used in "github.com/ipfs/go-cid"
to marshal and unmarshal)
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 1f4869568a8adb450275257154ea3a26d03a30f3
Merge: 7acfd28 a244af9
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 23 07:18:56 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 7acfd282732ddf2282a67d4f9d0170a494eb3ed4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 22 18:14:32 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- RPC must always use serializable structs
- In command, just use pin with path as cid is also a valid path
- Addressing many other small review comments as in
https://github.com/ipfs/ipfs-cluster/pull/634#pullrequestreview-192122534
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 36905041e1e3f0b204942030aab3ab7b5b9e4d62
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 16 09:36:42 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Extra logic for path checking should go into resolve so that it can be
properly reused
Added sharness tests
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 9116bda3534e77bb391d873051bb520a1b01a326
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 16 08:08:07 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
error strings should not be capitalized
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit ca7e61861374f456300a85ddc0374e594f74f963
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 15 23:40:25 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
Tests
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 522fbcd899f01c01680375561a32a87464157c0a
Merge: f1a56ab f7bc468
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 15 10:40:54 2019 +0530
Merge branch 'master' into issue_450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit f1a56ab925fb74c0c44273a4524afa4843cf757f
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Mon Jan 14 20:58:17 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- IPFS Connector should act as a pure IPFS client, any extra logic
should go to cluster.go
- Use cid.Undef, instead of cid.Cid{}
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit c83b91054f6774f1f9d4930cfc3f1fa28236f57c
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Thu Jan 10 08:57:17 2019 +0530
Support PinPath, UnpinPath(resolve before pinning)
- Separate handlers, methods and rpc apis for PinPath and UnpinPath from
Pin and Unpin
- Support ipld paths as well
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 719dff88129366ce3ccb5e04cb6f8082a0915c5c
Merge: 91ceb47 21170c4
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 9 19:38:35 2019 +0530
Merge branch 'issue_450_old' into HEAD
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 91ceb4796259ca7ef2974ec43e6a278a12796b13
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Wed Jan 9 19:36:41 2019 +0530
Revert "WIP: Figure out why test does not impleme"
This reverts commit 28a3a3f25dce6f296c8cbef86221644c099a7e75.
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
commit 28a3a3f25dce6f296c8cbef86221644c099a7e75
Author: cd10012 <ced361@nyu.edu>
Date: Tue Jul 24 23:23:10 2018 -0400
WIP: Figure out why test does not implement IPFSConnector interface...
License: MIT
Signed-off-by: cd10012 <ced361@nyu.edu>
commit 21170c48e77e69583db64544b08120a9baf40d8d
Author: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Date: Tue Jan 8 10:37:59 2019 +0530
Support PinPath, UnpinPath (resolve before pinning)
This commit adds API support for pinning using path
`POST /pins/<ipfs or ipns path>` and `DELETE /pins/<ipfs or ipns path>`
will resolve the path into a cid and perform perform pinning or
unpinning
Fixes #450
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Co-authored-by: Hector Sanjuan <hector@protocol.ai>
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2019-02-20 11:07:50 +00:00
|
|
|
// PinPath 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.
|
2018-09-22 01:00:10 +00:00
|
|
|
func PinCid(c cid.Cid) Pin {
|
2017-03-08 15:57:27 +00:00
|
|
|
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.
|
2018-09-22 01:00:10 +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
|
|
|
|
}
|
|
|
|
|
2017-03-08 15:57:27 +00:00
|
|
|
// PinSerial is a serializable version of Pin
|
|
|
|
type PinSerial struct {
|
2018-07-04 16:30:24 +00:00
|
|
|
PinOptions
|
|
|
|
|
2019-02-19 17:59:46 +00:00
|
|
|
Cid string `json:"cid" codec:"c,omitempty"`
|
|
|
|
Type uint64 `json:"type" codec:"t,omitempty"`
|
|
|
|
Allocations []string `json:"allocations" codec:"a,omitempty"`
|
|
|
|
MaxDepth int `json:"max_depth" codec:"d,omitempty"`
|
|
|
|
Reference string `json:"reference" codec:"r,omitempty"`
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 15:57:27 +00:00
|
|
|
// ToSerial converts a Pin to PinSerial.
|
|
|
|
func (pin Pin) ToSerial() PinSerial {
|
2017-12-07 22:59:24 +00:00
|
|
|
c := ""
|
2018-09-22 01:00:10 +00:00
|
|
|
if pin.Cid.Defined() {
|
2017-12-07 22:59:24 +00:00
|
|
|
c = pin.Cid.String()
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
2018-07-23 13:56:46 +00:00
|
|
|
ref := ""
|
2018-09-22 01:00:10 +00:00
|
|
|
if pin.Reference.Defined() {
|
2018-07-23 13:56:46 +00:00
|
|
|
ref = pin.Reference.String()
|
2018-03-18 19:29:02 +00:00
|
|
|
}
|
2017-02-13 15:46:53 +00:00
|
|
|
|
2017-12-08 00:09:52 +00:00
|
|
|
allocs := PeersToStrings(pin.Allocations)
|
|
|
|
|
2017-03-08 15:57:27 +00:00
|
|
|
return PinSerial{
|
2018-07-04 16:30:24 +00:00
|
|
|
Cid: c,
|
|
|
|
Allocations: allocs,
|
2018-08-10 12:39:44 +00:00
|
|
|
Type: uint64(pin.Type),
|
2018-07-04 16:30:24 +00:00
|
|
|
MaxDepth: pin.MaxDepth,
|
2018-07-23 13:56:46 +00:00
|
|
|
Reference: ref,
|
2019-02-19 17:59:46 +00:00
|
|
|
PinOptions: pin.PinOptions,
|
2017-02-08 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
pbPin := &pb.Pin{
|
|
|
|
Cid: pin.Cid.Bytes(),
|
|
|
|
Type: convertPinType(pin.Type),
|
|
|
|
Allocations: allocs,
|
|
|
|
MaxDepth: int32(pin.MaxDepth),
|
|
|
|
Reference: pin.Reference.Bytes(),
|
|
|
|
ReplicationFactorMin: int32(pin.ReplicationFactorMin),
|
|
|
|
ReplicationFactorMax: int32(pin.ReplicationFactorMax),
|
|
|
|
Name: pin.Name,
|
|
|
|
ShardSize: pin.ShardSize,
|
|
|
|
Metadata: pin.Metadata,
|
|
|
|
}
|
|
|
|
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 {
|
|
|
|
pin.Reference = cid.Undef
|
|
|
|
|
|
|
|
} else {
|
|
|
|
pin.Reference = ref
|
|
|
|
}
|
|
|
|
pin.Reference = ref
|
|
|
|
pin.ReplicationFactorMin = int(pbPin.GetReplicationFactorMin())
|
|
|
|
pin.ReplicationFactorMax = int(pbPin.GetReplicationFactorMax())
|
|
|
|
pin.Name = pbPin.GetName()
|
|
|
|
pin.ShardSize = pbPin.GetShardSize()
|
|
|
|
pin.Metadata = pbPin.GetMetadata()
|
|
|
|
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.
|
|
|
|
func (pin Pin) Equals(pin2 Pin) bool {
|
|
|
|
pin1s := pin.ToSerial()
|
|
|
|
pin2s := pin2.ToSerial()
|
|
|
|
|
|
|
|
if pin1s.Cid != pin2s.Cid {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if pin1s.Name != pin2s.Name {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-03-18 19:29:02 +00:00
|
|
|
if pin1s.Type != pin2s.Type {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-07-04 16:30:24 +00:00
|
|
|
if pin1s.MaxDepth != pin2s.MaxDepth {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if pin1s.ShardSize != pin2s.ShardSize {
|
2018-03-01 19:52:10 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-01-16 10:21:34 +00:00
|
|
|
sort.Strings(pin1s.Allocations)
|
|
|
|
sort.Strings(pin2s.Allocations)
|
|
|
|
|
|
|
|
if strings.Join(pin1s.Allocations, ",") != strings.Join(pin2s.Allocations, ",") {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if pin1s.ReplicationFactorMax != pin2s.ReplicationFactorMax {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if pin1s.ReplicationFactorMin != pin2s.ReplicationFactorMin {
|
|
|
|
return false
|
|
|
|
}
|
2018-03-18 19:29:02 +00:00
|
|
|
|
2018-07-23 13:56:46 +00:00
|
|
|
if pin1s.Reference != pin2s.Reference {
|
2018-03-18 19:29:02 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-01-16 10:21:34 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-03-08 15:57:27 +00:00
|
|
|
// ToPin converts a PinSerial to its native form.
|
|
|
|
func (pins PinSerial) ToPin() Pin {
|
2017-12-07 22:59:24 +00:00
|
|
|
c, err := cid.Decode(pins.Cid)
|
|
|
|
if err != nil {
|
2018-03-28 17:16:49 +00:00
|
|
|
logger.Debug(pins.Cid, err)
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
2018-09-22 01:00:10 +00:00
|
|
|
var ref cid.Cid
|
2018-07-23 13:56:46 +00:00
|
|
|
if pins.Reference != "" {
|
|
|
|
ref, err = cid.Decode(pins.Reference)
|
2018-03-18 19:29:02 +00:00
|
|
|
if err != nil {
|
2018-07-23 13:56:46 +00:00
|
|
|
logger.Warning(pins.Reference, err)
|
2018-03-18 19:29:02 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-08 17:28:43 +00:00
|
|
|
|
2017-03-08 15:57:27 +00:00
|
|
|
return Pin{
|
2018-07-04 16:30:24 +00:00
|
|
|
Cid: c,
|
|
|
|
Allocations: StringsToPeers(pins.Allocations),
|
|
|
|
Type: PinType(pins.Type),
|
|
|
|
MaxDepth: pins.MaxDepth,
|
2018-07-23 13:56:46 +00:00
|
|
|
Reference: ref,
|
2018-07-04 16:30:24 +00:00
|
|
|
PinOptions: PinOptions{
|
|
|
|
Name: pins.Name,
|
|
|
|
ReplicationFactorMin: pins.ReplicationFactorMin,
|
|
|
|
ReplicationFactorMax: pins.ReplicationFactorMax,
|
|
|
|
ShardSize: pins.ShardSize,
|
|
|
|
},
|
2018-04-27 21:12:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 22:40:06 +00:00
|
|
|
// Clone returns a deep copy of the PinSerial.
|
|
|
|
func (pins PinSerial) Clone() PinSerial {
|
|
|
|
new := pins // this copy all the simple fields.
|
|
|
|
// slices are pointers. We need to explicitally copy them.
|
|
|
|
new.Allocations = make([]string, len(pins.Allocations))
|
|
|
|
copy(new.Allocations, pins.Allocations)
|
|
|
|
return new
|
|
|
|
}
|
|
|
|
|
2018-10-30 02:00:38 +00:00
|
|
|
// DecodeCid retrieves just the cid from a PinSerial without
|
|
|
|
// allocating a Pin.
|
|
|
|
func (pins PinSerial) DecodeCid() cid.Cid {
|
|
|
|
c, err := cid.Decode(pins.Cid)
|
|
|
|
if err != nil {
|
|
|
|
logger.Debug(pins.Cid, err)
|
|
|
|
}
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
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 {
|
2018-07-19 13:17:27 +00:00
|
|
|
Data []byte
|
|
|
|
Cid string
|
2018-07-24 12:21:29 +00:00
|
|
|
CumSize uint64 // Cumulative size
|
2018-07-19 13:17:27 +00:00
|
|
|
Format string
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
type Metric struct {
|
|
|
|
Name string
|
2018-10-23 18:21:27 +00:00
|
|
|
Peer peer.ID
|
2017-02-13 15:46:53 +00:00
|
|
|
Value string
|
2018-10-23 18:21:27 +00:00
|
|
|
Expire int64
|
|
|
|
Valid bool
|
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()
|
|
|
|
}
|
|
|
|
|
2018-12-14 13:22:03 +00:00
|
|
|
// MetricSerial is a helper for JSON marshaling. The Metric type is already
|
2018-10-23 18:21:27 +00:00
|
|
|
// serializable, but not pretty to humans (API).
|
2018-12-14 13:22:03 +00:00
|
|
|
type MetricSerial struct {
|
2018-10-23 18:21:27 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Peer string `json:"peer"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
Expire int64 `json:"expire"`
|
|
|
|
Valid bool `json:"valid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON allows a Metric to produce a JSON representation
|
|
|
|
// of itself.
|
|
|
|
func (m *Metric) MarshalJSON() ([]byte, error) {
|
2018-12-14 13:22:03 +00:00
|
|
|
return json.Marshal(&MetricSerial{
|
2018-10-23 18:21:27 +00:00
|
|
|
Name: m.Name,
|
|
|
|
Peer: peer.IDB58Encode(m.Peer),
|
|
|
|
Value: m.Value,
|
|
|
|
Expire: m.Expire,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON decodes JSON on top of the Metric.
|
|
|
|
func (m *Metric) UnmarshalJSON(j []byte) error {
|
|
|
|
if bytes.Equal(j, []byte("null")) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-12-14 13:22:03 +00:00
|
|
|
ms := &MetricSerial{}
|
2018-10-23 18:21:27 +00:00
|
|
|
err := json.Unmarshal(j, ms)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
p, err := peer.IDB58Decode(ms.Peer)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
m.Name = ms.Name
|
|
|
|
m.Peer = p
|
|
|
|
m.Value = ms.Value
|
|
|
|
m.Expire = ms.Expire
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-13 15:46:53 +00:00
|
|
|
// 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 {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
RepoSize uint64
|
|
|
|
StorageMax uint64
|
|
|
|
}
|