Files
vt1200/harness/mame/fontwork/custom_serve.py
T
arti 3a51b95317 harness/fontwork: reproduction scripts for the TFTP Disk-full investigation
Isolated-netns test setup (a private tap-mess-0-0 so a second MAME can run
without holding the owner's tap), the one-file/one-index TFTP servers, the
trace/probe run wrappers, and the two server logs quoted in
FONT_STORAGE_REPORT.md.
2026-10-16 22:03:49 +03:00

37 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""fontwork server: serve ONE chosen file for every requested name.
Used to test whether the terminal's TFTP abort is a size/capacity effect: the
same name ('69') is served as the 680-byte baseline or as a small file, and we
watch whether the transfer completes. Uses the project's own TFTPServer class.
python3 custom_serve.py <file-to-serve> [bind-ip]
"""
import os
import sys
import time
ROOT = "/home/arti/code/k-space/vt1200"
sys.path.insert(0, os.path.join(ROOT, "tools"))
import fontgen # noqa: E402
src = sys.argv[1]
host = sys.argv[2] if len(sys.argv) > 2 else "192.168.99.1"
with open(src, "rb") as fh:
blob = fh.read()
print(f"serving {src} ({len(blob)} bytes) as EVERY name on {host}:69", flush=True)
srv = fontgen.TFTPServer((host, 69), {}, timeout=60.0, retries=10,
resolver=lambda name: blob).start()
try:
while True:
time.sleep(0.5)
while srv.log:
ts, name, addr = srv.log.pop(0)
stamp = time.strftime("%H:%M:%S", time.localtime(ts))
print(f"{stamp} {addr[0]}:{addr[1]} requested {name!r}", flush=True)
except KeyboardInterrupt:
pass
finally:
srv.stop()