pub struct InterfaceBuilder { /* private fields */ }
Expand description
Builder, that used for creating Interface
s.
§Examples
use wireguard_conf::prelude::*;
let server_private_key = PrivateKey::random();
let interface = InterfaceBuilder::new()
.address("10.0.0.1/24".parse().unwrap())
.listen_port(6969)
.private_key(server_private_key.clone())
.set_dns(vec!["8.8.8.8".to_string(), "8.8.4.4".to_string()])
.endpoint("vpn.example.com".to_string())
// .add_peer(some_peer)
.build();
assert_eq!(interface.address, "10.0.0.1/24".parse().unwrap());
assert_eq!(interface.listen_port, Some(6969));
assert_eq!(interface.private_key, server_private_key);
assert_eq!(interface.dns, vec!["8.8.8.8", "8.8.4.4"]);
assert_eq!(interface.endpoint, Some("vpn.example.com".to_string()));
Implementations§
Source§impl InterfaceBuilder
impl InterfaceBuilder
pub fn new() -> InterfaceBuilder
Sourcepub fn listen_port(self, listen_port: u16) -> Self
pub fn listen_port(self, listen_port: u16) -> Self
Set the listen port.
Sourcepub fn private_key(self, private_key: PrivateKey) -> Self
pub fn private_key(self, private_key: PrivateKey) -> Self
Set the private key.
Sourcepub fn endpoint(self, endpoint: String) -> Self
pub fn endpoint(self, endpoint: String) -> Self
Set the endpoint.
§Note
[Interface]
section will have# Name = <endpoint>
comment at the top.- Exported
Peer
(viaInterface::to_peer
) will have this endpoint.
Sourcepub fn set_mtu(self, value: usize) -> Self
pub fn set_mtu(self, value: usize) -> Self
Set Maximum Transmission Unit (MTU, aka packet/frame size).
Sourcepub fn amnezia_settings(self, amnezia_settings: AmneziaSettings) -> Self
Available on crate feature amneziawg
only.
pub fn amnezia_settings(self, amnezia_settings: AmneziaSettings) -> Self
amneziawg
only.Sets AmneziaWG obfuscation values.
Sourcepub fn set_pre_up(self, snippets: Vec<String>) -> Self
pub fn set_pre_up(self, snippets: Vec<String>) -> Self
Set commands, that will be executed before the interface is brought up.
Sourcepub fn add_pre_up(self, snippet: String) -> Self
pub fn add_pre_up(self, snippet: String) -> Self
Add command, that will be executed before the interface is brought up.
Sourcepub fn set_pre_down(self, snippets: Vec<String>) -> Self
pub fn set_pre_down(self, snippets: Vec<String>) -> Self
Set commands, that will be executed before the interface is brought down.
Sourcepub fn add_pre_down(self, snippet: String) -> Self
pub fn add_pre_down(self, snippet: String) -> Self
Add command, that will be executed before the interface is brought down.
Sourcepub fn set_post_up(self, snippets: Vec<String>) -> Self
pub fn set_post_up(self, snippets: Vec<String>) -> Self
Set commands, that will be executed after the interface is brought up.
Sourcepub fn add_post_up(self, snippet: String) -> Self
pub fn add_post_up(self, snippet: String) -> Self
Add command, that will be executed after the interface is brought up.
Sourcepub fn set_post_down(self, snippets: Vec<String>) -> Self
pub fn set_post_down(self, snippets: Vec<String>) -> Self
Set commands, that will be executed after the interface is brought down.
Sourcepub fn add_post_down(self, snippet: String) -> Self
pub fn add_post_down(self, snippet: String) -> Self
Add command, that will be executed after the interface is brought down.
Trait Implementations§
Source§impl Default for InterfaceBuilder
impl Default for InterfaceBuilder
Source§fn default() -> InterfaceBuilder
fn default() -> InterfaceBuilder
Auto Trait Implementations§
impl Freeze for InterfaceBuilder
impl RefUnwindSafe for InterfaceBuilder
impl Send for InterfaceBuilder
impl Sync for InterfaceBuilder
impl Unpin for InterfaceBuilder
impl UnwindSafe for InterfaceBuilder
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
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>
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>
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