// Ported from filius-ipad (GPLv2/GPLv3): // State/TopologyNetworkRuntimeEngine.swift (packet trace model) // Java counterpart: filius.rahmenprogramm.nachrichten.Lauscher — here every // step a frame or packet takes is one trace event; the packet viewer groups them. import type { Id } from '../ids.js'; export type TraceDirection = 'inbound' | 'outbound' | 'local'; export type TraceLayer = 'application' | 'transport' | 'network' | 'dataLink' | 'physical'; export type TraceOperation = | 'created' | 'sent' | 'received' | 'forwarded' | 'accepted' | 'dropped' | 'rewritten' | 'retransmitted' | 'compatibilityAdapter'; export interface HeaderField { readonly name: string; readonly value: string; } export interface TraceEvent { readonly id: number; readonly timeMilliseconds: number; readonly frameIdentity?: number; readonly packetIdentity?: number; readonly nodeId: Id; readonly interfaceId?: Id; readonly direction: TraceDirection; readonly layer: TraceLayer; readonly operation: TraceOperation; readonly beforeHeaders: readonly HeaderField[]; readonly afterHeaders: readonly HeaderField[]; readonly detail?: string; } /** How many trace events the runtime keeps, and how many it drops at once when full. */ export interface TraceRetentionPolicy { readonly maximumEventCount: number; readonly evictionBatchSize: number; } export function traceRetentionPolicy(maximumEventCount: number, evictionBatchSize: number): TraceRetentionPolicy { if (!(maximumEventCount > 0)) throw new RangeError('Packet-trace retention must keep at least one event'); if (!(evictionBatchSize > 0)) throw new RangeError('Packet-trace eviction must remove at least one event'); if (evictionBatchSize > maximumEventCount) { throw new RangeError('Packet-trace eviction cannot exceed the retention limit'); } return { maximumEventCount, evictionBatchSize }; } export const PRODUCTION_TRACE_RETENTION = traceRetentionPolicy(10_000, 1_000);