incorporate config into daemon main
This commit is contained in:
parent
af09c610b2
commit
d68f36455f
3 changed files with 29 additions and 21 deletions
|
|
@ -20,6 +20,7 @@ pub use net::start_srv;
|
||||||
pub use net::DaemonClient;
|
pub use net::DaemonClient;
|
||||||
pub use response::{DaemonResponse, DaemonResponseData, ServerInfo};
|
pub use response::{DaemonResponse, DaemonResponseData, ServerInfo};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
use crate::wireguard::Config;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
daemon::net::listen,
|
daemon::net::listen,
|
||||||
|
|
@ -50,25 +51,8 @@ pub async fn daemon_main() -> Result<()> {
|
||||||
let (commands_tx, commands_rx) = async_channel::unbounded();
|
let (commands_tx, commands_rx) = async_channel::unbounded();
|
||||||
let (response_tx, response_rx) = async_channel::unbounded();
|
let (response_tx, response_rx) = async_channel::unbounded();
|
||||||
|
|
||||||
let private_key = parse_secret_key("GNqIAOCRxjl/cicZyvkvpTklgQuUmGUIEkH7IXF/sEE=")?;
|
let config = Config::default();
|
||||||
let public_key = parse_public_key("uy75leriJay0+oHLhRMpV+A5xAQ0hCJ+q7Ww81AOvT4=")?;
|
let iface: Interface = config.try_into()?;
|
||||||
let preshared_key = Some(parse_key("s7lx/mg+reVEMnGnqeyYOQkzD86n2+gYnx1M9ygi08k=")?);
|
|
||||||
tracing::debug!("beginning to find endpoint location");
|
|
||||||
let endpoint = "wg.burrow.rs:51820"
|
|
||||||
.to_socket_addrs()?
|
|
||||||
.filter(|sock| sock.is_ipv4())
|
|
||||||
.next()
|
|
||||||
.ok_or(anyhow!("DNS Lookup Fails!"))?; // DNS lookup under macos fails, somehow
|
|
||||||
|
|
||||||
tracing::debug!("endpoint initialized: {:?}", endpoint.to_string());
|
|
||||||
|
|
||||||
let iface = Interface::new(vec![Peer {
|
|
||||||
endpoint,
|
|
||||||
private_key,
|
|
||||||
public_key,
|
|
||||||
preshared_key,
|
|
||||||
allowed_ips: vec![IpNetwork::V4(Ipv4Network::DEFAULT_ROUTE)],
|
|
||||||
}])?;
|
|
||||||
|
|
||||||
let mut inst: DaemonInstance =
|
let mut inst: DaemonInstance =
|
||||||
DaemonInstance::new(commands_rx, response_tx, Arc::new(RwLock::new(iface)));
|
DaemonInstance::new(commands_rx, response_tx, Arc::new(RwLock::new(iface)));
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ pub struct Peer {
|
||||||
pub preshared_key: Option<String>,
|
pub preshared_key: Option<String>,
|
||||||
pub allowed_ips: Vec<String>,
|
pub allowed_ips: Vec<String>,
|
||||||
pub endpoint: String,
|
pub endpoint: String,
|
||||||
pub persistent_keepalive: u32,
|
pub persistent_keepalive: Option<u32>,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ pub struct Interface {
|
||||||
pub address: String,
|
pub address: String,
|
||||||
pub listen_port: u32,
|
pub listen_port: u32,
|
||||||
pub dns: Vec<String>,
|
pub dns: Vec<String>,
|
||||||
pub mtu: u32,
|
pub mtu: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|
@ -90,3 +90,26 @@ impl TryFrom<Config> for WgInterface {
|
||||||
Ok(WgInterface::new(wg_peers)?)
|
Ok(WgInterface::new(wg_peers)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Default for Config {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self{
|
||||||
|
interface: Interface{
|
||||||
|
private_key: "GNqIAOCRxjl/cicZyvkvpTklgQuUmGUIEkH7IXF/sEE=".into(),
|
||||||
|
address: "10.13.13.2/24".into(),
|
||||||
|
listen_port: 51820,
|
||||||
|
dns: Default::default(),
|
||||||
|
mtu: Default::default()
|
||||||
|
},
|
||||||
|
peers: vec![Peer{
|
||||||
|
endpoint: "wg.burrow.rs:51820".into(),
|
||||||
|
allowed_ips: vec!["8.8.8.8/32".into()],
|
||||||
|
public_key: "uy75leriJay0+oHLhRMpV+A5xAQ0hCJ+q7Ww81AOvT4=".into(),
|
||||||
|
preshared_key: Some("s7lx/mg+reVEMnGnqeyYOQkzD86n2+gYnx1M9ygi08k=".into()),
|
||||||
|
persistent_keepalive: Default::default(),
|
||||||
|
name: Default::default()
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ pub use iface::Interface;
|
||||||
pub use pcb::PeerPcb;
|
pub use pcb::PeerPcb;
|
||||||
pub use peer::Peer;
|
pub use peer::Peer;
|
||||||
pub use x25519_dalek::{PublicKey, StaticSecret};
|
pub use x25519_dalek::{PublicKey, StaticSecret};
|
||||||
|
pub use config::Config;
|
||||||
|
|
||||||
const WIREGUARD_CONFIG: &str = r#"
|
const WIREGUARD_CONFIG: &str = r#"
|
||||||
[Interface]
|
[Interface]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue