fixes to the banlist

This commit is contained in:
Lev Kokotov
2022-02-09 21:19:14 -08:00
parent 28c70d47b6
commit a9b2a41a9b
7 changed files with 87 additions and 10 deletions

View File

@@ -3,7 +3,7 @@ use tokio::fs::File;
use tokio::io::AsyncReadExt;
use toml;
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use crate::errors::Error;
@@ -77,6 +77,21 @@ pub async fn parse(path: &str) -> Result<Config, Error> {
}
};
// We use addresses as unique identifiers,
// let's make sure they are unique in the config as well.
for shard in &config.shards {
let mut dup_check = HashSet::new();
for server in &shard.1.servers {
dup_check.insert(server);
}
if dup_check.len() != shard.1.servers.len() {
println!("> Shard {} contains duplicate server configs.", &shard.0);
return Err(Error::BadConfig);
}
}
Ok(config)
}