Struct wireguard_control::PeerConfigBuilder[][src]

pub struct PeerConfigBuilder { /* fields omitted */ }
Expand description

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
DeviceUpdate::new().add_peer(peer).apply(&"wg-example".parse().unwrap(), Backend::Userspace);

println!("Send these keys to your peer: {:#?}", peer_keypair);

Implementations

Creates a new PeerConfigBuilder that does nothing when applied.

The public key used in this builder.

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.

Specifies an exact endpoint that this peer should be allowed to connect from.

Specifies the interval between keepalive packets to be sent to this peer.

Specifies that this peer does not require keepalive packets.

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.

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.

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.

Specifies that the allowed IP addresses in this configuration should replace the existing configuration of the interface, not be appended to it.

Mark peer for removal from interface.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.