forked from arti/vt1200
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.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""fontwork index-then-font server (v4).
|
|
|
|
Serves the project's real fonts.dir verbatim for the font path and for
|
|
'<path>/fonts.dir', and serves the crafted multi-block font for the font name
|
|
listed in that index (and for anything else that looks like a file). This is
|
|
the closest reproduction of the owner's intended flow with a valid, one-block
|
|
index, so we can see whether the crafted font's own transfer completes.
|
|
"""
|
|
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
|
|
|
|
host = sys.argv[1] if len(sys.argv) > 1 else "192.168.99.1"
|
|
with open(os.path.join(ROOT, "reference/fonts/fonts.dir"), "rb") as fh:
|
|
fonts_dir = fh.read()
|
|
with open(os.path.join(ROOT, "reference/fonts/evil-real.pcf"), "rb") as fh:
|
|
evil = fh.read()
|
|
print(f"fonts.dir={fonts_dir!r}; font -> evil-real.pcf ({len(evil)} bytes)", flush=True)
|
|
|
|
|
|
def resolve(name):
|
|
if name.endswith("fonts.dir") or name == "69":
|
|
return fonts_dir
|
|
return evil
|
|
|
|
|
|
srv = fontgen.TFTPServer((host, 69), {}, timeout=60.0, retries=10,
|
|
resolver=resolve).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()
|