Fix discovery: key peers on (addr, tcp_port) not (addr, name)
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 <noreply@anthropic.com>
This commit is contained in:
@@ -56,11 +56,11 @@ static uint64_t now_ms(void) {
|
|||||||
return (uint64_t)ts.tv_sec * 1000u + (uint64_t)ts.tv_nsec / 1000000u;
|
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++) {
|
for (int i = 0; i < DISCOVERY_MAX_PEERS; i++) {
|
||||||
if (d->peers[i].active
|
if (d->peers[i].active
|
||||||
&& d->peers[i].info.addr == addr
|
&& d->peers[i].info.addr == addr
|
||||||
&& strcmp(d->peers[i].info.name, name) == 0) {
|
&& d->peers[i].info.tcp_port == tcp_port) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ static void *receive_thread_fn(void *arg) {
|
|||||||
|
|
||||||
/* skip our own announcements */
|
/* skip our own announcements */
|
||||||
if (site_id == d->config.site_id
|
if (site_id == d->config.site_id
|
||||||
&& strcmp(name, d->config.name) == 0) {
|
&& tcp_port == d->config.tcp_port) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ static void *receive_thread_fn(void *arg) {
|
|||||||
|
|
||||||
pthread_mutex_lock(&d->peers_mutex);
|
pthread_mutex_lock(&d->peers_mutex);
|
||||||
|
|
||||||
int idx = find_peer(d, addr, name);
|
int idx = find_peer(d, addr, tcp_port);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
d->peers[idx].last_seen_ms = ts;
|
d->peers[idx].last_seen_ms = ts;
|
||||||
d->peers[idx].info.site_id = site_id;
|
d->peers[idx].info.site_id = site_id;
|
||||||
|
|||||||
Reference in New Issue
Block a user