feat(core): Java's IP and ICMP threads, measured with Java FILIUS

Every packet that comes in goes through its node's IP thread (UDP, TCP) or
ICMP thread (ICMP), as Java's IPThread and ICMPThread: deliver, answer an
echo request or forward, one after the other; while one waits for ARP, the
next wait behind it. A packet a node sends to itself is delivered at once,
as Java's IP.senden does. The transport send threads and these are one
mechanism now (handToProtocolThread).

ArpRun has three stories through the router (routedUdpBehind,
routedPingBesideUdp, routedPingBehindPing); the oracle writes ICMP frames
with type, code, addresses and sequence number. All seven ArpRun stories
match Java FILIUS.

Measured and not taken: Java's ARP wakes one waiter with notify, not the
one whose answer came; the core wakes all that wait for the address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 18:32:48 +00:00
co-authored by Claude Opus 5.5
parent 7e0348636c
commit f5c61cdce7
13 changed files with 950 additions and 97 deletions
+20 -8
View File
@@ -41,6 +41,7 @@ export interface JavaFrame {
destinationPort?: number;
payload?: string | null;
icmp?: number;
icmpCode?: number;
tcpFlags?: string;
sequence?: number;
acknowledgement?: number;
@@ -54,7 +55,7 @@ export interface SeenFrame {
function javaText(frame: JavaFrame): string {
const macs = `${frame.source} > ${frame.destination}`.toUpperCase();
if (frame.arp !== undefined) return `${macs} ARP ${frame.arp === 1 ? 'request' : 'reply'} ${frame.senderIp} > ${frame.targetIp}`;
if (frame.icmp !== undefined) return `${macs} ICMP ${frame.icmp}`;
if (frame.icmp !== undefined) return icmpText(macs, frame.icmp, frame.icmpCode!, frame.sourceIp!, frame.destinationIp!, frame.sequence!);
const ends = `${frame.sourceIp}:${frame.sourcePort} > ${frame.destinationIp}:${frame.destinationPort}`;
if (frame.tcpFlags !== undefined) {
return `${macs} TCP ${ends} ${frame.tcpFlags || '-'} seq=${frame.sequence} ack=${frame.acknowledgement} length=${(frame.payload ?? '').length}`;
@@ -63,14 +64,21 @@ function javaText(frame: JavaFrame): string {
}
/** The ICMP type numbers Java logs. */
const ICMP_TYPES: Record<string, number> = {
echoReply: 0,
destinationNetworkUnreachable: 3,
destinationHostUnreachable: 3,
echoRequest: 8,
timeExceeded: 11,
/** Type and code of each ICMP message the engine knows. */
const ICMP_TYPES: Record<string, [number, number]> = {
echoReply: [0, 0],
destinationNetworkUnreachable: [3, 0],
destinationHostUnreachable: [3, 1],
echoRequest: [8, 0],
timeExceeded: [11, 0],
};
/** The sequence number only for echo messages: an error carries none of its own. */
function icmpText(macs: string, type: number, code: number, source: string, destination: string, sequence: number): string {
const echo = type === 0 || type === 8 ? ` seq=${sequence}` : '';
return `${macs} ICMP ${type}/${code} ${source} > ${destination}${echo}`;
}
const FLAG_LETTERS: [number, string][] = [
[TCP_FLAG.synchronize, 'S'],
[TCP_FLAG.acknowledgement, 'A'],
@@ -86,7 +94,11 @@ function engineText(frame: EthernetFrame): string {
return `${macs} ARP ${arp.operation} ${arp.senderIPAddress} > ${arp.targetIPAddress}`;
}
const packet = frame.payload.packet;
if (packet.payload.kind === 'icmp') return `${macs} ICMP ${ICMP_TYPES[packet.payload.message.kind]}`;
if (packet.payload.kind === 'icmp') {
const message = packet.payload.message;
const [type, code] = ICMP_TYPES[message.kind]!;
return icmpText(macs, type, code, packet.senderIPAddress, packet.receiverIPAddress, message.sequenceNumber);
}
if (packet.payload.kind === 'tcp') {
const segment = packet.payload.segment;
const flags = FLAG_LETTERS.filter(([bit]) => (segment.flags & bit) !== 0).map(([, letter]) => letter).join('');