mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 19:44:08 +00:00
[wireguard] Restart the connection while the peer is offline so the endpoint is re-resolved (#20231)
This commit is contained in:
@@ -101,8 +101,13 @@ void Wireguard::update() {
|
||||
if (this->wg_peer_offline_time_ == 0) {
|
||||
ESP_LOGW(TAG, LOGMSG_PEER_STATUS, LOGMSG_OFFLINE, latest_handshake.c_str());
|
||||
this->wg_peer_offline_time_ = millis();
|
||||
this->wg_reconnect_time_ = this->wg_peer_offline_time_;
|
||||
} else if (this->enabled_) {
|
||||
ESP_LOGD(TAG, LOGMSG_PEER_STATUS, LOGMSG_OFFLINE, latest_handshake.c_str());
|
||||
if (millis() - this->wg_reconnect_time_ >= RECONNECT_INTERVAL_MS) {
|
||||
this->wg_reconnect_time_ = millis();
|
||||
this->stop_connection_();
|
||||
}
|
||||
this->start_connection_();
|
||||
}
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ class Wireguard final : public PollingComponent {
|
||||
|
||||
/// The last time the remote peer become offline.
|
||||
uint32_t wg_peer_offline_time_ = 0;
|
||||
uint32_t wg_reconnect_time_ = 0;
|
||||
|
||||
/** \brief The latest saved handshake.
|
||||
*
|
||||
@@ -159,6 +160,7 @@ void resume_wdt();
|
||||
|
||||
/// Size of buffer required for mask_key_to: 5 chars + "[...]=" + null = 12
|
||||
static constexpr size_t MASK_KEY_BUFFER_SIZE = 12;
|
||||
static constexpr uint32_t RECONNECT_INTERVAL_MS = 30000;
|
||||
|
||||
/// Strip most part of the key only for secure printing
|
||||
void mask_key_to(char *buffer, size_t len, const char *key);
|
||||
|
||||
Reference in New Issue
Block a user