mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-17 04:49:13 +02:00
Optimize handshake by using ping instead of DNS lookup
Removed DNS lookup for handshake and replaced with ping.
This commit is contained in:
@@ -197,24 +197,17 @@ _wg_wait_handshake() {
|
|||||||
local timeout="${1:-20}"
|
local timeout="${1:-20}"
|
||||||
local iface="${config["Interface"]}"
|
local iface="${config["Interface"]}"
|
||||||
local peer_pk="${config["PublicKey"]}"
|
local peer_pk="${config["PublicKey"]}"
|
||||||
local deadline ts dns_ip
|
local deadline ts
|
||||||
|
|
||||||
deadline=$(( $(date +%s) + timeout ))
|
deadline=$(( $(date +%s) + timeout ))
|
||||||
|
|
||||||
while [ "$(date +%s)" -lt "${deadline}" ]; do
|
while [ "$(date +%s)" -lt "${deadline}" ]; do
|
||||||
# Trigger handshake using DNS servers from /etc/resolv.conf
|
ping -I "${iface}" -c1 -W1 1.1.1.1 >/dev/null 2>&1 || true
|
||||||
dns_ip="$(awk '/^nameserver[[:space:]]+/ {print $2; exit}' /etc/resolv.conf 2>/dev/null)"
|
|
||||||
if [ -n "${dns_ip}" ]; then
|
|
||||||
timeout 2 nslookup example.com "${dns_ip}" >/dev/null 2>&1 || true
|
|
||||||
else
|
|
||||||
getent ahosts example.com >/dev/null 2>&1 || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
ts="$(wg show "${iface}" latest-handshakes 2>/dev/null | awk -v pk="${peer_pk}" '$1==pk{print $2; exit}')"
|
ts="$(wg show "${iface}" latest-handshakes 2>/dev/null | awk -v pk="${peer_pk}" '$1==pk{print $2; exit}')"
|
||||||
if [ -n "${ts}" ] && [ "${ts}" -gt 0 ] 2>/dev/null; then
|
if [ -n "${ts}" ] && [ "${ts}" -gt 0 ] 2>/dev/null; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user