@@ -1632,33 +1632,41 @@ async def api_edges(request):
16321632
16331633 edges = {}
16341634
1635- # Traceroutes
1636- async for tr in store .get_traceroutes (since ):
1637- route = decode_payload .decode_payload (PortNum .TRACEROUTE_APP , tr .route )
1638- path = [tr .packet .from_node_id ] + list (route .route )
1639- path .append (tr .packet .to_node_id if tr .done else tr .gateway_node_id )
1635+ # Only build traceroute edges if requested
1636+ if filter_type in (None , "traceroute" ):
1637+ async for tr in store .get_traceroutes (since ):
1638+ try :
1639+ route = decode_payload .decode_payload (PortNum .TRACEROUTE_APP , tr .route )
1640+ except Exception as e :
1641+ print (f"Error decoding Traceroute { tr .id } : { e } " )
1642+ continue
16401643
1641- for a , b in zip ( path , path [ 1 :]):
1642- edges [( a , b )] = "traceroute"
1644+ path = [ tr . packet . from_node_id ] + list ( route . route )
1645+ path . append ( tr . packet . to_node_id if tr . done else tr . gateway_node_id )
16431646
1644- # NeighborInfo
1645- for packet in await store .get_packets (portnum = PortNum .NEIGHBORINFO_APP , after = since ):
1646- try :
1647- _ , neighbor_info = decode_payload .decode (packet )
1648- for node in neighbor_info .neighbors :
1649- edges .setdefault ((node .node_id , packet .from_node_id ), "neighbor" )
1650- except Exception as e :
1651- print (f"Error decoding NeighborInfo packet: { e } " )
1647+ for a , b in zip (path , path [1 :]):
1648+ edges [(a , b )] = "traceroute"
1649+
1650+ # Only build neighbor edges if requested
1651+ if filter_type in (None , "neighbor" ):
1652+ packets = await store .get_packets (portnum = PortNum .NEIGHBORINFO_APP , after = since )
1653+ for packet in packets :
1654+ try :
1655+ _ , neighbor_info = decode_payload .decode (packet )
1656+ for node in neighbor_info .neighbors :
1657+ edges .setdefault ((node .node_id , packet .from_node_id ), "neighbor" )
1658+ except Exception as e :
1659+ print (f"Error decoding NeighborInfo packet { getattr (packet , 'id' , '?' )} : { e } " )
16521660
16531661 return web .json_response ({
16541662 "edges" : [
16551663 {"from" : a , "to" : b , "type" : typ }
16561664 for (a , b ), typ in edges .items ()
1657- if filter_type is None or typ == filter_type
16581665 ]
16591666 })
16601667
16611668
1669+
16621670# Generic static HTML route
16631671@routes .get ("/{page}" )
16641672async def serve_page (request ):
0 commit comments