Fix deleted centers not being deleted and do some work on delivery reports
This commit is contained in:
@@ -132,6 +132,7 @@ export default class Center extends SmppSession {
|
|||||||
close(): Promise<void> {
|
close(): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.logger.log1(`Center-${this.id} closing active connections`);
|
this.logger.log1(`Center-${this.id} closing active connections`);
|
||||||
|
this.server.close();
|
||||||
this.sessions.forEach((session: any) => {
|
this.sessions.forEach((session: any) => {
|
||||||
session.close();
|
session.close();
|
||||||
});
|
});
|
||||||
|
@@ -0,0 +1,58 @@
|
|||||||
|
import SmppSession from "../../../SmppSession";
|
||||||
|
import Postprocessor from "../Postprocessor";
|
||||||
|
|
||||||
|
const smpp = require("smpp");
|
||||||
|
|
||||||
|
export default class DeliveryReceiptProcessor extends Postprocessor {
|
||||||
|
constructor(type: string) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||||
|
return new Promise<any>((resolve, reject) => {
|
||||||
|
if (!!pdu.command && pdu.command === "submit_sm" && pdu.registered_delivery) {
|
||||||
|
session.send(pdu.response());
|
||||||
|
|
||||||
|
let DRPdu = new smpp.PDU('deliver_sm', {
|
||||||
|
source_addr: pdu.destination_addr,
|
||||||
|
destination_addr: pdu.source_addr,
|
||||||
|
short_message: pdu.short_message
|
||||||
|
});
|
||||||
|
console.log(pdu);
|
||||||
|
session.send(DRPdu);
|
||||||
|
|
||||||
|
resolve(pdu);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// private void sendDeliveryReceipt(Address mtDestinationAddress, Address mtSourceAddress, String messageId, String text) {
|
||||||
|
// SmppSession session = sessionRef.get();
|
||||||
|
//
|
||||||
|
// DeliverSm deliver = new DeliverSm();
|
||||||
|
// deliver.setEsmClass(SmppConstants.ESM_CLASS_MT_SMSC_DELIVERY_RECEIPT);
|
||||||
|
// deliver.setSourceAddress(mtSourceAddress);
|
||||||
|
// deliver.setDestAddress(mtDestinationAddress);
|
||||||
|
// deliver.setDataCoding(SmppConstants.DATA_CODING_GSM);
|
||||||
|
//
|
||||||
|
// DeliverReportStatus delivered = DeliverReportStatus.DELIVERED;
|
||||||
|
//
|
||||||
|
// DeliveryReceipt deliveryReceipt = new DeliveryReceipt();
|
||||||
|
// deliveryReceipt.setDeliveredCount(1);
|
||||||
|
// deliveryReceipt.setDoneDate(DateTime.now());
|
||||||
|
// deliveryReceipt.setRawErrorCode(delivered.getErrorCode());
|
||||||
|
// deliveryReceipt.setMessageId(messageId);
|
||||||
|
// deliveryReceipt.setStateText(delivered.getStateText());
|
||||||
|
// deliveryReceipt.setSubmitCount(1);
|
||||||
|
// deliveryReceipt.setSubmitDate(DateTime.now());
|
||||||
|
// deliveryReceipt.setText(text);
|
||||||
|
// try {
|
||||||
|
// deliver.setShortMessage(deliveryReceipt.toShortMessage().getBytes());
|
||||||
|
// } catch (SmppInvalidArgumentException e) {
|
||||||
|
// //should not be reached
|
||||||
|
// //ignore
|
||||||
|
// }
|
||||||
|
// sendRequestPdu(session, deliver);
|
||||||
|
// }
|
@@ -0,0 +1,18 @@
|
|||||||
|
import SmppSession from "../../../SmppSession";
|
||||||
|
import Preprocessor from "../Preprocessor";
|
||||||
|
|
||||||
|
export default class DeliveryReceiptRequestProcessor extends Preprocessor {
|
||||||
|
private iterator: number = 0;
|
||||||
|
|
||||||
|
constructor(type: string) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||||
|
return new Promise<any>((resolve, reject) => {
|
||||||
|
if (!!pdu.command && pdu.command === "submit_sm") {
|
||||||
|
pdu.registered_delivery = 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -5,10 +5,12 @@ import SmppSession from "../SmppSession";
|
|||||||
import PduProcessor from "./PduProcessor";
|
import PduProcessor from "./PduProcessor";
|
||||||
import BindTranscieverReplyProcessor from "./Postprocessor/Center/BindTranscieverReplyProcessor";
|
import BindTranscieverReplyProcessor from "./Postprocessor/Center/BindTranscieverReplyProcessor";
|
||||||
import DebugPduProcessor from "./Postprocessor/Center/DebugPduProcessor";
|
import DebugPduProcessor from "./Postprocessor/Center/DebugPduProcessor";
|
||||||
|
import DeliveryReceiptProcessor from "./Postprocessor/Center/DeliveryReceiptProcessor";
|
||||||
import EchoPduProcessor from "./Postprocessor/Center/EchoPduProcessor";
|
import EchoPduProcessor from "./Postprocessor/Center/EchoPduProcessor";
|
||||||
import SubmitSmReplyProcessor from "./Postprocessor/Center/SubmitSmReplyProcessor";
|
import SubmitSmReplyProcessor from "./Postprocessor/Center/SubmitSmReplyProcessor";
|
||||||
import DeliverSmReplyProcessor from "./Postprocessor/Client/DeliverSmReplyProcessor";
|
import DeliverSmReplyProcessor from "./Postprocessor/Client/DeliverSmReplyProcessor";
|
||||||
import Postprocessor from "./Postprocessor/Postprocessor";
|
import Postprocessor from "./Postprocessor/Postprocessor";
|
||||||
|
import DeliveryReceiptRequestProcessor from "./Preprocessor/Client/DeliveryReceiptRequestProcessor";
|
||||||
import DestinationEnumeratorProcessor from "./Preprocessor/Client/DestinationEnumeratorProcessor";
|
import DestinationEnumeratorProcessor from "./Preprocessor/Client/DestinationEnumeratorProcessor";
|
||||||
import SourceEnumeratorProcessor from "./Preprocessor/Client/SourceEnumeratorProcessor";
|
import SourceEnumeratorProcessor from "./Preprocessor/Client/SourceEnumeratorProcessor";
|
||||||
import Preprocessor from "./Preprocessor/Preprocessor";
|
import Preprocessor from "./Preprocessor/Preprocessor";
|
||||||
@@ -21,16 +23,18 @@ export default class ProcessorManager {
|
|||||||
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.preprocessors = [
|
|
||||||
new DestinationEnumeratorProcessor(Client.name),
|
|
||||||
new SourceEnumeratorProcessor(Client.name)
|
|
||||||
];
|
|
||||||
ProcessorManager.postprocessors = [
|
ProcessorManager.postprocessors = [
|
||||||
new DebugPduProcessor(Center.name),
|
new DebugPduProcessor(Center.name),
|
||||||
new EchoPduProcessor(Center.name),
|
new EchoPduProcessor(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 DeliveryReceiptProcessor(Center.name)
|
||||||
|
];
|
||||||
|
ProcessorManager.preprocessors = [
|
||||||
|
new DestinationEnumeratorProcessor(Client.name),
|
||||||
|
new SourceEnumeratorProcessor(Client.name),
|
||||||
|
new DeliveryReceiptRequestProcessor(Client.name)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,6 +40,7 @@ export default abstract class SessionManager {
|
|||||||
removeSession(session: SmppSession): Promise<void> {
|
removeSession(session: SmppSession): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
this.logger.log1(`Removing session with id ${session.id}`);
|
this.logger.log1(`Removing session with id ${session.id}`);
|
||||||
|
session.close();
|
||||||
this.sessions = this.sessions.filter(s => s.id !== session.id);
|
this.sessions = this.sessions.filter(s => s.id !== session.id);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
@@ -50,7 +50,7 @@ async function main() {
|
|||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
||||||
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