Browse Source

chat_core_connect_auto: dedup addresses by (addr,port)

topo_upd
Evgeny 3 months ago
parent
commit
0adf7d07ef
  1. 9
      tools/chatgui/transport/chat_core.c

9
tools/chatgui/transport/chat_core.c

@ -1006,6 +1006,15 @@ void chat_core_connect_auto(uint64_t node_id,
} }
sqlite3_finalize(st); 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) { if (addr_count == 0) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: auto_connect no IPv4 addrs for node 0x%016llx", DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: auto_connect no IPv4 addrs for node 0x%016llx",
CC_ID, (unsigned long long)node_id); CC_ID, (unsigned long long)node_id);

Loading…
Cancel
Save