Skip to content

Commit

Permalink
ready -> fullyBootstrapped
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Oct 5, 2024
1 parent 0dc8b5f commit ae27973
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/basic-connectivity/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
8 changes: 4 additions & 4 deletions examples/isolated-dht.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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')
Expand Down
24 changes: 12 additions & 12 deletions test/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 }])

Expand All @@ -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)
Expand All @@ -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 }])

Expand Down
4 changes: 2 additions & 2 deletions testnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand All @@ -32,7 +32,7 @@ module.exports = async function createTestnet (size = 10, opts = {}) {
host: bindHost
})

await node.ready()
await node.fullyBootstrapped()
swarm.push(node)
}

Expand Down

0 comments on commit ae27973

Please sign in to comment.