Skip to content

Commit

Permalink
Merge pull request #73 from orbitdb/rename-to-voyager
Browse files Browse the repository at this point in the history
Unify naming
  • Loading branch information
haydenyoung authored Nov 29, 2024
2 parents ab7b74f + dca79fb commit 331e34b
Show file tree
Hide file tree
Showing 33 changed files with 364 additions and 369 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/npm-publish-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run lint
- name: Run an Orbiter 1 instance in the background
run: npm run start:orbiter1:background
- name: Run an Orbiter 2 instance in the background
run: npm run start:orbiter2:background
- name: Run an Voyager 1 instance in the background
run: npm run start:host1:background
- name: Run an Voyager 2 instance in the background
run: npm run start:host2:background
- run: npm test
- run: |
npm version prerelease --no-git-tag-version \
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
node-version: 'lts/*'
registry-url: https://registry.npmjs.org/
- run: npm ci
- name: Run an Orbiter 1 instance in the background
run: npm run start:orbiter1:background
- name: Run an Orbiter 2 instance in the background
run: npm run start:orbiter2:background
- name: Run an Voyager 1 instance in the background
run: npm run start:host1:background
- name: Run an Voyager 2 instance in the background
run: npm run start:host2:background
- run: npm test
- run: npm publish
env:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
run: npm run lint
- name: Run libp2p relay in the background
run: npm run start:relay:background
- name: Run an Orbiter 1 instance in the background
run: npm run start:orbiter1:background
- name: Run an Orbiter 2 instance in the background
run: npm run start:orbiter2:background
- name: Run an Voyager 1 instance in the background
run: npm run start:host1:background
- name: Run an Voyager 2 instance in the background
run: npm run start:host2:background
- name: Run tests
run: npm run test:ci
- name: Run browser tests
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ node_modules
coverage
voyager
bundle.js*
orbiter1/
orbiter2/
host1/
host2/
47 changes: 22 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ npm i -g @orbitdb/voyager

## Usage

Voyager, like OrbitDB, is peer-to-peer and does not have a traditional server/client architecture and so terms "server" and "client" do not apply. Therefore, in keeping with OrbitDB's "celestial" naming convention, the storage service peer is called ***"Orbiter"*** and the interface which the developer or user uses to communicate with the storage service peer is called ***"Lander"***.

### CLI

The `voyager` CLI tool can be used to manage a Voyager instance. Run `voyager` on the command line to get started.
Expand All @@ -41,15 +39,15 @@ voyager address Show the voyager's network addresses
voyager auth Add or remove authorized user
```

### Orbiter Daemon
### Daemon

Voyager's **Orbiter**, the storage service, can be run as a daemon process. You can install the package globally and run it using the `voyager` CLI binary:
Voyager can be run as a daemon process. You can install the package globally and run it using the `voyager` CLI binary:

```sh
voyager daemon
```

To store Orbiter's configuration and data to a different directory, use the `-d` or `--directory` flag or `VOYAGER_PATH` environment variable:
To store Voyager's configuration and data to a different directory, use the `-d` or `--directory` flag or `VOYAGER_PATH` environment variable:

```sh
voyager daemon -d /path/to/voyager
Expand All @@ -61,7 +59,7 @@ VOYAGER_PATH=/path/to/voyager voyager daemon

### Docker

You can run an Orbiter storage service using a pre-configured Docker image.
You can run an Voyager storage service using a pre-configured Docker image.

Once you have cloned this repo, cd into the voyager directory root and run:

Expand All @@ -72,39 +70,39 @@ docker run --rm -d -p 8000:8000 orbitdb-voyager

Adjust the port if required.

## Managing Orbiter Access
## Managing Voyager Access

Orbiter will deny all requests by default. To allow a user to interact with Orbiter, the (requesting) user's `id` must be added to Orbiter's "allow" list.
Voyager will deny all requests by default. To allow a user to interact with Voyager, the (requesting) user's `id` must be added to Voyager's "allow" list.

Access to Orbiter can be configured in two ways; from the terminal and programmatically, using RPC.
Access can be configured in two ways; from the terminal and programmatically, using RPC.

**NOTE** The user's `id` used in the examples below can be retrieved using **`orbitdb.identity.id`**, which is available from the user's OrbitDB instance.

### Managing access from the terminal

To add an authorized user to Orbiter:
To add an authorized user to Voyager:

```sh
voyager auth add <id>
```

where `<id>` identifies a user who can add databases to this Orbiter. The `<id>` is the string from user's OrbitDB instance `orbitdb.identity.id`.
where `<id>` identifies a user who can add databases to this Voyager instance. The `<id>` is the string from user's OrbitDB instance `orbitdb.identity.id`.

To remove an authorized user from Orbiter:
To remove an authorized user from Voyager:

```sh
voyager auth del <id>
```

where `<id>` identifies a user who can add databases to this Orbiter. The `<id>` is the string from user's OrbitDB instance `orbitdb.identity.id`.
where `<id>` identifies a user who can add databases to this Voyager instance. The `<id>` is the string from user's OrbitDB instance `orbitdb.identity.id`.

List authorized users:

```sh
voyager auth list
```

If Orbiter is deployed to a custom directory, call Voyager with the `-d` or `--directory` flag, or `VOYAGER_PATH`environment variable, and specify the directory:
If Voyager is deployed to a custom directory, call Voyager with the `-d` or `--directory` flag, or `VOYAGER_PATH`environment variable, and specify the directory:

```sh
voyager auth add -d /custom/voyager/path <id>
Expand Down Expand Up @@ -150,35 +148,34 @@ And to remove an authorization:
await rpc.authDel()
```

## Adding databases using Lander
## Adding databases to Voyager

To make databases accessible from Voyager, the database needs to be added to an Orbiter storage service instance. This can be achieved programmatically by using the **Lander** module.
To make databases accessible from a Voyager storage service, the database needs to be added to a Voyager instance. This can be achieved programmatically by using the **Voyager remote API** module.

To use Lander, first install the [@orbitdb/voyager](https://www.npmjs.com/package/@orbitdb/voyager) package:
To use Voyager remote API, first install the [@orbitdb/voyager](https://www.npmjs.com/package/@orbitdb/voyager) package:

```sh
npm i @orbitdb/voyager
```

Next, instantiate Lander:
Next, instantiate Voyager remote API:

```js
import { createLibp2p } from 'libp2p'
import { createHelia } from 'helia'
import { createOrbitDB } from '@orbitdb/core'
import { Lander } from '@orbitdb/voyager'
import { Voyager } from '@orbitdb/voyager'

// set up libp2p, helia and orbitdb

const libp2p = await createLibp2p()
const ipfs = await createHelia({ libp2p })
const orbitdb = await createOrbitDB({ ipfs })

// deployed orbiter peer id or listening address, it looks like this:
// deployed voyager peer's listening address, it looks like this:
// /ip4/127.0.0.1/tcp/54322/p2p/16Uiu2HAmATMovCwY46yyJib7bGZF2f2XLRar7d7R3NJCSJtuyQLt
const orbiterAddressOrId = '...'
const address = '...'

const lander = await Lander({ orbitdb, orbiterAddressOrId })
const voyager = await Voyager({ orbitdb, address })
```

To add a database to voyager:
Expand All @@ -188,7 +185,7 @@ To add a database to voyager:
const db = await orbitdb.open('my-db')

// add the address to voyager (can also pass an array of addresses)
await lander.add(db.address)
await voyager.add(db.address)
```

To remove a database from voyager:
Expand All @@ -198,7 +195,7 @@ To remove a database from voyager:
const db = await orbitdb.open('my-db')

// remove the address from voyager (can also pass an array of addresses)
await lander.remove(db.address)
await voyager.remove(db.address)
```

## The OrbitDB Voyager Protocol
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
"test:ci": "c8 npm run test",
"lint": "standard",
"lint:fix": "standard --fix",
"copy:fixtures1": "rm -rf ./orbiter1 && mkdir -p ./orbiter1/voyager/orbiter/keystore && cp -Rf test/fixtures/keystore1/** ./orbiter1/voyager/orbiter/keystore/",
"copy:fixtures2": "rm -rf ./orbiter2 && mkdir -p ./orbiter2/voyager/orbiter/keystore && cp -Rf test/fixtures/keystore2/** ./orbiter2/voyager/orbiter/keystore/",
"copy:fixtures1": "rm -rf ./host1 && mkdir -p ./host1/voyager/host/keystore && cp -Rf test/fixtures/keystore1/** ./host1/voyager/host/keystore/",
"copy:fixtures2": "rm -rf ./host2 && mkdir -p ./host2/voyager/host/keystore && cp -Rf test/fixtures/keystore2/** ./host2/voyager/host/keystore/",
"start:relay": "node ./test/utils/relay.js",
"start:relay:background": "node ./test/utils/relay.js &",
"start:orbiter1": "npm run copy:fixtures1 && node ./src/bin/cli.js daemon -p 54321 -w 55441 --allow --directory ./orbiter1 -vv",
"start:orbiter2": "npm run copy:fixtures2 && node ./src/bin/cli.js daemon -p 54322 -w 55442 --allow --directory ./orbiter2 -vv",
"start:orbiter1:background": "npm run copy:fixtures1 && node ./src/bin/cli.js daemon -p 54321 -w 55441 --allow --directory ./orbiter1 &",
"start:orbiter2:background": "npm run copy:fixtures2 && node ./src/bin/cli.js daemon -p 54322 -w 55442 --allow --directory ./orbiter2 &",
"start:host1": "npm run copy:fixtures1 && node ./src/bin/cli.js daemon -p 54321 -w 55441 --allow --directory ./host1 -vv",
"start:host2": "npm run copy:fixtures2 && node ./src/bin/cli.js daemon -p 54322 -w 55442 --allow --directory ./host2 -vv",
"start:host1:background": "npm run copy:fixtures1 && node ./src/bin/cli.js daemon -p 54321 -w 55441 --allow --directory ./host1 &",
"start:host2:background": "npm run copy:fixtures2 && node ./src/bin/cli.js daemon -p 54322 -w 55442 --allow --directory ./host2 &",
"test:browser": "npm run build:tests && ./node_modules/.bin/playwright-test test/browser/bundle.js --runner mocha"
},
"standard": {
Expand Down
28 changes: 13 additions & 15 deletions src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { createOrbitDB, Identities, KeyStore } from '@orbitdb/core'
import { LevelBlockstore } from 'blockstore-level'
import { LevelDatastore } from 'datastore-level'
import { pipe } from 'it-pipe'
import Orbiter from './lib/orbiter.js'
import Host from './lib/host.js'
import { voyagerRPCProtocol } from './rpc/protocol.js'
import { handleCommand } from './rpc/index.js'
import { Access } from './lib/authorization.js'
import { config as libp2pConfig } from './utils/libp2p-config.js'
import { rpc as rpcId, appPath, rpcPath, app, orbiter as orbiterId, orbiterPath } from './utils/id.js'
import { rpc as rpcId, appPath, rpcPath, app, host as hostId, hostPath } from './utils/id.js'
import { saveConfig } from './utils/config-manager.js'
import { logger, enable } from '@libp2p/logger'

Expand Down Expand Up @@ -41,19 +41,17 @@ export default async ({ options }) => {
options.port = options.port || 0
options.wsport = options.wsport || 0

const id = orbiterId

log('app:', app)
log('orbiter:', id)
log('host:', hostId)
log('rpc:', rpcId)

const appDirectory = appPath(options.directory)
const orbiterDirectory = orbiterPath(options.directory)
const hostDirectory = hostPath(options.directory)

log('directory:', orbiterDirectory)
log('directory:', hostDirectory)

const blockstore = new LevelBlockstore(join(orbiterDirectory, '/', 'ipfs', '/', 'blocks'))
const datastore = new LevelDatastore(join(orbiterDirectory, '/', 'ipfs', '/', 'data'))
const blockstore = new LevelBlockstore(join(hostDirectory, '/', 'ipfs', '/', 'blocks'))
const datastore = new LevelDatastore(join(hostDirectory, '/', 'ipfs', '/', 'data'))

const libp2p = await createLibp2p(libp2pConfig({ port: options.port, websocketPort: options.wsport }))

Expand All @@ -68,25 +66,25 @@ export default async ({ options }) => {
}

const ipfs = await createHelia({ libp2p, datastore, blockstore })
const orbitdb = await createOrbitDB({ ipfs, directory: orbiterDirectory, id })
const orbiter = await Orbiter({ defaultAccess, verbose: options.verbose, orbitdb })
const orbitdb = await createOrbitDB({ ipfs, directory: hostDirectory, id: hostId })
const host = await Host({ defaultAccess, verbose: options.verbose, orbitdb })

const authorizedRPCIdentity = await createRPCIdentity({ id: rpcId, directory: options.directory })

const rpcConfig = {
address: orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().shift(), // get 127.0.0.1 address
address: host.orbitdb.ipfs.libp2p.getMultiaddrs().shift(), // get 127.0.0.1 address
identities: [authorizedRPCIdentity]
}
await saveConfig({ path: appDirectory, config: rpcConfig })

const handleRPCMessages = async ({ stream }) => {
await pipe(stream, handleCommand(rpcConfig, orbiter), stream)
await pipe(stream, handleCommand(rpcConfig, host), stream)
}

await orbiter.orbitdb.ipfs.libp2p.handle(voyagerRPCProtocol, handleRPCMessages)
await host.orbitdb.ipfs.libp2p.handle(voyagerRPCProtocol, handleRPCMessages)

process.on('SIGINT', async () => {
await orbiter.stop()
await host.stop()
await blockstore.close()
await datastore.close()
process.exit(0)
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Orbiter from './lib/orbiter.js'
import Lander from './lib/lander.js'
import Host from './lib/host.js'
import Voyager from './lib/voyager.js'
import RPC from './rpc-client.js'

export {
Orbiter,
Lander,
Host,
Voyager,
RPC
}
6 changes: 3 additions & 3 deletions src/lib/handle-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import handleAddRequest from './handlers/add.js'
import handleRemoveRequest from './handlers/remove.js'
import { ResponseMessage, parseMessage, Requests, Responses } from './messages/index.js'

export const handleRequest = (orbiter) => source => {
export const handleRequest = (host) => source => {
return (async function * () {
for await (const chunk of source) {
const { type, signature, id, addresses } = parseMessage(chunk.subarray())
const { orbitdb, auth, databases, log } = orbiter
const { orbitdb, auth, databases, log } = host

log('handle request', type, signature, id, addresses)

Expand All @@ -21,7 +21,7 @@ export const handleRequest = (orbiter) => source => {
await orbitdb.identities.verifyIdentity(identity)
}

// check that the identity is authorized to store their databases on this orbiter
// check that the identity is authorized to store their databases on this voyager
if (!await auth.hasAccess(identity.id)) {
throw Object.assign(new Error('user is not authorized to add'), { type: Responses.E_NOT_AUTHORIZED })
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/handlers/add.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '@libp2p/logger'

const log = logger('voyager:orbiter:add')
const log = logger('voyager:add')

const waitForReplication = (db) => {
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/handlers/remove.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '@libp2p/logger'

const log = logger('voyager:orbiter:remove')
const log = logger('voyager:remove')

export default async ({ orbitdb, databases, id, addresses }) => {
for (const address of addresses) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/orbiter.js → src/lib/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { handleRequest } from './handle-request.js'
import Authorization, { Access } from './authorization.js'

export default async ({ orbitdb, defaultAccess, verbose } = {}) => {
const log = logger('voyager:orbiter')
const log = logger('voyager:host')

if (verbose > 0) {
enable('voyager:orbiter' + (verbose > 1 ? '*' : ':error'))
enable('voyager:host' + (verbose > 1 ? '*' : ':error'))
}

log('start orbiter')
log('start voyager')

defaultAccess = defaultAccess || Access.DENY

Expand Down
6 changes: 3 additions & 3 deletions src/lib/lander.js → src/lib/voyager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const getSubarray = (e) => e.subarray()
const getType = (e) => e.type
const isOk = (e) => e === Responses.OK

export default async ({ orbitdb, orbiterAddressOrId }) => {
export default async ({ orbitdb, address }) => {
const request = async (type, addresses) => {
return await RequestMessage(type, addresses, orbitdb.identity)
}
Expand All @@ -22,14 +22,14 @@ export default async ({ orbitdb, orbiterAddressOrId }) => {

const add = async (addresses) => {
const addDBs = () => [request(Requests.ADD, toArray(addresses))]
const stream = await orbitdb.ipfs.libp2p.dialProtocol(orbiterAddressOrId, voyagerProtocol, { runOnLimitedConnection: true })
const stream = await orbitdb.ipfs.libp2p.dialProtocol(address, voyagerProtocol, { runOnLimitedConnection: true })
const added = await pipe(addDBs, stream, parseResponse)
return added
}

const remove = async (addresses) => {
const removeDBs = () => [request(Requests.REMOVE, toArray(addresses))]
const stream = await orbitdb.ipfs.libp2p.dialProtocol(orbiterAddressOrId, voyagerProtocol, { runOnLimitedConnection: true })
const stream = await orbitdb.ipfs.libp2p.dialProtocol(address, voyagerProtocol, { runOnLimitedConnection: true })
const removed = await pipe(removeDBs, stream, parseResponse)
return removed
}
Expand Down
Loading

0 comments on commit 331e34b

Please sign in to comment.