Stop a thrown listener escaping, bound what a peer can pin, and drop the body from failure responses

This commit is contained in:
2026-08-27 10:55:34 +02:00
parent 5af75a3c57
commit 884afdb87b
17 changed files with 420 additions and 87 deletions
+25 -1
View File
@@ -1,4 +1,5 @@
import type { Dlr } from './dlr.ts';
import type { MessageState } from './defs/constants.ts';
import type { LogInt } from '@larvit/log';
import { ExpiringGroups } from './expiring-groups.ts';
@@ -24,6 +25,29 @@ const numbered = /^(.*)-(\d+)$/;
* numbered its ids `<base>-<n>` off one base — the convention this library's own server follows. An
* SMSC that hands out unrelated ids per segment cannot be merged, so nothing is reported for it.
*/
/**
* MESSAGE_STATE is a flat enum, not a ranking — ACCEPTED is 6 where UNDELIVERABLE is 5 — so reducing
* on the wire value reports a part-failed message as delivered. Rank it deliberately instead.
*/
const severity: Record<MessageState, number> = {
DELIVERED: 0,
ACCEPTED: 1,
ENROUTE: 2,
SCHEDULED: 3,
SKIPPED: 4,
UNKNOWN: 5,
EXPIRED: 6,
DELETED: 7,
REJECTED: 8,
UNDELIVERABLE: 9,
};
function severityOf(dlr: Dlr): number {
const ranked: Record<string, number | undefined> = severity;
return ranked[dlr.statusMsg] ?? severity.UNKNOWN;
}
export class DlrMerger {
private readonly groups: ExpiringGroups<Group>;
private readonly log: LogInt;
@@ -86,7 +110,7 @@ export class DlrMerger {
this.groups.delete(base);
const segments = [...group.parts.entries()].sort(([a], [b]) => a - b).map(([, one]) => one);
const worst = segments.reduce((carry, one) => (one.statusId > carry.statusId ? one : carry));
const worst = segments.reduce((carry, one) => (severityOf(one) > severityOf(carry) ? one : carry));
return { ...worst, segments, smsId: base };
}