mirror of
https://github.com/itdoginfo/podkop.git
synced 2026-01-01 22:28:59 +03:00
⚡️ perf(dns): improve DNS query performance and error handling
This commit is contained in:
@@ -2212,30 +2212,45 @@ check_dns_available() {
|
|||||||
|
|
||||||
if [ "$dns_type" = "doh" ]; then
|
if [ "$dns_type" = "doh" ]; then
|
||||||
# Generate random DNS query ID (2 bytes)
|
# Generate random DNS query ID (2 bytes)
|
||||||
local random_id=$(head -c2 /dev/urandom | hexdump -ve '1/1 "%.2x"')
|
local random_id=$(head -c2 /dev/urandom | hexdump -ve '1/1 "%.2x"' 2>/dev/null)
|
||||||
# Create DNS wire format query for google.com A record with random ID
|
if [ $? -ne 0 ]; then
|
||||||
local dns_query=$(printf "\x${random_id:0:2}\x${random_id:2:2}\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01" | base64)
|
error_message="Failed to generate random ID"
|
||||||
|
status="internal error"
|
||||||
# Try POST method first (RFC 8484 compliant)
|
|
||||||
local result=$(echo "$dns_query" | base64 -d | curl -H "Content-Type: application/dns-message" \
|
|
||||||
-H "Accept: application/dns-message" \
|
|
||||||
--data-binary @- \
|
|
||||||
--connect-timeout 5 -s \
|
|
||||||
"https://$dns_server/dns-query" 2>/dev/null)
|
|
||||||
|
|
||||||
if [ $? -eq 0 ] && [ -n "$result" ]; then
|
|
||||||
is_available=1
|
|
||||||
status="available"
|
|
||||||
else
|
else
|
||||||
# Try GET method as fallback, remove padding from base64
|
# Create DNS wire format query for google.com A record with random ID
|
||||||
local dns_query_no_padding=$(echo "$dns_query" | tr -d '=')
|
local dns_query=$(printf "\x${random_id:0:2}\x${random_id:2:2}\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01" | base64 2>/dev/null)
|
||||||
result=$(curl -H "accept: application/dns-message" \
|
if [ $? -ne 0 ]; then
|
||||||
--connect-timeout 5 -s \
|
error_message="Failed to generate DNS query"
|
||||||
"https://$dns_server/dns-query?dns=$dns_query_no_padding" 2>/dev/null)
|
status="internal error"
|
||||||
|
else
|
||||||
if [ $? -eq 0 ] && [ -n "$result" ]; then
|
# Try POST method first (RFC 8484 compliant) with shorter timeout
|
||||||
is_available=1
|
local result=$(echo "$dns_query" | base64 -d 2>/dev/null | curl -H "Content-Type: application/dns-message" \
|
||||||
status="available"
|
-H "Accept: application/dns-message" \
|
||||||
|
--data-binary @- \
|
||||||
|
--max-time 2 \
|
||||||
|
--connect-timeout 1 \
|
||||||
|
-s \
|
||||||
|
"https://$dns_server/dns-query" 2>/dev/null)
|
||||||
|
|
||||||
|
if [ $? -eq 0 ] && [ -n "$result" ]; then
|
||||||
|
is_available=1
|
||||||
|
status="available"
|
||||||
|
else
|
||||||
|
# Try GET method as fallback with shorter timeout
|
||||||
|
local dns_query_no_padding=$(echo "$dns_query" | tr -d '=' 2>/dev/null)
|
||||||
|
result=$(curl -H "accept: application/dns-message" \
|
||||||
|
--max-time 2 \
|
||||||
|
--connect-timeout 1 \
|
||||||
|
-s \
|
||||||
|
"https://$dns_server/dns-query?dns=$dns_query_no_padding" 2>/dev/null)
|
||||||
|
|
||||||
|
if [ $? -eq 0 ] && [ -n "$result" ]; then
|
||||||
|
is_available=1
|
||||||
|
status="available"
|
||||||
|
else
|
||||||
|
error_message="DoH server not responding"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif [ "$dns_type" = "dot" ]; then
|
elif [ "$dns_type" = "dot" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user