Skip to content

Commit c69e4da

Browse files
committed
Add stable swarm ID and noise keypair to network options
1 parent 6147726 commit c69e4da

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"hypercore": "^9.5.4",
3838
"hypercore-cache": "^1.0.2",
3939
"hypercore-default-storage": "^1.0.0",
40+
"hypercore-protocol": "^8.0.7",
4041
"hyperswarm": "^2.15.1",
4142
"hypertrie": "^5.1.1",
4243
"inspect-custom-symbol": "^1.1.1",

server.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const os = require('os')
44
const Corestore = require('corestore')
55
const Networker = require('@corestore/networker')
66
const HypercoreCache = require('hypercore-cache')
7+
const HypercoreProtocol = require('hypercore-protocol')
78
const hypercoreStorage = require('hypercore-default-storage')
89
const { NanoresourcePromise: Nanoresource } = require('nanoresource-promise/emitter')
910

@@ -25,6 +26,7 @@ const DATA_CACHE_SIZE = TOTAL_CACHE_SIZE * (1 - CACHE_RATIO)
2526
const DEFAULT_STORAGE_DIR = path.join(os.homedir(), '.hyperspace', 'storage')
2627
const MAX_PEERS = 256
2728
const SWARM_PORT = 49737
29+
const NAMESPACE = '@hypercore-protocol/hyperspace'
2830

2931
module.exports = class Hyperspace extends Nanoresource {
3032
constructor (opts = {}) {
@@ -78,8 +80,17 @@ module.exports = class Hyperspace extends Nanoresource {
7880
async _open () {
7981
await this.corestore.ready()
8082
await this.db.open()
81-
this.networker = new Networker(this.corestore, this._networkOpts)
83+
84+
// Note: This API is not exposed anymore -- this is a temporary fix.
85+
const seed = this.corestore.inner._deriveSecret(NAMESPACE, 'replication-keypair')
86+
const swarmId = this.corestore.inner._deriveSecret(NAMESPACE, 'swarm-id')
87+
this.networker = new Networker(this.corestore, {
88+
keyPair: HypercoreProtocol.keyPair(seed),
89+
id: swarmId,
90+
...this._networkOpts
91+
})
8292
await this.networker.listen()
93+
8394
this._registerCoreTimeouts()
8495
await this._rejoin()
8596

test/helpers/create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async function createMany (numDaemons, opts) {
4242
return bootstrapper.once('listening', resolve)
4343
})
4444
const bootstrapPort = bootstrapper.address().port
45-
const bootstrapOpt = [`localhost:${bootstrapPort}}`]
45+
const bootstrapOpt = [`localhost:${bootstrapPort}`]
4646

4747
for (let i = 0; i < numDaemons; i++) {
4848
const serverOpts = opts ? Array.isArray(opts) ? opts[i] : opts : null

0 commit comments

Comments
 (0)