View Source Wireguardex (Wireguardex v0.3.2)
Wireguardex is an Elixir library for configuring WireGuard interfaces. It uses Rust NIFs for performance and safety.
This is the main module, providing the API for interface configuration and utilities such as key generation.
Link to this section Summary
Functions
Add a peer to a Device
using a config for the peer. A config can be generated
using a PeerConfigBuilder
.
Delete a Device
by its interface name.
Generates a random preshared key. It is returned as a base64 string
.
Generates a random private key. It is returned as a base64 string
.
Get a Device
by its interface name.
Return a private key's public key as a base64 string
.
Get a list of interface names of WireGuard devices.
Remove a peer from a Device
by the peer's public key.
Set a Device
by its interface name with a config. The config can be generated
using a DeviceConfigBuilder
.
Link to this section Types
@type device() :: Wireguardex.Device.t()
@type device_config() :: Wireguardex.DeviceConfig.t()
@type key() :: String.t()
@type name() :: String.t()
@type peer_config() :: Wireguardex.PeerConfig.t()
@type peer_stats() :: Wireguardex.PeerStats.t()
Link to this section Functions
@spec add_peer(name(), peer_config()) :: :ok | {:error, String.t()}
Add a peer to a Device
using a config for the peer. A config can be generated
using a PeerConfigBuilder
.
Returns :ok
if successful. {:error, error_info}
will be returned if adding
the peer to the device fails.
Delete a Device
by its interface name.
Returns :ok
if successful. {:error, error_info}
will be returned if deleting
the device fails.
@spec generate_private_key() :: key()
Generates a random private key. It is returned as a base64 string
.
Get a Device
by its interface name.
Returns {:ok, Device}
if successful. {:error, error_info}
will be returned
if getting the device fails.
Return a private key's public key as a base64 string
.
Returns {:ok, public_key}
if successful. {:error, error_info}
will be returned if
if getting the public key fails.
Get a list of interface names of WireGuard devices.
Returns {:ok, [...]}
if successful. {:error, error_info}
will be returned
if listing device interface names fails.
Remove a peer from a Device
by the peer's public key.
Returns :ok
if successful. {:error, error_info}
will be returned if removing
the peer from the device fails.
@spec set_device(device_config(), name()) :: :ok | {:error, String.t()}
Set a Device
by its interface name with a config. The config can be generated
using a DeviceConfigBuilder
.
Note if no device is present, a new one will be created for the given interface name.
Returns :ok
if successful. {:error, error_info}
will be returned if setting
the device fails.