mirror of
https://github.com/bitinflow/server.git
synced 2026-03-13 13:35:53 +00:00
use pump to pipe sockets
Ensures that destination socket close or destroy also does the same for the source socket.
This commit is contained in:
@@ -20,6 +20,8 @@ class ClientManager {
|
||||
};
|
||||
|
||||
this.debug = Debug('lt:ClientManager');
|
||||
|
||||
this.graceTimeout = null;
|
||||
}
|
||||
|
||||
// create a new tunnel with `id`
|
||||
@@ -36,11 +38,13 @@ class ClientManager {
|
||||
|
||||
const maxSockets = this.opt.max_tcp_sockets;
|
||||
const agent = new TunnelAgent({
|
||||
clientId: id,
|
||||
maxSockets: 10,
|
||||
});
|
||||
|
||||
agent.on('online', () => {
|
||||
this.debug('client online %s', id);
|
||||
clearTimeout(this.graceTimeout);
|
||||
});
|
||||
|
||||
agent.on('offline', () => {
|
||||
@@ -48,7 +52,11 @@ class ClientManager {
|
||||
// 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);
|
||||
this.removeClient(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?
|
||||
@@ -81,6 +89,7 @@ class ClientManager {
|
||||
}
|
||||
|
||||
removeClient(id) {
|
||||
this.debug('removing client: %s', id);
|
||||
const client = this.clients[id];
|
||||
if (!client) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user