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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: vasco-santos <vasco.santos@ua.pt>
- Loading branch information
1 parent
6f1381f
commit 8712542
Showing
23 changed files
with
818 additions
and
31 deletions.
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
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,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) { | ||
} | ||
} |
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,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') | ||
} | ||
}) | ||
} | ||
} |
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,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') | ||
} | ||
}) | ||
} | ||
} |
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,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) | ||
}) | ||
} | ||
}) | ||
} | ||
} |
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,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') | ||
} | ||
|
||
// 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) | ||
}) | ||
} | ||
} |
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
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
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
Oops, something went wrong.