[wireguard] Restart the connection while the peer is offline so the endpoint is re-resolved (#20231)

This commit is contained in:
Jonathan Swoboda
2026-10-06 11:16:57 -04:00
committed by GitHub
parent 74d0a90308
commit fb20966353
2 changed files with 7 additions and 0 deletions
@@ -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_();
}
+2
View File
@@ -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);