@@ -205,27 +205,72 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
205205
206206async def handle_log_rx (event ):
207207 mc = handle_log_rx .mc
208- if handle_log_rx .json_log_rx : # json mode ... raw dump
209- msg = json .dumps (event .payload )
210- if handle_message .above :
211- print_above (msg )
212- else :
213- print (msg )
214- return
215208
216209 pkt = bytes ().fromhex (event .payload ["payload" ])
217210 pbuf = io .BytesIO (pkt )
218211 header = pbuf .read (1 )[0 ]
219-
220- if header & ~ 1 == 0x14 : # flood msg / channel
212+ route_type = header & 0x03
213+ payload_type = (header & 0x3c ) >> 2
214+ payload_ver = (header & 0xc0 ) >> 6
215+
216+ transport_code = None
217+ if route_type == 0x00 or route_type == 0x03 : # has transport code
218+ transport_code = pbuf .read (4 ) # discard transport code
219+
220+ path_len = pbuf .read (1 )[0 ]
221+ path = pbuf .read (path_len ).hex () # Beware of traces where pathes are mixed
222+
223+ pkt_payload = pbuf .read ()
224+
225+ event .payload ["header" ] = header
226+ event .payload ["route_type" ] = route_type
227+ event .payload ["payload_type" ] = payload_type
228+
229+ match payload_type :
230+ case 0x0 :
231+ typename = "REQ"
232+ case 0x01 :
233+ typename = "RESPONSE"
234+ case 0x02 :
235+ typename = "TXT_MSG"
236+ case 0x03 :
237+ typename = "ACK"
238+ case 0x04 :
239+ typename = "ADVERT"
240+ case 0x05 :
241+ typename = "GRP_TXT"
242+ case 0x06 :
243+ typename = "GRP_DATA"
244+ case 0x07 :
245+ typename = "ANON_REQ"
246+ case 0x08 :
247+ typename = "PATH"
248+ case 0x09 :
249+ typename = "TRACE"
250+ case 0x0A :
251+ typename = "MULTIPART"
252+ case 0x0B :
253+ typename = "CONTROL"
254+
255+ if typename :
256+ event .payload ["payload_typename" ]= typename
257+
258+ event .payload ["payload_ver" ] = payload_ver
259+
260+ if not transport_code is None :
261+ event .payload ["transport_code" ] = transport_code .hex ()
262+
263+ event .payload ["path_len" ] = path_len
264+ event .payload ["path" ] = path
265+
266+ event .payload ["pkt_payload" ] = pkt_payload .hex ()
267+
268+ if payload_type == 0x05 : # flood msg / channel
221269 if handle_log_rx .channel_echoes :
222- if header & 1 == 0 : # has transport code
223- pbuf .read (4 ) # discard transport code
224- path_len = pbuf .read (1 )[0 ]
225- path = pbuf .read (path_len ).hex ()
226- chan_hash = pbuf .read (1 ).hex ()
227- cipher_mac = pbuf .read (2 )
228- msg = pbuf .read () # until the end of buffer
270+ pk_buf = io .BytesIO (pkt_payload )
271+ chan_hash = pk_buf .read (1 ).hex ()
272+ cipher_mac = pk_buf .read (2 )
273+ msg = pk_buf .read () # until the end of buffer
229274
230275 channel = None
231276 for c in await get_channels (mc ):
@@ -258,6 +303,14 @@ async def handle_log_rx(event):
258303 else :
259304 print (txt )
260305
306+ if handle_log_rx .json_log_rx : # json mode ... raw dump
307+ msg = json .dumps (event .payload )
308+ if handle_message .above :
309+ print_above (msg )
310+ else :
311+ print (msg )
312+
313+
261314handle_log_rx .json_log_rx = False
262315handle_log_rx .channel_echoes = False
263316handle_log_rx .mc = None
0 commit comments