feat: F4.6g3 a computer's firewall window, measured against Java's with traffic from two networks

The firewall-pc scenario and FirewallWindowRun use Java's window as a person
does and send a ping, a TCP connection and a DNS question from the server's
network and from behind the router after each step. The core adds and
removes port rules (personalFirewall.ts) and writes both into the firewall's
log, which now carries each line's time; the room takes the window's
actions and sends its view and the log as lines; the editor shows Java's
window with its two tabs. Not adopted from Java: any integer as a port,
a port after a space refused without a word, a log one can type into.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-03 21:18:05 +00:00
co-authored by Claude Opus 5.5
parent 065b42430d
commit 2b85e7432c
25 changed files with 2092 additions and 19 deletions
+38 -8
View File
@@ -124,6 +124,8 @@ import { EmailServer } from './apps/emailServer.js';
import { Terminal } from './apps/terminal.js';
import { firewallLogPage, forwardingTablePage, ripTablePage, routerIndexPage } from './apps/routerPages.js';
import { applyFirewallSettings, firewallSettingsPage } from './apps/firewallSettings.js';
import { withoutRule, withPortRule, type PortRuleProtocol } from './apps/personalFirewall.js';
import type { LogLine } from './apps/program.js';
import { parentPath, VirtualFileSystem } from '../model/virtualFileSystem.js';
import { clientAccountFileText, EMAIL_CLIENT_ACCOUNT_FILE, EMAIL_SERVER_ACCOUNTS_FILE, serverAccountsFileText } from './emailAccountsFile.js';
import { GNUTELLA_FOLDER, GnutellaPeer } from './apps/gnutella.js';
@@ -320,10 +322,11 @@ export interface FirewallDecision {
/**
* A line of a firewall's log (Firewall.benachrichtigeBeobachter, shown by
* the router's page "log"): a rule that matched a TCP or UDP packet, with
* the node's first interface (the rule's text names its network for "any
* directly connected network"), or an ICMP packet dropped by the general
* setting.
* the router's page "log" and a computer's firewall window): a rule that
* matched a TCP or UDP packet, with the node's first interface (the rule's
* text names its network for "any directly connected network"), or an ICMP
* packet dropped by the general setting; and, from a computer's window
* (Java writes them into the window only), a port rule added or removed.
*/
export type FirewallLogEntry =
| {
@@ -333,7 +336,9 @@ export type FirewallLogEntry =
readonly firstInterface: { readonly ipAddress: string; readonly subnetMask: string } | undefined;
readonly accepted: boolean;
}
| { readonly kind: 'icmpDropped'; readonly senderIPAddress: string; readonly receiverIPAddress: string; readonly type: number; readonly code: number };
| { readonly kind: 'icmpDropped'; readonly senderIPAddress: string; readonly receiverIPAddress: string; readonly type: number; readonly code: number }
| { readonly kind: 'portRuleAdded'; readonly port: number; readonly protocol: PortRuleProtocol }
| { readonly kind: 'portRuleRemoved' };
export type RuntimePhase = 'stopped' | 'running';
@@ -945,7 +950,7 @@ export class NetworkRuntimeEngine {
/** The time of day a program writes into a mail (Java's new Date()). */
private readonly wallClock: () => number;
/** Each node's firewall log; it outlives a stop and a new start, as Java's log page does. */
private readonly firewallLogsByNodeId = new Map<Id, FirewallLogEntry[]>();
private readonly firewallLogsByNodeId = new Map<Id, LogLine<FirewallLogEntry>[]>();
/** Accepted connections a program has taken (acceptTcpSteps). */
private readonly handedOutTcpSocketIds = new Set<Id>();
private nextApplicationWakeId = 1;
@@ -1127,12 +1132,12 @@ export class NetworkRuntimeEngine {
}
/** The node's firewall log, since the engine was made. */
firewallLog(nodeId: Id): readonly FirewallLogEntry[] {
firewallLog(nodeId: Id): readonly LogLine<FirewallLogEntry>[] {
return this.firewallLogsByNodeId.get(nodeId) ?? [];
}
private logFirewall(nodeId: Id, entry: FirewallLogEntry): void {
getOrCreate(this.firewallLogsByNodeId, nodeId, () => []).push(entry);
getOrCreate(this.firewallLogsByNodeId, nodeId, () => []).push({ ...entry, timeMilliseconds: this.stateValue.currentTimeMilliseconds });
}
/** Firewall.notifyRuleApplication. */
@@ -5615,6 +5620,31 @@ export class NetworkRuntimeEngine {
return this.stateValue.topologySnapshot.firewallConfigurationsByNodeId.get(nodeId) ?? firewallConfiguration();
}
/** A computer's firewall, when it has one installed (a router's is no program; its page changes it). */
personalFirewall(nodeId: Id): FirewallConfiguration | undefined {
const node = this.nodeSnapshot(nodeId);
return node !== undefined && isPcClassEndpoint(node.kind) ? this.stateValue.topologySnapshot.firewallConfigurationsByNodeId.get(nodeId) : undefined;
}
/** The window's "Hinzufügen": the port opened, written into its log; false for a computer without a firewall. */
addFirewallPortRule(nodeId: Id, port: number, protocol: PortRuleProtocol, sameNetworkOnly: boolean): boolean {
const configuration = this.personalFirewall(nodeId);
if (configuration === undefined) return false;
this.setFirewallConfiguration(nodeId, withPortRule(configuration, port, protocol, sameNetworkOnly));
this.logFirewall(nodeId, { kind: 'portRuleAdded', port, protocol });
return true;
}
/** The window's "Löschen": the rule of that row removed, written into its log; false when there is none. */
removeFirewallRule(nodeId: Id, index: number): boolean {
const configuration = this.personalFirewall(nodeId);
const changed = configuration === undefined ? undefined : withoutRule(configuration, index);
if (changed === undefined) return false;
this.setFirewallConfiguration(nodeId, changed);
this.logFirewall(nodeId, { kind: 'portRuleRemoved' });
return true;
}
setFirewallConfiguration(nodeId: Id, configuration: FirewallConfiguration): void {
const configurations = new Map(this.stateValue.topologySnapshot.firewallConfigurationsByNodeId);
configurations.set(nodeId, configuration);