chat_core_connect_auto: dedup addresses by (addr,port)

This commit is contained in:
Evgeny committed 2026-07-15 10:32:06 +03:00
1 parent 33aa6bbd5a
commit 0adf7d07ef
1 file changed
+9
+9
View File
@@ -1006,6 +1006,15 @@ void chat_core_connect_auto(uint64_t node_id,
}
sqlite3_finalize(st);
}
/* dedup by (addr, port) — can't have two links to same socket */
{ int uniq = 0;
for (int i = 0; i < addr_count; i++) {
int dup = 0;
for (int j = 0; j < uniq; j++)
if (memcmp(addrs[i].addr, addrs[j].addr, 4) == 0 && addrs[i].port == addrs[j].port) { dup = 1; break; }
if (!dup) { if (i != uniq) addrs[uniq] = addrs[i]; uniq++; }
}
addr_count = uniq; }
if (addr_count == 0) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: auto_connect no IPv4 addrs for node 0x%016llx",
CC_ID, (unsigned long long)node_id);