Skip to content

Commit

Permalink
refactor: Upgrade helia.
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenyoung committed Oct 10, 2024
1 parent 1c49d0b commit 031ba51
Show file tree
Hide file tree
Showing 11 changed files with 4,916 additions and 5,007 deletions.
9,867 changes: 4,890 additions & 4,977 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
},
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^14.1.0",
"@orbitdb/core": "https://github.com/orbitdb/orbitdb.git#expose-identities",
"@orbitdb/core": "github:orbitdb/orbitdb#expose-identities",
"@orbitdb/set-db": "^1.0.2",
"blockstore-level": "^1.1.8",
"datastore-level": "^10.1.8",
"helia": "^4.2.5",
"it-pipe": "^3.0.1",
"libp2p": "^2.1.8",
"yargs": "^17.7.2"
"blockstore-level": "^2.0.1",
"datastore-level": "^11.0.1",
"helia": "^5.0.0"
},
"devDependencies": {
"c8": "^10.1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ 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 { saveConfig } from './utils/config-manager.js'
import { createFromPrivKey } from '@libp2p/peer-id-factory'
import { logger, enable } from '@libp2p/logger'
import { privateKeyFromProtobuf } from '@libp2p/crypto/keys'

export default async ({ options }) => {
options = options || {}
Expand Down Expand Up @@ -50,7 +50,7 @@ export default async ({ options }) => {
let identities = await Identities({ keystore })
await identities.createIdentity({ id })

const privateKey = await keystore.getKey(id)
const privateKey = privateKeyFromProtobuf((await keystore.getKey(id)).bytes)
await keystore.close()

const libp2p = await createLibp2p(await libp2pConfig({ privateKey, port: options.port, websocketPort: options.wsport }))
Expand Down
6 changes: 3 additions & 3 deletions src/rpc-client.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { join } from 'path'
import { Identities, KeyStore } from '@orbitdb/core'
import { createLibp2p } from 'libp2p'
import { createFromPrivKey } from '@libp2p/peer-id-factory'
import { Commands, sendCommand } from './rpc/index.js'
import { rpc as rpcId, appPath, rpcPath } from './utils/id.js'
import { loadConfig } from './utils/config-manager.js'
import { config as libp2pConfig } from './utils/libp2p-config.js'
import { privateKeyFromProtobuf } from '@libp2p/crypto/keys'

const authAdd = (identity, libp2p, address) => async ({ id }) => {
return sendCommand(identity, libp2p, address, Commands.AUTH_ADD, [id])
Expand Down Expand Up @@ -37,8 +37,8 @@ export default async ({ id, directory }) => {
const identities = await Identities({ keystore })
const identity = await identities.createIdentity({ id: rpcId })

const peerId = await createFromPrivKey(await keystore.getKey(rpcId))
const libp2p = await createLibp2p(await libp2pConfig({ peerId }))
const privateKey = privateKeyFromProtobuf((await keystore.getKey(id)).bytes)
const libp2p = await createLibp2p(await libp2pConfig({ privateKey }))

return {
authAdd: authAdd(identity, libp2p, config.orbiter.api),
Expand Down
11 changes: 8 additions & 3 deletions test/e2e-browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('End-to-End Browser Tests', function () {
deepStrictEqual(expected, res)
})

it('pin and replicate a database - lander1->orbiter1->orbiter2->lander3', async function () {
it.only('pin and replicate a database - lander1->orbiter1->orbiter2->lander3', async function () {
const entryAmount = 100
let replicated = false

Expand All @@ -96,7 +96,12 @@ describe('End-to-End Browser Tests', function () {
}

const expected = await db1.all()

lander1.orbitdb.ipfs.libp2p.services.pubsub.addEventListener('subscription-change', (event) => {
console.log("subscription lander 1")
})
lander3.orbitdb.ipfs.libp2p.services.pubsub.addEventListener('subscription-change', (event) => {
console.log("subscription lander 3")
})
console.time('pin')
await lander1.pin(db1.address)
console.timeEnd('pin')
Expand All @@ -108,7 +113,7 @@ describe('End-to-End Browser Tests', function () {

console.time('replicate')
const db2 = await lander3.orbitdb.open(db1.address)

console.log(lander1.orbitdb.ipfs.libp2p.peerId)
const onConnected = (peerId, heads) => {
replicated = true
}
Expand Down
1 change: 0 additions & 1 deletion test/utils/launch-lander.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const heliaOptions = {

export const launchLander = async ({ directory, orbiterAddress } = {}) => {
const options = Libp2pOptions

const libp2p = await createLibp2p({ ...options })
const ipfs = await createHelia({ libp2p, ...heliaOptions })

Expand Down
12 changes: 4 additions & 8 deletions test/utils/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@ import { circuitRelayServer } from '@libp2p/circuit-relay-v2'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { identify } from '@libp2p/identify'
import { createFromPrivKey } from '@libp2p/peer-id-factory'
import { unmarshalPrivateKey } from '@libp2p/crypto/keys'
import { generateKeyPair, privateKeyFromProtobuf } from '@libp2p/crypto/keys'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'

// output of: console.log(server.peerId.privateKey.toString('hex'))
const relayPrivKey = '08011240821cb6bc3d4547fcccb513e82e4d718089f8a166b23ffcd4a436754b6b0774cf07447d1693cd10ce11ef950d7517bad6e9472b41a927cd17fc3fb23f8c70cd99'
// the peer id of the above key
// const relayId = '12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE'

const encoded = uint8ArrayFromString(relayPrivKey, 'hex')
const privateKey = await unmarshalPrivateKey(encoded)
const peerId = await createFromPrivKey(privateKey)
const privateKey = privateKeyFromProtobuf(uint8ArrayFromString(relayPrivKey, 'hex'))

const server = await createLibp2p({
peerId,
privateKey,
addresses: {
listen: ['/ip4/0.0.0.0/tcp/12345/ws']
},
Expand All @@ -28,7 +24,7 @@ const server = await createLibp2p({
filter: filters.all
})
],
connectionEncryption: [noise()],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
services: {
identify: identify(),
Expand Down
2 changes: 1 addition & 1 deletion test/utils/test-config-browser/lander-libp2p-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Libp2pBrowserOptions = {
discoverRelays: 1
})
],
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand Down
2 changes: 1 addition & 1 deletion test/utils/test-config-browser/orbiter-libp2p-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Libp2pBrowserOptions = {
discoverRelays: 1
})
],
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand Down
5 changes: 2 additions & 3 deletions test/utils/test-config/lander-libp2p-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Libp2pOptions = {
tcp(),
webSockets()
],
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand All @@ -32,8 +32,7 @@ const Libp2pOptions = {
services: {
identify: identify(),
pubsub: gossipsub({
emitSelf: true,
allowPublishToZeroPeers: true
emitSelf: true
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/utils/test-config/orbiter-libp2p-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Libp2pOptions = {
tcp(),
webSockets()
],
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand Down

0 comments on commit 031ba51

Please sign in to comment.