no more delay on pings
parent
966dc965f2
commit
556b940cc1
|
|
@ -3,7 +3,7 @@ const Keyv = require('keyv');
|
||||||
const { KeyvFile } = require('keyv-file');
|
const { KeyvFile } = require('keyv-file');
|
||||||
const { Signale } = require('signale');
|
const { Signale } = require('signale');
|
||||||
const log = new Signale().scope('GTWY');
|
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 stp = require('./STP');
|
||||||
const appdata = require('./appdata');
|
const appdata = require('./appdata');
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ class Gateway {
|
||||||
.map(endpoint => this.endpoints.get(endpoint))
|
.map(endpoint => this.endpoints.get(endpoint))
|
||||||
)).map(EndpointRecord.fromJson);
|
)).map(EndpointRecord.fromJson);
|
||||||
|
|
||||||
for(const endpoint of endpoints) {
|
for (const endpoint of endpoints) {
|
||||||
await this.testEndpoint(endpoint.host, endpoint.port);
|
await this.testEndpoint(endpoint.host, endpoint.port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +60,7 @@ class Gateway {
|
||||||
let connectionAttempts = 0;
|
let connectionAttempts = 0;
|
||||||
log.info(`Connecting to ${host}:${port}...`);
|
log.info(`Connecting to ${host}:${port}...`);
|
||||||
|
|
||||||
while(connectionAttempts < 10 && pings.length < maxPings) {
|
while (connectionAttempts < 10 && pings.length < maxPings) {
|
||||||
|
|
||||||
await new Promise(async (res) => {
|
await new Promise(async (res) => {
|
||||||
const client = stp.connect({
|
const client = stp.connect({
|
||||||
|
|
@ -72,7 +72,7 @@ class Gateway {
|
||||||
client.on('error', _ => _);
|
client.on('error', _ => _);
|
||||||
|
|
||||||
client.on('ready', async () => {
|
client.on('ready', async () => {
|
||||||
while(pings.length < maxPings) {
|
while (pings.length < maxPings) {
|
||||||
interactive.info(`[${pings.length + 1}/${maxPings}] Testing connection...`);
|
interactive.info(`[${pings.length + 1}/${maxPings}] Testing connection...`);
|
||||||
pings.push(await client.ping());
|
pings.push(await client.ping());
|
||||||
// pings.push(10);
|
// pings.push(10);
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,7 @@ class STPSocket extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.readyState === this.SECURED && obj.cmd === 'PING') {
|
if (this.readyState === this.SECURED && obj.cmd === 'PING') {
|
||||||
setTimeout(() => {
|
this.tcpSocket.write(new PongPacket(obj.data.id).toBuffer());
|
||||||
this.tcpSocket.write(new PongPacket(obj.data.id).toBuffer());
|
|
||||||
}, 1000);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"relay": "supervisor -w relay,lib -n exit relay/index.js",
|
"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": {
|
"dependencies": {
|
||||||
"bonjour": "^3.5.0",
|
"bonjour": "^3.5.0",
|
||||||
|
|
|
||||||
Reference in New Issue