-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: ipns over pubsub #1559
feat: ipns over pubsub #1559
Changes from all commits
310c379
4c40fc1
66907b5
3a4b139
9bb8816
62f25a6
b2755a0
7edade9
fa5b652
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
|
||
/* | ||
Manage and inspect the state of the IPNS pubsub resolver. | ||
Note: this command is experimental and subject to change as the system is refined. | ||
*/ | ||
module.exports = { | ||
command: 'pubsub', | ||
|
||
description: 'IPNS pubsub management.', | ||
|
||
builder (yargs) { | ||
return yargs.commandDir('pubsub') | ||
}, | ||
|
||
handler (argv) { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
const print = require('../../../utils').print | ||
|
||
module.exports = { | ||
command: 'cancel <name>', | ||
|
||
describe: 'Cancel a name subscription.', | ||
|
||
handler (argv) { | ||
argv.ipfs.name.pubsub.cancel(argv.name, (err, result) => { | ||
if (err) { | ||
throw err | ||
} else { | ||
print(result.canceled ? 'canceled' : 'no subscription') | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
const print = require('../../../utils').print | ||
|
||
module.exports = { | ||
command: 'state', | ||
|
||
describe: 'Query the state of IPNS pubsub.', | ||
|
||
handler (argv) { | ||
argv.ipfs.name.pubsub.state((err, result) => { | ||
if (err) { | ||
throw err | ||
} else { | ||
print(result.enabled ? 'enabled' : 'disabled') | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
|
||
const print = require('../../../utils').print | ||
|
||
module.exports = { | ||
command: 'subs', | ||
|
||
describe: 'Show current name subscriptions.', | ||
|
||
handler (argv) { | ||
argv.ipfs.name.pubsub.subs((err, result) => { | ||
if (err) { | ||
throw err | ||
} else { | ||
result.forEach((s) => { | ||
print(s) | ||
}) | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
'use strict' | ||
|
||
const debug = require('debug') | ||
const errcode = require('err-code') | ||
const promisify = require('promisify-es6') | ||
|
||
const IpnsPubsubDatastore = require('../ipns/routing/pubsub-datastore') | ||
|
||
const log = debug('jsipfs:name-pubsub') | ||
log.error = debug('jsipfs:name-pubsub:error') | ||
|
||
// Is pubsub enabled | ||
const isNamePubsubEnabled = (node) => { | ||
try { | ||
return Boolean(getPubsubRouting(node)) | ||
} catch (err) { | ||
return false | ||
} | ||
} | ||
|
||
// Get pubsub from IPNS routing | ||
const getPubsubRouting = (node) => { | ||
if (!node._ipns || !node._options.EXPERIMENTAL.ipnsPubsub) { | ||
const errMsg = 'IPNS pubsub subsystem is not enabled' | ||
|
||
throw errcode(errMsg, 'ERR_IPNS_PUBSUB_NOT_ENABLED') | ||
vasco-santos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// Only one store and it is pubsub | ||
if (IpnsPubsubDatastore.isIpnsPubsubDatastore(node._ipns.routing)) { | ||
return node._ipns.routing | ||
} | ||
|
||
// Find in tiered | ||
const pubsub = (node._ipns.routing.stores || []).find(s => IpnsPubsubDatastore.isIpnsPubsubDatastore(s)) | ||
|
||
if (!pubsub) { | ||
const errMsg = 'IPNS pubsub datastore not found' | ||
|
||
throw errcode(errMsg, 'ERR_PUBSUB_DATASTORE_NOT_FOUND') | ||
} | ||
|
||
return pubsub | ||
} | ||
|
||
module.exports = function namePubsub (self) { | ||
return { | ||
/** | ||
* Query the state of IPNS pubsub. | ||
* | ||
* @returns {Promise|void} | ||
*/ | ||
state: promisify((callback) => { | ||
callback(null, { | ||
enabled: isNamePubsubEnabled(self) | ||
}) | ||
}), | ||
/** | ||
* Cancel a name subscription. | ||
* | ||
* @param {String} name subscription name. | ||
* @param {function(Error)} [callback] | ||
* @returns {Promise|void} | ||
*/ | ||
cancel: promisify((name, callback) => { | ||
let pubsub | ||
try { | ||
pubsub = getPubsubRouting(self) | ||
} catch (err) { | ||
return callback(err) | ||
} | ||
|
||
pubsub.cancel(name, callback) | ||
}), | ||
/** | ||
* Show current name subscriptions. | ||
* | ||
* @param {function(Error)} [callback] | ||
* @returns {Promise|void} | ||
*/ | ||
subs: promisify((callback) => { | ||
let pubsub | ||
try { | ||
pubsub = getPubsubRouting(self) | ||
} catch (err) { | ||
return callback(err) | ||
} | ||
|
||
pubsub.getSubscriptions(callback) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,11 +2,13 @@ | |||||
|
||||||
const series = require('async/series') | ||||||
const Bitswap = require('ipfs-bitswap') | ||||||
const get = require('lodash/get') | ||||||
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. use smaller package
Suggested change
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. Cool, thanks! Will add 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. I'm fine with using 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. If you agree, I can create other PR with all those occurrences changed to |
||||||
const setImmediate = require('async/setImmediate') | ||||||
const promisify = require('promisify-es6') | ||||||
const { TieredDatastore } = require('datastore-core') | ||||||
|
||||||
const IPNS = require('../ipns') | ||||||
const PubsubDatastore = require('../ipns/routing/pubsub-datastore') | ||||||
const OfflineDatastore = require('../ipns/routing/offline-datastore') | ||||||
|
||||||
module.exports = (self) => { | ||||||
|
@@ -41,7 +43,16 @@ module.exports = (self) => { | |||||
// Setup online routing for IPNS with a tiered routing composed by a DHT and a Pubsub router (if properly enabled) | ||||||
const ipnsStores = [] | ||||||
|
||||||
// TODO Add IPNS pubsub if enabled | ||||||
// Add IPNS pubsub if enabled | ||||||
let pubsubDs | ||||||
if (get(self._options, 'EXPERIMENTAL.ipnsPubsub', false)) { | ||||||
const pubsub = self._libp2pNode.pubsub | ||||||
const localDatastore = self._repo.datastore | ||||||
const peerId = self._peerInfo.id | ||||||
|
||||||
pubsubDs = new PubsubDatastore(pubsub, localDatastore, peerId) | ||||||
ipnsStores.push(pubsubDs) | ||||||
} | ||||||
|
||||||
// NOTE: IPNS routing is being replaced by the local repo datastore while the IPNS over DHT is not ready | ||||||
// When DHT is added, if local option enabled, should receive offlineDatastore as well | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,14 @@ class IPFS extends EventEmitter { | |
if (this._options.EXPERIMENTAL.pubsub) { | ||
this.log('EXPERIMENTAL pubsub is enabled') | ||
} | ||
if (this._options.EXPERIMENTAL.ipnsPubsub) { | ||
if (!this._options.EXPERIMENTAL.pubsub) { | ||
this.log('EXPERIMENTAL pubsub is enabled to use IPNS pubsub') | ||
this._options.EXPERIMENTAL.pubsub = true | ||
} | ||
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. Does go-ipfs do IPNS over PubSub as an experimental flag? Why not just one flag that enables all of PubSub 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. Yes, 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. "Experimental features on Alpha software", how much more bleeding edge can you go 😅 |
||
|
||
this.log('EXPERIMENTAL IPNS pubsub is enabled') | ||
} | ||
if (this._options.EXPERIMENTAL.sharding) { | ||
this.log('EXPERIMENTAL sharding is enabled') | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.