Add configuration items to determine DNS records returned and sort order

This commit is contained in:
Deon George 2024-10-25 23:28:39 +11:00
parent 179233385b
commit 271bf937cf
3 changed files with 29 additions and 8 deletions

View File

@ -47,7 +47,7 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
FIDO_DIR=fido
FIDO_PACKET_KEEP=
FIDO_PACKET_KEEP=false
FIDO_STRICT=false
FILESYSTEM_DISK=s3
@ -58,6 +58,12 @@ AWS_ENDPOINT=
AWS_DEFAULT_REGION=home
AWS_USE_PATH_STYLE_ENDPOINT=true
MATRIX_SERVER=
MATRIX_AS_TOKEN=
MATRIX_HS_TOKEN=
#MATRIX_SERVER=
#MATRIX_AS_TOKEN=
#MATRIX_HS_TOKEN=
#FIDO_DNS_NS=
#FIDO_DNS_AAAA=
#FIDO_DNS_ORDER_AAAA=
#FIDO_DNS_A=
#FIDO_DNS_ORDER_A=

View File

@ -190,7 +190,8 @@ final class SocketClient {
{
Log::info(sprintf('%s:+ Creating connection to [%s:%d]',self::LOGKEY,$address,$port));
$sort = collect(['AAAA','A']);
$type = collect(config('fido.ip'))
->filter(fn($item)=>$item['enabled']);
if (filter_var($address,FILTER_VALIDATE_IP))
$resolved = collect([[
@ -199,9 +200,9 @@ final class SocketClient {
]]);
else
// We only look at AAAA/A records
$resolved = collect(dns_get_record($address,DNS_AAAA|DNS_A))
->filter(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')) !== FALSE; })
->sort(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')); });
$resolved = collect(dns_get_record($address,$type->map(fn($item)=>$item['type'])->sum()))
->filter(fn($item)=>$type->has(Arr::get($item,'type')))
->sort(fn($a,$b)=>$type->get(Arr::get($a,'type'))['order'] < $type->get(Arr::get($b,'type'))['order']);
if (! $resolved->count())
throw new SocketException(SocketException::CANT_CONNECT,sprintf('%s doesnt resolved to an IPv4/IPv6 address',$address));

View File

@ -43,4 +43,18 @@ return [
'down' => 35,
'delist' => 45,
],
// IP Address Resolution preferences
'ip' => [
'AAAA' => [
'enabled' => env('FIDO_DNS_AAAA',TRUE),
'order' => env('FIDO_DNS_ORDER_AAAA',2),
'type' => DNS_AAAA,
],
'A' => [
'enabled' => env('FIDO_DNS_A',TRUE),
'order' => env('FIDO_DNS_ORDER__ORDER',1),
'type' => DNS_A,
],
],
];