Fix multicast storm: only re-announce on new peer, not every received packet
The announce thread was being woken (triggering a multicast send) on every received announcement packet, including ones from already-known peers. With two or more nodes this created a feedback loop: each incoming packet triggered an outbound multicast which triggered another incoming packet on the peer, and so on at full CPU/network speed. Gate the cond_signal on is_new so we only fast-announce when a genuinely new peer is seen. The periodic interval-based announcement continues to handle keepalives and reconnections for existing peers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -233,11 +233,13 @@ static void *receive_thread_fn(void *arg) {
|
|||||||
|
|
||||||
pthread_mutex_unlock(&d->peers_mutex);
|
pthread_mutex_unlock(&d->peers_mutex);
|
||||||
|
|
||||||
/* respond to every announcement — the sender may be a fresh instance
|
if (is_new) {
|
||||||
* that doesn't know about us yet even if we already have it in our table */
|
/* announce ourselves immediately so the new peer learns about us
|
||||||
|
* without waiting up to interval_ms */
|
||||||
pthread_mutex_lock(&d->announce_mutex);
|
pthread_mutex_lock(&d->announce_mutex);
|
||||||
pthread_cond_signal(&d->announce_cond);
|
pthread_cond_signal(&d->announce_cond);
|
||||||
pthread_mutex_unlock(&d->announce_mutex);
|
pthread_mutex_unlock(&d->announce_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_new && d->config.on_peer_found) {
|
if (is_new && d->config.on_peer_found) {
|
||||||
d->config.on_peer_found(&peer_copy, d->config.userdata);
|
d->config.on_peer_found(&peer_copy, d->config.userdata);
|
||||||
|
|||||||
Reference in New Issue
Block a user