fix: update loop detection thresholds and improve path hash handling in API endpoints

This commit is contained in:
Lloyd
2026-05-21 12:29:21 +01:00
parent d25e97af3c
commit 5b93d1023d
2 changed files with 11 additions and 3 deletions
+8 -2
View File
@@ -36,7 +36,7 @@ LOOP_DETECT_MINIMAL = "minimal"
LOOP_DETECT_MODERATE = "moderate"
LOOP_DETECT_STRICT = "strict"
# Thresholds for 1-byte path hashes loop detection.
# Thresholds for flood loop detection (hash-size-aware: 1, 2, or 3 bytes per hop).
# Count how many times our own hash already exists in the incoming FLOOD path.
# If occurrences >= threshold, treat as loop and drop.
LOOP_DETECT_MAX_COUNTERS = {
@@ -742,8 +742,14 @@ class RepeaterHandler(BaseHandler):
if max_counter is None:
return False
hash_size = packet.get_path_hash_size()
hop_count = packet.get_path_hash_count()
path = packet.path or bytearray()
local_count = sum(1 for hop in path if hop == self.local_hash)
local_hash = self.local_hash_bytes[:hash_size]
local_count = sum(
1 for i in range(hop_count)
if bytes(path[i * hash_size:(i + 1) * hash_size]) == local_hash
)
return local_count >= max_counter
def _check_transport_codes(self, packet: Packet) -> Tuple[bool, str]:
+3 -1
View File
@@ -2718,6 +2718,8 @@ class APIEndpoints:
# 0 = 1-byte (legacy), 1 = 2-byte, 2 = 3-byte
path_hash_mode = self.config.get("mesh", {}).get("path_hash_mode", 0)
byte_count = {0: 1, 1: 2, 2: 3}.get(path_hash_mode, 1)
trace_flags = {1: 0x00, 2: 0x01}.get(byte_count, 0x00)
hex_chars = byte_count * 2
max_hash = (1 << (byte_count * 8)) - 1
@@ -2752,7 +2754,7 @@ class APIEndpoints:
path_bytes = list(target_hash.to_bytes(byte_count, "big"))
packet = PacketBuilder.create_trace(
tag=trace_tag, auth_code=0x12345678, flags=0x00, path=path_bytes
tag=trace_tag, auth_code=0x12345678, flags=trace_flags, path=path_bytes
)
# Wait for response with timeout