bunch of changes
This commit is contained in:
+9
-11
@@ -1,8 +1,8 @@
|
||||
import { hri } from 'human-readable-ids';
|
||||
import Debug from 'debug';
|
||||
|
||||
import Client from './Client';
|
||||
import TunnelAgent from './TunnelAgent';
|
||||
import Client from './Client.js';
|
||||
import TunnelAgent from './TunnelAgent.js';
|
||||
|
||||
// Manage sets of clients
|
||||
//
|
||||
@@ -20,20 +20,14 @@ class ClientManager {
|
||||
};
|
||||
|
||||
this.debug = Debug('lt:ClientManager');
|
||||
|
||||
// This is totally wrong :facepalm: this needs to be per-client...
|
||||
this.graceTimeout = null;
|
||||
}
|
||||
|
||||
// create a new tunnel with `id`
|
||||
// if the id is already used, a random id is assigned
|
||||
// if the tunnel could not be created, throws an error
|
||||
async newClient(id) {
|
||||
const clients = this.clients;
|
||||
const stats = this.stats;
|
||||
|
||||
// can't ask for id already is use
|
||||
if (clients[id]) {
|
||||
if (this.clients[id]) {
|
||||
id = hri.random();
|
||||
}
|
||||
|
||||
@@ -51,7 +45,7 @@ class ClientManager {
|
||||
|
||||
// add to clients map immediately
|
||||
// avoiding races with other clients requesting same id
|
||||
clients[id] = client;
|
||||
this.clients[id] = client;
|
||||
|
||||
client.once('close', () => {
|
||||
this.removeClient(id);
|
||||
@@ -60,7 +54,7 @@ class ClientManager {
|
||||
// try/catch used here to remove client id
|
||||
try {
|
||||
const info = await agent.listen();
|
||||
++stats.tunnels;
|
||||
++this.stats.tunnels;
|
||||
return {
|
||||
id: id,
|
||||
port: info.port,
|
||||
@@ -74,6 +68,10 @@ class ClientManager {
|
||||
}
|
||||
}
|
||||
|
||||
getClients() {
|
||||
return Object.keys(this.clients);
|
||||
}
|
||||
|
||||
removeClient(id) {
|
||||
this.debug('removing client: %s', id);
|
||||
const client = this.clients[id];
|
||||
|
||||
Reference in New Issue
Block a user