Rate limit the amount of inbound connections (#2928)

* add sleep to `accept_inbound_connections()`

* Expand docs

* Expand comments again

Co-authored-by: teor <teor@riseup.net>
This commit is contained in:
Alfredo Garcia 2021-10-21 21:35:34 -03:00 committed by GitHub
parent 35290db052
commit ad5f5ff24a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -415,6 +415,16 @@ where
.instrument(handshaker_span),
);
}
// Only spawn one inbound connection handshake per `MIN_PEER_CONNECTION_INTERVAL`.
// But clear out failed connections as fast as possible.
//
// If there is a flood of connections,
// this stops Zebra overloading the network with handshake data.
//
// Zebra can't control how many queued connections are waiting,
// but most OSes also limit the number of queued inbound connections on a listener port.
tokio::time::sleep(constants::MIN_PEER_CONNECTION_INTERVAL).await;
}
}
}