Don't change lqos.conf, generate a node ID hash based on ip link output.

This commit is contained in:
Herbert Wolverson
2023-03-20 19:47:30 +00:00
parent 26efcdb208
commit 84e4306b22
4 changed files with 17 additions and 15 deletions

View File

@@ -164,6 +164,7 @@ pub fn insert_stats_dump(stats: &AnonymousUsageV1, ip: &str) -> anyhow::Result<(
}
// Not a great idea, this is for test data
#[allow(dead_code)]
pub fn dump_all_to_string() -> anyhow::Result<String> {
let mut result = String::new();
let cn = sqlite::open(DBPATH)?;

View File

@@ -1,8 +1,7 @@
//! Manages the `/etc/lqos.conf` file.
use log::error;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use std::{path::Path, fs};
use std::{path::Path, fs, process::Command};
use thiserror::Error;
/// Represents the top-level of the `/etc/lqos.conf` file. Serialization
@@ -180,15 +179,19 @@ impl EtcLqos {
}
fn check_config(cfg: &mut EtcLqos) {
let mut changed = false;
if cfg.node_id.is_none() {
let new_id = Uuid::new_v4();
cfg.node_id = Some(new_id.to_string());
changed = true;
}
use sha2::Digest;
use sha2::digest::Update;
if changed {
let _ = cfg.save();
if cfg.node_id.is_none() {
if let Ok(out) = Command::new("/bin/ip").args(["link"]).output() {
if let Ok(raw_ip_link) = String::from_utf8(out.stdout) {
let hash = sha2::Sha256::new().chain(raw_ip_link).finalize();
cfg.node_id = Some(format!("{:x}", hash));
log::info!("Generated node ID: {:?}", cfg.node_id);
log::warn!("Please consider adding a line to your /etc/lqos.conf configuration:");
log::warn!("node_id = (big random number)");
}
}
}
}

View File

@@ -140,7 +140,7 @@ vlan_mapping = []
[usage_stats]
send_anonymous = {ALLOW_ANONYMOUS}
anonymous_server = \"127.0.0.1:9125\"
anonymous_server = \"stats.libreqos.io:9125\"
";
fn write_etc_lqos_conf(internet: &str, isp: &str, allow_anonymous: bool) {

View File

@@ -3,7 +3,7 @@ mod version;
use std::{time::Duration, net::TcpStream, io::Write};
use lqos_bus::anonymous::{AnonymousUsageV1, build_stats};
use lqos_config::{EtcLqos, LibreQoSConfig};
use lqos_sys::num_possible_cpus;
use lqos_sys::libbpf_num_possible_cpus;
use sysinfo::{System, SystemExt, CpuExt};
use crate::shaped_devices_tracker::{SHAPED_DEVICES, NETWORK_JSON};
@@ -36,9 +36,7 @@ fn anonymous_usage_dump() -> anyhow::Result<()> {
if let Some(kernel) = sys.kernel_version() {
data.kernel_version = kernel;
}
if let Ok(cores) = num_possible_cpus() {
data.usable_cores = cores;
}
data.usable_cores = unsafe { libbpf_num_possible_cpus() } as u32;
let cpu = sys.cpus().first();
if let Some(cpu) = cpu {
data.cpu_brand = cpu.brand().to_string();