From ae279731c8fcf0d3c902b3cd75ed11e67413fcdd Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 5 Oct 2024 12:49:17 +0200 Subject: [PATCH] ready -> fullyBootstrapped --- examples/basic-connectivity/server.mjs | 2 +- examples/bootstrap.js | 2 +- examples/isolated-dht.mjs | 8 ++++---- test/connections.js | 24 ++++++++++++------------ testnet.js | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/basic-connectivity/server.mjs b/examples/basic-connectivity/server.mjs index f3e5af0d..8025adc4 100644 --- a/examples/basic-connectivity/server.mjs +++ b/examples/basic-connectivity/server.mjs @@ -30,7 +30,7 @@ process.once('SIGINT', async function () { }) async function printInfo () { - await node.ready() + await node.fullyBootstrapped() console.log('DHT node info:') console.log('- host: ' + node.host) diff --git a/examples/bootstrap.js b/examples/bootstrap.js index 77095e5d..4f7a28da 100644 --- a/examples/bootstrap.js +++ b/examples/bootstrap.js @@ -3,6 +3,6 @@ const DHT = require('../') // You must use the public IP of the server where this bootstrap is running const node = DHT.bootstrapper(49737, '127.0.0.1') -node.ready().then(function () { +node.fullyBootstrapped().then(function () { console.log('Bootstrapper running on port ' + node.address().port) }) diff --git a/examples/isolated-dht.mjs b/examples/isolated-dht.mjs index cbe7842d..ee45556a 100644 --- a/examples/isolated-dht.mjs +++ b/examples/isolated-dht.mjs @@ -6,7 +6,7 @@ const MY_PUBLIC_IP = '67.205.140.151' // If you're on a local machine then use ' // Inside that server, to create our first bootstrap node: const bootstrap1 = DHT.bootstrapper(49737, MY_PUBLIC_IP) -await bootstrap1.ready() +await bootstrap1.fullyBootstrapped() // Your bootstrap node is now running at 67.205.140.151:49737 and it's globally accessible for anyone to use it. // This would be the list of bootstrap nodes: @@ -42,7 +42,7 @@ const bootstrap = [{ host: MY_PUBLIC_IP, port: bootstrap1.address().port }] // Inside the same server, create a new persistent node: const persistent1 = new DHT({ bootstrap, ephemeral: false }) -await persistent1.ready() +await persistent1.fullyBootstrapped() // CAUTION: // As we're the ones creating the network, we provide at least one persistent node, this is for the network to be fully operational. // From now on, nobody uses the {ephemeral:false} option to create nodes, otherwise you could damage the network health. @@ -54,8 +54,8 @@ await persistent1.ready() const node1 = new DHT({ bootstrap }) const node2 = new DHT({ bootstrap }) -await node1.ready() -await node2.ready() +await node1.fullyBootstrapped() +await node2.fullyBootstrapped() const server = node1.createServer(function (socket) { console.log('server connection') diff --git a/test/connections.js b/test/connections.js index 4e362cb4..f26afab5 100644 --- a/test/connections.js +++ b/test/connections.js @@ -145,8 +145,8 @@ test('createServer + connect - force holepunch', async function (t) { const a = new DHT({ bootstrap, quickFirewall: false, ephemeral: true }) const b = new DHT({ bootstrap, quickFirewall: false, ephemeral: true }) - await a.ready() - await b.ready() + await a.fullyBootstrapped() + await b.fullyBootstrapped() const lc = t.test('socket lifecycle') lc.plan(4) @@ -188,8 +188,8 @@ test('server choosing to abort holepunch', async function (t) { const a = new DHT({ bootstrap, quickFirewall: false, ephemeral: true }) const b = new DHT({ bootstrap, quickFirewall: false, ephemeral: true }) - await a.ready() - await b.ready() + await a.fullyBootstrapped() + await b.fullyBootstrapped() const lc = t.test('socket lifecycle') lc.plan(2) @@ -233,8 +233,8 @@ test('client choosing to abort holepunch', async function (t) { const a = new DHT({ bootstrap, quickFirewall: false, ephemeral: true }) const b = new DHT({ bootstrap, quickFirewall: false, ephemeral: true }) - await a.ready() - await b.ready() + await a.fullyBootstrapped() + await b.fullyBootstrapped() const lc = t.test('socket lifecycle') lc.plan(2) @@ -501,8 +501,8 @@ test('create many connections with reusable sockets', async function (t) { const a = new DHT({ bootstrap, quickFirewall: false, ephemeral: true }) const b = new DHT({ bootstrap, quickFirewall: false, ephemeral: true }) - await a.ready() - await b.ready() + await a.fullyBootstrapped() + await b.fullyBootstrapped() const server = a.createServer({ reusableSocket: true }) await server.listen() @@ -769,7 +769,7 @@ test('bootstrap with suggested-IP', async function (t) { const [boot] = await swarm(t, 1) const bootstrap = ['127.0.0.1@invalid:' + boot.address().port] const a = new DHT({ bootstrap, quickFirewall: false, ephemeral: false }) - await a.ready() + await a.fullyBootstrapped() t.alike(boot.toArray(), [{ host: '127.0.0.1', port: a.address().port }]) @@ -780,7 +780,7 @@ test('fail to bootstrap completely', async function (t) { const [boot] = await swarm(t, 1) const bootstrap = ['invalid:49737'] const a = new DHT({ bootstrap, quickFirewall: false, ephemeral: false }) - await a.ready() + await a.fullyBootstrapped() const empty = [] t.alike(a.toArray(), empty) @@ -791,11 +791,11 @@ test('fail to bootstrap completely', async function (t) { test('Populate DHT with options.knownNodes', async function (t) { const a = new DHT({ bootstrap: [] }) - await a.ready() + await a.fullyBootstrapped() const nodes = [{ host: '127.0.0.1', port: a.address().port }] const b = new DHT({ nodes, bootstrap: [] }) - await b.ready() + await b.fullyBootstrapped() t.alike(b.toArray(), [{ host: '127.0.0.1', port: a.address().port }]) diff --git a/testnet.js b/testnet.js index 4855ec78..83602ca2 100644 --- a/testnet.js +++ b/testnet.js @@ -18,7 +18,7 @@ module.exports = async function createTestnet (size = 10, opts = {}) { host: bindHost }) - await first.ready() + await first.fullyBootstrapped() if (bootstrap.length === 0) bootstrap.push({ host, port: first.address().port }) @@ -32,7 +32,7 @@ module.exports = async function createTestnet (size = 10, opts = {}) { host: bindHost }) - await node.ready() + await node.fullyBootstrapped() swarm.push(node) }