Add Trace DASP preference to print protocol transactions to terminal

New checkbox in Preferences (default off). When enabled, every DASP
send (>>>) and receive (<<<) prints message type, seq/ack numbers,
payload size, and remote address to stdout.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-11 23:48:10 +03:00
co-authored by Claude Opus 4.6
parent 4431f11d83
commit 643bcdc952
3 changed files with 42 additions and 7 deletions
+20
View File
@@ -78,6 +78,24 @@ ERR_TIMEOUT = 0xE5
DEFAULT_PORT = 1876
_MSG_TYPE_NAMES = {
DISCOVER: "DISCOVER", HELLO: "HELLO", CHALLENGE: "CHALLENGE",
AUTHENTICATE: "AUTHENTICATE", WELCOME: "WELCOME", KEEPALIVE: "KEEPALIVE",
DATAGRAM: "DATAGRAM", CLOSE: "CLOSE",
}
def _trace(direction, msg, addr=None):
import app_state
if not app_state.TRACE_DASP:
return
name = _MSG_TYPE_NAMES.get(msg.msg_type, f"?{msg.msg_type}")
seq = f" seq={msg.seq_num}" if msg.seq_num >= 0 else ""
ack = f" ack={msg.ack}" if msg.ack >= 0 else ""
plen = len(msg.payload) if msg.payload else 0
dest = f" {addr[0]}:{addr[1]}" if addr else ""
print(f"[DASP] {direction}{dest} {name}{seq}{ack} payload={plen}")
class DaspException(Exception):
def __init__(self, msg, error_code=-1):
@@ -898,6 +916,7 @@ class DaspSocket:
# ── Network I/O ─────────────────────────────────────────────
def _send_msg(self, session, msg):
_trace(">>>", msg, (session.host, session.port))
data = msg.encode()
with self._send_lock:
try:
@@ -922,6 +941,7 @@ class DaspSocket:
break
def _dispatch(self, msg, addr):
_trace("<<<", msg, addr)
session_id = msg.session_id
with self._sessions_lock:
session = self._sessions.get(session_id)