Optimise the setting of our configuration via Setup::class, optimise the calculation of our_addresses()
This commit is contained in:
parent
1b228a58c9
commit
3b7ce4b9ce
@ -504,8 +504,6 @@ class Message extends FTNBase
|
|||||||
*/
|
*/
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
$s = Setup::findOrFail(config('app.id'));
|
|
||||||
|
|
||||||
$return = pack(collect(self::HEADER)->pluck(1)->join(''),
|
$return = pack(collect(self::HEADER)->pluck(1)->join(''),
|
||||||
$this->mo->fftn->node_id, // Originating Node
|
$this->mo->fftn->node_id, // Originating Node
|
||||||
$this->mo->tftn->node_id, // Destination 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('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);
|
$this->mo->kludges->put('DBID:',$this->mo->id);
|
||||||
|
|
||||||
if ($this->mo instanceof Echomail)
|
if ($this->mo instanceof Echomail)
|
||||||
@ -561,7 +559,7 @@ class Message extends FTNBase
|
|||||||
$return .= sprintf("\x01Via %s @%s.UTC %s %s\r",
|
$return .= sprintf("\x01Via %s @%s.UTC %s %s\r",
|
||||||
$this->us->ftn3d,
|
$this->us->ftn3d,
|
||||||
Carbon::now()->format('Ymd.His'),
|
Carbon::now()->format('Ymd.His'),
|
||||||
Setup::PRODUCT_NAME_SHORT,$s->version);
|
Setup::PRODUCT_NAME_SHORT,Setup::version());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// FTS-0004.001/FSC-0068.001 The message SEEN-BY lines
|
// FTS-0004.001/FSC-0068.001 The message SEEN-BY lines
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Classes;
|
namespace App\Classes;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Config;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use App\Classes\File\{Receive,Send};
|
use App\Classes\File\{Receive,Send};
|
||||||
@ -107,7 +108,7 @@ abstract class Protocol
|
|||||||
public const TCP_SPEED = 115200;
|
public const TCP_SPEED = 115200;
|
||||||
|
|
||||||
protected SocketClient $client; /* Our socket details */
|
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 */
|
protected Node $node; /* The node we are communicating with */
|
||||||
/** The list of files we are sending */
|
/** The list of files we are sending */
|
||||||
protected Send $send;
|
protected Send $send;
|
||||||
@ -134,12 +135,9 @@ abstract class Protocol
|
|||||||
|
|
||||||
abstract protected function protocol_session(bool $force_queue=FALSE): int;
|
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())
|
$this->setup = Config::get('setup');
|
||||||
throw new \Exception('We dont have any ACTIVE FTN addresses assigned');
|
|
||||||
|
|
||||||
$this->setup = $o;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -318,7 +316,7 @@ abstract class Protocol
|
|||||||
Log::debug(sprintf('%s:- Presenting limited AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
|
Log::debug(sprintf('%s:- Presenting limited AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$addresses = $this->setup->system->akas;
|
$addresses = our_address();
|
||||||
|
|
||||||
Log::debug(sprintf('%s:- Presenting ALL our AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
|
Log::debug(sprintf('%s:- Presenting ALL our AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
|
||||||
}
|
}
|
||||||
|
@ -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('NDL %d,TCP,BINKP',$this->client->speed));
|
||||||
$this->msgs(self::BPM_NUL,sprintf('TIME %s',Carbon::now()->toRfc2822String()));
|
$this->msgs(self::BPM_NUL,sprintf('TIME %s',Carbon::now()->toRfc2822String()));
|
||||||
$this->msgs(self::BPM_NUL,
|
$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) {
|
if ($this->originate) {
|
||||||
$opt = $this->capGet(self::F_NOREL,self::O_WANT) ? ' NR' : '';
|
$opt = $this->capGet(self::F_NOREL,self::O_WANT) ? ' NR' : '';
|
||||||
|
@ -208,7 +208,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
|
|||||||
$makedata .= sprintf('{%s}{%s}{%s}{%s}',
|
$makedata .= sprintf('{%s}{%s}{%s}{%s}',
|
||||||
Setup::product_id(),
|
Setup::product_id(),
|
||||||
Setup::PRODUCT_NAME_SHORT,
|
Setup::PRODUCT_NAME_SHORT,
|
||||||
$this->setup->version,
|
Setup::version(),
|
||||||
'#000000' // Serial Numbers
|
'#000000' // Serial Numbers
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\Config;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use App\Classes\Protocol\{Binkp,DNS,EMSI};
|
use App\Classes\Protocol\{Binkp,DNS,EMSI};
|
||||||
use App\Classes\Sock\Exception\SocketException;
|
use App\Classes\Sock\Exception\SocketException;
|
||||||
use App\Classes\Sock\SocketServer;
|
use App\Classes\Sock\SocketServer;
|
||||||
use App\Models\Setup;
|
|
||||||
|
|
||||||
class ServerStart extends Command
|
class ServerStart extends Command
|
||||||
{
|
{
|
||||||
@ -37,7 +37,11 @@ class ServerStart extends Command
|
|||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
Log::info(sprintf('%s:+ Server Starting (%d)',self::LOGKEY,getmypid()));
|
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();
|
$start = collect();
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ namespace App\Http\Middleware;
|
|||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Contracts\Auth\Authenticatable;
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
|
use Illuminate\Support\Facades\Config;
|
||||||
|
|
||||||
use App\Models\Setup;
|
use App\Models\Setup;
|
||||||
|
|
||||||
@ -45,8 +46,10 @@ class AddUserToView
|
|||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
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('user',$this->user);
|
||||||
$this->factory->share('setup',Setup::find(config('app.id')));
|
$this->factory->share('setup',$x);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ class TestEmail extends Mailable
|
|||||||
->markdown('mail.system.test_email')
|
->markdown('mail.system.test_email')
|
||||||
->subject('Just a test...')
|
->subject('Just a test...')
|
||||||
->with([
|
->with([
|
||||||
'url'=>'https://localhost',
|
'url'=>sprintf('https://%s',gethostname()),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -71,9 +71,6 @@ class Setup extends Model
|
|||||||
case 'msgs_pkt':
|
case 'msgs_pkt':
|
||||||
return Arr::get($this->options,$key,self::MAX_MSGS_PKT);
|
return Arr::get($this->options,$key,self::MAX_MSGS_PKT);
|
||||||
|
|
||||||
case 'version':
|
|
||||||
return File::exists('VERSION') ? chop(File::get('VERSION')) : 'dev';
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return parent::__get($key);
|
return parent::__get($key);
|
||||||
}
|
}
|
||||||
@ -113,6 +110,16 @@ class Setup extends Model
|
|||||||
return hexstr($c);
|
return hexstr($c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application version
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function version(): string
|
||||||
|
{
|
||||||
|
return File::exists('VERSION') ? chop(File::get('VERSION')) : 'dev';
|
||||||
|
}
|
||||||
|
|
||||||
/* RELATIONS */
|
/* RELATIONS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Config;
|
||||||
|
|
||||||
use App\Models\{Address,Domain,Setup};
|
use App\Models\{Address,Domain,Setup};
|
||||||
|
|
||||||
@ -93,33 +93,29 @@ if (! function_exists('hexstr')) {
|
|||||||
*/
|
*/
|
||||||
function our_address(Domain|Address $o=NULL): Collection|Address|NULL
|
function our_address(Domain|Address $o=NULL): Collection|Address|NULL
|
||||||
{
|
{
|
||||||
$so = Cache::remember('so',5,function() {
|
if (! Config::has('setup'))
|
||||||
return Setup::findOrFail(config('app.id'));
|
Config::set('setup',Setup::findOrFail(config('app.id')));
|
||||||
});
|
|
||||||
|
|
||||||
$our = Cache::remember(sprintf('%d-akas',$so->system_id),60,function() use ($so) {
|
$so = Config::get('setup');
|
||||||
$so->load([
|
$so->loadMissing([
|
||||||
'system:id,name',
|
'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: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:id,domain_id,zone_id',
|
||||||
'system.akas.zone.domain:id,name',
|
'system.akas.zone.domain:id,name',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $so->system->akas;
|
|
||||||
});
|
|
||||||
|
|
||||||
// If we dont have any addresses
|
// If we dont have any addresses
|
||||||
if ($our->count() === 0)
|
if ($so->system->akas->count() === 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// We havent asked for an address/domain, so we'll return them all.
|
// We havent asked for an address/domain, so we'll return them all.
|
||||||
if (is_null($o))
|
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
|
// We are requesting a list of addresses for a Domain, or a specific Address, and we have more than 1
|
||||||
switch (get_class($o)) {
|
switch (get_class($o)) {
|
||||||
case Address::class:
|
case Address::class:
|
||||||
$filter = $our
|
$filter = $so->system->akas
|
||||||
->filter(fn($item)=>$item->zone->domain_id === $o->zone->domain_id)
|
->filter(fn($item)=>$item->zone->domain_id === $o->zone->domain_id)
|
||||||
->sortBy('role_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;
|
return $filter->count() ? $filter->last()->unsetRelation('nodes_hub') : NULL;
|
||||||
|
|
||||||
case Domain::class:
|
case Domain::class:
|
||||||
return $our
|
return $so->system->akas
|
||||||
->filter(fn($item)=>$item->zone->domain_id === $o->id)
|
->filter(fn($item)=>$item->zone->domain_id === $o->id)
|
||||||
->sortBy('role_id');
|
->sortBy('role_id');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user