Further enhancement with #9063a2a - to ensure our message addressing and content picks the right address

This commit is contained in:
Deon George 2023-12-18 15:13:16 +11:00
parent 1ded66990c
commit 13e51724c0
34 changed files with 68 additions and 93 deletions

View File

@ -90,7 +90,7 @@ class Tic extends FTNBase
if (! $this->to)
throw new \Exception('No to address defined');
$sysaddress = ($x=Setup::findOrFail(config('app.id'))->system)->match($this->to->zone)->first();
$sysaddress = our_address($this->to->zone->domain,$this->to);
$result = collect();
@ -233,7 +233,7 @@ class Tic extends FTNBase
// This should be one of my addresses
case 'to':
$ftns = Setup::findOrFail(config('app.id'))->system->addresses->pluck('ftn3d');
$ftns = our_address()->pluck('ftn3d');
if (! ($ftns->contains($m[2])))
throw new NotToMeException(sprintf('FTN Address [%s] not found or not one of my addresses',$m[2]));

View File

@ -307,14 +307,14 @@ abstract class Protocol
$addresses = collect();
foreach (($this->originate ? $this->node->aka_remote_authed : $this->node->aka_remote) as $ao)
$addresses = $addresses->merge($this->setup->system->match($ao->zone,Address::NODE_ZC|Address::NODE_RC|Address::NODE_NC|Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT));
$addresses = $addresses->merge(our_address($ao->zone->domain));
$addresses = $addresses->unique();
Log::debug(sprintf('%s:- Presenting limited AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
} else {
$addresses = $this->setup->system->addresses;
$addresses = $this->setup->system->akas;
Log::debug(sprintf('%s:- Presenting ALL our AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
}

View File

@ -833,12 +833,11 @@ class SystemController extends Controller
if (! $request->system_id)
return redirect('user/system/register');
$s = Setup::findOrFail(config('app.id'))->system;
$so = System::findOrFail($request->system_id);
$ca = NULL;
$la = NULL;
foreach ($s->akas as $ao) {
foreach (our_address() as $ao) {
if (($ca=$so->match($ao->zone))->count())
break;
}

View File

@ -27,7 +27,7 @@ class AreafixRequest extends FormRequest
],
'fftn_id' => [
'required',
Rule::in(Setup::findOrFail(config('app.id'))->system->akas->pluck('id')),
Rule::in(our_address()->pluck('id')),
],
'tftn_id' => [
'required',

View File

@ -58,7 +58,7 @@ class MessageProcess implements ShouldQueue
public function handle()
{
// Load our details
$ftns = Setup::findOrFail(config('app.id'))->system->addresses;
$ftns = our_address();
// If we are a netmail
if ($this->msg->isNetmail()) {

View File

@ -74,7 +74,6 @@ class NodelistImport implements ShouldQueue
*/
public function handle()
{
$us = Setup::findOrFail(config('app.id'));
$our_systems = SystemZone::select('system_id')
->get()
->pluck('system')
@ -94,7 +93,7 @@ class NodelistImport implements ShouldQueue
->pluck('id')
->diff($our_systems);
$our_addresses = $us->system->addresses->pluck('id');
$our_addresses = our_address()->pluck('id');
// Get the file from the host
$file = $this->getFileFromHost(self::importkey,$this->file);

View File

@ -26,7 +26,7 @@ class SystemHeartbeat #implements ShouldQueue
public function handle(): void
{
// Our zones
$our_zones = Setup::findOrFail(config('app.id'))->system->addresses->pluck('zone_id')->unique();
$our_zones = our_address()->pluck('zone_id')->unique();
// Find our uplinks that are hubs, NC, RC or ZCs
// Find any system that also has heartbeat configured

View File

@ -846,6 +846,7 @@ class Address extends Model
* Netmail alerts waiting to be sent to this system
*
* @return Collection
* @throws \Exception
*/
public function netmailAlertWaiting(): Collection
{

View File

@ -146,16 +146,6 @@ class Domain extends Model
*/
public function managed(): bool
{
static $so = NULL;
if (is_null($so))
$so = Setup::findOrFail(config('app.id'));
return $so
->system
->addresses
->where('zone.domain.active',TRUE)
->pluck('zone.domain_id')
->contains($this->id);
return our_address($this)->count() > 0;
}
}

View File

@ -214,7 +214,7 @@ final class Echomail extends Model implements Packet
{
Log::info(sprintf('%s:+ Bundling [%s]',self::LOGKEY,$this->id));
$sysaddress = Setup::findOrFail(config('app.id'))->system->match($this->fftn->zone)->first();
$sysaddress = our_address($this->fftn->zone->domain,$this->fftn);
if (! $sysaddress)
throw new \Exception(sprintf('%s:! We dont have an address in this network? (%s)',self::LOGKEY,$this->fftn->zone->domain->name));

View File

@ -206,12 +206,11 @@ final class Netmail extends Model implements Packet
$o->tearline = $this->tearline;
// VIA kludge
$sysaddress = Setup::findOrFail(config('app.id'))->system->match($this->fftn->zone)->first();
$via = $this->via ?: collect();
// Add our address to the VIA line
$via->push(
sprintf('%s @%s.UTC %s %d.%d/%s %s',
$sysaddress->ftn3d,
our_address($this->fftn->zone->domain,$this->fftn)->ftn3d,
Carbon::now()->utc()->format('Ymd.His'),
str_replace(' ','_',Setup::PRODUCT_NAME),
Setup::PRODUCT_VERSION_MAJ,

View File

@ -65,7 +65,12 @@ class System extends Model
public function akas()
{
return $this->hasMany(Address::class)
->active()
->select('addresses.*')
->join('zones',['zones.id'=>'addresses.zone_id'])
->join('domains',['domains.id'=>'zones.domain_id'])
->where('addresses.active',TRUE)
->where('zones.active',TRUE)
->where('domains.active',TRUE)
->FTNorder()
->orderBy('role','ASC');
}

View File

@ -39,8 +39,7 @@ class EchomailChannel
if (! $echoarea = $notifiable->routeNotificationFor('echomail',$notification))
return;
$so = Setup::findOrFail(config('app.id'))->system;
$o = $notification->toEchomail($so,$notifiable);
$o = $notification->toEchomail($notifiable);
Log::info(sprintf('%s:= Posted echomail [%s] to [%s]',self::LOGKEY,$o->msgid,$echoarea));
}

View File

@ -39,8 +39,7 @@ class NetmailChannel
if (! $ao = $notifiable->routeNotificationFor('netmail',$notification))
return;
$so = Setup::findOrFail(config('app.id'))->system;
$o = $notification->toNetmail($so,$notifiable);
$o = $notification->toNetmail($notifiable);
Log::info(sprintf('%s:= Sent netmail [%s] to [%s]',self::LOGKEY,$o->msgid,$ao->ftn));
}

View File

@ -40,14 +40,13 @@ abstract class Echomails extends Notification //implements ShouldQueue
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Echomail
* @throws \Exception
*/
abstract public function toEchomail(System $so,object $notifiable): Echomail;
abstract public function toEchomail(object $notifiable): Echomail;
protected function setupEchomail(Message $mo,System $so,object $notifiable): Echomail
protected function setupEchomail(Message $mo,object $notifiable): Echomail
{
$echoarea = $notifiable->routeNotificationFor(static::via);
$eo = Echoarea::where('name',$echoarea)->singleOrFail();
@ -61,7 +60,7 @@ abstract class Echomails extends Notification //implements ShouldQueue
$o->datetime = Carbon::now();
$o->tzoffset = $o->datetime->utcOffset();
$o->fftn_id = ($x=$so->match($mo->fboss_o->zone)->first())->id;
$o->fftn_id = ($x=our_address($mo->fboss_o->zone->domain,$mo->fboss_o))->id;
$o->flags = (Message::FLAG_LOCAL);
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);

View File

@ -34,14 +34,13 @@ class Test extends Echomails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Echomail
* @throws \Exception
*/
public function toEchomail(System $so,object $notifiable): Echomail
public function toEchomail(object $notifiable): Echomail
{
$o = $this->setupEchomail($this->mo,$so,$notifiable);
$o = $this->setupEchomail($this->mo,$notifiable);
$echoarea = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Creating test echomail to [%s]',self::LOGKEY,$echoarea));

View File

@ -40,14 +40,13 @@ abstract class Netmails extends Notification //implements ShouldQueue
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
abstract public function toNetmail(System $so,object $notifiable): Netmail;
abstract public function toNetmail(object $notifiable): Netmail;
protected function setupNetmail(System $so,object $notifiable): Netmail
protected function setupNetmail(object $notifiable): Netmail
{
$ao = $notifiable->routeNotificationFor(static::via);
@ -58,7 +57,7 @@ abstract class Netmails extends Notification //implements ShouldQueue
$o->datetime = Carbon::now();
$o->tzoffset = $o->datetime->utcOffset();
$o->fftn_id = $so->match($ao->zone)->first()->id;
$o->fftn_id = our_address($ao->zone->domain,$ao);
$o->tftn_id = $ao->id;
$o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE);
$o->cost = 0;

View File

@ -31,14 +31,13 @@ class AddressLink extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Sending a link code for address [%s]',self::LOGKEY,$ao->ftn));

View File

@ -32,14 +32,13 @@ class Areafix extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Responding to areafix with netmail to [%s]',self::LOGKEY,$ao->ftn));

View File

@ -32,14 +32,13 @@ class NotConfiguredHere extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Responding to areafix for a node [%s] not configured here',self::LOGKEY,$ao->ftn));

View File

@ -33,14 +33,13 @@ class EchoareaNoWrite extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Creating ECHOMAIL NO WRITE netmail to [%s]',self::LOGKEY,$ao->ftn));

View File

@ -33,14 +33,13 @@ class EchoareaNotExist extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Creating ECHOMAIL NOT EXIST netmail to [%s]',self::LOGKEY,$ao->ftn));

View File

@ -33,14 +33,13 @@ class EchoareaNotSubscribed extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Creating ECHOMAIL NOT SUBSCRIBED netmail to [%s]',self::LOGKEY,$ao->ftn));

View File

@ -33,14 +33,13 @@ class EchomailBadAddress extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Creating ECHOMAIL BAD ADDRESS netmail to [%s]',self::LOGKEY,$ao->ftn));

View File

@ -35,14 +35,13 @@ class NetmailForward extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Advising [%s@%s] that netmail to [%s] will be forwarded to [%s].',self::LOGKEY,$this->mo->user_from,$ao->ftn,$this->mo->user_to,$this->ao->ftn));

View File

@ -31,10 +31,13 @@ class PacketPasswordInvalid extends Netmails
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Creating netmail to [%s] - system using invalid packet password',self::LOGKEY,$ao->ftn));

View File

@ -34,14 +34,13 @@ class Ping extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Creating PING netmail to [%s]',self::LOGKEY,$ao->ftn));

View File

@ -21,14 +21,13 @@ class PollingFailed extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Creating auto hold netmail to [%s]',self::LOGKEY,$ao->ftn));

View File

@ -33,14 +33,13 @@ class Reject extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Creating reject netmail to [%s]',self::LOGKEY,$ao->ftn));

View File

@ -17,14 +17,13 @@ class Test extends Netmails
/**
* Get the mail representation of the notification.
*
* @param System $so
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(System $so,object $notifiable): Netmail
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($so,$notifiable);
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Creating TEST netmail to [%s]',self::LOGKEY,$ao->ftn));

View File

@ -15,11 +15,9 @@ trait MsgID
public function save(array $options = [])
{
// Only create a MSGID for locally generated content
if ((! $this->exists) && ($this->flags & Message::FLAG_LOCAL)) {
$ftns = Setup::findOrFail(config('app.id'))->system->match($this->fftn->zone)->first();
if (is_null(Arr::get($this->attributes,'msgid')))
$this->attributes['msgid'] = sprintf('%s %08x',$ftns->ftn4d,timew());
if ((! $this->exists) && ($this->flags & Message::FLAG_LOCAL) && (is_null(Arr::get($this->attributes,'msgid')))) {
$ftn = our_address($this->fftn->zone->domain,$this->fftn);
$this->attributes['msgid'] = sprintf('%s %08x',$ftn->ftn4d,timew());
}
return parent::save($options);

View File

@ -91,15 +91,13 @@ if (! function_exists('hexstr')) {
*/
function our_address(Domain $do=NULL,Address $ao=NULL): Collection|Address|NULL
{
$our = Setup::findOrFail(config('app.id'))
->system
->akas;
$our = Setup::findOrFail(config('app.id'))->system->akas;
if ($do)
$our = $our->filter(function($item) use ($do) { return $item->zone->domain_id === $do->id; });
$our = $our->filter(function($item) use ($do) { return $item->zone->domain_id === $do->id; })->sortBy('role');
// 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())
if ($ao && config('fido.strict') && ($x=$our->filter(function($item) use ($ao) { return $item->role <= $ao->role; })->sortBy('role'))->count())
$our = $x;
return $ao ? $our->last() : $our;

View File

@ -61,10 +61,10 @@ use App\Classes\Protocol\{Binkp,EMSI,DNS};
<tr><th colspan="2">System Addresses</th></tr>
</thead>
<tbody>
@foreach ($o->system->addresses->sortBy('zone.domain.name')->groupBy('zone_id') as $zones)
@foreach ($o->system->akas->sortBy('zone.domain.name')->groupBy('zone_id') as $addresses)
<tr>
<th>{{ $zones->first()->zone->domain->name }}</th>
<th class="text-end">{!! $zones->pluck('ftn')->join('<br>') !!}</th>
<th>{{ $addresses->first()->zone->domain->name }}</th>
<th class="text-end">{!! $addresses->pluck('ftn')->join('<br>') !!}</th>
</tr>
@endforeach
</tbody>

View File

@ -88,7 +88,7 @@ class RoutingTest extends TestCase
// Make sure I'm configured correctly for the rest of the tests
public function test_my_addresses()
{
$ftns = Setup::findOrFail(config('app.id'))->system->addresses;
$ftns = our_address();
$this->assertEquals(1,$ftns->count());
}