Refuse to answer a message whose link went, instead of reporting it delivered
This commit is contained in:
+2
-2
@@ -120,8 +120,8 @@ export class DlrMerger {
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.groups.clear();
|
||||
this.spent.clear();
|
||||
this.groups.takeAll();
|
||||
this.spent.takeAll();
|
||||
}
|
||||
|
||||
/** Drops every group past its deadline. Runs before each collect and on its own timer. */
|
||||
|
||||
@@ -58,9 +58,14 @@ export class ExpiringGroups<T> {
|
||||
this.idle();
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
/** Removes every group and hands them over. */
|
||||
takeAll(): [string, T][] {
|
||||
const taken: [string, T][] = [...this.entries].map(([key, entry]) => [key, entry.group]);
|
||||
|
||||
this.entries.clear();
|
||||
this.idle();
|
||||
|
||||
return taken;
|
||||
}
|
||||
|
||||
/** Removes every group past its deadline and hands them over. */
|
||||
|
||||
+10
-1
@@ -20,6 +20,7 @@ function keyOf(pduObjs: PduObject[]): string | undefined {
|
||||
|
||||
/** The messages handed to the application that it has not answered yet, held by their segments. */
|
||||
export class HeldMessages {
|
||||
private readonly droppedWithLink = new WeakSet<PduObject[]>();
|
||||
private readonly held: ExpiringGroups<PduObject[]>;
|
||||
private readonly idleWaiters = new IdleWaiters();
|
||||
private readonly log: SmppLog;
|
||||
@@ -64,6 +65,11 @@ export class HeldMessages {
|
||||
return key !== undefined && this.held.get(key) === pduObjs;
|
||||
}
|
||||
|
||||
/** Whether this message's link went before it was answered, so no answer of ours correlates. */
|
||||
lostLink(pduObjs: PduObject[]): boolean {
|
||||
return this.droppedWithLink.has(pduObjs);
|
||||
}
|
||||
|
||||
release(pduObjs: PduObject[]): void {
|
||||
const key = keyOf(pduObjs);
|
||||
|
||||
@@ -76,7 +82,10 @@ export class HeldMessages {
|
||||
|
||||
/** Drops every message: their segments went with the link, so no answer of ours correlates now. */
|
||||
clear(): void {
|
||||
this.held.clear();
|
||||
for (const [, pduObjs] of this.held.takeAll()) {
|
||||
this.droppedWithLink.add(pduObjs);
|
||||
}
|
||||
|
||||
this.idleWaiters.settle();
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +170,7 @@ export class IncomingRequests {
|
||||
session: this.session,
|
||||
to: paramText(first.params.destination_addr),
|
||||
}, {
|
||||
lostLink: () => this.held.lostLink(pduObjs),
|
||||
// A turn later, so a listener sending its receipt straight after the response still holds.
|
||||
onAnswered: () => { setImmediate(() => { this.held.release(pduObjs); }); },
|
||||
// Past the refusal only while a drain is still waiting for this message; an ordinary send after.
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ export class Reassembler {
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.groups.clear();
|
||||
this.groups.takeAll();
|
||||
this.octets = 0;
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -54,6 +54,8 @@ export type SmsInput = {
|
||||
|
||||
/** What the session's incoming side gives a message so it can be answered and accounted for. */
|
||||
export type SmsHandlers = {
|
||||
/** Whether the link this message arrived on is gone, so no answer of ours correlates. */
|
||||
lostLink: () => boolean;
|
||||
onAnswered: () => void;
|
||||
send: (input: PduObjectInput) => Promise<Result<{ pduObj: PduObject }>>;
|
||||
};
|
||||
@@ -76,7 +78,8 @@ export function createSms(input: SmsInput, handlers: SmsHandlers): Sms {
|
||||
message: input.message,
|
||||
pduObjs: input.pduObjs,
|
||||
sendDlr: status => sendDlr(sms, handlers.send, status),
|
||||
sendResp: options => sendResp(sms, answered, options ?? {}).finally(handlers.onAnswered),
|
||||
sendResp: options => sendResp(sms, answered, options ?? {}, handlers.lostLink)
|
||||
.finally(handlers.onAnswered),
|
||||
session: input.session,
|
||||
get smsId(): string {
|
||||
return answered.smsId;
|
||||
@@ -92,6 +95,7 @@ async function sendResp(
|
||||
sms: Sms,
|
||||
answered: { smsId: string },
|
||||
options: SendRespOptions,
|
||||
lostLink: () => boolean,
|
||||
): Promise<VoidResult> {
|
||||
const total = sms.pduObjs.length;
|
||||
|
||||
@@ -103,6 +107,11 @@ async function sendResp(
|
||||
return { err: new Error('smsId must not be empty') };
|
||||
}
|
||||
|
||||
// A response carries the sequence number it was asked on, which the next link knows nothing about.
|
||||
if (lostLink()) {
|
||||
return { err: new Error('The link this message arrived on is gone, so nothing would correlate the response') };
|
||||
}
|
||||
|
||||
if (options.smsId !== undefined) answered.smsId = options.smsId;
|
||||
|
||||
const results = await Promise.all(sms.pduObjs.map((pduObj, index) => sms.session.sendReturn(
|
||||
|
||||
Reference in New Issue
Block a user