diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index 75980c9..996d1a7 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -684,11 +684,6 @@ class Message extends FTNBase */ private function parseAddresses(string $type,Collection $addresses,Collection &$rogue): Collection { - static $aos = NULL; - - if (! $aos) - $aos = collect(); - $nodes = collect(); $net = NULL; @@ -706,23 +701,37 @@ class Message extends FTNBase if ($this->fdomain && $this->fdomain->flatten) { $ao = Address::findZone($this->fdomain,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX,0); + $ftn = sprintf('%d:%d/%d@%s',0,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX,$this->fdomain->name); $aoid = $ao?->id; - if (! $ao) - $ftn = sprintf('%d:%d/%d',0,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX); - } else { $ftn = sprintf('%d:%d/%d',$this->fz,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX); + $aoid = NULL; + } - // @todo This should be enhanced to include the address at the time of the message. - if ($aos->has($ftn)) - $aoid = $aos->get($ftn); - else - $aos->put($ftn,($aoid=(Address::findFTN($ftn))?->id)); + switch ($type) { + case 'path': + if (! $aoid) { + $ao = (Address::findFTN($ftn,TRUE)); + $aoid = $ao?->id; + } + + break; + + case 'seenby': + if (! $aoid) { + $ao = (Address::findFTN($ftn)); + $aoid = $ao?->id; + } + + break; + + default: + throw new \Exception('Unknown type: '.$type); } if (! $aoid) { - Log::alert(sprintf('%s:! Undefined Node [%s] in %s.',self::LOGKEY,$ftn,$type)); + Log::alert(sprintf('%s:! Undefined Node [%s] in [%s].',self::LOGKEY,$ftn,$type)); $rogue->push($ftn); } else { diff --git a/app/Classes/Protocol.php b/app/Classes/Protocol.php index dcd51e0..448adbb 100644 --- a/app/Classes/Protocol.php +++ b/app/Classes/Protocol.php @@ -431,8 +431,9 @@ abstract class Protocol // Add unknown FTNs to the DB if ($this->node->aka_remote_authed->count()) { $so = $this->node->aka_remote_authed->first()->system; + } else { - $so = System::where('name','Discovered System')->single(); + $so = System::where('name','Discovered System')->first(); } if ($so && $so->exists) { diff --git a/app/Models/Address.php b/app/Models/Address.php index e0cf560..30c475d 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -472,8 +472,16 @@ class Address extends Model } if ($create) { - if (! $so) - throw new \Exception(sprintf('%s:AKA create requested for [%s], but system not provided',self::LOGKEY,$address)); + if (! $so) { + System::unguard(); + $so = System::firstOrCreate([ + 'name' => 'Discovered System', + 'sysop' => 'Unknown', + 'location' => '', + 'active' => TRUE, + ]); + System::reguard(); + } if (! $ftn['d']) { Log::alert(sprintf('%s:! Refusing to create address [%s] no domain available',self::LOGKEY,$address)); @@ -503,7 +511,7 @@ class Address extends Model if (! $zo->exists) { $zo->active = TRUE; $zo->notes = 'Auto created'; - $zo->system_id = System::where('name','Discovered System')->single()->id; + $zo->system_id = System::where('name','Discovered System')->first()->id; $do->zones()->save($zo); } @@ -525,6 +533,7 @@ class Address extends Model try { $so->addresses()->save($o); + } catch (\Exception $e) { Log::error(sprintf('%s:! ERROR creating address [%s] (%s)',self::LOGKEY,$x->toSql(),get_class($e)),['bindings'=>$x->getBindings()]); return NULL; diff --git a/resources/views/domain/list.blade.php b/resources/views/domain/list.blade.php index b298751..11d8606 100644 --- a/resources/views/domain/list.blade.php +++ b/resources/views/domain/list.blade.php @@ -33,7 +33,7 @@ {{ $do->name }} @endif - {{ $do->zones->pluck('zone_id')->sort()->join(', ') }} + {{ $do->zones->where('active',TRUE)->pluck('zone_id')->sort()->join(', ') }} {{ $do->active ? 'YES' : 'NO' }} {{ $do->managed() ? 'YES' : 'NO' }}