mirror of
https://github.com/bitinflow/server.git
synced 2026-03-13 13:35:53 +00:00
grace period disconnect should be per-client
This commit is contained in:
@@ -21,6 +21,7 @@ class ClientManager {
|
||||
|
||||
this.debug = Debug('lt:ClientManager');
|
||||
|
||||
// This is totally wrong :facepalm: this needs to be per-client...
|
||||
this.graceTimeout = null;
|
||||
}
|
||||
|
||||
@@ -42,35 +43,19 @@ class ClientManager {
|
||||
maxSockets: 10,
|
||||
});
|
||||
|
||||
agent.on('online', () => {
|
||||
this.debug('client online %s', id);
|
||||
clearTimeout(this.graceTimeout);
|
||||
const client = new Client({
|
||||
id,
|
||||
agent,
|
||||
});
|
||||
|
||||
agent.on('offline', () => {
|
||||
// TODO(roman): grace period for re-connecting
|
||||
// this period is short as the client is expected to maintain connections actively
|
||||
// if they client does not reconnect on a dropped connection they need to re-establish
|
||||
this.debug('client offline %s', id);
|
||||
|
||||
// client is given a grace period in which they can re-connect before they are _removed_
|
||||
this.graceTimeout = setTimeout(() => {
|
||||
this.removeClient(id);
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// TODO(roman): an agent error removes the client, the user needs to re-connect?
|
||||
// how does a user realize they need to re-connect vs some random client being assigned same port?
|
||||
agent.once('error', (err) => {
|
||||
this.removeClient(id);
|
||||
});
|
||||
|
||||
const client = new Client({ agent });
|
||||
|
||||
// add to clients map immediately
|
||||
// avoiding races with other clients requesting same id
|
||||
clients[id] = client;
|
||||
|
||||
client.once('close', () => {
|
||||
this.removeClient(id);
|
||||
});
|
||||
|
||||
// try/catch used here to remove client id
|
||||
try {
|
||||
const info = await agent.listen();
|
||||
@@ -96,11 +81,11 @@ class ClientManager {
|
||||
}
|
||||
--this.stats.tunnels;
|
||||
delete this.clients[id];
|
||||
client.agent.destroy();
|
||||
client.close();
|
||||
}
|
||||
|
||||
hasClient(id) {
|
||||
return this.clients[id];
|
||||
return !!this.clients[id];
|
||||
}
|
||||
|
||||
getClient(id) {
|
||||
|
||||
Reference in New Issue
Block a user