From 7dea3d744fb6707118fc49c3748ddd311a86c894 Mon Sep 17 00:00:00 2001 From: Arda Aydin Date: Sat, 12 Sep 2026 22:08:12 +0300 Subject: [PATCH] Improve DASP trace: use S/R labels, add timestamp and full hex datagram Co-Authored-By: Claude Opus 4.6 --- app_state.py | 2 +- dasp.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app_state.py b/app_state.py index 6ba5f13..4ae77f3 100644 --- a/app_state.py +++ b/app_state.py @@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it. import configparser import os -VERSION = "0.0.0.093" +VERSION = "0.0.0.094" PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties") DEFAULT_GRID_SIZE = 10 DEFAULT_ADD_TIMESTAMP = True diff --git a/dasp.py b/dasp.py index f2b0100..fafe369 100644 --- a/dasp.py +++ b/dasp.py @@ -85,16 +85,20 @@ _MSG_TYPE_NAMES = { } -def _trace(direction, msg, addr=None): +def _trace(direction, msg, datagram=None): import app_state if not app_state.TRACE_DASP: return + import datetime + ts = datetime.datetime.now().strftime("%H:%M:%S.%f")[:-3] 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}") + hexdump = "" + if datagram: + hexdump = " [" + datagram.hex(" ") + "]" + print(f"[DASP] {ts} {direction} {name}{seq}{ack} payload={plen}{hexdump}") class DaspException(Exception): @@ -916,8 +920,8 @@ class DaspSocket: # ── Network I/O ───────────────────────────────────────────── def _send_msg(self, session, msg): - _trace(">>>", msg, (session.host, session.port)) data = msg.encode() + _trace("S", msg, data) with self._send_lock: try: self._sock.sendto(data, (session.host, session.port)) @@ -931,8 +935,9 @@ class DaspSocket: nbytes, addr = self._sock.recvfrom_into(buf) if nbytes < 5: continue + raw = bytes(buf[:nbytes]) msg = DaspMsg.decode(buf, nbytes) - self._dispatch(msg, addr) + self._dispatch(msg, addr, raw) except socket.timeout: continue except OSError: @@ -940,8 +945,8 @@ class DaspSocket: continue break - def _dispatch(self, msg, addr): - _trace("<<<", msg, addr) + def _dispatch(self, msg, addr, raw=None): + _trace("R", msg, raw) session_id = msg.session_id with self._sessions_lock: session = self._sessions.get(session_id)