disambiguate between anon and binary

This commit is contained in:
Florent
2026-02-02 17:04:42 -04:00
parent d57162375a
commit ce6d14d618
2 changed files with 71 additions and 67 deletions

View File

@@ -205,6 +205,6 @@ class CommandHandlerBase:
# Use provided timeout or fallback to suggested timeout (with 5s default) # Use provided timeout or fallback to suggested timeout (with 5s default)
actual_timeout = timeout if timeout is not None and timeout > 0 else result.payload.get("suggested_timeout", 4000) / 800.0 actual_timeout = timeout if timeout is not None and timeout > 0 else result.payload.get("suggested_timeout", 4000) / 800.0
actual_timeout = min_timeout if actual_timeout < min_timeout else actual_timeout actual_timeout = min_timeout if actual_timeout < min_timeout else actual_timeout
self._reader.register_binary_request(pubkey_prefix.hex(), exp_tag, request_type, actual_timeout, context=context) self._reader.register_binary_request(pubkey_prefix.hex(), exp_tag, request_type, actual_timeout, context=context, is_anon=True)
return result return result

View File

@@ -24,7 +24,7 @@ class MessageReader:
# Track pending binary requests by tag for proper response parsing # Track pending binary requests by tag for proper response parsing
self.pending_binary_requests: Dict[str, Dict[str, Any]] = {} # tag -> {request_type, expires_at} self.pending_binary_requests: Dict[str, Dict[str, Any]] = {} # tag -> {request_type, expires_at}
def register_binary_request(self, prefix: str, tag: str, request_type: BinaryReqType, timeout_seconds: float, context={}): def register_binary_request(self, prefix: str, tag: str, request_type: BinaryReqType, timeout_seconds: float, context={}, is_anon=False):
"""Register a pending binary request for proper response parsing""" """Register a pending binary request for proper response parsing"""
# Clean up expired requests before adding new one # Clean up expired requests before adding new one
self.cleanup_expired_requests() self.cleanup_expired_requests()
@@ -34,6 +34,7 @@ class MessageReader:
"request_type": request_type, "request_type": request_type,
"pubkey_prefix": prefix, "pubkey_prefix": prefix,
"expires_at": expires_at, "expires_at": expires_at,
"is_anon": is_anon,
"context": context # optional info we want to keep from req to resp "context": context # optional info we want to keep from req to resp
} }
logger.debug(f"Registered binary request: tag={tag}, type={request_type}, expires in {timeout_seconds}s") logger.debug(f"Registered binary request: tag={tag}, type={request_type}, expires in {timeout_seconds}s")
@@ -618,11 +619,14 @@ class MessageReader:
# Check for tracked request type and dispatch specific response # Check for tracked request type and dispatch specific response
if tag in self.pending_binary_requests: if tag in self.pending_binary_requests:
request_type = self.pending_binary_requests[tag]["request_type"] request_type = self.pending_binary_requests[tag]["request_type"]
is_anon = self.pending_binary_requests[tag]["is_anon"]
pubkey_prefix = self.pending_binary_requests[tag]["pubkey_prefix"] pubkey_prefix = self.pending_binary_requests[tag]["pubkey_prefix"]
context = self.pending_binary_requests[tag]["context"] context = self.pending_binary_requests[tag]["context"]
del self.pending_binary_requests[tag] del self.pending_binary_requests[tag]
logger.debug(f"Processing binary response for tag {tag}, type {request_type}, pubkey_prefix {pubkey_prefix}") logger.debug(f"Processing binary response for tag {tag}, type {request_type}, pubkey_prefix {pubkey_prefix}")
if not is_anon:
if request_type == BinaryReqType.STATUS and len(response_data) >= 52: if request_type == BinaryReqType.STATUS and len(response_data) >= 52:
res = {} res = {}
res = parse_status(response_data, pubkey_prefix=pubkey_prefix) res = parse_status(response_data, pubkey_prefix=pubkey_prefix)
@@ -630,7 +634,7 @@ class MessageReader:
Event(EventType.STATUS_RESPONSE, res, {"pubkey_prefix": res["pubkey_pre"], "tag": tag}) Event(EventType.STATUS_RESPONSE, res, {"pubkey_prefix": res["pubkey_pre"], "tag": tag})
) )
elif request_type == BinaryReqType.TELEMETRY: elif request_type == BinaryReqType.TELEMETRY :
try: try:
lpp = lpp_parse(response_data) lpp = lpp_parse(response_data)
telem_res = {"tag": tag, "lpp": lpp, "pubkey_prefix": pubkey_prefix} telem_res = {"tag": tag, "lpp": lpp, "pubkey_prefix": pubkey_prefix}