Honor max_relays beyond just at startup

This commit is contained in:
Mike Dilger 2023-01-13 08:20:09 +13:00
parent 0782b21c06
commit b8d402287a
2 changed files with 13 additions and 1 deletions

View File

@ -18,6 +18,9 @@ pub enum Error {
#[error("Task join error: {0}")]
JoinError(#[from] tokio::task::JoinError),
#[error("Maximum relay connections reached, will not connect to another")]
MaxRelaysReached,
#[error("Error sending mpsc: {0}")]
MpscSend(#[from] tokio::sync::mpsc::error::SendError<ToOverlordMessage>),

View File

@ -249,10 +249,19 @@ impl Overlord {
}
async fn start_minion(&mut self, url: String) -> Result<(), Error> {
if GLOBALS.settings.read().await.offline {
let (offline, max_relays) = {
let settings = GLOBALS.settings.read().await;
(settings.offline, settings.max_relays)
};
if offline {
return Ok(());
}
if GLOBALS.relays_watching.read().await.len() >= max_relays.into() {
return Err(Error::MaxRelaysReached);
}
let url = Url::new(&url);
if !url.is_valid_relay_url() {
return Err(Error::InvalidUrl(url.inner().to_owned()));