Skip to content

Commit 4c74d74

Browse files
committed
Retry endpoint name resolution 5 times.
1 parent 38ed4af commit 4c74d74

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/WireGuard.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ void WireGuard::begin(const IPAddress& localIP, const char* privateKey, const ch
6363
peer.allowed_mask = allowed_mask;
6464
}
6565
// If we know the endpoint's address can add here
66-
{
66+
for(int retry = 0; retry < 5; retry++) {
6767
ip_addr_t endpoint_ip = IPADDR4_INIT_BYTES(0, 0, 0, 0);
6868
struct addrinfo *res = NULL;
6969
struct addrinfo hint;
7070
memset(&hint, 0, sizeof(hint));
7171
memset(&endpoint_ip, 0, sizeof(endpoint_ip));
72-
ESP_ERROR_CHECK(lwip_getaddrinfo(remotePeerAddress, NULL, &hint, &res) == 0 ? ESP_OK : ESP_FAIL);
72+
if( lwip_getaddrinfo(remotePeerAddress, NULL, &hint, &res) != 0 ) {
73+
vTaskDelay(pdMS_TO_TICKS(2000));
74+
continue;
75+
}
7376
struct in_addr addr4 = ((struct sockaddr_in *) (res->ai_addr))->sin_addr;
7477
inet_addr_to_ip4addr(ip_2_ip4(&endpoint_ip), &addr4);
7578
lwip_freeaddrinfo(res);

0 commit comments

Comments
 (0)