Add source and desitnation set processors
This commit is contained in:
@@ -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
3
pnpm-lock.yaml
generated
@@ -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
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -20,106 +20,112 @@ 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[];
|
||||||
static postprocessors: PduProcessor[];
|
static postprocessors: PduProcessor[];
|
||||||
private static readonly logger: Logger = new Logger(this.name);
|
private static readonly logger: Logger = new Logger(this.name);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// This is an IDIOTIC solution, but it works
|
// This is an IDIOTIC solution, but it works
|
||||||
// Try running eb22a43 to find out what's wrong with the previous approach
|
// Try running eb22a43 to find out what's wrong with the previous approach
|
||||||
ProcessorManager.postprocessors = [
|
ProcessorManager.postprocessors = [
|
||||||
new EnquireLinkReplyProcessor(Center.name),
|
new EnquireLinkReplyProcessor(Center.name),
|
||||||
new DeliverSmReplyProcessor(Client.name),
|
new DeliverSmReplyProcessor(Client.name),
|
||||||
new SubmitSmReplyProcessor(Center.name),
|
new SubmitSmReplyProcessor(Center.name),
|
||||||
new BindTranscieverReplyProcessor(Center.name),
|
new BindTranscieverReplyProcessor(Center.name),
|
||||||
new EchoPduProcessor(Center.name),
|
new EchoPduProcessor(Center.name),
|
||||||
new DeliveryReceiptProcessor(Center.name)
|
new DeliveryReceiptProcessor(Center.name)
|
||||||
];
|
];
|
||||||
ProcessorManager.preprocessors = [
|
ProcessorManager.preprocessors = [
|
||||||
new DestinationEnumeratorProcessor(Client.name),
|
new DestinationEnumeratorProcessor(Client.name),
|
||||||
new SourceEnumeratorProcessor(Client.name),
|
new SourceEnumeratorProcessor(Client.name),
|
||||||
new DestinationEnumeratorProcessor(Center.name),
|
new DestinationEnumeratorProcessor(Center.name),
|
||||||
new SourceEnumeratorProcessor(Center.name),
|
new SourceEnumeratorProcessor(Center.name),
|
||||||
new DeliveryReceiptRequestProcessor(Client.name),
|
new DeliveryReceiptRequestProcessor(Client.name),
|
||||||
new LongSmsProcessor(Client.name),
|
new LongSmsProcessor(Client.name),
|
||||||
new LongSmsProcessor(Center.name),
|
new LongSmsProcessor(Center.name),
|
||||||
new ProtocolIdProcessor(Client.name),
|
new ProtocolIdProcessor(Client.name),
|
||||||
new ProtocolIdProcessor(Center.name),
|
new ProtocolIdProcessor(Center.name),
|
||||||
new UCS2Preprocessor(Client.name),
|
new UCS2Preprocessor(Client.name),
|
||||||
new UCS2Preprocessor(Center.name),
|
new UCS2Preprocessor(Center.name),
|
||||||
new ProtocolId2DigitProcessor(Client.name),
|
new ProtocolId2DigitProcessor(Client.name),
|
||||||
new ProtocolId2DigitProcessor(Center.name),
|
new ProtocolId2DigitProcessor(Center.name),
|
||||||
new ProtocolId3DigitProcessor(Client.name),
|
new ProtocolId3DigitProcessor(Client.name),
|
||||||
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)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
static get processors(): PduProcessor[] {
|
static get processors(): PduProcessor[] {
|
||||||
return this.preprocessors.concat(this.postprocessors);
|
return this.preprocessors.concat(this.postprocessors);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getProcessors(name: string): PduProcessor[] {
|
static getProcessors(name: string): PduProcessor[] {
|
||||||
this.logger.log1(`Looking for processor with name ${name}...`);
|
this.logger.log1(`Looking for processor with name ${name}...`);
|
||||||
let pduProcessors: PduProcessor[] = this.processors.filter((processor: PduProcessor) => processor.name === name);
|
let pduProcessors: PduProcessor[] = this.processors.filter((processor: PduProcessor) => processor.name === name);
|
||||||
this.logger.log1(`Found ${pduProcessors.length} processor(s) with name ${name}`);
|
this.logger.log1(`Found ${pduProcessors.length} processor(s) with name ${name}`);
|
||||||
return pduProcessors;
|
return pduProcessors;
|
||||||
}
|
}
|
||||||
|
|
||||||
static attachProcessors(session: SmppSession, processors: PduProcessor[]): void {
|
static attachProcessors(session: SmppSession, processors: PduProcessor[]): void {
|
||||||
this.logger.log1(`Trying to attach processor ${processors.toString()} to session ${session.constructor.name}-${session.id}`);
|
this.logger.log1(`Trying to attach processor ${processors.toString()} to session ${session.constructor.name}-${session.id}`);
|
||||||
for (const processor of processors) {
|
for (const processor of processors) {
|
||||||
if (this.areCompatible(session, processor)) {
|
if (this.areCompatible(session, processor)) {
|
||||||
// This could be done a little better but this is OK for now
|
// This could be done a little better but this is OK for now
|
||||||
switch (processor.type) {
|
switch (processor.type) {
|
||||||
case Preprocessor.name:
|
case Preprocessor.name:
|
||||||
session.attachPreprocessor(processor);
|
session.attachPreprocessor(processor);
|
||||||
break;
|
break;
|
||||||
case Postprocessor.name:
|
case Postprocessor.name:
|
||||||
session.attachPostprocessor(processor);
|
session.attachPostprocessor(processor);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.logger.log1(`Processor ${processor.name} is not a preprocessor or a postprocessor`);
|
this.logger.log1(`Processor ${processor.name} is not a preprocessor or a postprocessor`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static detachProcessors(session: SmppSession, processors: PduProcessor[]): void {
|
static detachProcessors(session: SmppSession, processors: PduProcessor[]): void {
|
||||||
this.logger.log1(`Trying to detach processors ${processors.toString()} from session ${session.constructor.name}-${session.id}`);
|
this.logger.log1(`Trying to detach processors ${processors.toString()} from session ${session.constructor.name}-${session.id}`);
|
||||||
for (const processor of processors) {
|
for (const processor of processors) {
|
||||||
switch (processor.type) {
|
switch (processor.type) {
|
||||||
case Preprocessor.name:
|
case Preprocessor.name:
|
||||||
session.detachPreprocessor(processor);
|
session.detachPreprocessor(processor);
|
||||||
break;
|
break;
|
||||||
case Postprocessor.name:
|
case Postprocessor.name:
|
||||||
session.detachPostprocessor(processor);
|
session.detachPostprocessor(processor);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.logger.log1(`Processor ${processor.name} is not a preprocessor or a postprocessor`);
|
this.logger.log1(`Processor ${processor.name} is not a preprocessor or a postprocessor`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static areCompatible(session: SmppSession, processor: PduProcessor): boolean {
|
static areCompatible(session: SmppSession, processor: PduProcessor): boolean {
|
||||||
this.logger.log1(`Checking compatibility between session ${session.constructor.name}-${session.id} and processor ${processor.name}`);
|
this.logger.log1(`Checking compatibility between session ${session.constructor.name}-${session.id} and processor ${processor.name}`);
|
||||||
return session.constructor.name === processor.sessionType;
|
return session.constructor.name === processor.sessionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getProcessorsForType(type: string): PduProcessor[] {
|
static getProcessorsForType(type: string): PduProcessor[] {
|
||||||
return this.processors.filter((processor: PduProcessor) => processor.sessionType === type);
|
return this.processors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getPreprocessorsForType(type: string): PduProcessor[] {
|
static getPreprocessorsForType(type: string): PduProcessor[] {
|
||||||
return this.preprocessors.filter((processor: PduProcessor) => processor.sessionType === type);
|
return this.preprocessors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getPostprocessorsForType(type: string): PduProcessor[] {
|
static getPostprocessorsForType(type: string): PduProcessor[] {
|
||||||
return this.postprocessors.filter((processor: PduProcessor) => processor.sessionType === type);
|
return this.postprocessors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
||||||
|
Reference in New Issue
Block a user