Add source and desitnation set processors
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
"nanotimer": "^0.3.15",
|
||||
"smpp": "0.6.0-rc.4",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.1.3",
|
||||
"ws": "^8.13.0",
|
||||
"zlib": "^1.0.5"
|
||||
}
|
||||
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -26,6 +26,9 @@ dependencies:
|
||||
ts-node:
|
||||
specifier: ^10.9.1
|
||||
version: 10.9.1(@types/node@20.2.5)(typescript@5.1.3)
|
||||
typescript:
|
||||
specifier: ^5.1.3
|
||||
version: 5.1.3
|
||||
ws:
|
||||
specifier: ^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 ProtocolId3DigitProcessor from "./Preprocessor/Client/ProtocolId-3Digit-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 {
|
||||
static preprocessors: PduProcessor[];
|
||||
static postprocessors: PduProcessor[];
|
||||
private static readonly logger: Logger = new Logger(this.name);
|
||||
static preprocessors: PduProcessor[];
|
||||
static postprocessors: PduProcessor[];
|
||||
private static readonly logger: Logger = new Logger(this.name);
|
||||
|
||||
constructor() {
|
||||
// This is an IDIOTIC solution, but it works
|
||||
// Try running eb22a43 to find out what's wrong with the previous approach
|
||||
ProcessorManager.postprocessors = [
|
||||
new EnquireLinkReplyProcessor(Center.name),
|
||||
new DeliverSmReplyProcessor(Client.name),
|
||||
new SubmitSmReplyProcessor(Center.name),
|
||||
new BindTranscieverReplyProcessor(Center.name),
|
||||
new EchoPduProcessor(Center.name),
|
||||
new DeliveryReceiptProcessor(Center.name)
|
||||
];
|
||||
ProcessorManager.preprocessors = [
|
||||
new DestinationEnumeratorProcessor(Client.name),
|
||||
new SourceEnumeratorProcessor(Client.name),
|
||||
new DestinationEnumeratorProcessor(Center.name),
|
||||
new SourceEnumeratorProcessor(Center.name),
|
||||
new DeliveryReceiptRequestProcessor(Client.name),
|
||||
new LongSmsProcessor(Client.name),
|
||||
new LongSmsProcessor(Center.name),
|
||||
new ProtocolIdProcessor(Client.name),
|
||||
new ProtocolIdProcessor(Center.name),
|
||||
new UCS2Preprocessor(Client.name),
|
||||
new UCS2Preprocessor(Center.name),
|
||||
new ProtocolId2DigitProcessor(Client.name),
|
||||
new ProtocolId2DigitProcessor(Center.name),
|
||||
new ProtocolId3DigitProcessor(Client.name),
|
||||
new ProtocolId3DigitProcessor(Center.name),
|
||||
new ProtocolId4DigitProcessor(Client.name),
|
||||
new ProtocolId4DigitProcessor(Center.name),
|
||||
];
|
||||
}
|
||||
constructor() {
|
||||
// This is an IDIOTIC solution, but it works
|
||||
// Try running eb22a43 to find out what's wrong with the previous approach
|
||||
ProcessorManager.postprocessors = [
|
||||
new EnquireLinkReplyProcessor(Center.name),
|
||||
new DeliverSmReplyProcessor(Client.name),
|
||||
new SubmitSmReplyProcessor(Center.name),
|
||||
new BindTranscieverReplyProcessor(Center.name),
|
||||
new EchoPduProcessor(Center.name),
|
||||
new DeliveryReceiptProcessor(Center.name)
|
||||
];
|
||||
ProcessorManager.preprocessors = [
|
||||
new DestinationEnumeratorProcessor(Client.name),
|
||||
new SourceEnumeratorProcessor(Client.name),
|
||||
new DestinationEnumeratorProcessor(Center.name),
|
||||
new SourceEnumeratorProcessor(Center.name),
|
||||
new DeliveryReceiptRequestProcessor(Client.name),
|
||||
new LongSmsProcessor(Client.name),
|
||||
new LongSmsProcessor(Center.name),
|
||||
new ProtocolIdProcessor(Client.name),
|
||||
new ProtocolIdProcessor(Center.name),
|
||||
new UCS2Preprocessor(Client.name),
|
||||
new UCS2Preprocessor(Center.name),
|
||||
new ProtocolId2DigitProcessor(Client.name),
|
||||
new ProtocolId2DigitProcessor(Center.name),
|
||||
new ProtocolId3DigitProcessor(Client.name),
|
||||
new ProtocolId3DigitProcessor(Center.name),
|
||||
new ProtocolId4DigitProcessor(Client.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[] {
|
||||
return this.preprocessors.concat(this.postprocessors);
|
||||
}
|
||||
static get processors(): PduProcessor[] {
|
||||
return this.preprocessors.concat(this.postprocessors);
|
||||
}
|
||||
|
||||
static getProcessors(name: string): PduProcessor[] {
|
||||
this.logger.log1(`Looking for processor with name ${name}...`);
|
||||
let pduProcessors: PduProcessor[] = this.processors.filter((processor: PduProcessor) => processor.name === name);
|
||||
this.logger.log1(`Found ${pduProcessors.length} processor(s) with name ${name}`);
|
||||
return pduProcessors;
|
||||
}
|
||||
static getProcessors(name: string): PduProcessor[] {
|
||||
this.logger.log1(`Looking for processor with name ${name}...`);
|
||||
let pduProcessors: PduProcessor[] = this.processors.filter((processor: PduProcessor) => processor.name === name);
|
||||
this.logger.log1(`Found ${pduProcessors.length} processor(s) with name ${name}`);
|
||||
return pduProcessors;
|
||||
}
|
||||
|
||||
static attachProcessors(session: SmppSession, processors: PduProcessor[]): void {
|
||||
this.logger.log1(`Trying to attach processor ${processors.toString()} to session ${session.constructor.name}-${session.id}`);
|
||||
for (const processor of processors) {
|
||||
if (this.areCompatible(session, processor)) {
|
||||
// This could be done a little better but this is OK for now
|
||||
switch (processor.type) {
|
||||
case Preprocessor.name:
|
||||
session.attachPreprocessor(processor);
|
||||
break;
|
||||
case Postprocessor.name:
|
||||
session.attachPostprocessor(processor);
|
||||
break;
|
||||
default:
|
||||
this.logger.log1(`Processor ${processor.name} is not a preprocessor or a postprocessor`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
static attachProcessors(session: SmppSession, processors: PduProcessor[]): void {
|
||||
this.logger.log1(`Trying to attach processor ${processors.toString()} to session ${session.constructor.name}-${session.id}`);
|
||||
for (const processor of processors) {
|
||||
if (this.areCompatible(session, processor)) {
|
||||
// This could be done a little better but this is OK for now
|
||||
switch (processor.type) {
|
||||
case Preprocessor.name:
|
||||
session.attachPreprocessor(processor);
|
||||
break;
|
||||
case Postprocessor.name:
|
||||
session.attachPostprocessor(processor);
|
||||
break;
|
||||
default:
|
||||
this.logger.log1(`Processor ${processor.name} is not a preprocessor or a postprocessor`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static detachProcessors(session: SmppSession, processors: PduProcessor[]): void {
|
||||
this.logger.log1(`Trying to detach processors ${processors.toString()} from session ${session.constructor.name}-${session.id}`);
|
||||
for (const processor of processors) {
|
||||
switch (processor.type) {
|
||||
case Preprocessor.name:
|
||||
session.detachPreprocessor(processor);
|
||||
break;
|
||||
case Postprocessor.name:
|
||||
session.detachPostprocessor(processor);
|
||||
break;
|
||||
default:
|
||||
this.logger.log1(`Processor ${processor.name} is not a preprocessor or a postprocessor`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
static detachProcessors(session: SmppSession, processors: PduProcessor[]): void {
|
||||
this.logger.log1(`Trying to detach processors ${processors.toString()} from session ${session.constructor.name}-${session.id}`);
|
||||
for (const processor of processors) {
|
||||
switch (processor.type) {
|
||||
case Preprocessor.name:
|
||||
session.detachPreprocessor(processor);
|
||||
break;
|
||||
case Postprocessor.name:
|
||||
session.detachPostprocessor(processor);
|
||||
break;
|
||||
default:
|
||||
this.logger.log1(`Processor ${processor.name} is not a preprocessor or a postprocessor`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static areCompatible(session: SmppSession, processor: PduProcessor): boolean {
|
||||
this.logger.log1(`Checking compatibility between session ${session.constructor.name}-${session.id} and processor ${processor.name}`);
|
||||
return session.constructor.name === processor.sessionType;
|
||||
}
|
||||
static areCompatible(session: SmppSession, processor: PduProcessor): boolean {
|
||||
this.logger.log1(`Checking compatibility between session ${session.constructor.name}-${session.id} and processor ${processor.name}`);
|
||||
return session.constructor.name === processor.sessionType;
|
||||
}
|
||||
|
||||
static getProcessorsForType(type: string): PduProcessor[] {
|
||||
return this.processors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||
}
|
||||
static getProcessorsForType(type: string): PduProcessor[] {
|
||||
return this.processors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||
}
|
||||
|
||||
static getPreprocessorsForType(type: string): PduProcessor[] {
|
||||
return this.preprocessors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||
}
|
||||
static getPreprocessorsForType(type: string): PduProcessor[] {
|
||||
return this.preprocessors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||
}
|
||||
|
||||
static getPostprocessorsForType(type: string): PduProcessor[] {
|
||||
return this.postprocessors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||
}
|
||||
static getPostprocessorsForType(type: string): PduProcessor[] {
|
||||
return this.postprocessors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ function cleanup(): void {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
process.on('exit', cleanup);
|
||||
process.on('SIGINT', cleanup);
|
||||
process.on('SIGUSR1', cleanup);
|
||||
process.on('SIGUSR2', cleanup);
|
||||
// process.on('exit', cleanup);
|
||||
// process.on('SIGINT', cleanup);
|
||||
// process.on('SIGUSR1', cleanup);
|
||||
// process.on('SIGUSR2', cleanup);
|
||||
|
Reference in New Issue
Block a user