Optimise the setting of our configuration via Setup::class, optimise the calculation of our_addresses()

This commit is contained in:
Deon George 2024-11-02 23:30:42 +11:00
parent 1b228a58c9
commit 3b7ce4b9ce
9 changed files with 72 additions and 66 deletions

View File

@ -504,8 +504,6 @@ class Message extends FTNBase
*/
public function __toString(): string
{
$s = Setup::findOrFail(config('app.id'));
$return = pack(collect(self::HEADER)->pluck(1)->join(''),
$this->mo->fftn->node_id, // Originating Node
$this->mo->tftn->node_id, // Destination Node
@ -529,7 +527,7 @@ class Message extends FTNBase
$this->mo->kludges->put('TOPT',$this->mo->tftn->point_id);
}
$this->mo->kludges->put($this->mo->isFlagSet(self::FLAG_LOCAL) ? 'PID:' : 'TID:',sprintf('%s %s',Setup::PRODUCT_NAME_SHORT,$s->version));
$this->mo->kludges->put($this->mo->isFlagSet(self::FLAG_LOCAL) ? 'PID:' : 'TID:',sprintf('%s %s',Setup::PRODUCT_NAME_SHORT,Setup::version()));
$this->mo->kludges->put('DBID:',$this->mo->id);
if ($this->mo instanceof Echomail)
@ -561,7 +559,7 @@ class Message extends FTNBase
$return .= sprintf("\x01Via %s @%s.UTC %s %s\r",
$this->us->ftn3d,
Carbon::now()->format('Ymd.His'),
Setup::PRODUCT_NAME_SHORT,$s->version);
Setup::PRODUCT_NAME_SHORT,Setup::version());
} else {
// FTS-0004.001/FSC-0068.001 The message SEEN-BY lines

View File

@ -3,6 +3,7 @@
namespace App\Classes;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use App\Classes\File\{Receive,Send};
@ -107,7 +108,7 @@ abstract class Protocol
public const TCP_SPEED = 115200;
protected SocketClient $client; /* Our socket details */
protected ?Setup $setup; /* Our setup */
protected Setup $setup; /* Our setup */
protected Node $node; /* The node we are communicating with */
/** The list of files we are sending */
protected Send $send;
@ -134,12 +135,9 @@ abstract class Protocol
abstract protected function protocol_session(bool $force_queue=FALSE): int;
public function __construct(Setup $o=NULL)
public function __construct()
{
if ($o && ! $o->system->akas->count())
throw new \Exception('We dont have any ACTIVE FTN addresses assigned');
$this->setup = $o;
$this->setup = Config::get('setup');
}
/**
@ -318,7 +316,7 @@ abstract class Protocol
Log::debug(sprintf('%s:- Presenting limited AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
} else {
$addresses = $this->setup->system->akas;
$addresses = our_address();
Log::debug(sprintf('%s:- Presenting ALL our AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
}

View File

@ -195,7 +195,7 @@ final class Binkp extends BaseProtocol
$this->msgs(self::BPM_NUL,sprintf('NDL %d,TCP,BINKP',$this->client->speed));
$this->msgs(self::BPM_NUL,sprintf('TIME %s',Carbon::now()->toRfc2822String()));
$this->msgs(self::BPM_NUL,
sprintf('VER %s-%s %s/%s',Setup::PRODUCT_NAME_SHORT,$this->setup->version,self::PROT,self::VERSION));
sprintf('VER %s-%s %s/%s',Setup::PRODUCT_NAME_SHORT,Setup::version(),self::PROT,self::VERSION));
if ($this->originate) {
$opt = $this->capGet(self::F_NOREL,self::O_WANT) ? ' NR' : '';

View File

@ -208,7 +208,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$makedata .= sprintf('{%s}{%s}{%s}{%s}',
Setup::product_id(),
Setup::PRODUCT_NAME_SHORT,
$this->setup->version,
Setup::version(),
'#000000' // Serial Numbers
);

View File

@ -3,12 +3,12 @@
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use App\Classes\Protocol\{Binkp,DNS,EMSI};
use App\Classes\Sock\Exception\SocketException;
use App\Classes\Sock\SocketServer;
use App\Models\Setup;
class ServerStart extends Command
{
@ -37,7 +37,11 @@ class ServerStart extends Command
public function handle(): int
{
Log::info(sprintf('%s:+ Server Starting (%d)',self::LOGKEY,getmypid()));
$o = Setup::findOrFail(config('app.id'));
if (! our_address()->count())
throw new \Exception('We dont have any ACTIVE FTN addresses assigned');
$o = Config::get('setup');
$start = collect();

View File

@ -5,6 +5,7 @@ namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Config;
use App\Models\Setup;
@ -45,8 +46,10 @@ class AddUserToView
*/
public function handle($request, Closure $next)
{
Config::set('setup',$x=Setup::find(config('app.id'))->load('system'));
$this->factory->share('user',$this->user);
$this->factory->share('setup',Setup::find(config('app.id')));
$this->factory->share('setup',$x);
return $next($request);
}

View File

@ -12,37 +12,37 @@ use App\Models\{Setup,User};
class TestEmail extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels;
/* User to send mail to */
public User $user;
/* Our setup object */
public Setup $setup;
/* User to send mail to */
public User $user;
/* Our setup object */
public Setup $setup;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(User $o)
{
$this->user = $o;
}
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(User $o)
{
$this->user = $o;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$this->setup = Setup::findOrFail(config('app.id'));
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$this->setup = Setup::findOrFail(config('app.id'));
return $this
->markdown('mail.system.test_email')
->subject('Just a test...')
->with([
'url'=>'https://localhost',
return $this
->markdown('mail.system.test_email')
->subject('Just a test...')
->with([
'url'=>sprintf('https://%s',gethostname()),
]);
}
}
}

View File

@ -71,9 +71,6 @@ class Setup extends Model
case 'msgs_pkt':
return Arr::get($this->options,$key,self::MAX_MSGS_PKT);
case 'version':
return File::exists('VERSION') ? chop(File::get('VERSION')) : 'dev';
default:
return parent::__get($key);
}
@ -113,6 +110,16 @@ class Setup extends Model
return hexstr($c);
}
/**
* Application version
*
* @return string
*/
public static function version(): string
{
return File::exists('VERSION') ? chop(File::get('VERSION')) : 'dev';
}
/* RELATIONS */
/**

View File

@ -2,7 +2,7 @@
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
use App\Models\{Address,Domain,Setup};
@ -93,33 +93,29 @@ if (! function_exists('hexstr')) {
*/
function our_address(Domain|Address $o=NULL): Collection|Address|NULL
{
$so = Cache::remember('so',5,function() {
return Setup::findOrFail(config('app.id'));
});
if (! Config::has('setup'))
Config::set('setup',Setup::findOrFail(config('app.id')));
$our = Cache::remember(sprintf('%d-akas',$so->system_id),60,function() use ($so) {
$so->load([
'system:id,name',
'system.akas:addresses.id,addresses.zone_id,region_id,host_id,node_id,point_id,addresses.system_id,addresses.active,role',
'system.akas.zone:id,domain_id,zone_id',
'system.akas.zone.domain:id,name',
]);
return $so->system->akas;
});
$so = Config::get('setup');
$so->loadMissing([
'system:id,name',
'system.akas:addresses.id,addresses.zone_id,region_id,host_id,node_id,point_id,addresses.system_id,addresses.active,role',
'system.akas.zone:id,domain_id,zone_id',
'system.akas.zone.domain:id,name',
]);
// If we dont have any addresses
if ($our->count() === 0)
if ($so->system->akas->count() === 0)
return NULL;
// We havent asked for an address/domain, so we'll return them all.
if (is_null($o))
return $our;
return $so->system->akas;
// We are requesting a list of addresses for a Domain, or a specific Address, and we have more than 1
switch (get_class($o)) {
case Address::class:
$filter = $our
$filter = $so->system->akas
->filter(fn($item)=>$item->zone->domain_id === $o->zone->domain_id)
->sortBy('role_id');
@ -130,7 +126,7 @@ function our_address(Domain|Address $o=NULL): Collection|Address|NULL
return $filter->count() ? $filter->last()->unsetRelation('nodes_hub') : NULL;
case Domain::class:
return $our
return $so->system->akas
->filter(fn($item)=>$item->zone->domain_id === $o->id)
->sortBy('role_id');