mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
prefer btreemap over hashmap
This commit is contained in:
committed by
Aiden McClelland
parent
f8472135f5
commit
7622616856
@@ -1,4 +1,4 @@
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::anyhow;
|
||||
@@ -72,7 +72,7 @@ impl Interfaces {
|
||||
&self,
|
||||
secrets: &mut Ex,
|
||||
package_id: &PackageId,
|
||||
) -> Result<HashMap<InterfaceId, TorSecretKeyV3>, Error>
|
||||
) -> Result<BTreeMap<InterfaceId, TorSecretKeyV3>, Error>
|
||||
where
|
||||
for<'a> &'a mut Ex: Executor<'a, Database = Sqlite>,
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use avahi_sys::{
|
||||
self, avahi_entry_group_add_service, avahi_entry_group_commit, avahi_entry_group_free,
|
||||
@@ -35,7 +35,7 @@ impl MdnsController {
|
||||
pub struct MdnsControllerInner {
|
||||
hostname: Vec<u8>,
|
||||
entry_group: *mut AvahiEntryGroup,
|
||||
services: HashMap<(PackageId, InterfaceId), TorSecretKeyV3>,
|
||||
services: BTreeMap<(PackageId, InterfaceId), TorSecretKeyV3>,
|
||||
}
|
||||
unsafe impl Send for MdnsControllerInner {}
|
||||
unsafe impl Sync for MdnsControllerInner {}
|
||||
@@ -115,7 +115,7 @@ impl MdnsControllerInner {
|
||||
MdnsControllerInner {
|
||||
hostname: hostname_buf,
|
||||
entry_group: group,
|
||||
services: HashMap::new(),
|
||||
services: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::collections::BTreeMap;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -35,14 +35,14 @@ impl NginxController {
|
||||
|
||||
pub struct NginxControllerInner {
|
||||
nginx_root: PathBuf,
|
||||
interfaces: HashMap<PackageId, PackageNetInfo>,
|
||||
interfaces: BTreeMap<PackageId, PackageNetInfo>,
|
||||
ssl_manager: SslManager,
|
||||
}
|
||||
impl NginxControllerInner {
|
||||
async fn init(nginx_root: PathBuf, db: SqlitePool) -> Result<Self, Error> {
|
||||
Ok(NginxControllerInner {
|
||||
nginx_root,
|
||||
interfaces: HashMap::new(),
|
||||
interfaces: BTreeMap::new(),
|
||||
ssl_manager: SslManager::init(db).await?,
|
||||
})
|
||||
}
|
||||
@@ -60,7 +60,7 @@ impl NginxControllerInner {
|
||||
// also don't add nginx unless it has at least one exposed port
|
||||
&& meta.lan_config.len() > 0
|
||||
})
|
||||
.collect::<HashMap<InterfaceId, InterfaceMetadata>>();
|
||||
.collect::<BTreeMap<InterfaceId, InterfaceMetadata>>();
|
||||
|
||||
for (id, meta) in interface_map.iter() {
|
||||
for (port, lan_port_config) in meta.lan_config.iter() {
|
||||
@@ -197,7 +197,7 @@ impl NginxControllerInner {
|
||||
}
|
||||
struct PackageNetInfo {
|
||||
ip: Ipv4Addr,
|
||||
interfaces: HashMap<InterfaceId, InterfaceMetadata>,
|
||||
interfaces: BTreeMap<InterfaceId, InterfaceMetadata>,
|
||||
}
|
||||
pub struct InterfaceMetadata {
|
||||
pub dns_base: String,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::BTreeMap;
|
||||
use std::net::{Ipv4Addr, SocketAddr};
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -137,7 +137,7 @@ pub struct TorControllerInner {
|
||||
embassyd_tor_key: TorSecretKeyV3,
|
||||
control_addr: SocketAddr,
|
||||
connection: Option<AuthenticatedConnection>,
|
||||
services: HashMap<(PackageId, InterfaceId), (TorSecretKeyV3, TorConfig, Ipv4Addr)>,
|
||||
services: BTreeMap<(PackageId, InterfaceId), (TorSecretKeyV3, TorConfig, Ipv4Addr)>,
|
||||
}
|
||||
impl TorControllerInner {
|
||||
async fn add<'a, I: IntoIterator<Item = (InterfaceId, TorConfig, TorSecretKeyV3)>>(
|
||||
@@ -230,7 +230,7 @@ impl TorControllerInner {
|
||||
embassyd_tor_key,
|
||||
control_addr: tor_control,
|
||||
connection: Some(connection),
|
||||
services: HashMap::new(),
|
||||
services: BTreeMap::new(),
|
||||
};
|
||||
controller.add_embassyd_onion().await?;
|
||||
Ok(controller)
|
||||
@@ -314,7 +314,7 @@ impl TorControllerInner {
|
||||
self.connection.replace(new_connection);
|
||||
|
||||
// swap empty map for owned old service map
|
||||
let old_services = std::mem::replace(&mut self.services, HashMap::new());
|
||||
let old_services = std::mem::replace(&mut self.services, BTreeMap::new());
|
||||
|
||||
// re add all of the services on the new control socket
|
||||
for ((package_id, interface_id), (tor_key, tor_cfg, ipv4)) in old_services {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -353,7 +353,7 @@ impl<'a> WpaCli<'a> {
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
pub async fn list_networks_low(&self) -> Result<HashMap<String, NetworkId>, Error> {
|
||||
pub async fn list_networks_low(&self) -> Result<BTreeMap<String, NetworkId>, Error> {
|
||||
let r = Command::new("wpa_cli")
|
||||
.arg("-i")
|
||||
.arg(self.interface)
|
||||
@@ -369,7 +369,7 @@ impl<'a> WpaCli<'a> {
|
||||
let ssid = cs.next()?.to_owned();
|
||||
Some((ssid, nid))
|
||||
})
|
||||
.collect::<HashMap<String, NetworkId>>())
|
||||
.collect::<BTreeMap<String, NetworkId>>())
|
||||
}
|
||||
pub async fn select_network_low(&self, id: &NetworkId) -> Result<(), Error> {
|
||||
let _ = Command::new("wpa_cli")
|
||||
|
||||
Reference in New Issue
Block a user