Skip to content

Commit 94b0d81

Browse files
authored
Merge branch 'master' into dpaez/drive-import-export
2 parents a2b5520 + 4e5d5d9 commit 94b0d81

File tree

5 files changed

+106
-11
lines changed

5 files changed

+106
-11
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior.
15+
16+
**Expected Behavior**
17+
What did you expect to happen?
18+
19+
** OS **
20+
21+
** Node version **
22+
23+
** Was the daemon installed from NPM or bundled with Beaker? **
24+
25+
Add any other context about the problem here.
26+
27+
__Important Note__: Daemon errors are likely to be found in `~/.hyperdrive/log.json` or `~/.hyperdrive/output.log` (the latter is for unexpected, non-JSON output). These files might contain sensitive drive keys, so don't upload the whole thing -- just extract any stack traces or odd error messages!

README.md

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ The client exposes a gRPC interface for a) creating and interacting with remote
2525
Check out the [daemon tests](https://github.com/andrewosh/hyperdrive-daemon/blob/hyperdrive-api/test/hyperdrive.js) for more example usage.
2626

2727
### Hyperdrive
28-
The client's Hyperdrive API is designed to mirror the methods in Hyperdrive as closely as possible.
28+
The client's Hyperdrive API is designed to mirror the methods in Hyperdrive as closely as possible.
29+
30+
All drive commands can be found through the `client.drives` object.
2931

3032
#### General Operations
3133
Operations to manage sessions or get more general information about the state of the daemon.
@@ -101,7 +103,9 @@ Method arguments take the same form as those in Hyperdrive. The following method
101103
20. `drive.checkout(version)` // Returns a new `RemoteHyperdrive` instance for the checkout.
102104

103105
### FUSE
104-
The client library also provides programmatic access to the daemon's FUSE interface. You can mount/unmount your root drive, or mount and share subdrives:
106+
The client library also provides programmatic access to the daemon's FUSE interface.
107+
108+
All FUSE commands can be found on the `client.fuse` object.
105109

106110
##### `client.fuse.mount(mnt, opts, cb)`
107111
Mount either the root drive (if `/mnt` is not specified), or a subdirectory within the root drive.
@@ -112,10 +116,66 @@ Mount either the root drive (if `/mnt` is not specified), or a subdirectory with
112116
Unmounts either a subdrive, or the root drive if `mnt` is not specified.
113117

114118
##### `client.fuse.publish(path, cb)`
115-
Advertise the drive mounted at `path` to the network.
119+
Advertise the drive mounted at `path` to the swarm.
116120

117121
##### `client.fuse.unpublish(path, cb)`
118-
Stop advertisingthe drive mounted at `path` to the network.
122+
Stop advertising the drive mounted at `path` to the swarm.
123+
124+
### Peersockets
125+
`client.peersockets` lets your directly exchange messages with connected peers. You can discover all peers swarming a given discovery key using the peers API (`client.peers`) described below.
126+
127+
Peers are all identified by aliases in order to reduce bandwidth consumtion, as the alternative is to attach NOISE keys to every message. Aliases can be mapped to/from NOISE keys through the `client.peers` API.
128+
129+
##### `const topicHandle = client.peersockets.join(topicName, { onmessage })`
130+
- `topicName`: A String
131+
- `onmessage`: A function of the form `(alias, msg) => { ... }`
132+
Create a TopicHandle for sending/receiving messages on topic `topicName`.
133+
134+
##### `topicHandle.send(alias, msg)`
135+
- `alias`: A numeric peer alias
136+
- `msg`: A Buffer
137+
138+
Attempt to send a message on the handle's topic to the given peer.
139+
140+
This message will be delivered with best-effort, but if the remote peer is not subscribed to the topic the message will silently be discarded.
141+
142+
##### `topicHandle.on('close', ...)`
143+
Emitted when the topic stream has closed.
144+
145+
You can check out the internals in the [peersockets repo](https://github.com/andrewosh/peersockets).
146+
147+
### Peers
148+
`client.peers` allows you to get information about currently-connected peers.
149+
150+
##### `const peerList = await client.peers.listPeers([discoveryKey])`
151+
- `discoveryKey`: A Buffer
152+
153+
Get the list of connected peers either globally or swarming a specific discovery key.
154+
155+
`peerList` has the form:
156+
```js
157+
[
158+
{
159+
noiseKey: 0x123...
160+
address: '10.21...`,
161+
type: 'utp'|'tcp'
162+
},
163+
...
164+
]
165+
```
166+
167+
##### `const destroy = client.peers.watchPeers([discoveryKey], { onjoin, onleave })`
168+
- `discoveryKey`: A Buffer
169+
170+
Watch for peers joining or leaving either globally or for a specific discovery key.
171+
172+
`onjoin` and `onleave` both take a single `peer` argument with `{ noiseKey, address, type }` fields.
173+
174+
##### `const alias = await client.peers.getAlias(key)`
175+
Gets or creates a numeric alias for the given NOISE `key`.
176+
177+
##### `const key = await client.peers.getKey(alias)`
178+
Returns the NOISE `key` for a previously-assigned `alias`.
119179
120180
## License
121181
MIT

bin/commands/import.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ImportCommand extends DaemonCommand {
4343

4444
if (!key) key = await loadKeyFromFile()
4545
const drive = await this.client.drive.get({ key })
46+
await drive.configureNetwork({ lookup: true, announce: true, remember: true })
4647
if (!drive.writable) {
4748
console.error('The target drive is not writable!')
4849
return process.exit(1)

lib/clients/drive.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,14 @@ class RemoteHyperdrive {
506506

507507
return maybe(cb, new Promise((resolve, reject) => {
508508
this._client.mkdir(req, toMetadata({ token: this.token }), (err, rsp) => {
509-
if (err) return reject(err)
509+
if (err) {
510+
// TODO: Found this bug late, and it hightlights the need for more structured errors from gRPC.
511+
// This is the most straightforward way to fix the import command, but the API should be updated to handle this.
512+
if (err.details && err.details.indexOf('Path already')) {
513+
err.code = 'EEXIST'
514+
}
515+
return reject(err)
516+
}
510517
return resolve()
511518
})
512519
}))

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hyperdrive-daemon-client",
3-
"version": "1.14.1",
3+
"version": "1.14.7",
44
"description": "A client library and CLI tool for interacting with the Hyperdrive daemon.",
55
"main": "index.js",
66
"bin": {
@@ -35,28 +35,28 @@
3535
"@grpc/grpc-js": "^0.5.1",
3636
"@oclif/command": "^1.5.19",
3737
"@oclif/config": "^1.14.0",
38+
"@oclif/errors": "^1.2.2",
3839
"@oclif/plugin-autocomplete": "^0.1.5",
3940
"@oclif/plugin-help": "^2.2.3",
4041
"call-me-maybe": "^1.0.1",
4142
"cli-progress": "^3.4.0",
4243
"codecs": "^2.0.0",
4344
"dat-encoding": "^5.0.1",
44-
"fs-extended-attributes": "^1.0.1",
45-
"fs-extra": "^8.0.1",
4645
"globby": "^11.0.0",
4746
"google-protobuf": "^3.8.0",
48-
"hyperdrive-schemas": "beta",
47+
"hyperdrive-schemas": "^1.9.0",
4948
"last-one-wins": "^1.0.4",
5049
"mirror-folder": "^3.0.1",
5150
"ora": "^4.0.3",
51+
"protocol-buffers-encodings": "^1.1.0",
52+
"pump": "^3.0.0",
5253
"pumpify": "^2.0.0",
5354
"stream-collector": "^1.0.1",
5455
"streamx": "^2.6.0",
5556
"through2-map": "^3.0.0"
5657
},
5758
"devDependencies": {
58-
"grpc-tools": "^1.7.3",
59-
"protocol-buffers-encodings": "^1.1.0"
59+
"grpc-tools": "^1.7.3"
6060
},
6161
"oclif": {
6262
"commands": "./bin/commands",

0 commit comments

Comments
 (0)