From c07d24d3879056d88351c655932d94d7c8a93e3f Mon Sep 17 00:00:00 2001 From: agessaman Date: Sat, 14 Feb 2026 21:07:18 -0800 Subject: [PATCH] Fix frame building functionality for advert push in CompanionFrameServer - Introduced a new method `_build_advert_push_frames` to construct short and full advert frames from provided data. - Refactored the handling of contact data to build and send advert frames asynchronously, improving performance and thread safety. - Enhanced data structure for advert frame construction, including optional fields for full advert details. --- repeater/companion/frame_server.py | 77 +++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/repeater/companion/frame_server.py b/repeater/companion/frame_server.py index 88d5971..a38bf7c 100644 --- a/repeater/companion/frame_server.py +++ b/repeater/companion/frame_server.py @@ -92,6 +92,26 @@ from .constants import ( logger = logging.getLogger("CompanionFrameServer") +def _build_advert_push_frames(data: dict) -> tuple[bytes, Optional[bytes]]: + """Build PUSH_CODE_ADVERT short frame and optional PUSH_CODE_NEW_ADVERT full frame from extracted data. Thread-safe for asyncio.to_thread.""" + pubkey_b = data["pubkey_b"] + short = bytes([PUSH_CODE_ADVERT]) + pubkey_b + if not data.get("include_full"): + return (short, None) + full = ( + bytes([PUSH_CODE_NEW_ADVERT]) + + pubkey_b + + bytes([data["adv_type"], data["flags"], data["opl_byte"]]) + + data["out_path"] + + data["name_b"] + + struct.pack("= 32: