Add source and desitnation set processors

This commit is contained in:
2023-06-07 13:49:39 +02:00
parent a1e7d3f885
commit a18ac0355c
6 changed files with 185 additions and 95 deletions

View File

@@ -19,6 +19,7 @@
"nanotimer": "^0.3.15", "nanotimer": "^0.3.15",
"smpp": "0.6.0-rc.4", "smpp": "0.6.0-rc.4",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^5.1.3",
"ws": "^8.13.0", "ws": "^8.13.0",
"zlib": "^1.0.5" "zlib": "^1.0.5"
} }

3
pnpm-lock.yaml generated
View File

@@ -26,6 +26,9 @@ dependencies:
ts-node: ts-node:
specifier: ^10.9.1 specifier: ^10.9.1
version: 10.9.1(@types/node@20.2.5)(typescript@5.1.3) version: 10.9.1(@types/node@20.2.5)(typescript@5.1.3)
typescript:
specifier: ^5.1.3
version: 5.1.3
ws: ws:
specifier: ^8.13.0 specifier: ^8.13.0
version: 8.13.0 version: 8.13.0

View File

@@ -0,0 +1,40 @@
import SmppSession from "../../../SmppSession";
import Preprocessor from "../Preprocessor";
import {PDU} from "../../../CommonObjects";
export default class DestinationSetPreprocessor extends Preprocessor {
applicableCommands: string[] = ['submit_sm', 'deliver_sm'];
private sourceSet: string[] = [];
constructor(type: string) {
super(type);
while (this.sourceSet.length < 100) {
this.sourceSet.push(this.getRandomInt(100000, 999999).toString());
}
}
protected doProcess(session: any, pdu: PDU, entity?: SmppSession | undefined): Promise<any> {
return new Promise<any>((resolve, reject) => {
if (pdu.short_message) {
if (pdu.short_message.includes("arg:")) {
let temp: string = pdu.short_message.split(";");
let arg: number = Number(temp[0].split(":")[1]);
while (this.sourceSet.length < arg) {
this.sourceSet.push(this.getRandomInt(100000, 999999).toString());
}
while (this.sourceSet.length > arg) {
this.sourceSet.pop();
}
pdu.short_message = temp[1];
}
}
pdu.destination_addr = pdu.destination_addr + this.sourceSet[this.getRandomInt(0, this.sourceSet.length)];
});
}
private getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
}
}

View File

@@ -0,0 +1,40 @@
import SmppSession from "../../../SmppSession";
import Preprocessor from "../Preprocessor";
import {PDU} from "../../../CommonObjects";
export default class SourceSetPreprocessor extends Preprocessor {
applicableCommands: string[] = ['submit_sm', 'deliver_sm'];
private sourceSet: string[] = [];
constructor(type: string) {
super(type);
while (this.sourceSet.length < 100) {
this.sourceSet.push(this.getRandomInt(100000, 999999).toString());
}
}
protected doProcess(session: any, pdu: PDU, entity?: SmppSession | undefined): Promise<any> {
return new Promise<any>((resolve, reject) => {
if (pdu.short_message) {
if (pdu.short_message.includes("arg:")) {
let temp: string = pdu.short_message.split(";");
let arg: number = Number(temp[0].split(":")[1]);
while (this.sourceSet.length < arg) {
this.sourceSet.push(this.getRandomInt(100000, 999999).toString());
}
while (this.sourceSet.length > arg) {
this.sourceSet.pop();
}
pdu.short_message = temp[1];
}
}
pdu.source_addr = pdu.source_addr + this.sourceSet[this.getRandomInt(0, this.sourceSet.length)];
});
}
private getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
}
}

View File

@@ -20,6 +20,8 @@ import UCS2Preprocessor from "./Preprocessor/Client/UCS2Preprocessor";
import ProtocolId2DigitProcessor from "./Preprocessor/Client/ProtocolId-2Digit-Processor"; import ProtocolId2DigitProcessor from "./Preprocessor/Client/ProtocolId-2Digit-Processor";
import ProtocolId3DigitProcessor from "./Preprocessor/Client/ProtocolId-3Digit-Processor"; import ProtocolId3DigitProcessor from "./Preprocessor/Client/ProtocolId-3Digit-Processor";
import ProtocolId4DigitProcessor from "./Preprocessor/Client/ProtocolId-4Digit-Processor"; import ProtocolId4DigitProcessor from "./Preprocessor/Client/ProtocolId-4Digit-Processor";
import SourceSetPreprocessor from "./Preprocessor/Client/SourceSetPreprocessor";
import DestinationSetPreprocessor from "./Preprocessor/Client/DestinationSetPreprocessor";
export default class ProcessorManager { export default class ProcessorManager {
static preprocessors: PduProcessor[]; static preprocessors: PduProcessor[];
@@ -55,6 +57,10 @@ export default class ProcessorManager {
new ProtocolId3DigitProcessor(Center.name), new ProtocolId3DigitProcessor(Center.name),
new ProtocolId4DigitProcessor(Client.name), new ProtocolId4DigitProcessor(Client.name),
new ProtocolId4DigitProcessor(Center.name), new ProtocolId4DigitProcessor(Center.name),
new SourceSetPreprocessor(Client.name),
new SourceSetPreprocessor(Center.name),
new DestinationSetPreprocessor(Client.name),
new DestinationSetPreprocessor(Center.name)
]; ];
} }

View File

@@ -23,7 +23,7 @@ function cleanup(): void {
process.exit(0); process.exit(0);
} }
process.on('exit', cleanup); // process.on('exit', cleanup);
process.on('SIGINT', cleanup); // process.on('SIGINT', cleanup);
process.on('SIGUSR1', cleanup); // process.on('SIGUSR1', cleanup);
process.on('SIGUSR2', cleanup); // process.on('SIGUSR2', cleanup);