From 556b940cc18c7a67a68e0a058cbb550aae083a40 Mon Sep 17 00:00:00 2001 From: Bronwen Date: Thu, 1 Apr 2021 23:21:39 -0400 Subject: [PATCH] no more delay on pings --- lib/Gateway.js | 10 +++++----- lib/STP/index.js | 4 +--- package.json | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/Gateway.js b/lib/Gateway.js index 79ae0e0..dfe3732 100644 --- a/lib/Gateway.js +++ b/lib/Gateway.js @@ -3,7 +3,7 @@ const Keyv = require('keyv'); const { KeyvFile } = require('keyv-file'); const { Signale } = require('signale'); const log = new Signale().scope('GTWY'); -const interactive = new Signale({interactive: true, scope: 'GTWY'}); +const interactive = new Signale({ interactive: true, scope: 'GTWY' }); const stp = require('./STP'); const appdata = require('./appdata'); @@ -47,8 +47,8 @@ class Gateway { (await this.endpoints.get('cache')) .map(endpoint => this.endpoints.get(endpoint)) )).map(EndpointRecord.fromJson); - - for(const endpoint of endpoints) { + + for (const endpoint of endpoints) { await this.testEndpoint(endpoint.host, endpoint.port); } } @@ -60,7 +60,7 @@ class Gateway { let connectionAttempts = 0; log.info(`Connecting to ${host}:${port}...`); - while(connectionAttempts < 10 && pings.length < maxPings) { + while (connectionAttempts < 10 && pings.length < maxPings) { await new Promise(async (res) => { const client = stp.connect({ @@ -72,7 +72,7 @@ class Gateway { client.on('error', _ => _); client.on('ready', async () => { - while(pings.length < maxPings) { + while (pings.length < maxPings) { interactive.info(`[${pings.length + 1}/${maxPings}] Testing connection...`); pings.push(await client.ping()); // pings.push(10); diff --git a/lib/STP/index.js b/lib/STP/index.js index 45bdce7..64bd6f2 100644 --- a/lib/STP/index.js +++ b/lib/STP/index.js @@ -136,9 +136,7 @@ class STPSocket extends EventEmitter { } if (this.readyState === this.SECURED && obj.cmd === 'PING') { - setTimeout(() => { - this.tcpSocket.write(new PongPacket(obj.data.id).toBuffer()); - }, 1000); + this.tcpSocket.write(new PongPacket(obj.data.id).toBuffer()); return; } diff --git a/package.json b/package.json index 374d28d..a2c18f0 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ }, "scripts": { "relay": "supervisor -w relay,lib -n exit relay/index.js", - "relay:service": "supervisor -- relay/service" + "relay:service": "supervisor -- relay/service", + "sloc": "find lib -type f | xargs wc -l" }, "dependencies": { "bonjour": "^3.5.0",