retry connection backoff
parent
906c2a2f9a
commit
e02bab2948
|
|
@ -7,11 +7,14 @@ const { Identity } = require('../lib/Identity');
|
||||||
const stp = require('../lib/STP');
|
const stp = require('../lib/STP');
|
||||||
title('relay', false);
|
title('relay', false);
|
||||||
const identity = await new Identity('relay', 'default');
|
const identity = await new Identity('relay', 'default');
|
||||||
|
const upnp = require('../lib/upnp');
|
||||||
|
|
||||||
const clients = [];
|
const clients = [];
|
||||||
|
|
||||||
// const client = stp.connect(identity, config.ports.relay, '127.0.0.1');
|
// const client = stp.connect(identity, config.ports.relay, '127.0.0.1');
|
||||||
|
|
||||||
|
// upnp.mapIndefinite(5600);
|
||||||
|
|
||||||
// ==================================== [STP SERVER]
|
// ==================================== [STP SERVER]
|
||||||
stp.createServer({
|
stp.createServer({
|
||||||
identity: identity,
|
identity: identity,
|
||||||
|
|
@ -21,14 +24,26 @@ stp.createServer({
|
||||||
clients.push(socket);
|
clients.push(socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
const client = stp.connect({
|
function connectNetwork(t = 1000) {
|
||||||
identity,
|
if(t > 65000) t /= 2;
|
||||||
port: config.ports.relay,
|
|
||||||
ip: 'valnet.xyz'
|
const client = stp.connect({
|
||||||
});
|
identity,
|
||||||
client.on('error', e => {
|
port: config.ports.relay,
|
||||||
log.error(e)
|
ip: 'valnet.xyz'
|
||||||
})
|
});
|
||||||
|
client.on('ready', () => {
|
||||||
|
log.success('connectd!');
|
||||||
|
t = 500;
|
||||||
|
})
|
||||||
|
client.on('error', e => {
|
||||||
|
});
|
||||||
|
client.on('close', e => {
|
||||||
|
setTimeout(connectNetwork.bind(global, t*2), t);
|
||||||
|
log.debug('retrying connection... ' + (t/1000) + 's')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
connectNetwork();
|
||||||
|
|
||||||
// ==================================== [EXPRESS]
|
// ==================================== [EXPRESS]
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
|
|
||||||
Reference in New Issue