This repository was 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.
- Loading branch information
1 parent
2790e6d
commit 3c90cbf
Showing
28 changed files
with
1,062 additions
and
56 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.strings.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
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,60 @@ | ||
'use strict' | ||
|
||
const debug = require('debug') | ||
const errcode = require('err-code') | ||
const promisify = require('promisify-es6') | ||
|
||
const log = debug('jsipfs:name-pubsub') | ||
log.error = debug('jsipfs:name-pubsub:error') | ||
|
||
const isNamePubsubEnabled = (node) => ( | ||
node._options.EXPERIMENTAL.ipnsPubsub && node._libp2pNode._floodSub | ||
) | ||
|
||
module.exports = function namePubsub (self) { | ||
return { | ||
/** | ||
* Query the state of IPNS pubsub. | ||
* | ||
* @returns {Promise|void} | ||
*/ | ||
state: promisify((callback) => { | ||
callback(null, { | ||
enabled: Boolean(isNamePubsubEnabled(self)) | ||
}) | ||
}), | ||
/** | ||
* Cancel a name subscription. | ||
* | ||
* @param {String} name subscription name. | ||
* @param {function(Error)} [callback] | ||
* @returns {Promise|void} | ||
*/ | ||
cancel: promisify((name, callback) => { | ||
if (!isNamePubsubEnabled(self)) { | ||
const errMsg = 'IPNS pubsub subsystem is not enabled' | ||
|
||
log.error(errMsg) | ||
return callback(errcode(errMsg, 'ERR_IPNS_PS_NOT_ENABLED')) | ||
} | ||
|
||
self._ipns.pubsub.cancel(name, callback) | ||
}), | ||
/** | ||
* Show current name subscriptions. | ||
* | ||
* @param {function(Error)} [callback] | ||
* @returns {Promise|void} | ||
*/ | ||
subs: promisify((callback) => { | ||
if (!isNamePubsubEnabled(self)) { | ||
const errMsg = 'IPNS pubsub subsystem is not enabled' | ||
|
||
log.error(errMsg) | ||
return callback(errcode(errMsg, 'ERR_IPNS_PS_NOT_ENABLED')) | ||
} | ||
|
||
self._ipns.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.