Finally make the stupid pre/post processors work

This commit is contained in:
David Majdandžić
2023-04-05 17:19:53 +02:00
parent 7a4aa1eb9c
commit d032239105
9 changed files with 58 additions and 19 deletions

View File

@@ -1,11 +1,16 @@
import {PDU} from "../CommonObjects"; import {PDU} from "../CommonObjects";
import Logger from "../Logger"; import Logger from "../Logger";
import SmppSession from "../SmppSession";
export default abstract class PduProcessor { export default abstract class PduProcessor {
abstract readonly serverSessionType: string; readonly serverSessionType: string;
readonly name: string = this.constructor.name; readonly name: string = this.constructor.name;
readonly logger: Logger = new Logger(`PduProcessor: ${this.name}`); readonly logger: Logger = new Logger(`PduProcessor: ${this.name}`);
constructor(type: string) {
this.serverSessionType = type;
}
abstract processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any>; abstract processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any>;
serialize(): object { serialize(): object {

View File

@@ -1,9 +1,14 @@
import Center from "../../../Center/Center"; import Center from "../../../Center/Center";
import Client from "../../../Client/Client";
import {PDU} from "../../../CommonObjects"; import {PDU} from "../../../CommonObjects";
import SmppSession from "../../../SmppSession";
import Postprocessor from "../Postprocessor"; import Postprocessor from "../Postprocessor";
export default class DebugPduProcessor extends Postprocessor { export default class DebugPduProcessor extends Postprocessor {
serverSessionType: string = Center.name; constructor(type: string) {
super(type);
console.log(this.serverSessionType);
}
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> { processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {

View File

@@ -1,11 +1,15 @@
import Center from "../../../Center/Center"; import Center from "../../../Center/Center";
import {PDU} from "../../../CommonObjects"; import {PDU} from "../../../CommonObjects";
import SmppSession from "../../../SmppSession";
import Postprocessor from "../Postprocessor"; import Postprocessor from "../Postprocessor";
const smpp = require("smpp"); const smpp = require("smpp");
export default class EchoPduProcessor extends Postprocessor { export default class EchoPduProcessor extends Postprocessor {
serverSessionType: string = Center.name; constructor(type: string) {
super(type);
console.log(this.serverSessionType);
}
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> { processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {

View File

@@ -1,9 +1,13 @@
import Client from "../../../Client/Client"; import Client from "../../../Client/Client";
import {PDU} from "../../../CommonObjects"; import {PDU} from "../../../CommonObjects";
import SmppSession from "../../../SmppSession";
import Postprocessor from "../Postprocessor"; import Postprocessor from "../Postprocessor";
export default class DeliverSmReplyProcessor extends Postprocessor { export default class DeliverSmReplyProcessor extends Postprocessor {
serverSessionType: string = Client.name; constructor(type: string) {
super(type);
console.log(this.serverSessionType);
}
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> { processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {

View File

@@ -1,10 +1,14 @@
import Client from "../../../Client/Client"; import Client from "../../../Client/Client";
import {PDU} from "../../../CommonObjects"; import {PDU} from "../../../CommonObjects";
import SmppSession from "../../../SmppSession";
import Preprocessor from "../Preprocessor"; import Preprocessor from "../Preprocessor";
export default class DestinationEnumeratorProcessor extends Preprocessor { export default class DestinationEnumeratorProcessor extends Preprocessor {
serverSessionType: string = Client.name; private iterator: number = 0;
private iterator = 0; constructor(type: string) {
super(type);
console.log(this.serverSessionType);
}
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> { processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {

View File

@@ -1,10 +1,14 @@
import Client from "../../../Client/Client"; import Client from "../../../Client/Client";
import {PDU} from "../../../CommonObjects"; import {PDU} from "../../../CommonObjects";
import SmppSession from "../../../SmppSession";
import Preprocessor from "../Preprocessor"; import Preprocessor from "../Preprocessor";
export default class SourceEnumeratorProcessor extends Preprocessor { export default class SourceEnumeratorProcessor extends Preprocessor {
serverSessionType: string = Client.name; private iterator: number = 0;
private iterator = 0; constructor(type: string) {
super(type);
console.log(this.serverSessionType);
}
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> { processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {

View File

@@ -1,3 +1,5 @@
import Center from "../Center/Center";
import Client from "../Client/Client";
import Logger from "../Logger"; import Logger from "../Logger";
import SmppSession from "../SmppSession"; import SmppSession from "../SmppSession";
import PduProcessor from "./PduProcessor"; import PduProcessor from "./PduProcessor";
@@ -8,18 +10,22 @@ import DestinationEnumeratorProcessor from "./Preprocessor/Client/DestinationEnu
import SourceEnumeratorProcessor from "./Preprocessor/Client/SourceEnumeratorProcessor"; import SourceEnumeratorProcessor from "./Preprocessor/Client/SourceEnumeratorProcessor";
export default class ProcessorManager { export default class ProcessorManager {
static readonly preprocessors: PduProcessor[] = [ static preprocessors: PduProcessor[];
new DestinationEnumeratorProcessor(), static postprocessors: PduProcessor[];
new SourceEnumeratorProcessor()
];
static readonly postprocessors: PduProcessor[] = [
new DebugPduProcessor(),
new EchoPduProcessor(),
new DeliverSmReplyProcessor(),
];
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
// Try running eb22a43 to find out what's wrong with the previous approach
ProcessorManager.preprocessors = [
new DestinationEnumeratorProcessor(Client.name),
new SourceEnumeratorProcessor(Client.name)
];
ProcessorManager.postprocessors = [
new DebugPduProcessor(Center.name),
new EchoPduProcessor(Center.name),
new DeliverSmReplyProcessor(Center.name),
];
} }
static get processors(): PduProcessor[] { static get processors(): PduProcessor[] {

View File

@@ -6,7 +6,7 @@ const WebSocket = require("ws");
const WS_SERVER_PORT: number = Number(process.env.WS_SERVER_PORT) || 8191; const WS_SERVER_PORT: number = Number(process.env.WS_SERVER_PORT) || 8191;
export class WSServer { export default class WSServer {
private readonly clients: ClientSet[]; private readonly clients: ClientSet[];
private readonly unknownClients: any[]; private readonly unknownClients: any[];
private readonly server: any; private readonly server: any;

View File

@@ -3,17 +3,20 @@ import CenterSessionManager from "./Center/CenterSessionManager";
import Client from "./Client/Client"; import Client from "./Client/Client";
import ClientSessionManager from "./Client/ClientSessionManager"; import ClientSessionManager from "./Client/ClientSessionManager";
import Logger from "./Logger"; import Logger from "./Logger";
import ProcessorManager from "./PDUProcessor/ProcessorManager";
import WSServer from "./WS/WSServer";
const {PDU} = require("smpp"); const {PDU} = require("smpp");
let logger = new Logger("main"); let logger = new Logger("main");
new ProcessorManager();
let clientManager: ClientSessionManager = new ClientSessionManager(); let clientManager: ClientSessionManager = new ClientSessionManager();
let centerManager: CenterSessionManager = new CenterSessionManager(); let centerManager: CenterSessionManager = new CenterSessionManager();
// TODO: Add support for encodings // TODO: Add support for encodings
// TODO: Fix reading and writing processors // TODO: Fix reading and writing processors
// TODO: Try creating multiple entries with the same arg // TODO: Try creating multiple entries with the same arg
// let wss: WSServer = new WSServer([clientManager, centerManager]); let wss: WSServer = new WSServer([clientManager, centerManager]);
// let httpServer: HttpServer = new HttpServer(clientManager, centerManager); // let httpServer: HttpServer = new HttpServer(clientManager, centerManager);
function cleanup(): void { function cleanup(): void {
@@ -38,6 +41,10 @@ async function main() {
} }
// main(); // main();
console.log(ProcessorManager);
// console.log(ProcessorManager.getProcessorsForType(Center.name));
// console.log(ProcessorManager.processors);
console.log("OK");
// process.on('exit', cleanup); // process.on('exit', cleanup);
// process.on('SIGINT', cleanup); // process.on('SIGINT', cleanup);