Skip to content

Commit c4e42c9

Browse files
committed
fix parsing direct addrs
1 parent fa27500 commit c4e42c9

File tree

1 file changed

+48
-18
lines changed

1 file changed

+48
-18
lines changed

netsim/main.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,46 @@ def parse_node_params(node, prefix, node_params, runner_id):
6464
if idx + 1 < len(lines):
6565
node_params[node_name] = lines[idx + 1].strip()
6666
break
67-
if node["param_parser"] == "iroh_endpoint_with_addrs" and line.startswith(
68-
"Our endpoint id:"
69-
):
70-
if idx + 1 >= len(lines):
71-
break
72-
endpoint_id = lines[idx + 1].strip()
73-
direct_addrs = []
74-
j = idx + 2
75-
if j < len(lines) and lines[j].startswith("Our direct addresses:"):
76-
j += 1
77-
while j < len(lines) and lines[j].startswith("\t"):
78-
direct_addrs.append(lines[j].strip())
67+
if node["param_parser"] == "iroh_endpoint_with_addrs":
68+
# Handle both "Our endpoint id:" (from bind_endpoint) and "Endpoint id:" (from provide)
69+
if line.startswith("Our endpoint id:"):
70+
if idx + 1 >= len(lines):
71+
break
72+
endpoint_id = lines[idx + 1].strip()
73+
direct_addrs = []
74+
j = idx + 2
75+
if j < len(lines) and lines[j].startswith("Our direct addresses:"):
7976
j += 1
80-
node_params[node_name] = {
81-
"endpoint_id": endpoint_id,
82-
"direct_addrs": direct_addrs
83-
}
84-
break
77+
while j < len(lines) and lines[j].startswith("\t"):
78+
direct_addrs.append(lines[j].strip())
79+
j += 1
80+
node_params[node_name] = {
81+
"endpoint_id": endpoint_id,
82+
"direct_addrs": direct_addrs
83+
}
84+
break
85+
elif line.startswith("Endpoint id:") and node_name not in node_params:
86+
# Fallback for simple "Endpoint id:" output (no "Our")
87+
# Format: "Endpoint id:\n<id>\n"
88+
if idx + 1 < len(lines):
89+
endpoint_id = lines[idx + 1].strip()
90+
# Try to find direct addresses from debug logs
91+
direct_addrs = []
92+
# Look backwards and forwards for direct_addrs debug line
93+
for search_idx in range(max(0, idx - 20), min(len(lines), idx + 20)):
94+
search_line = lines[search_idx]
95+
if "direct_addrs:" in search_line and "DirectAddr" in search_line:
96+
# Extract address from: addrs={DirectAddr { addr: 10.0.0.2:47103, typ: Local }}
97+
import re
98+
match = re.search(r'addr:\s*([0-9.]+:\d+)', search_line)
99+
if match:
100+
direct_addrs.append(match.group(1))
101+
break
102+
node_params[node_name] = {
103+
"endpoint_id": endpoint_id,
104+
"direct_addrs": direct_addrs
105+
}
106+
break
85107
return node_params
86108

87109

@@ -145,7 +167,15 @@ def handle_connection_strategy(node, node_counts, i, runner_id, node_ips, node_p
145167
if isinstance(param_data, dict):
146168
endpoint_id = param_data["endpoint_id"]
147169
direct_addrs = param_data.get("direct_addrs", [])
148-
first_addr = direct_addrs[0] if direct_addrs else ""
170+
# Use parsed direct address if available, otherwise construct from node IP
171+
if direct_addrs:
172+
first_addr = direct_addrs[0]
173+
else:
174+
# Fallback: use the node's IP from mininet (need to find the port)
175+
# For now, return just endpoint ID and let discovery work
176+
ip = node_ips[connect_to]
177+
# Default QUIC port for iroh-transfer
178+
first_addr = f"{ip}:11204"
149179
return cmd % (first_addr, endpoint_id)
150180
else:
151181
return cmd % param_data

0 commit comments

Comments
 (0)