no more delay on pings
parent
966dc965f2
commit
556b940cc1
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Reference in New Issue