Fix issues with multiple sessions and shared timer
This commit is contained in:
22
center.js
22
center.js
@@ -40,15 +40,16 @@ let failed = 0;
|
|||||||
const sendTimer = new NanoTimer();
|
const sendTimer = new NanoTimer();
|
||||||
const metricManager = new MetricManager(options);
|
const metricManager = new MetricManager(options);
|
||||||
|
|
||||||
// TODO: Fix issue where a client disconnecting does not stop this timer
|
// TODO: Currently bars are broken
|
||||||
// TODO: Fix issue where only one session is being utilized because they all share the same timer
|
// A major rework will need to happen before bars are able to play nice with multiple sessions
|
||||||
// TODO: Maybe add only receiver and only transmitter modes instead of transciever
|
// TODO: Maybe add only receiver and only transmitter modes instead of transciever
|
||||||
// Instead just use the same timer but make a pool of connections; That way both problems will be solved
|
// Instead just use the same timer but make a pool of connections; That way both problems will be solved
|
||||||
function startInterval(session, sessionLogger, rxMetrics) {
|
function startInterval(sessions, sessionLogger, rxMetrics) {
|
||||||
if (!options.messagecount > 0) {
|
if (!options.messagecount > 0) {
|
||||||
sessionLogger.info("No messages to send");
|
sessionLogger.info("No messages to send");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let sessionPointer = 0;
|
||||||
sendTimer.setInterval(
|
sendTimer.setInterval(
|
||||||
async () => {
|
async () => {
|
||||||
if (sent >= options.messagecount) {
|
if (sent >= options.messagecount) {
|
||||||
@@ -62,7 +63,10 @@ function startInterval(session, sessionLogger, rxMetrics) {
|
|||||||
short_message: options.message,
|
short_message: options.message,
|
||||||
});
|
});
|
||||||
|
|
||||||
sendPdu(session, pdu, sessionLogger, options.longsms)
|
if (sessionPointer >= sessions.length) {
|
||||||
|
sessionPointer = 0;
|
||||||
|
}
|
||||||
|
sendPdu(sessions[sessionPointer++], pdu, sessionLogger, options.longsms)
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
inFlight--;
|
inFlight--;
|
||||||
sessionLogger.info(`Received response with id ${resp.message_id}`);
|
sessionLogger.info(`Received response with id ${resp.message_id}`);
|
||||||
@@ -73,10 +77,6 @@ function startInterval(session, sessionLogger, rxMetrics) {
|
|||||||
sessionLogger.warn(`Message failed with id ${resp.message_id}`);
|
sessionLogger.warn(`Message failed with id ${resp.message_id}`);
|
||||||
failed++;
|
failed++;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (rxMetrics) {
|
|
||||||
rxMetrics.AddEvent();
|
|
||||||
}
|
|
||||||
sent++;
|
sent++;
|
||||||
inFlight++;
|
inFlight++;
|
||||||
} else {
|
} else {
|
||||||
@@ -84,7 +84,7 @@ function startInterval(session, sessionLogger, rxMetrics) {
|
|||||||
`${inFlight}/${options.window} messages pending, waiting for a reply before sending more`
|
`${inFlight}/${options.window} messages pending, waiting for a reply before sending more`
|
||||||
);
|
);
|
||||||
sendTimer.clearInterval();
|
sendTimer.clearInterval();
|
||||||
setTimeout(() => startInterval(session, sessionLogger), options.windowsleep);
|
setTimeout(() => startInterval(sessions, sessionLogger), options.windowsleep);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
@@ -111,7 +111,7 @@ const server = smpp.createServer(
|
|||||||
sessions.push(session);
|
sessions.push(session);
|
||||||
sessionLogger.info(`Client connected, currently: ${sessions.length}`);
|
sessionLogger.info(`Client connected, currently: ${sessions.length}`);
|
||||||
session.send(pdu.response());
|
session.send(pdu.response());
|
||||||
startInterval(session, sessionLogger);
|
startInterval(sessions, sessionLogger);
|
||||||
} else {
|
} else {
|
||||||
sessionLogger.warn(
|
sessionLogger.warn(
|
||||||
`Client tried to connect with incorrect login ('${pdu.system_id}' '${pdu.password}')`
|
`Client tried to connect with incorrect login ('${pdu.system_id}' '${pdu.password}')`
|
||||||
@@ -126,7 +126,7 @@ const server = smpp.createServer(
|
|||||||
if (pdu.system_id === options.systemid && pdu.password === options.password) {
|
if (pdu.system_id === options.systemid && pdu.password === options.password) {
|
||||||
sessionLogger.info("Client connected");
|
sessionLogger.info("Client connected");
|
||||||
session.send(pdu.response());
|
session.send(pdu.response());
|
||||||
startInterval(session, sessionLogger);
|
startInterval(session, sessionLogger, rxMetrics);
|
||||||
} else {
|
} else {
|
||||||
sessionLogger.warn(
|
sessionLogger.warn(
|
||||||
`Client tried to connect with incorrect login ('${pdu.system_id}' '${pdu.password}')`
|
`Client tried to connect with incorrect login ('${pdu.system_id}' '${pdu.password}')`
|
||||||
|
Reference in New Issue
Block a user