Fix yet another bug with node IDs
* Pick appropriate slot * Log nodeId vs clientId/etc. for less confusion
This commit is contained in:
parent
714f32f695
commit
fd6bb47427
|
@ -96,7 +96,7 @@ function Client(/*input, output*/) {
|
|||
|
||||
Object.defineProperty(this, 'node', {
|
||||
get : function() {
|
||||
return self.session.id + 1;
|
||||
return self.session.id;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -61,27 +61,27 @@ function getActiveConnectionList(authUsersOnly) {
|
|||
|
||||
function addNewClient(client, clientSock) {
|
||||
//
|
||||
// Assign ID/client ID to next lowest & available #
|
||||
// Find a node ID "slot"
|
||||
//
|
||||
let id = 0;
|
||||
for(let i = 0; i < clientConnections.length; ++i) {
|
||||
if(clientConnections[i].id > id) {
|
||||
break;
|
||||
let nodeId;
|
||||
for (nodeId = 1; nodeId < Number.MAX_SAFE_INTEGER; ++nodeId) {
|
||||
const existing = clientConnections.find(client => nodeId === client.node);
|
||||
if (!existing) {
|
||||
break; // available slot
|
||||
}
|
||||
id++;
|
||||
}
|
||||
|
||||
client.session.id = id;
|
||||
const remoteAddress = client.remoteAddress = clientSock.remoteAddress;
|
||||
client.session.id = nodeId;
|
||||
const remoteAddress = client.remoteAddress = clientSock.remoteAddress;
|
||||
// create a unique identifier one-time ID for this session
|
||||
client.session.uniqueId = new hashids('ENiGMA½ClientSession').encode([ id, moment().valueOf() ]);
|
||||
client.session.uniqueId = new hashids('ENiGMA½ClientSession').encode([ nodeId, moment().valueOf() ]);
|
||||
|
||||
clientConnections.push(client);
|
||||
clientConnections.sort( (c1, c2) => c1.session.id - c2.session.id);
|
||||
|
||||
// Create a client specific logger
|
||||
// Note that this will be updated @ login with additional information
|
||||
client.log = logger.log.child( { clientId : id, sessionId : client.session.uniqueId } );
|
||||
client.log = logger.log.child( { nodeId, sessionId : client.session.uniqueId } );
|
||||
|
||||
const connInfo = {
|
||||
remoteAddress : remoteAddress,
|
||||
|
@ -101,7 +101,7 @@ function addNewClient(client, clientSock) {
|
|||
{ client : client, connectionCount : clientConnections.length }
|
||||
);
|
||||
|
||||
return id;
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
function removeClient(client) {
|
||||
|
@ -114,7 +114,7 @@ function removeClient(client) {
|
|||
logger.log.info(
|
||||
{
|
||||
connectionCount : clientConnections.length,
|
||||
clientId : client.session.id
|
||||
nodeId : client.node,
|
||||
},
|
||||
'Client disconnected'
|
||||
);
|
||||
|
|
|
@ -86,9 +86,9 @@ module.exports = class DownloadQueue {
|
|||
this.add(entry, true); // true=systemFile
|
||||
|
||||
// clean up after ourselves when the session ends
|
||||
const thisClientId = this.client.session.id;
|
||||
const thisUniqueId = this.client.session.uniqueId;
|
||||
Events.once(Events.getSystemEvents().ClientDisconnected, evt => {
|
||||
if(thisClientId === _.get(evt, 'client.session.id')) {
|
||||
if(thisUniqueId === _.get(evt, 'client.session.uniqueId')) {
|
||||
FileEntry.removeEntry(entry, { removePhysFile : true }, err => {
|
||||
const Log = require('./logger').log;
|
||||
if(err) {
|
||||
|
|
|
@ -72,12 +72,12 @@ module.exports = class LoginServerModule extends ServerModule {
|
|||
});
|
||||
|
||||
client.on('error', err => {
|
||||
logger.log.info({ clientId : client.session.id, error : err.message }, 'Connection error');
|
||||
logger.log.info({ nodeId : client.node, error : err.message }, 'Connection error');
|
||||
});
|
||||
|
||||
client.on('close', err => {
|
||||
const logFunc = err ? logger.log.info : logger.log.debug;
|
||||
logFunc( { clientId : client.session.id }, 'Connection closed');
|
||||
logFunc( { nodeId : client.node }, 'Connection closed');
|
||||
|
||||
clientConns.removeClient(client);
|
||||
});
|
||||
|
|
|
@ -81,9 +81,9 @@ function userLogin(client, username, password, options, cb) {
|
|||
if(existingClientConnection) {
|
||||
client.log.info(
|
||||
{
|
||||
existingClientId : existingClientConnection.session.id,
|
||||
username : user.username,
|
||||
userId : user.userId
|
||||
existingNodeId : existingClientConnection.node,
|
||||
username : user.username,
|
||||
userId : user.userId
|
||||
},
|
||||
'Already logged in'
|
||||
);
|
||||
|
@ -97,11 +97,12 @@ function userLogin(client, username, password, options, cb) {
|
|||
// update client logger with addition of username
|
||||
client.log = logger.log.child(
|
||||
{
|
||||
clientId : client.log.fields.clientId,
|
||||
nodeId : client.log.fields.nodeId,
|
||||
sessionId : client.log.fields.sessionId,
|
||||
username : user.username,
|
||||
}
|
||||
);
|
||||
|
||||
client.log.info('Successful login');
|
||||
|
||||
// User's unique session identifier is the same as the connection itself
|
||||
|
|
Loading…
Reference in New Issue