This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feature: implement remote pinning API #3588
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7291eab
stub out remote pin api
yusefnapora 9c9a1e7
implement remote pinning API
yusefnapora e3d9683
implement timeouts for remote pin methods
yusefnapora 93cb6ee
fix pin.remote.ls
yusefnapora bdb3d1e
add pin.remote tests to tests-interface-core.js
yusefnapora 2e232b4
fix lint issues
yusefnapora a1f7d8f
mv remote/index.js remote.js
yusefnapora a7b6e84
use commit hash for pinning client dependency
yusefnapora 0047a58
make interface-core tests pass
yusefnapora a2e9846
bump client dependency
yusefnapora cd57853
use default status "pinned" if none provided in ls
yusefnapora 2bb4779
wip - refactor code style
yusefnapora 4ce386f
wip - more refactoring
yusefnapora 2808e3e
remove pinning client dependency
yusefnapora a64118e
fix lint issues
yusefnapora 0fa8549
fix timeout for remote service stat
yusefnapora 1648b22
add Pinning.RemoteServices to IpfsConfig
yusefnapora c01fe6c
refactor class into lambda factory fn
yusefnapora 47713cc
rm unused type imports
yusefnapora da1ef9d
move serviceNamed fn outside of pin.remote.service api object
yusefnapora b8634c3
consolidate input validation
yusefnapora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ const createIDAPI = require('./id') | |
const createConfigAPI = require('./config') | ||
const DagAPI = require('./dag') | ||
const PinManagerAPI = require('./pin/pin-manager') | ||
const PinRemoteAPI = require('./pin/remote') | ||
const createPreloadAPI = require('../preload') | ||
const createMfsPreloadAPI = require('../mfs-preload') | ||
const createFilesAPI = require('./files') | ||
|
@@ -57,6 +58,8 @@ class IPFS { | |
constructor ({ print, storage, options }) { | ||
const { peerId, repo, keychain } = storage | ||
const network = Service.create(Network) | ||
const swarm = new SwarmAPI({ network }) | ||
const config = createConfigAPI({ repo }) | ||
|
||
const preload = createPreloadAPI(options.preload) | ||
|
||
|
@@ -86,7 +89,8 @@ class IPFS { | |
}) | ||
const resolve = createResolveAPI({ ipld, name }) | ||
const pinManager = new PinManagerAPI({ repo, dagReader }) | ||
const pin = new PinAPI({ gcLock, pinManager, dagReader }) | ||
const pinRemote = new PinRemoteAPI({ swarm, config, peerId }) | ||
const pin = new PinAPI({ gcLock, pinManager, dagReader, pinRemote }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
const block = new BlockAPI({ blockService, preload, gcLock, pinManager, pin }) | ||
const dag = new DagAPI({ ipld, preload, gcLock, pin, dagReader }) | ||
const refs = Object.assign(createRefsAPI({ ipld, resolve, preload }), { | ||
|
@@ -155,7 +159,7 @@ class IPFS { | |
this.version = createVersionAPI({ repo }) | ||
this.bitswap = new BitswapAPI({ network }) | ||
this.bootstrap = new BootstrapAPI({ repo }) | ||
this.config = createConfigAPI({ repo }) | ||
this.config = config | ||
this.ping = createPingAPI({ network }) | ||
|
||
this.add = add | ||
|
@@ -170,7 +174,7 @@ class IPFS { | |
this.object = new ObjectAPI({ ipld, preload, gcLock, dag }) | ||
this.repo = new RepoAPI({ gcLock, pin, repo, refs }) | ||
this.stats = new StatsAPI({ repo, network }) | ||
this.swarm = new SwarmAPI({ network }) | ||
this.swarm = swarm | ||
|
||
// For the backwards compatibility | ||
Object.defineProperty(this, 'libp2p', { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option') | ||
|
||
module.exports = ({ serviceRegistry }) => { | ||
/** | ||
* Asks a remote pinning service to pin an IPFS object from a given path | ||
* | ||
* @param {string|CID} cid | ||
* @param {AddOptions & AbortOptions} options | ||
* @returns {Promise<Pin>} | ||
*/ | ||
async function add (cid, options) { | ||
const { service } = options | ||
const svc = serviceRegistry.serviceNamed(service) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this will not handle a case when service was aded in one session and pin is added in the next one, because clients aren't populated unless add / ls / rm is called. |
||
return svc.add(cid, options) | ||
} | ||
|
||
return withTimeoutOption(add) | ||
} | ||
|
||
/** | ||
* @typedef {import('cids')} CID | ||
* @typedef {import('ipfs-core-types/src/basic').AbortOptions} AbortOptions | ||
* @typedef {import('ipfs-core-types/src/pin/remote').Pin} Pin | ||
* @typedef {import('ipfs-core-types/src/pin/remote').AddOptions} AddOptions | ||
*/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go-ipfs settled on omitting endpoint keys when printing config so that they aren't easy to leak (See https://github.com/ipfs/go-ipfs/pull/7661/files#r537641281)
We should at least do the same, although @lidel suggested something smarter is needed in the long term, not sure what exactly he meant but it might be worth doing that here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The smarter thing to do is to move all secrets to separate files outside the JSON config.
The only secret right now is
Identity.PrivKey
this PR adds second type of secret underPinning.RemoteServices[*].API.Key
.I may be less work to move secrets outside, than to sanitize the output of
ipfs config
and make sureipfs config replace
does not forget the secrets.