From d6fe653a2e68905ea4f19488bfa5834231de93c1 Mon Sep 17 00:00:00 2001 From: mikael-lovqvists-claude-agent Date: Sun, 29 Mar 2026 19:28:15 +0000 Subject: [PATCH] Fix discovery: key peers on (addr, tcp_port) not (addr, name) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two nodes on the same host with the same name (e.g. unnamed:0) would collide — the second announcement just updated the first entry's port. Peer identity is addr+port; name is metadata, not identity. Same fix applied to the self-skip check. Co-Authored-By: Claude Sonnet 4.6 --- src/modules/discovery/discovery.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/discovery/discovery.c b/src/modules/discovery/discovery.c index 46ccd15..787dea8 100644 --- a/src/modules/discovery/discovery.c +++ b/src/modules/discovery/discovery.c @@ -56,11 +56,11 @@ static uint64_t now_ms(void) { return (uint64_t)ts.tv_sec * 1000u + (uint64_t)ts.tv_nsec / 1000000u; } -static int find_peer(struct Discovery *d, uint32_t addr, const char *name) { +static int find_peer(struct Discovery *d, uint32_t addr, uint16_t tcp_port) { for (int i = 0; i < DISCOVERY_MAX_PEERS; i++) { if (d->peers[i].active - && d->peers[i].info.addr == addr - && strcmp(d->peers[i].info.name, name) == 0) { + && d->peers[i].info.addr == addr + && d->peers[i].info.tcp_port == tcp_port) { return i; } } @@ -198,7 +198,7 @@ static void *receive_thread_fn(void *arg) { /* skip our own announcements */ if (site_id == d->config.site_id - && strcmp(name, d->config.name) == 0) { + && tcp_port == d->config.tcp_port) { continue; } @@ -209,7 +209,7 @@ static void *receive_thread_fn(void *arg) { pthread_mutex_lock(&d->peers_mutex); - int idx = find_peer(d, addr, name); + int idx = find_peer(d, addr, tcp_port); if (idx >= 0) { d->peers[idx].last_seen_ms = ts; d->peers[idx].info.site_id = site_id;