From 27c050dc387e8f6c32d5f3aca9f813fa35ddf09a Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 14 Dec 2023 16:53:56 +1100 Subject: [PATCH] When we have multiple addresses, add we want a specific address, return the lowest role, or if strict mode enable, return the lowest role that is higher than the target --- .env.example | 1 + app/Classes/Dynamic/HubStats.php | 2 +- app/Models/Address.php | 3 ++- app/Models/System.php | 4 +++- app/helpers.php | 22 +++++++++++++++------- config/fido.php | 2 ++ 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 10a909b..ca84754 100644 --- a/.env.example +++ b/.env.example @@ -48,6 +48,7 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" FIDO_DIR=fido FIDO_PACKET_KEEP= +FIDO_STRICT=FALSE FILESYSTEM_DISK=s3 AWS_ACCESS_KEY_ID= diff --git a/app/Classes/Dynamic/HubStats.php b/app/Classes/Dynamic/HubStats.php index 5ba653a..c3f081d 100644 --- a/app/Classes/Dynamic/HubStats.php +++ b/app/Classes/Dynamic/HubStats.php @@ -70,7 +70,7 @@ class HubStats extends Dynamic $header = "| %-12s | %4d | %3d | %3d | %16s | %5s | %5s |\r\n"; - $output = sprintf("Hub Status for [%s] as at [%s]\r\n",our_address($this->ao->zone->domain)->where('active',TRUE)->first()->ftn,$date); + $output = sprintf("Hub Status for [%s] as at [%s]\r\n",our_address($this->ao->zone->domain,$this->ao)->ftn,$date); $output .= "\r"; $output .= "+--------------+------+-----+-----+------------------+-------+-------+\r\n"; $output .= "| FTN | ECHO | NET |FILES| LAST SESSION | MODE |AUTOHLD|\r\n"; diff --git a/app/Models/Address.php b/app/Models/Address.php index 812ed5c..2d2da41 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -714,6 +714,7 @@ class Address extends Model * * @param bool $update * @return Packet|null + * @throws \Exception */ public function getNetmail(bool $update=FALSE): ?Packet { @@ -769,7 +770,7 @@ class Address extends Model public function getPacket(Collection $msgs,string $passwd=NULL): ?Packet { $s = Setup::findOrFail(config('app.id')); - $ao = $s->system->match($this->zone)->first(); + $ao = our_address($this->zone->domain,$this); // If we dont match on the address, we cannot pack mail for that system if (! $ao) { diff --git a/app/Models/System.php b/app/Models/System.php index d5370e9..148ba31 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -65,7 +65,9 @@ class System extends Model public function akas() { return $this->hasMany(Address::class) - ->active(); + ->active() + ->FTNorder() + ->orderBy('role','ASC'); } public function mailers() diff --git a/app/helpers.php b/app/helpers.php index 5aaceea..41f9f82 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -85,16 +85,24 @@ if (! function_exists('hexstr')) { * Return our addresses. * If zone provided, limit the list to those within the zone * - * @param Domain|NULL $do - * @return Collection + * @param Domain|NULL $do Limit the addresses for the specific domain + * @param Address|null $ao If address is presented, show the address we use when talking to that address + * @return Collection|Address|NULL */ -function our_address(Domain $do=NULL): Collection +function our_address(Domain $do=NULL,Address $ao=NULL): Collection|Address|NULL { - $our = Setup::findOrFail(config('app.id'))->system->addresses; + $our = Setup::findOrFail(config('app.id')) + ->system + ->akas; - return $do - ? $our->filter(function($item) use ($do) { return $item->zone->domain_id === $do->id; }) - : $our; + if ($do) + $our = $our->filter(function($item) use ($do) { return $item->zone->domain_id === $do->id; }); + + // If we are looking for a specific address, and there is only 1 result, return it, otherwise return what we have + if ($ao && config('fido.strict') && ($x=$our->filter(function($item) use ($ao) { return $item->role <= $ao->role; }))->count()) + $our = $x; + + return $ao ? $our->last() : $our; } /** diff --git a/config/fido.php b/config/fido.php index b182ed5..7f18b92 100644 --- a/config/fido.php +++ b/config/fido.php @@ -34,4 +34,6 @@ return [ // Number of messages in a packet that will result in them being queued for processing 'queue_msgs' => env('FIDO_QUEUE_MSGS', 50), + // Strict mode enforces what address we present to uplinks, when we carry more than 1 address with different roles + 'strict' => env('FIDO_STRICT',FALSE), ]; \ No newline at end of file