Struct wgctrl_rs::PeerConfigBuilder [−][src]
pub struct PeerConfigBuilder { /* fields omitted */ }
Builds and represents a single peer in a WireGuard interface configuration.
Note that if a peer with that public key already exists on the interface, the settings specified here will be applied on top of the existing settings, similarly to interface-wide settings.
If this is not what you want, use DeviceConfigBuilder::replace_peers
to replace all peer settings on the interface, or use
DeviceConfigBuilder::remove_peer_by_key
first
to remove the peer from the interface, and then apply a second configuration to re-add it.
Example
let peer_keypair = KeyPair::generate(); // create a new peer and allow it to connect from 192.168.1.2 let peer = PeerConfigBuilder::new(&peer_keypair.public) .replace_allowed_ips() .add_allowed_ip("192.168.1.2".parse()?, 32); // update our existing configuration with the new peer DeviceConfigBuilder::new().add_peer(peer).apply("wg-example"); println!("Send these keys to your peer: {:#?}", peer_keypair);
Methods
impl PeerConfigBuilder
[src]
impl PeerConfigBuilder
pub fn new(public_key: &Key) -> Self
[src]
pub fn new(public_key: &Key) -> Self
Creates a new PeerConfigBuilder
that does nothing when applied.
pub fn from_peer_config(config: PeerConfig) -> Self
[src]
pub fn from_peer_config(config: PeerConfig) -> Self
Creates a PeerConfigBuilder
from a PeerConfig
.
This is mostly a convenience method for cases when you want to copy some or most of the existing peer configuration to a new configuration.
This returns a PeerConfigBuilder
, so you can still call any methods
you need to override the imported settings.
Specifies a preshared key to be set for this peer.
Specifies that this peer's preshared key should be unset.
pub fn set_endpoint(self, address: IpAddr, port: u16) -> Self
[src]
pub fn set_endpoint(self, address: IpAddr, port: u16) -> Self
Specifies an exact endpoint that this peer should be allowed to connect from.
pub fn set_persistent_keepalive_interval(self, interval: u16) -> Self
[src]
pub fn set_persistent_keepalive_interval(self, interval: u16) -> Self
Specifies the interval between keepalive packets to be sent to this peer.
pub fn disable_persistent_keepalive(self) -> Self
[src]
pub fn disable_persistent_keepalive(self) -> Self
Specifies that this peer does not require keepalive packets.
pub fn add_allowed_ip(self, address: IpAddr, cidr: u8) -> Self
[src]
pub fn add_allowed_ip(self, address: IpAddr, cidr: u8) -> Self
Specifies an IP address this peer will be allowed to connect from/to.
See AllowedIp
for details. This method can be called
more than once, and all IP addresses will be added to the configuration.
pub fn add_allowed_ips(self, ips: &[AllowedIp]) -> Self
[src]
pub fn add_allowed_ips(self, ips: &[AllowedIp]) -> Self
Specifies multiple IP addresses this peer will be allowed to connect from/to.
See AllowedIp
for details. This method can be called
more than once, and all IP addresses will be added to the configuration.
pub fn allow_all_ips(self) -> Self
[src]
pub fn allow_all_ips(self) -> Self
Specifies this peer should be allowed to connect to all IP addresses.
This is a convenience method for cases when you want to connect to a server that all traffic should be routed through.
pub fn replace_allowed_ips(self) -> Self
[src]
pub fn replace_allowed_ips(self) -> Self
Specifies that the allowed IP addresses in this configuration should replace the existing configuration of the interface, not be appended to it.
Trait Implementations
impl Debug for PeerConfigBuilder
[src]
impl Debug for PeerConfigBuilder
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for PeerConfigBuilder
[src]
impl PartialEq for PeerConfigBuilder
fn eq(&self, other: &PeerConfigBuilder) -> bool
[src]
fn eq(&self, other: &PeerConfigBuilder) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &PeerConfigBuilder) -> bool
[src]
fn ne(&self, other: &PeerConfigBuilder) -> bool
This method tests for !=
.
impl Eq for PeerConfigBuilder
[src]
impl Eq for PeerConfigBuilder
impl Clone for PeerConfigBuilder
[src]
impl Clone for PeerConfigBuilder
fn clone(&self) -> PeerConfigBuilder
[src]
fn clone(&self) -> PeerConfigBuilder
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl Send for PeerConfigBuilder
impl Send for PeerConfigBuilder
impl Sync for PeerConfigBuilder
impl Sync for PeerConfigBuilder