10#ifdef USE_BINARY_SENSOR
22#include <esp_wireguard.h>
34#ifdef USE_BINARY_SENSOR
36 SUB_BINARY_SENSOR(enabled)
46 void setup()
override;
48 void update()
override;
49 void dump_config()
override;
50 void on_shutdown()
override;
51 bool can_proceed()
override;
56 void set_netmask(
const char *netmask) { this->
netmask_ = netmask; }
58 void set_peer_endpoint(
const char *endpoint) { this->
peer_endpoint_ = endpoint; }
60 void set_peer_port(uint16_t port) { this->
peer_port_ = port; }
64 void set_address(
const std::string &
address) =
delete;
65 void set_netmask(
const std::string &netmask) =
delete;
66 void set_private_key(
const std::string &
key) =
delete;
67 void set_peer_endpoint(
const std::string &endpoint) =
delete;
68 void set_peer_public_key(
const std::string &
key) =
delete;
69 void set_preshared_key(
const std::string &
key) =
delete;
74 void set_keepalive(
const uint16_t seconds) { this->
keepalive_ = seconds; }
88 void publish_enabled_state();
91 bool is_enabled() {
return this->
enabled_; }
93 bool is_peer_up()
const;
94 time_t get_latest_handshake()
const;
118 wireguard_config_t
wg_config_ = ESP_WIREGUARD_CONFIG_DEFAULT();
119 wireguard_ctx_t
wg_ctx_ = ESP_WIREGUARD_CONTEXT_DEFAULT();
145static constexpr size_t MASK_KEY_BUFFER_SIZE = 12;
146static constexpr uint32_t RECONNECT_INTERVAL_MS = 30000;
virtual void setup()
Where the component's initialization should happen.
This class simplifies creating components that periodically check a state.
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
Main Wireguard component class.
bool enabled_
When false the wireguard link will not be established.
time::RealTimeClock * srctime_
bool proceed_allowed_
Set to false to block the setup step until peer is connected.
const char * private_key_
uint32_t wg_peer_offline_time_
The last time the remote peer become offline.
uint32_t wg_reconnect_time_
esp_err_t wg_initialized_
const char * peer_public_key_
const char * preshared_key_
const AllowedIP * allowed_ips_
const char * peer_endpoint_
time_t latest_saved_handshake_
The latest saved handshake.
wireguard_config_t wg_config_
constexpr float BEFORE_CONNECTION
For components that should be initialized after WiFi and before API is connected.
void mask_key_to(char *buffer, size_t len, const char *key)
Strip most part of the key only for secure printing.
Allowed IP entry for WireGuard peer configuration.