From d171536e1743702a409f5a71a81f1176512cde1a Mon Sep 17 00:00:00 2001 From: Brian Boucheron Date: Sat, 12 Dec 2020 22:57:21 -0500 Subject: [PATCH 01/41] fix broken links to 'list-seeds.md' guide --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a2dcf62..7dfef61 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ A CLI for peer-to-peer file sharing (and more) using the [Hypercore Protocol](ht - [Sharing a folder](./docs/guides/sharing-a-folder.md) - [Downloading a folder](./docs/guides/downloading-a-folder.md) - [Keeping hypers online (seeding)](./docs/guides/seeding.md) - - [List your current seeds](./docs/guide/list-seeds.md) + - [List your current seeds](./docs/guides/list-seeds.md) - [Creating a hyperdrive](./docs/guides/creating-a-hyperdrive.md) - [Reading a file from a hyperdrive](./docs/guides/reading-a-file.md) - [Writing a file to a hyperdrive](./docs/guides/writing-a-file.md) @@ -123,7 +123,7 @@ Further guides: - [Sharing a folder](./docs/guides/sharing-a-folder.md) - [Downloading a folder](./docs/guides/downloading-a-folder.md) - [Keeping hypers online (seeding)](./docs/guides/seeding.md) -- [List your current seeds](./docs/guide/list-seeds.md) +- [List your current seeds](./docs/guides/list-seeds.md) - [Reading a file from a hyperdrive](./docs/guides/reading-a-file.md) - [Writing a file to a hyperdrive](./docs/guides/writing-a-file.md) -- [Diffing hyperdrives and local folders](./docs/guides/diffing-a-hyperdrive.md) \ No newline at end of file +- [Diffing hyperdrives and local folders](./docs/guides/diffing-a-hyperdrive.md) From bf922b0eef731e73f1dc66a22d7a9f05a7107e8e Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sun, 13 Dec 2020 07:54:05 -0600 Subject: [PATCH 02/41] Add beam command --- README.md | 2 ++ bin/hyp.js | 4 ++- lib/commands/beam.js | 70 ++++++++++++++++++++++++++++++++++++++++++++ lib/usage.js | 2 ++ package.json | 5 ++-- 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 lib/commands/beam.js diff --git a/README.md b/README.md index a2dcf62..74fae2c 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ General Commands: hyp unseed {urls...} - Stop making hyper data available to the network. hyp create {drive|bee} - Create a new hyperdrive or hyperbee. + hyp beam {pass_phrase} - Send a stream of data over the network. + Hyperdrive Commands: hyp drive ls {url} - List the entries of the given hyperdrive URL. diff --git a/bin/hyp.js b/bin/hyp.js index 60e5bbf..2a08d9d 100755 --- a/bin/hyp.js +++ b/bin/hyp.js @@ -9,6 +9,7 @@ import info from '../lib/commands/info.js' import create from '../lib/commands/create.js' import seed from '../lib/commands/seed.js' import unseed from '../lib/commands/unseed.js' +import beam from '../lib/commands/beam.js' import driveLs from '../lib/commands/drive/ls.js' import driveCat from '../lib/commands/drive/cat.js' @@ -38,6 +39,7 @@ const commands = { seed, unseed, create, + beam, driveLs, driveCat, @@ -93,7 +95,7 @@ function wrapCommand (obj) { } try { - if (!obj.name.startsWith('daemon')) { + if (!obj.name.startsWith('daemon') && obj.name !== 'beam') { await hyper.setup() } await innerCommand(...args) diff --git a/lib/commands/beam.js b/lib/commands/beam.js new file mode 100644 index 0000000..f7db6d5 --- /dev/null +++ b/lib/commands/beam.js @@ -0,0 +1,70 @@ +import Hyperbeam from 'hyperbeam' + +const FULL_USAGE = ` + The beam command is a general-purpose tool for sending data over the network + according to a secret passphrase. You choose a phrase (try to make it hard-ish + to guess!) and then share the phrase with your recipient. The phrase is only + good for 30-60 minutes. + +On the sending device: + + cat hello.txt | hyp beam "for bob roberts" + +On the receiving device: + + hyp beam "for bob roberts" > ./hello.txt + +This can be really useful for sharing hyper keys between devices. For instance: + + > hyp sync ./my-folder --no-live + Creating new hyperdrive... + Source: my-folder/ + Target: hyper://f7145e1bbc0d17705861e996b47422e0ca50a80db9441249bd721ff426b79f2a/ + Begin sync? [y/N] y + Syncing... + Synced + > echo "hyper://f7145e1bbc0d17705861e996b47422e0ca50a80db9441249bd721ff426b79f2a/" \\ + | hyp beam "nobody can guess" +` + +export default { + name: 'beam', + description: 'Send a stream of data over the network.', + usage: { + simple: '{pass_phrase}', + full: FULL_USAGE + }, + command: async function (args) { + const beam = new Hyperbeam(args._[0]) + + beam.on('remote-address', function ({ host, port }) { + if (!host) console.error('[hyperbeam] Could not detect remote address') + else console.error('[hyperbeam] Joined the DHT - remote address is ' + host + ':' + port) + if (port) console.error('[hyperbeam] Network is holepunchable \\o/') + }) + + beam.on('connected', function () { + console.error('[hyperbeam] Success! Encrypted tunnel established to remote peer') + }) + + beam.on('end', () => beam.end()) + + process.stdin.pipe(beam).pipe(process.stdout) + process.stdin.unref() + + process.once('SIGINT', () => { + if (!beam.connected) closeASAP() + else beam.end() + }) + + function closeASAP () { + console.error('[hyperbeam] Shutting down beam...') + + const timeout = setTimeout(() => process.exit(1), 2000) + beam.destroy() + beam.on('close', function () { + clearTimeout(timeout) + }) + } + } +} diff --git a/lib/usage.js b/lib/usage.js index fc7a4c3..e2af388 100644 --- a/lib/usage.js +++ b/lib/usage.js @@ -23,6 +23,8 @@ ${chalk.bold(`General Commands:`)} ${simple(commands.unseed)} ${simple(commands.create)} + ${simple(commands.beam)} + ${chalk.bold(`Hyperdrive Commands:`)} ${simple(commands.driveLs)} diff --git a/package.json b/package.json index 96d083d..6821948 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,10 @@ "chokidar": "^3.4.3", "concat-stream": "^2.0.0", "diff-file-tree": "^2.5.1", - "hyperbee": "^1.0.0", + "hyperbeam": "^1.1.1", + "hyperbee": "^1.0.1", "hyperdrive": "^10.18.0", - "hyperspace": "^3.16.0", + "hyperspace": "^3.17.0", "hyperspace-mirroring-service": "^1.0.0", "identify-filetype": "^1.0.0", "mime": "^1.4.0", From b65aeb074d96f2b0594a582de3c1bd76270fe413 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sun, 13 Dec 2020 07:54:09 -0600 Subject: [PATCH 03/41] 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6821948..5b9d5a5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.0.1", + "version": "1.1.0", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From 290b59d7f215d81cc28b264e3934ca69a978501f Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sun, 13 Dec 2020 08:22:47 -0600 Subject: [PATCH 04/41] Add beam guide --- README.md | 14 ++++++++++++++ docs/guides/beaming-data.md | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 docs/guides/beaming-data.md diff --git a/README.md b/README.md index fb76e8e..c6ac850 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ A CLI for peer-to-peer file sharing (and more) using the [Hypercore Protocol](ht - [Downloading a folder](./docs/guides/downloading-a-folder.md) - [Keeping hypers online (seeding)](./docs/guides/seeding.md) - [List your current seeds](./docs/guides/list-seeds.md) + - ["Beaming" data](./docs/guides/beaming-data.md) - [Creating a hyperdrive](./docs/guides/creating-a-hyperdrive.md) - [Reading a file from a hyperdrive](./docs/guides/reading-a-file.md) - [Writing a file to a hyperdrive](./docs/guides/writing-a-file.md) @@ -120,12 +121,25 @@ To see what hypers you are currently seeding, run `info`: hyp info ``` +If you're sharing with a single friend or one of your own devices, you can [beam the URL](./docs/guides/beaming-data.md) with a pass phrase you create. One your sending device: + +``` +echo "hyper://515bbbc1db2139ef27b6c45dfa418c8be6a1dec16823ea7cb9e61af8d060049e/" | hyp beam +``` + +This will generate a pass-phrase which you can enter on the receiving device to get the key: + +``` +hyp beam "the generated phrase" +``` + Further guides: - [Sharing a folder](./docs/guides/sharing-a-folder.md) - [Downloading a folder](./docs/guides/downloading-a-folder.md) - [Keeping hypers online (seeding)](./docs/guides/seeding.md) - [List your current seeds](./docs/guides/list-seeds.md) +- ["Beaming" data](./docs/guides/beaming-data.md) - [Reading a file from a hyperdrive](./docs/guides/reading-a-file.md) - [Writing a file to a hyperdrive](./docs/guides/writing-a-file.md) - [Diffing hyperdrives and local folders](./docs/guides/diffing-a-hyperdrive.md) diff --git a/docs/guides/beaming-data.md b/docs/guides/beaming-data.md new file mode 100644 index 0000000..9d0aad0 --- /dev/null +++ b/docs/guides/beaming-data.md @@ -0,0 +1,23 @@ +# Beaming data + +``` +hyp beam [passphrase] +``` + +Ever wish you had a fast way to send files or data to a device? For instance... + + - Send a `hyper://` URL to another device for syncing + - Copy an individual file to a friend's device + - Run a command and share the output with a team-mate to debug + +That's what the "beam" command is for. It acts like a stream, so you can pipe data in and out of the command. + +``` +cat my-file.txt | hyp beam +``` + +It will generate a passphrase for you, like "manager-car-factory". You use that phrase on the receiving device and pipe out the data: + +``` +hyp beam "manager-car-factory" > ./their-file.txt +``` From f01e499160944bfe60cc9d23d0b97e8194f589f8 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sun, 13 Dec 2020 08:22:55 -0600 Subject: [PATCH 05/41] Generate passphrase when not supplied in beam --- lib/commands/beam.js | 14 ++++++++++++-- package.json | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/commands/beam.js b/lib/commands/beam.js index f7db6d5..f1b0552 100644 --- a/lib/commands/beam.js +++ b/lib/commands/beam.js @@ -1,4 +1,6 @@ import Hyperbeam from 'hyperbeam' +import randomWords from 'random-words' +import chalk from 'chalk' const FULL_USAGE = ` The beam command is a general-purpose tool for sending data over the network @@ -31,11 +33,19 @@ export default { name: 'beam', description: 'Send a stream of data over the network.', usage: { - simple: '{pass_phrase}', + simple: '[passphrase]', full: FULL_USAGE }, command: async function (args) { - const beam = new Hyperbeam(args._[0]) + var phrase = args._[0] || randomWords(3).join('-') + const beam = new Hyperbeam(phrase) + + if (!args._[0]) { + console.error('[hyperbeam] Generated passphrase:') + console.error('') + console.error(' ', chalk.bold(phrase)) + console.error('') + } beam.on('remote-address', function ({ host, port }) { if (!host) console.error('[hyperbeam] Could not detect remote address') diff --git a/package.json b/package.json index 5b9d5a5..7e80525 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "pretty-hash": "^1.0.1", "progress-string": "^1.2.1", "pump": "^3.0.0", + "random-words": "^1.1.1", "range-parser": "^1.2.1", "speedometer": "^1.1.0", "subcommand": "^2.1.1", From 0054cb083f636d0027ddf5850f37c70f463fd611 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sun, 13 Dec 2020 08:23:00 -0600 Subject: [PATCH 06/41] 1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e80525..b0fdf7c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.1.0", + "version": "1.1.1", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From efa84f1fee900356fb5b8a1ded1527be235e3594 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 14 Dec 2020 10:49:16 -0600 Subject: [PATCH 07/41] Use spaces in the beam passphrases --- docs/guides/beaming-data.md | 4 ++-- lib/commands/beam.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guides/beaming-data.md b/docs/guides/beaming-data.md index 9d0aad0..9a28e89 100644 --- a/docs/guides/beaming-data.md +++ b/docs/guides/beaming-data.md @@ -16,8 +16,8 @@ That's what the "beam" command is for. It acts like a stream, so you can pipe da cat my-file.txt | hyp beam ``` -It will generate a passphrase for you, like "manager-car-factory". You use that phrase on the receiving device and pipe out the data: +It will generate a passphrase for you, like "manager car factory". You use that phrase on the receiving device and pipe out the data: ``` -hyp beam "manager-car-factory" > ./their-file.txt +hyp beam "manager car factory" > ./their-file.txt ``` diff --git a/lib/commands/beam.js b/lib/commands/beam.js index f1b0552..e2a163e 100644 --- a/lib/commands/beam.js +++ b/lib/commands/beam.js @@ -37,7 +37,7 @@ export default { full: FULL_USAGE }, command: async function (args) { - var phrase = args._[0] || randomWords(3).join('-') + var phrase = args._[0] ? args._.join(' ') : randomWords(3).join(' ') const beam = new Hyperbeam(phrase) if (!args._[0]) { From f76837cfe065dbf9f28cc46b2257ddddf937b896 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 14 Dec 2020 17:22:05 -0600 Subject: [PATCH 08/41] "sync" and "info" now default to non-live output (close #16) --- docs/guides/downloading-a-folder.md | 4 ++-- docs/guides/sharing-a-folder.md | 6 ++--- lib/commands/beam.js | 2 +- lib/commands/drive/sync.js | 10 ++++---- lib/commands/info.js | 37 ++++++++++++++++++++++------- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/docs/guides/downloading-a-folder.md b/docs/guides/downloading-a-folder.md index 648eda2..0e4294a 100644 --- a/docs/guides/downloading-a-folder.md +++ b/docs/guides/downloading-a-folder.md @@ -10,9 +10,9 @@ hyp sync {source} [target] Example: ``` -hyp sync hyper://1234..af ./target-folder --no-live +hyp sync hyper://1234..af ./target-folder ``` You can re-run the command to update the target folder. It will cause the target folder to match the hyperdrive *exactly* so watch out for data loss. -> If you don't include `--no-live` the sync command will continuously sync the source to the target. \ No newline at end of file +> If you include `--watch` the sync command will continuously sync the source to the target. \ No newline at end of file diff --git a/docs/guides/sharing-a-folder.md b/docs/guides/sharing-a-folder.md index cb9ac2d..5fafcae 100644 --- a/docs/guides/sharing-a-folder.md +++ b/docs/guides/sharing-a-folder.md @@ -10,7 +10,7 @@ hyp sync {source} [target] If no target is supplied, `hyp` will create a new hyperdrive for you. ``` -hyp sync ./target-folder --no-live +hyp sync ./target-folder ``` The sync command will output the URL of your new hyperdrive, and it will now contain your folder's files. @@ -18,9 +18,9 @@ The sync command will output the URL of your new hyperdrive, and it will now con To update the hyperdrive again, run: ``` -hyp sync ./target-folder hyper://1234..af --no-live +hyp sync ./target-folder hyper://1234..af ``` Where `hyper://1234..af` is your hyperdrive's URL. -> If you don't include `--no-live` the sync command will continuously sync the source to the target. \ No newline at end of file +> If you include `--watch` the sync command will continuously sync the source to the target. \ No newline at end of file diff --git a/lib/commands/beam.js b/lib/commands/beam.js index e2a163e..c38efef 100644 --- a/lib/commands/beam.js +++ b/lib/commands/beam.js @@ -18,7 +18,7 @@ On the receiving device: This can be really useful for sharing hyper keys between devices. For instance: - > hyp sync ./my-folder --no-live + > hyp sync ./my-folder Creating new hyperdrive... Source: my-folder/ Target: hyper://f7145e1bbc0d17705861e996b47422e0ca50a80db9441249bd721ff426b79f2a/ diff --git a/lib/commands/drive/sync.js b/lib/commands/drive/sync.js index eb1814c..ec3d3d5 100644 --- a/lib/commands/drive/sync.js +++ b/lib/commands/drive/sync.js @@ -18,7 +18,7 @@ Options: --no-add - Don't include additions to the target location. --no-overwrite - Don't include overwrites to the target location. --no-delete - Don't include deletions to the target location. - --no-live - Don't continuously sync changes. + -w/--watch/--live - Continuously sync changes. Examples: @@ -40,11 +40,13 @@ export default { {name: 'add', default: true, boolean: true}, {name: 'overwrite', default: true, boolean: true}, {name: 'delete', default: true, boolean: true}, - {name: 'live', default: true, boolean: true} + {name: 'live', default: false, boolean: true}, + {name: 'watch', abbr: 'w', default: false, boolean: true} ], command: async function (args) { if (!args._[0]) throw new Error('A source path or URL is required') + var live = args.watch || args.live var leftArgs = await parseArgs(args._[0]) var rightArgs = args._[1] ? await parseArgs(args._[1]) : await createTarget(leftArgs) if (!args._[1]) console.error('Creating new hyperdrive...') @@ -57,7 +59,7 @@ export default { }) if (!rightArgs.isHyper) mkdirp.sync(rightArgs.path) if (!ok) process.exit(0) - console.error(args.live ? 'Live syncing (Ctrl+c to exit)...' : 'Syncing...') + console.error(live ? 'Live syncing (Ctrl+c to exit)...' : 'Syncing...') var statusLines = [''] var statusLog = statusLogger(statusLines) @@ -69,7 +71,7 @@ export default { var right = toDftParam(rightArgs) await sync(left, right, args, {statusLines, statusLog}) - if (!args.live) return process.exit(0) + if (!live) return process.exit(0) const watcher = watch(left, debounce(() => sync(left, right, args, {statusLines, statusLog}), SYNC_INTERVAL)) let exiting = false diff --git a/lib/commands/info.js b/lib/commands/info.js index ecb5867..96dbde3 100644 --- a/lib/commands/info.js +++ b/lib/commands/info.js @@ -9,11 +9,13 @@ const FULL_USAGE = ` Options: + --live - Continuously output the current state. -l/--long - List the full keys of the hypers. Examples: hyp info + hyp info --live hyp info hyper://1234..af/ hyp info hyper://1234..af/ hyper://fedc..21/ ` @@ -31,6 +33,11 @@ export default { default: false, abbr: 'l', boolean: true + }, + { + name: 'live', + default: false, + boolean: true } ], command: async function (args) { @@ -57,7 +64,7 @@ export default { var statusLog = statusLogger(statusLines) statusLog.print() - keys.forEach(async (key, i) => { + await Promise.all(keys.map(async (key, i) => { var tracker = new HyperStructInfoTracker(key) await tracker.attemptLoadStruct() var mirror = null @@ -72,23 +79,26 @@ export default { const seedingStatusLine = mirror && mirror.mirroring ? 'Seeding' : `Not seeding ${networkStatusLine}` statusLines[i] = ` ${tracker.genStatusIdent(args.long)}: - ${tracker.genStatusPeerCount()} | - ${tracker.genStatusNetStats()} + ${tracker.genStatusPeerCount()} + ${args.live ? `| ${tracker.genStatusNetStats()}` : ''} - ${seedingStatusLine} - `.split('\n').map(s => s.trim()).join(' ') + `.split('\n').map(s => s.trim()).filter(Boolean).join(' ') } statusLog.print() } updateStatusLine() - setInterval(updateStatusLine, 1e3).unref() // periodically calculate the size of the hyper structure const updateState = async () => { try { + await tracker.fetchState() + if (!args.live && tracker.loadStructPromise) { + // if not live, we should wait until the struct finishes loading + await tracker.loadStructPromise + } if (tracker.struct) { ;({ mirror, network } = await getStatus(key, tracker.struct.type, tracker.struct.api.discoveryKey)) } - await tracker.fetchState() } catch (e) { if (e.toString().includes('RPC stream destroyed')) { // ignore @@ -96,10 +106,19 @@ export default { console.error(e) } } - setTimeout(updateState, 1e3).unref() + updateStatusLine() + + if (args.live) { + // continuous update + setTimeout(updateState, 1e3).unref() + } } - updateState() - }) + await updateState() + })) + + if (!args.live) { + process.exit(0) + } async function getAllStatuses () { // TODO - --all switch From 7e4ee94c73d586f6988846ed7c12a71ab6ad92cd Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 14 Dec 2020 17:23:35 -0600 Subject: [PATCH 09/41] Add changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ca983e9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +- 1.2.0 + - "sync" and "info" now default to non-live output. +- 1.1.0 + - Add "beam" command. + - Drives created by "sync" are now automatically seeded. +- 1.0.0 + - Initial release. \ No newline at end of file From a43b3d2249f3c80dbba573e8c8dbe66582e617e1 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 14 Dec 2020 17:23:41 -0600 Subject: [PATCH 10/41] 1.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b0fdf7c..bbce8a9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.1.1", + "version": "1.2.0", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From e56967e510d89cf3d343f85c520176b507e6b82b Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 18 Dec 2020 15:45:25 -0600 Subject: [PATCH 11/41] Fix typo in usage --- lib/usage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/usage.js b/lib/usage.js index e2af388..f1238f3 100644 --- a/lib/usage.js +++ b/lib/usage.js @@ -60,7 +60,7 @@ ${chalk.bold(`Aliases:`)} ${chalk.bold('hyp cat')} -> hyp drive cat ${chalk.bold('hyp put')} -> hyp drive put - ${chalk.green(`Learn more at https://github.com/hypecore-protocol/cli`)} + ${chalk.green(`Learn more at https://github.com/hypercore-protocol/cli`)} `) process.exit(err ? 1 : 0) } From 3514cf3e8cbde3a42cb85ae6dc80872bb1c18faa Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 18 Dec 2020 15:57:38 -0600 Subject: [PATCH 12/41] Update 'hyp info' to correctly output when piped to streams (close #23) --- lib/commands/info.js | 36 ++++++++++++++++++++++++++++-------- lib/commands/seed.js | 1 - lib/commands/unseed.js | 1 - 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/commands/info.js b/lib/commands/info.js index 96dbde3..c459b00 100644 --- a/lib/commands/info.js +++ b/lib/commands/info.js @@ -41,9 +41,15 @@ export default { } ], command: async function (args) { + var useLiveOutput = process.stdout.isTTY var hyperClient = getClient() var mirroringClient = getMirroringClient() + if (!useLiveOutput && args.live) { + console.error('Cannot pipe output of "hyp info" with --live set, disabling live-mode.') + args.live = false + } + var keys if (!args._.length) { keys = await getAllKeys(mirroringClient) @@ -56,15 +62,30 @@ export default { } if (!keys.length) { - console.error(`No hypers active.`) + console.log(`No hypers active.`) process.exit(0) } - var statusLines = keys.map(k => `${chalk.bold(short(k))}: Loading...`) - var statusLog = statusLogger(statusLines) - statusLog.print() + if (useLiveOutput) { + var statusLines = keys.map(k => `${chalk.bold(short(k))}: Loading...`) + var statusLog = statusLogger(statusLines) + statusLog.print() + } await Promise.all(keys.map(async (key, i) => { + const log = (str) => { + if (useLiveOutput) { + statusLines[i] = str + statusLog.print() + } else { + console.log(str) + } + } + const weaklog = (str) => { + // only log if live output + if (useLiveOutput) log(str) + } + var tracker = new HyperStructInfoTracker(key) await tracker.attemptLoadStruct() var mirror = null @@ -73,18 +94,17 @@ export default { // periodically update stdout with the status-line const updateStatusLine = () => { if (!network && !mirror) { - statusLines[i] = `${tracker.genStatusIdent(args.long)}...` + weaklog(`${tracker.genStatusIdent(args.long)}...`) } else { const networkStatusLine = network && network.announce ? 'but online (announcing)' : 'and not online' const seedingStatusLine = mirror && mirror.mirroring ? 'Seeding' : `Not seeding ${networkStatusLine}` - statusLines[i] = ` + log(` ${tracker.genStatusIdent(args.long)}: ${tracker.genStatusPeerCount()} ${args.live ? `| ${tracker.genStatusNetStats()}` : ''} - ${seedingStatusLine} - `.split('\n').map(s => s.trim()).filter(Boolean).join(' ') + `.split('\n').map(s => s.trim()).filter(Boolean).join(' ')) } - statusLog.print() } updateStatusLine() diff --git a/lib/commands/seed.js b/lib/commands/seed.js index f01357e..d795a85 100644 --- a/lib/commands/seed.js +++ b/lib/commands/seed.js @@ -27,7 +27,6 @@ export default { keys.push(urlp.hostname) } - let i = 0 for (const key of keys) { var struct = await HyperStruct.get(key) await mirroringClient.mirror(struct.api.key, struct.type) diff --git a/lib/commands/unseed.js b/lib/commands/unseed.js index 0c34172..7c9f1bf 100644 --- a/lib/commands/unseed.js +++ b/lib/commands/unseed.js @@ -27,7 +27,6 @@ export default { keys.push(urlp.hostname) } - let i = 0 for (const key of keys) { var struct = await HyperStruct.get(key) await mirroringClient.unmirror(struct.api.key, struct.type) From fb4ab94a3deb2ade1160733ea1886a69d3c513ab Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 18 Dec 2020 15:57:43 -0600 Subject: [PATCH 13/41] 1.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbce8a9..a917b4b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.2.0", + "version": "1.3.0", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From ad5fe10f0dd4a478d0ed90ad734a0558c0982541 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 18 Dec 2020 16:37:14 -0600 Subject: [PATCH 14/41] Fix daemon-spawn code for windows (close #24, close #15) --- lib/hyper/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hyper/index.js b/lib/hyper/index.js index 5cd4d20..aaeb546 100644 --- a/lib/hyper/index.js +++ b/lib/hyper/index.js @@ -47,7 +47,7 @@ async function startDaemon (name, readable) { const daemonRoot = p.dirname(require.resolve(name)) const binPath = p.join(daemonRoot, 'bin', 'index.js') console.error(`${readable} daemon started`) - return spawn(binPath, { + return spawn('node', [binPath], { detached: true }) } From 85c4875e37f53ecd381915d76e857a92adfec807 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 18 Dec 2020 16:37:39 -0600 Subject: [PATCH 15/41] Increase the number of retries to connect to daemon, takes a little longer on windows --- lib/hyper/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hyper/index.js b/lib/hyper/index.js index aaeb546..bb29ca7 100644 --- a/lib/hyper/index.js +++ b/lib/hyper/index.js @@ -6,7 +6,7 @@ import mirroring from 'hyperspace-mirroring-service' const HyperspaceClient = hyperspace.Client const MirroringClient = mirroring.Client -const NUM_RETRIES = 5 +const NUM_RETRIES = 50 const RETRY_DELAY = 100 var clients = new Map() From 82859ed2315bd208f1ba04d653b205a8a0904d8c Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 18 Dec 2020 16:37:46 -0600 Subject: [PATCH 16/41] 1.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a917b4b..9eef7b3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.3.0", + "version": "1.3.1", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From 346a57aee7b518061d8951ec79d8f9561654448e Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sat, 19 Dec 2020 12:18:25 -0600 Subject: [PATCH 17/41] Dont dump unhelpful error state into the commandline during hyp info (close #26) --- lib/hyper/info-tracker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hyper/info-tracker.js b/lib/hyper/info-tracker.js index 51dc0b1..e568e9c 100644 --- a/lib/hyper/info-tracker.js +++ b/lib/hyper/info-tracker.js @@ -75,14 +75,14 @@ export class HyperStructInfoTracker { } async fetchState () { - this.netCfg = await hyper.getClient().network.status(this.discoveryKey) + this.netCfg = await hyper.getClient().network.status(this.discoveryKey).catch(e => undefined) if (!this.struct) { /* dont await */ this.attemptLoadStruct() return } - await this.calcBlockState() + await this.calcBlockState().catch(e => undefined) } async attemptLoadStruct () { From aa71378dba1826105687e293f0916bf1c5c98a3f Mon Sep 17 00:00:00 2001 From: Francesc Alted Date: Sun, 20 Dec 2020 09:57:46 +0100 Subject: [PATCH 18/41] Small fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6ac850..f35703e 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ To see what hypers you are currently seeding, run `info`: hyp info ``` -If you're sharing with a single friend or one of your own devices, you can [beam the URL](./docs/guides/beaming-data.md) with a pass phrase you create. One your sending device: +If you're sharing with a single friend or one of your own devices, you can [beam the URL](./docs/guides/beaming-data.md) with a pass phrase you create. On your sending device: ``` echo "hyper://515bbbc1db2139ef27b6c45dfa418c8be6a1dec16823ea7cb9e61af8d060049e/" | hyp beam From 3197b9e6e095630c77642e5bb727cf1ffcad7140 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 24 Dec 2020 10:09:37 -0600 Subject: [PATCH 19/41] Update docs to point to new website --- README.md | 50 +++++++++------------------- docs/guides/beaming-data.md | 22 ++---------- docs/guides/creating-a-hyperdrive.md | 8 ++--- docs/guides/diffing-a-hyperdrive.md | 17 ++-------- docs/guides/downloading-a-folder.md | 17 ++-------- docs/guides/list-seeds.md | 16 ++------- docs/guides/reading-a-file.md | 16 ++------- docs/guides/seeding.md | 22 ++---------- docs/guides/sharing-a-folder.md | 25 ++------------ docs/guides/writing-a-file.md | 18 ++-------- 10 files changed, 33 insertions(+), 178 deletions(-) diff --git a/README.md b/README.md index c6ac850..6c25eb6 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,17 @@ # Hyp +

[ + Demo Video + Installation | + Usage | + Overview | + Documentation +]

+ A CLI for peer-to-peer file sharing (and more) using the [Hypercore Protocol](https://hypercore-protocol.org). -- [Installation](#installation) -- [Usage](#usage) -- [Overview](#overview) -- Guides - - [Sharing a folder](./docs/guides/sharing-a-folder.md) - - [Downloading a folder](./docs/guides/downloading-a-folder.md) - - [Keeping hypers online (seeding)](./docs/guides/seeding.md) - - [List your current seeds](./docs/guides/list-seeds.md) - - ["Beaming" data](./docs/guides/beaming-data.md) - - [Creating a hyperdrive](./docs/guides/creating-a-hyperdrive.md) - - [Reading a file from a hyperdrive](./docs/guides/reading-a-file.md) - - [Writing a file to a hyperdrive](./docs/guides/writing-a-file.md) - - [Diffing hyperdrives and local folders](./docs/guides/diffing-a-hyperdrive.md) -- [Glossary of terms](./docs/glossary.md) -- [API Docs](https://github.com/hypercore-protocol/hyperspace-client) +[📺 Watch a Demo](https://www.youtube.com/watch?v=SVk1uIQxOO8) ## Installation @@ -121,25 +115,11 @@ To see what hypers you are currently seeding, run `info`: hyp info ``` -If you're sharing with a single friend or one of your own devices, you can [beam the URL](./docs/guides/beaming-data.md) with a pass phrase you create. One your sending device: - -``` -echo "hyper://515bbbc1db2139ef27b6c45dfa418c8be6a1dec16823ea7cb9e61af8d060049e/" | hyp beam -``` - -This will generate a pass-phrase which you can enter on the receiving device to get the key: - -``` -hyp beam "the generated phrase" -``` +## [Documentation](https://hypercore-protocol.org/guides/hyp/) -Further guides: +The [official docs](https://hypercore-protocol.org/guides/hyp/) have a lot of useful guides: -- [Sharing a folder](./docs/guides/sharing-a-folder.md) -- [Downloading a folder](./docs/guides/downloading-a-folder.md) -- [Keeping hypers online (seeding)](./docs/guides/seeding.md) -- [List your current seeds](./docs/guides/list-seeds.md) -- ["Beaming" data](./docs/guides/beaming-data.md) -- [Reading a file from a hyperdrive](./docs/guides/reading-a-file.md) -- [Writing a file to a hyperdrive](./docs/guides/writing-a-file.md) -- [Diffing hyperdrives and local folders](./docs/guides/diffing-a-hyperdrive.md) +- [Full Commands Reference](https://hypercore-protocol.org/guides/hyp/commands/) +- [Guide: Sharing Folders](https://hypercore-protocol.org/guides/hyp/sharing-folders/) +- [Guide: Seeding Data](https://hypercore-protocol.org/guides/hyp/seeding-data/) +- [Guide: Beaming Files](https://hypercore-protocol.org/guides/hyp/beaming-files/) \ No newline at end of file diff --git a/docs/guides/beaming-data.md b/docs/guides/beaming-data.md index 9a28e89..40a9d82 100644 --- a/docs/guides/beaming-data.md +++ b/docs/guides/beaming-data.md @@ -1,23 +1,5 @@ # Beaming data -``` -hyp beam [passphrase] -``` +This doc was moved to the website: -Ever wish you had a fast way to send files or data to a device? For instance... - - - Send a `hyper://` URL to another device for syncing - - Copy an individual file to a friend's device - - Run a command and share the output with a team-mate to debug - -That's what the "beam" command is for. It acts like a stream, so you can pipe data in and out of the command. - -``` -cat my-file.txt | hyp beam -``` - -It will generate a passphrase for you, like "manager car factory". You use that phrase on the receiving device and pipe out the data: - -``` -hyp beam "manager car factory" > ./their-file.txt -``` +https://hypercore-protocol.org/guides/hyp/beaming-files/ \ No newline at end of file diff --git a/docs/guides/creating-a-hyperdrive.md b/docs/guides/creating-a-hyperdrive.md index fe4e3ec..17e065f 100644 --- a/docs/guides/creating-a-hyperdrive.md +++ b/docs/guides/creating-a-hyperdrive.md @@ -1,9 +1,5 @@ # Creating a hyperdrive -``` -hyp create drive -``` +This doc was moved to the website: -This will output the URL of your new hyperdrive and you'll be ready to go. - -> If you're just looking to share a folder, you can [use the sync command](./sharing-a-folder.md). \ No newline at end of file +https://hypercore-protocol.org/guides/hyp/commands/create/ \ No newline at end of file diff --git a/docs/guides/diffing-a-hyperdrive.md b/docs/guides/diffing-a-hyperdrive.md index 75cec0d..b41ed05 100644 --- a/docs/guides/diffing-a-hyperdrive.md +++ b/docs/guides/diffing-a-hyperdrive.md @@ -1,18 +1,5 @@ # Diffing hyperdrives and local folders -``` -hyp diff {source} {target} -``` +This doc was moved to the website: - - **source** A local folder path or hyperdrive URL. - - **target** A local folder path or hyperdrive URL. - -The command will output a list of all files that differ and explain how they differ. - -You can sync the target so that it matches the source by adding the `--commit` switch: - -``` -hyp diff {source} {target} --commit -``` - -This will give you a chance to review the changes about to occur, then y/n the sync. \ No newline at end of file +https://hypercore-protocol.org/guides/hyp/commands/drive-diff/ \ No newline at end of file diff --git a/docs/guides/downloading-a-folder.md b/docs/guides/downloading-a-folder.md index 0e4294a..8cbe5dc 100644 --- a/docs/guides/downloading-a-folder.md +++ b/docs/guides/downloading-a-folder.md @@ -1,18 +1,5 @@ # Downloading a folder from a hyperdrive -``` -hyp sync {source} [target] -``` +This doc was moved to the website: -- **source** The hyperdrive you want to download. -- **target** The path of the local folder you want to download to. - -Example: - -``` -hyp sync hyper://1234..af ./target-folder -``` - -You can re-run the command to update the target folder. It will cause the target folder to match the hyperdrive *exactly* so watch out for data loss. - -> If you include `--watch` the sync command will continuously sync the source to the target. \ No newline at end of file +https://hypercore-protocol.org/guides/hyp/sharing-folders/ \ No newline at end of file diff --git a/docs/guides/list-seeds.md b/docs/guides/list-seeds.md index 2904ce9..4c0e29c 100644 --- a/docs/guides/list-seeds.md +++ b/docs/guides/list-seeds.md @@ -1,17 +1,5 @@ # List your current seeds -``` -hyp info [urls..] -``` +This doc was moved to the website: -The info command will tell you what you are currently seeding if given no arguments: - -``` -hyp info -``` - -If one (or more) URLs are supplied, it will give the current seeding state of that hyper: - -``` -hyp info hyper://1234..af -``` \ No newline at end of file +https://hypercore-protocol.org/guides/hyp/seeding-data/ \ No newline at end of file diff --git a/docs/guides/reading-a-file.md b/docs/guides/reading-a-file.md index 0e916d1..09686df 100644 --- a/docs/guides/reading-a-file.md +++ b/docs/guides/reading-a-file.md @@ -1,17 +1,5 @@ # Reading a file from a hyperdrive -``` -hyp cat {url} -``` +This doc was moved to the website: -To read the file, simply run `cat` on the file's URL: - -``` -hyp cat hyper://1234..af/hello.txt -``` - -You can save the file using pipes: - -``` -hyp cat hyper://1234..af/hello.txt > ./hello.txt -``` \ No newline at end of file +https://hypercore-protocol.org/guides/hyp/commands/drive-cat/ \ No newline at end of file diff --git a/docs/guides/seeding.md b/docs/guides/seeding.md index 16b452c..4717c42 100644 --- a/docs/guides/seeding.md +++ b/docs/guides/seeding.md @@ -1,23 +1,5 @@ # Keeping hypers online (seeding) -``` -hyp seed {url} -``` +This doc was moved to the website: -To sync the current data of a hyper and host its data for others to access, run the seed command on its URL: - -``` -hyp seed hyper://1234..af -``` - -You can stop seeding with the unseed command: - -``` -hyp unseed hyper://1234..af -``` - -You can list all currently-seeded hypers with the info command: - -``` -hyp info -``` \ No newline at end of file +https://hypercore-protocol.org/guides/hyp/seeding-data/ \ No newline at end of file diff --git a/docs/guides/sharing-a-folder.md b/docs/guides/sharing-a-folder.md index 5fafcae..a3ddbcb 100644 --- a/docs/guides/sharing-a-folder.md +++ b/docs/guides/sharing-a-folder.md @@ -1,26 +1,5 @@ # Sharing a folder in a hyperdrive -``` -hyp sync {source} [target] -``` +This doc was moved to the website: -- **source** The path of the folder to share. -- **target** Optional- the hyperdrive to sync the folder to. - -If no target is supplied, `hyp` will create a new hyperdrive for you. - -``` -hyp sync ./target-folder -``` - -The sync command will output the URL of your new hyperdrive, and it will now contain your folder's files. - -To update the hyperdrive again, run: - -``` -hyp sync ./target-folder hyper://1234..af -``` - -Where `hyper://1234..af` is your hyperdrive's URL. - -> If you include `--watch` the sync command will continuously sync the source to the target. \ No newline at end of file +https://hypercore-protocol.org/guides/hyp/sharing-folders/ \ No newline at end of file diff --git a/docs/guides/writing-a-file.md b/docs/guides/writing-a-file.md index 32873e5..49026d8 100644 --- a/docs/guides/writing-a-file.md +++ b/docs/guides/writing-a-file.md @@ -1,19 +1,5 @@ # Writing an individual file to hyperdrive -``` -hyp put {url} [value] -``` +This doc was moved to the website: -You'll first need to [create a hyperdrive](./creating-a-hyperdrive.md). - -To write a file, run the `put` command on the URL and provide the content of the file: - -``` -hyp put hyper://1234..af/hello.txt "Hello, world!" -``` - -If you want to copy an existing file into the hyperdrive, use pipes instead of supplying the value in the arguments: - -``` -cat hello.txt | hyp put hyper://1234..af/hello.txt -``` \ No newline at end of file +https://hypercore-protocol.org/guides/hyp/commands/drive-put/ \ No newline at end of file From 2d6ae63b4970a4f8009ce18eca6522dc3ab3bd5b Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 24 Dec 2020 10:13:51 -0600 Subject: [PATCH 20/41] Readme fixes --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6c25eb6..5e9da5e 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,16 @@ # Hyp

[ - Demo Video + Demo Video | Installation | Usage | Overview | - Documentation + Website ]

A CLI for peer-to-peer file sharing (and more) using the [Hypercore Protocol](https://hypercore-protocol.org). -[📺 Watch a Demo](https://www.youtube.com/watch?v=SVk1uIQxOO8) +📺 Watch The Demo Video ## Installation @@ -115,9 +115,9 @@ To see what hypers you are currently seeding, run `info`: hyp info ``` -## [Documentation](https://hypercore-protocol.org/guides/hyp/) +## Documentation -The [official docs](https://hypercore-protocol.org/guides/hyp/) have a lot of useful guides: +The [website documentation](https://hypercore-protocol.org/guides/hyp/) have a lot of useful guides: - [Full Commands Reference](https://hypercore-protocol.org/guides/hyp/commands/) - [Guide: Sharing Folders](https://hypercore-protocol.org/guides/hyp/sharing-folders/) From 2fcc0b9cc618cd61b914777c57d41e6828025c85 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 7 Jan 2021 12:44:27 -0600 Subject: [PATCH 21/41] Fix reference errors around hyperbee keys (close #30) --- .gitignore | 1 + lib/commands/create.js | 2 +- lib/commands/drive/sync.js | 2 +- lib/commands/info.js | 2 +- lib/commands/seed.js | 2 +- lib/commands/unseed.js | 2 +- lib/hyper/struct.js | 12 ++++++++++-- 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 5a088d9..1e5348d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules npm-debug.log package-lock.json +.DS_Store diff --git a/lib/commands/create.js b/lib/commands/create.js index 260535a..0e5b988 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -22,7 +22,7 @@ export default { process.exit(1) } - await getMirroringClient().mirror(struct.api.key, struct.type) + await getMirroringClient().mirror(struct.key, struct.type) console.log('Seeding', struct.type) process.exit(0) } diff --git a/lib/commands/drive/sync.js b/lib/commands/drive/sync.js index ec3d3d5..187e76a 100644 --- a/lib/commands/drive/sync.js +++ b/lib/commands/drive/sync.js @@ -171,7 +171,7 @@ async function createTarget (source) { } // If the source is a local directory, create a new drive to copy into. let drive = await HyperStruct.create('hyperdrive') - await getMirroringClient().mirror(drive.api.key, drive.type) + await getMirroringClient().mirror(drive.key, drive.type) return {fs: drive.api, path: '/', raw: drive.url + '/'} } diff --git a/lib/commands/info.js b/lib/commands/info.js index c459b00..595685a 100644 --- a/lib/commands/info.js +++ b/lib/commands/info.js @@ -117,7 +117,7 @@ export default { await tracker.loadStructPromise } if (tracker.struct) { - ;({ mirror, network } = await getStatus(key, tracker.struct.type, tracker.struct.api.discoveryKey)) + ;({ mirror, network } = await getStatus(key, tracker.struct.type, tracker.struct.discoveryKey)) } } catch (e) { if (e.toString().includes('RPC stream destroyed')) { diff --git a/lib/commands/seed.js b/lib/commands/seed.js index d795a85..ab330e1 100644 --- a/lib/commands/seed.js +++ b/lib/commands/seed.js @@ -29,7 +29,7 @@ export default { for (const key of keys) { var struct = await HyperStruct.get(key) - await mirroringClient.mirror(struct.api.key, struct.type) + await mirroringClient.mirror(struct.key, struct.type) console.log(`Seeding ${chalk.bold(short(key))}`) } process.exit(0) diff --git a/lib/commands/unseed.js b/lib/commands/unseed.js index 7c9f1bf..006eac1 100644 --- a/lib/commands/unseed.js +++ b/lib/commands/unseed.js @@ -29,7 +29,7 @@ export default { for (const key of keys) { var struct = await HyperStruct.get(key) - await mirroringClient.unmirror(struct.api.key, struct.type) + await mirroringClient.unmirror(struct.key, struct.type) console.log(`No longer seeding ${chalk.bold(short(key))}`) } process.exit(0) diff --git a/lib/hyper/struct.js b/lib/hyper/struct.js index c7d0ff7..5e05f2f 100644 --- a/lib/hyper/struct.js +++ b/lib/hyper/struct.js @@ -24,6 +24,14 @@ class HyperStructure extends EventEmitter { this.api = undefined } + get key () { + return this.core?.key + } + + get discoveryKey () { + return this.core?.discoveryKey + } + get url () { return `hyper://${this.keyStr}` } @@ -99,7 +107,7 @@ class HyperStructure extends EventEmitter { if (this.type === 'hyperdrive') { this.api = hyperdrive(getClient().corestore(), null, {extension: false}) await this.api.promises.ready() - this.keyStr = this.api.key.toString('hex') + this.keyStr = this.key.toString('hex') } else if (this.type === 'hyperbee') { let core = getClient().corestore().get(null) this.api = new Hyperbee(core, { @@ -107,7 +115,7 @@ class HyperStructure extends EventEmitter { valueEncoding: 'json' }) await this.api.ready() - this.keyStr = this.api.feed.key.toString('hex') + this.keyStr = this.key.toString('hex') } if (!noNetConfig) getClient().network.configure(this.core, {lookup: true, announce: true}) From 05fcfdc401b3689b8cde30b3ee5ed99340cc7843 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 7 Jan 2021 12:44:33 -0600 Subject: [PATCH 22/41] 1.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9eef7b3..5a99723 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.3.1", + "version": "1.3.2", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From c1255e16c781ba8b3669affc915948afad6b99d4 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 7 Jan 2021 12:55:59 -0600 Subject: [PATCH 23/41] Fix .version lookup (close #28) --- bin/hyp.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/hyp.js b/bin/hyp.js index 2a08d9d..fe090f5 100755 --- a/bin/hyp.js +++ b/bin/hyp.js @@ -2,6 +2,8 @@ import subcommand from 'subcommand' import fs from 'fs' +import path from 'path' +import { fileURLToPath } from 'url' import * as hyper from '../lib/hyper/index.js' @@ -74,7 +76,7 @@ match(argv) // error output when no/invalid command is given function none (args) { if (args.version) { - const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8')) + const packageJson = JSON.parse(fs.readFileSync(path.join(fileURLToPath(import.meta.url), '../../package.json'), 'utf8')) console.log(packageJson.version) process.exit(0) } From 168848cc3e0e652a60929d588fa77bc2fd38e9d1 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 7 Jan 2021 12:56:07 -0600 Subject: [PATCH 24/41] 1.3.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a99723..565290f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.3.2", + "version": "1.3.3", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From a012f4a583d5d0cab954bbf73025f62ac05174dc Mon Sep 17 00:00:00 2001 From: JPSO <66487668+J-P-S-O@users.noreply.github.com> Date: Mon, 11 Jan 2021 09:10:51 -0300 Subject: [PATCH 25/41] Update hyp.js --- bin/hyp.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/hyp.js b/bin/hyp.js index fe090f5..c8a58b1 100755 --- a/bin/hyp.js +++ b/bin/hyp.js @@ -1,5 +1,8 @@ #!/usr/bin/env node + +process.title = "Hypercore CLI" + import subcommand from 'subcommand' import fs from 'fs' import path from 'path' From a35052b9e8e6189211ccb22f35af52d109dd5a25 Mon Sep 17 00:00:00 2001 From: JPSO <66487668+J-P-S-O@users.noreply.github.com> Date: Mon, 11 Jan 2021 09:15:28 -0300 Subject: [PATCH 26/41] Change title to `hyp` as suggested. --- bin/hyp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/hyp.js b/bin/hyp.js index c8a58b1..70a324a 100755 --- a/bin/hyp.js +++ b/bin/hyp.js @@ -1,7 +1,7 @@ #!/usr/bin/env node -process.title = "Hypercore CLI" +process.title = "hyp" import subcommand from 'subcommand' import fs from 'fs' From d9d6535c247b73b6b52cc655c1d709c65109fc37 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 11 Jan 2021 10:36:11 -0600 Subject: [PATCH 27/41] 1.3.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 565290f..0d37b21 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.3.3", + "version": "1.3.4", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From b58395dd2370eacfaca8ecbb4d350a79c4b2387d Mon Sep 17 00:00:00 2001 From: Rik Date: Tue, 19 Jan 2021 23:47:29 +0000 Subject: [PATCH 28/41] include min node version in package.json (fixes #34) --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0d37b21..a3b1c4a 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "bugs": { "url": "https://github.com/hypercore-protocol/hypercore-cli/issues" }, + "engines" : { "node" : ">=14.0.0" }, "homepage": "https://github.com/hypercore-protocol/hypercore-cli#readme", "dependencies": { "ansi-diff-stream": "^1.2.1", From d61545a0894b4cb452995ba3c61cb06967a75cd1 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 22 Jan 2021 11:48:49 -0600 Subject: [PATCH 29/41] 1.3.5 --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a3b1c4a..318333a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.3.4", + "version": "1.3.5", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" @@ -23,7 +23,9 @@ "bugs": { "url": "https://github.com/hypercore-protocol/hypercore-cli/issues" }, - "engines" : { "node" : ">=14.0.0" }, + "engines": { + "node": ">=14.0.0" + }, "homepage": "https://github.com/hypercore-protocol/hypercore-cli#readme", "dependencies": { "ansi-diff-stream": "^1.2.1", From 0000676ca6bc97f9c945f0a7f20ccbf8daacebe4 Mon Sep 17 00:00:00 2001 From: Andrew Osheroff Date: Sun, 20 Dec 2020 16:03:31 +0100 Subject: [PATCH 30/41] Added daemon start command --- bin/hyp.js | 2 ++ lib/commands/daemon/start.js | 31 +++++++++++++++++++++++++++++++ lib/usage.js | 1 + 3 files changed, 34 insertions(+) create mode 100644 lib/commands/daemon/start.js diff --git a/bin/hyp.js b/bin/hyp.js index 70a324a..08cc97b 100755 --- a/bin/hyp.js +++ b/bin/hyp.js @@ -32,6 +32,7 @@ import beePut from '../lib/commands/bee/put.js' import beeDel from '../lib/commands/bee/del.js' import daemonStatus from '../lib/commands/daemon/status.js' +import daemonStart from '../lib/commands/daemon/start.js' import daemonStop from '../lib/commands/daemon/stop.js' import usage from '../lib/usage.js' @@ -62,6 +63,7 @@ const commands = { beeDel, daemonStatus, + daemonStart, daemonStop } diff --git a/lib/commands/daemon/start.js b/lib/commands/daemon/start.js new file mode 100644 index 0000000..5d19de1 --- /dev/null +++ b/lib/commands/daemon/start.js @@ -0,0 +1,31 @@ +import hyperspace from 'hyperspace' +const HyperspaceClient = hyperspace.Client + +import { setup } from '../../hyper/index.js' + +const FULL_USAGE = ` +Examples: + + hyp daemon start +` +export default { + name: 'daemon start', + description: 'Start the Hyperspace daemon.', + usage: { + full: FULL_USAGE + }, + command: async function (args) { + await setup() + try { + const client = new HyperspaceClient() + await client.ready() + await client.status() + } catch (err) { + console.error('Could not start the daemon:') + console.error(err) + process.exit(1) + } + console.log('Daemon is running.') + process.exit(0) + } +} diff --git a/lib/usage.js b/lib/usage.js index f1238f3..1a8b581 100644 --- a/lib/usage.js +++ b/lib/usage.js @@ -50,6 +50,7 @@ ${chalk.bold(`Hyperbee Commands:`)} ${chalk.bold(`Daemon Commands:`)} ${simple(commands.daemonStatus)} + ${simple(commands.daemonStart)} ${simple(commands.daemonStop)} ${chalk.bold(`Aliases:`)} From 3cbf165b77d2b78bfb0eb83bea5183c2bfa5281a Mon Sep 17 00:00:00 2001 From: Andrew Osheroff Date: Sun, 20 Dec 2020 16:08:04 +0100 Subject: [PATCH 31/41] Update README --- README.md | 3 ++- lib/commands/daemon/start.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e9da5e..1c5bbb0 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Hyperbee Commands: Daemon Commands: hyp daemon status - Check the status of the hyperspace daemon. + hyp daemon start - Start the hyperspace daemon. hyp daemon stop - Stop the hyperspace and mirroring daemons if active. Aliases: @@ -122,4 +123,4 @@ The [website documentation](https://hypercore-protocol.org/guides/hyp/) have a l - [Full Commands Reference](https://hypercore-protocol.org/guides/hyp/commands/) - [Guide: Sharing Folders](https://hypercore-protocol.org/guides/hyp/sharing-folders/) - [Guide: Seeding Data](https://hypercore-protocol.org/guides/hyp/seeding-data/) -- [Guide: Beaming Files](https://hypercore-protocol.org/guides/hyp/beaming-files/) \ No newline at end of file +- [Guide: Beaming Files](https://hypercore-protocol.org/guides/hyp/beaming-files/) diff --git a/lib/commands/daemon/start.js b/lib/commands/daemon/start.js index 5d19de1..32b5323 100644 --- a/lib/commands/daemon/start.js +++ b/lib/commands/daemon/start.js @@ -10,7 +10,7 @@ Examples: ` export default { name: 'daemon start', - description: 'Start the Hyperspace daemon.', + description: 'Start the hyperspace daemon.', usage: { full: FULL_USAGE }, From 2ab5cddbdb912ef6b2475ba92d60f3d700841f6f Mon Sep 17 00:00:00 2001 From: Andrew Osheroff Date: Sun, 24 Jan 2021 00:33:51 +0100 Subject: [PATCH 32/41] 1.4.0 --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a3b1c4a..8646783 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.3.4", + "version": "1.4.0", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" @@ -23,7 +23,9 @@ "bugs": { "url": "https://github.com/hypercore-protocol/hypercore-cli/issues" }, - "engines" : { "node" : ">=14.0.0" }, + "engines": { + "node": ">=14.0.0" + }, "homepage": "https://github.com/hypercore-protocol/hypercore-cli#readme", "dependencies": { "ansi-diff-stream": "^1.2.1", From 30132fbff180fdf32f7fab175bb4ffdfcfa58708 Mon Sep 17 00:00:00 2001 From: hamdy Date: Mon, 1 Feb 2021 17:14:50 +0200 Subject: [PATCH 33/41] add yes to sync options --- lib/commands/drive/sync.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/commands/drive/sync.js b/lib/commands/drive/sync.js index 187e76a..4a7bf3d 100644 --- a/lib/commands/drive/sync.js +++ b/lib/commands/drive/sync.js @@ -41,7 +41,8 @@ export default { {name: 'overwrite', default: true, boolean: true}, {name: 'delete', default: true, boolean: true}, {name: 'live', default: false, boolean: true}, - {name: 'watch', abbr: 'w', default: false, boolean: true} + {name: 'watch', abbr: 'w', default: false, boolean: true}, + {name: 'yes', abbr: 'y', default: false, boolean: true} ], command: async function (args) { if (!args._[0]) throw new Error('A source path or URL is required') @@ -53,10 +54,15 @@ export default { console.error(chalk.bold(`Source: ${leftArgs.raw}`)) console.error(chalk.bold(`Target: ${rightArgs.raw}`)) - var ok = await yesno({ - question: `Begin sync? [y/N]`, - defaultValue: false - }) + var ok = true + + if(!args.yes){ + ok = await yesno({ + question: `Begin sync? [y/N]`, + defaultValue: false + }) + } + if (!rightArgs.isHyper) mkdirp.sync(rightArgs.path) if (!ok) process.exit(0) console.error(live ? 'Live syncing (Ctrl+c to exit)...' : 'Syncing...') From 3cd01dd08ac40e1e7540d459be83a3fb93b714ea Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 2 Feb 2021 08:35:57 -0600 Subject: [PATCH 34/41] 1.5.0 --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 6debe3a..e2efca9 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.3.5", - "version": "1.4.0", + "version": "1.5.0", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From e9420d69a06896bc5a9eae63956c1e484f07649e Mon Sep 17 00:00:00 2001 From: Gerben Date: Mon, 5 Apr 2021 16:33:40 +0200 Subject: [PATCH 35/41] Document -y/--yes option of sync command Fixes #42 --- lib/commands/drive/sync.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/commands/drive/sync.js b/lib/commands/drive/sync.js index 4a7bf3d..c5e974b 100644 --- a/lib/commands/drive/sync.js +++ b/lib/commands/drive/sync.js @@ -19,6 +19,7 @@ Options: --no-overwrite - Don't include overwrites to the target location. --no-delete - Don't include deletions to the target location. -w/--watch/--live - Continuously sync changes. + -y/--yes - Do not ask for confirmation Examples: @@ -209,4 +210,4 @@ async function setupTracker (key, statusLines, statusLog) { setTimeout(updateState, 1e3).unref() } await updateState() -} \ No newline at end of file +} From 6c967305b1b51f94850c95359415df4df0d4a206 Mon Sep 17 00:00:00 2001 From: Dym Sohin Date: Mon, 5 Apr 2021 23:57:21 +0200 Subject: [PATCH 36/41] add closing / to the returned hash-url --- lib/hyper/struct.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hyper/struct.js b/lib/hyper/struct.js index 5e05f2f..2481848 100644 --- a/lib/hyper/struct.js +++ b/lib/hyper/struct.js @@ -33,7 +33,7 @@ class HyperStructure extends EventEmitter { } get url () { - return `hyper://${this.keyStr}` + return `hyper://${this.keyStr}/` } get core () { From 205dbc12fb5395113e4347367f49068b29ebaca8 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 12 Apr 2021 10:29:55 -0500 Subject: [PATCH 37/41] 1.5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e2efca9..dcf59c0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.5.0", + "version": "1.5.1", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From 20ee44d952b3896fa0cf0b5f248f65c71e26d7b4 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 16 Jul 2021 09:20:18 -0500 Subject: [PATCH 38/41] Switch daemon to manual start rather than automatic --- README.md | 12 ++++++++++++ bin/hyp.js | 9 +++++++++ lib/commands/daemon/start.js | 2 +- lib/hyper/index.js | 13 ++++++++----- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1c5bbb0..0febddc 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,18 @@ Requires nodejs 14+ npm install -g @hyperspace/cli ``` +To start using the network, run: + +``` +hyp daemon start +``` + +This will run in the background, sync data for you, until you run: + +``` +hyp daemon stop +``` + ## Usage Command overview: diff --git a/bin/hyp.js b/bin/hyp.js index 08cc97b..2c0256f 100755 --- a/bin/hyp.js +++ b/bin/hyp.js @@ -105,6 +105,15 @@ function wrapCommand (obj) { if (!obj.name.startsWith('daemon') && obj.name !== 'beam') { await hyper.setup() } + } catch (err) { + console.error('The daemon is not active. Please run:') + console.error('') + console.error(' hyp daemon start') + console.error('') + process.exit(1) + } + + try { await innerCommand(...args) } catch (err) { console.error('Error:', err.message) diff --git a/lib/commands/daemon/start.js b/lib/commands/daemon/start.js index 32b5323..d33c5a7 100644 --- a/lib/commands/daemon/start.js +++ b/lib/commands/daemon/start.js @@ -15,7 +15,7 @@ export default { full: FULL_USAGE }, command: async function (args) { - await setup() + await setup({canStartDaemon: true}) try { const client = new HyperspaceClient() await client.ready() diff --git a/lib/hyper/index.js b/lib/hyper/index.js index bb29ca7..cfacbe5 100644 --- a/lib/hyper/index.js +++ b/lib/hyper/index.js @@ -12,12 +12,12 @@ const RETRY_DELAY = 100 var clients = new Map() var running = new Set() -export async function setup () { - await setupClient('hyperspace', 'Hyperspace', () => new HyperspaceClient()) - await setupClient('hyperspace-mirroring-service', 'Mirroring', () => new MirroringClient()) +export async function setup ({canStartDaemon} = {canStartDaemon: false}) { + await setupClient('hyperspace', 'Hyperspace', () => new HyperspaceClient(), canStartDaemon) + await setupClient('hyperspace-mirroring-service', 'Mirroring', () => new MirroringClient(), canStartDaemon) } -async function setupClient (name, readable, clientFunc) { +async function setupClient (name, readable, clientFunc, canStartDaemon = false) { let retries = 0 while (!clients.get(name) && retries++ < NUM_RETRIES) { try { @@ -25,6 +25,7 @@ async function setupClient (name, readable, clientFunc) { await client.ready() clients.set(name, client) } catch { + if (!canStartDaemon) break if (!running.has(name)) { await startDaemon(name, readable) running.add(name) @@ -32,7 +33,9 @@ async function setupClient (name, readable, clientFunc) { await wait(RETRY_DELAY * retries) } } - if (!clients.has(name)) throw new Error(`Could not connect to the ${readable} daemon.`) + if (!clients.has(name)) { + throw new Error(`Could not connect to the ${readable} daemon.`) + } const cleanup = async () => { const client = clients.get(name) From 9564573b7fa465d715e6f8826966f531a19bd5e2 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 16 Jul 2021 09:22:40 -0500 Subject: [PATCH 39/41] Exit with a specific code when daemon is not active --- bin/hyp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/hyp.js b/bin/hyp.js index 2c0256f..043bdf4 100755 --- a/bin/hyp.js +++ b/bin/hyp.js @@ -110,7 +110,7 @@ function wrapCommand (obj) { console.error('') console.error(' hyp daemon start') console.error('') - process.exit(1) + process.exit(2) } try { From cd56bb6074b03733aece8b6a8716b8dd90f8ee4d Mon Sep 17 00:00:00 2001 From: Andrew Osheroff Date: Fri, 23 Jul 2021 13:34:21 +0200 Subject: [PATCH 40/41] 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dcf59c0..e7465b6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hyperspace/cli", "type": "module", - "version": "1.5.1", + "version": "2.0.0", "description": "A CLI for the hyper:// space network.", "bin": { "hyp": "./bin/hyp.js" From 2d4fe24bb9ff1d92bbc28bf5b963885b47eac340 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Thu, 18 Aug 2022 10:03:03 +0200 Subject: [PATCH 41/41] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0febddc..e2f025a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ -![./logo.png](./logo.png) +# NOTE +The CLI is currently mostly out of date, tracking the previous major version of the Hypercore stack. + +Check out the individual repos instead, like [Hypercore](https://github.com/hypercore-protocol/hypercore), [Hyperbee](https://github.com/hypercore-protocol/hyperbee), [Hyperbeam](https://github.com/mafintosh/hyperbeam), [Hyperswarm](https://github.com/hyperswarm) + +
Click to see the CLI README still + # Hyp

[ @@ -136,3 +142,4 @@ The [website documentation](https://hypercore-protocol.org/guides/hyp/) have a l - [Guide: Sharing Folders](https://hypercore-protocol.org/guides/hyp/sharing-folders/) - [Guide: Seeding Data](https://hypercore-protocol.org/guides/hyp/seeding-data/) - [Guide: Beaming Files](https://hypercore-protocol.org/guides/hyp/beaming-files/) +