Small refactoring

This commit is contained in:
2023-11-30 13:37:51 +01:00
parent acf1cf2bf4
commit 9326923b72
2 changed files with 32 additions and 3 deletions

View File

@@ -28,7 +28,6 @@ if (options.help) {
process.exit(0);
}
const metricManager = new MetricManager(options);
verifyDefaults(options, centerOptions);
verifyExists(options.port, "Port can not be undefined or empty! (--port)", logger);
@@ -40,6 +39,7 @@ let sent = 0;
let success = 0;
let failed = 0;
const sendTimer = new NanoTimer();
const metricManager = new MetricManager(options);
// TODO: Fix issue where a client disconnecting does not stop this timer
// TODO: Fix issue where only one session is being utilized because they all share the same timer
@@ -118,6 +118,36 @@ const server = smpp.createServer(
session.close();
}
});
session.on("bind_transmitter", function (pdu) {
if (pdu.system_id === options.systemid && pdu.password === options.password) {
sessionLogger.info("Client connected");
session.send(pdu.response());
startInterval(session, sessionLogger);
} else {
sessionLogger.warn(
`Client tried to connect with incorrect login ('${pdu.system_id}' '${pdu.password}')`
);
pdu.response({
command_status: smpp.ESME_RBINDFAIL,
});
session.close();
}
});
session.on("bind_receiver", function (pdu) {
if (pdu.system_id === options.systemid && pdu.password === options.password) {
sessionLogger.info("Client connected");
session.send(pdu.response());
startInterval(session, sessionLogger);
} else {
sessionLogger.warn(
`Client tried to connect with incorrect login ('${pdu.system_id}' '${pdu.password}')`
);
pdu.response({
command_status: smpp.ESME_RBINDFAIL,
});
session.close();
}
});
session.on("enquire_link", function (pdu) {
session.send(pdu.response());
});

View File

@@ -38,6 +38,7 @@ let sent = 0;
let success = 0;
let failed = 0;
const sendTimer = new NanoTimer();
const metricManager = new MetricManager(options);
function startInterval(session, sessionLogger, metrics) {
if (!metrics.progress && options.bars === true) {
@@ -95,8 +96,6 @@ function startInterval(session, sessionLogger, metrics) {
);
}
const metricManager = new MetricManager(options);
for (let i = 0; i < options.sessions; i++) {
const sessionLogger = createSessionLogger(options, i);
sessionLogger.info(`Connecting to ${options.host}:${options.port}...`);