pub struct WgConfigFile {
pub private_key: [u8; 32],
pub address: Ipv4Addr,
pub dns: Option<Ipv4Addr>,
pub mtu: Option<u16>,
pub peer_public_key: [u8; 32],
pub endpoint_host: String,
pub endpoint_port: u16,
pub preshared_key: Option<[u8; 32]>,
pub persistent_keepalive: Option<u16>,
}Expand description
Parsed WireGuard configuration file.
Fields§
§private_key: [u8; 32]Private key (base64 encoded in file).
address: Ipv4AddrInterface address (tunnel IP).
dns: Option<Ipv4Addr>DNS server (optional).
mtu: Option<u16>MTU for the tunnel interface (optional, defaults to 460).
peer_public_key: [u8; 32]Peer public key.
endpoint_host: StringPeer endpoint hostname or IP.
endpoint_port: u16Peer endpoint port.
Preshared key (optional).
persistent_keepalive: Option<u16>Persistent keepalive interval in seconds (optional).
Implementations§
Source§impl WgConfigFile
impl WgConfigFile
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Parse a WireGuard configuration file from the given path.
Sourcepub async fn into_wireguard_config(self) -> Result<WireGuardConfig>
pub async fn into_wireguard_config(self) -> Result<WireGuardConfig>
Convert to WireGuardConfig, resolving the endpoint hostname via DoH if needed. Uses the default Cloudflare DNS for resolution.
Sourcepub async fn into_wireguard_config_with_dns(
self,
dns_config: DohServerConfig,
) -> Result<WireGuardConfig>
pub async fn into_wireguard_config_with_dns( self, dns_config: DohServerConfig, ) -> Result<WireGuardConfig>
Convert to WireGuardConfig, resolving the endpoint hostname via DoH with custom DNS.
§Arguments
dns_config- The DNS server configuration to use for resolving the endpoint hostname.
§Example
use wireguard_netstack::{WgConfigFile, DohServerConfig};
let config = WgConfigFile::from_file("wg.conf")?
.into_wireguard_config_with_dns(DohServerConfig::google())
.await?;Trait Implementations§
Source§impl Clone for WgConfigFile
impl Clone for WgConfigFile
Source§fn clone(&self) -> WgConfigFile
fn clone(&self) -> WgConfigFile
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for WgConfigFile
impl RefUnwindSafe for WgConfigFile
impl Send for WgConfigFile
impl Sync for WgConfigFile
impl Unpin for WgConfigFile
impl UnsafeUnpin for WgConfigFile
impl UnwindSafe for WgConfigFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more