Reduce the need for Mailer::class in protocols
This commit is contained in:
parent
ff4ecddb76
commit
5874b2aef1
@ -7,7 +7,7 @@ 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};
|
||||||
use App\Classes\Protocol\EMSI;
|
use App\Classes\Protocol\{Binkp,DNS,EMSI,Zmodem};
|
||||||
use App\Classes\Sock\Exception\SocketException;
|
use App\Classes\Sock\Exception\SocketException;
|
||||||
use App\Classes\Sock\SocketClient;
|
use App\Classes\Sock\SocketClient;
|
||||||
use App\Models\{Address,Mailer,Setup,System,SystemLog};
|
use App\Models\{Address,Mailer,Setup,System,SystemLog};
|
||||||
@ -123,10 +123,13 @@ abstract class Protocol
|
|||||||
protected array $capability; // @todo make private
|
protected array $capability; // @todo make private
|
||||||
/** @var bool Are we originating a connection */
|
/** @var bool Are we originating a connection */
|
||||||
protected bool $originate;
|
protected bool $originate;
|
||||||
/** Our comms details */
|
|
||||||
|
|
||||||
|
/** @var bool Is the application down for maintenance */
|
||||||
protected bool $down = FALSE;
|
protected bool $down = FALSE;
|
||||||
|
|
||||||
|
/** @var int Our mailer ID for logging purposes */
|
||||||
|
private int $mailer_id;
|
||||||
|
|
||||||
private array $comms;
|
private array $comms;
|
||||||
|
|
||||||
protected bool $force_queue = FALSE;
|
protected bool $force_queue = FALSE;
|
||||||
@ -138,6 +141,24 @@ abstract class Protocol
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->setup = Config::get('setup',Setup::findOrFail(config('app.id')));
|
$this->setup = Config::get('setup',Setup::findOrFail(config('app.id')));
|
||||||
|
|
||||||
|
// Some initialisation details
|
||||||
|
switch (get_class($this)) {
|
||||||
|
case Binkp::class:
|
||||||
|
$this->mailer_id = Mailer::where('name','BINKP')->sole()->id;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DNS::class:
|
||||||
|
case Zmodem::class:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EMSI::class:
|
||||||
|
$this->mailer_id = Mailer::where('name','EMSI')->sole()->id;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new \Exception('not handled'.get_class($this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -302,6 +323,7 @@ abstract class Protocol
|
|||||||
* Our addresses to send to the remote
|
* Our addresses to send to the remote
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
protected function our_addresses(): Collection
|
protected function our_addresses(): Collection
|
||||||
{
|
{
|
||||||
@ -327,13 +349,12 @@ abstract class Protocol
|
|||||||
/**
|
/**
|
||||||
* Initialise our Session
|
* Initialise our Session
|
||||||
*
|
*
|
||||||
* @param Mailer $mo
|
|
||||||
* @param SocketClient $client
|
* @param SocketClient $client
|
||||||
* @param Address|null $o
|
* @param Address|null $o
|
||||||
* @return int
|
* @return int
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function session(Mailer $mo,SocketClient $client,Address $o=NULL): int
|
public function session(SocketClient $client,Address $o=NULL): int
|
||||||
{
|
{
|
||||||
if ($o->exists)
|
if ($o->exists)
|
||||||
Log::withContext(['ftn'=>$o->ftn]);
|
Log::withContext(['ftn'=>$o->ftn]);
|
||||||
@ -366,12 +387,10 @@ abstract class Protocol
|
|||||||
// We are an IP node
|
// We are an IP node
|
||||||
$this->optionSet(self::O_TCP);
|
$this->optionSet(self::O_TCP);
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
// @todo This appears to be a bug in laravel? Need to call app()->isDownForMaintenance() twice?
|
|
||||||
app()->isDownForMaintenance();
|
|
||||||
$this->down = app()->isDownForMaintenance();
|
$this->down = app()->isDownForMaintenance();
|
||||||
|
|
||||||
switch ($mo->name) {
|
switch (get_class($this)) {
|
||||||
case 'EMSI':
|
case EMSI::class:
|
||||||
Log::debug(sprintf('%s:- Starting EMSI',self::LOGKEY));
|
Log::debug(sprintf('%s:- Starting EMSI',self::LOGKEY));
|
||||||
|
|
||||||
$rc = $this->protocol_init();
|
$rc = $this->protocol_init();
|
||||||
@ -385,7 +404,7 @@ abstract class Protocol
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'BINKP':
|
case Binkp::class:
|
||||||
Log::debug(sprintf('%s:- Starting BINKP',self::LOGKEY));
|
Log::debug(sprintf('%s:- Starting BINKP',self::LOGKEY));
|
||||||
|
|
||||||
$rc = $this->protocol_session($this->originate);
|
$rc = $this->protocol_session($this->originate);
|
||||||
@ -393,13 +412,11 @@ abstract class Protocol
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Log::error(sprintf('%s:! Unsupported session type [%d]',self::LOGKEY,$mo->id));
|
Log::error(sprintf('%s:! Unsupported session type [%s]',self::LOGKEY,get_class($this)));
|
||||||
|
|
||||||
return self::S_FAILURE;
|
return self::S_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo Unlock outbounds
|
|
||||||
|
|
||||||
// @todo These flags determine when we connect to the remote.
|
// @todo These flags determine when we connect to the remote.
|
||||||
// If the remote indicated that they dont support file requests (NRQ) or temporarily hold them (HRQ)
|
// If the remote indicated that they dont support file requests (NRQ) or temporarily hold them (HRQ)
|
||||||
if (($this->node->optionGet(self::O_NRQ) && (! $this->setup->optionGet(EMSI::F_IGNORE_NRQ,'emsi_options'))) || $this->node->optionGet(self::O_HRQ))
|
if (($this->node->optionGet(self::O_NRQ) && (! $this->setup->optionGet(EMSI::F_IGNORE_NRQ,'emsi_options'))) || $this->node->optionGet(self::O_HRQ))
|
||||||
@ -430,6 +447,7 @@ abstract class Protocol
|
|||||||
if ($so && $so->exists) {
|
if ($so && $so->exists) {
|
||||||
foreach ($this->node->aka_other as $aka)
|
foreach ($this->node->aka_other as $aka)
|
||||||
// @todo For disabled zones, we shouldnt refuse to record the address
|
// @todo For disabled zones, we shouldnt refuse to record the address
|
||||||
|
// @todo If the system hasnt presented an address for a configured period (eg: 30 days) assume it no longer carries it
|
||||||
if ((! Address::findFTN($aka)) && ($oo=Address::createFTN($aka,$so))) {
|
if ((! Address::findFTN($aka)) && ($oo=Address::createFTN($aka,$so))) {
|
||||||
$oo->validated = TRUE;
|
$oo->validated = TRUE;
|
||||||
$oo->save();
|
$oo->save();
|
||||||
@ -441,7 +459,7 @@ abstract class Protocol
|
|||||||
$slo->items_sent_size = $this->send->total_sent_bytes;
|
$slo->items_sent_size = $this->send->total_sent_bytes;
|
||||||
$slo->items_recv = $this->recv->total_recv;
|
$slo->items_recv = $this->recv->total_recv;
|
||||||
$slo->items_recv_size = $this->recv->total_recv_bytes;
|
$slo->items_recv_size = $this->recv->total_recv_bytes;
|
||||||
$slo->mailer_id = $mo->id;
|
$slo->mailer_id = $this->mailer_id;
|
||||||
$slo->sessiontime = $this->node->session_time;
|
$slo->sessiontime = $this->node->session_time;
|
||||||
$slo->result = ($rc & self::S_MASK);
|
$slo->result = ($rc & self::S_MASK);
|
||||||
$slo->originate = $this->originate;
|
$slo->originate = $this->originate;
|
||||||
@ -455,12 +473,6 @@ abstract class Protocol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo Optional after session execution event
|
|
||||||
// if ($this->node->start_time && $this->setup->cfg('CFG_AFTERSESSION')) {}
|
|
||||||
|
|
||||||
// @todo Optional after session includes mail event
|
|
||||||
// if ($this->node->start_time && $this->setup->cfg('CFG_AFTERMAIL')) {}
|
|
||||||
|
|
||||||
return $rc;
|
return $rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ use App\Classes\Protocol as BaseProtocol;
|
|||||||
use App\Classes\Sock\Exception\SocketException;
|
use App\Classes\Sock\Exception\SocketException;
|
||||||
use App\Classes\Sock\SocketClient;
|
use App\Classes\Sock\SocketClient;
|
||||||
use App\Exceptions\{FileGrewException,InvalidFTNException};
|
use App\Exceptions\{FileGrewException,InvalidFTNException};
|
||||||
use App\Models\{Address,Mailer,Setup};
|
use App\Models\{Address,Setup};
|
||||||
|
|
||||||
final class Binkp extends BaseProtocol
|
final class Binkp extends BaseProtocol
|
||||||
{
|
{
|
||||||
@ -155,7 +155,7 @@ final class Binkp extends BaseProtocol
|
|||||||
if (! parent::onConnect($client)) {
|
if (! parent::onConnect($client)) {
|
||||||
Log::withContext(['pid'=>getmypid()]);
|
Log::withContext(['pid'=>getmypid()]);
|
||||||
|
|
||||||
$this->session(Mailer::where('name','BINKP')->singleOrFail(),$client,(new Address));
|
$this->session($client,(new Address));
|
||||||
$this->client->close();
|
$this->client->close();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use App\Classes\Sock\SocketClient;
|
|||||||
use App\Exceptions\InvalidFTNException;
|
use App\Exceptions\InvalidFTNException;
|
||||||
use App\Interfaces\CRC as CRCInterface;
|
use App\Interfaces\CRC as CRCInterface;
|
||||||
use App\Interfaces\Zmodem as ZmodemInterface;
|
use App\Interfaces\Zmodem as ZmodemInterface;
|
||||||
use App\Models\{Address,Mailer,Setup};
|
use App\Models\{Address,Setup};
|
||||||
use App\Traits\CRC as CRCTrait;
|
use App\Traits\CRC as CRCTrait;
|
||||||
|
|
||||||
// http://ftsc.org/docs/fsc-0056.001
|
// http://ftsc.org/docs/fsc-0056.001
|
||||||
@ -95,7 +95,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
|
|||||||
if (! parent::onConnect($client)) {
|
if (! parent::onConnect($client)) {
|
||||||
Log::withContext(['pid'=>getmypid()]);
|
Log::withContext(['pid'=>getmypid()]);
|
||||||
|
|
||||||
$this->session(Mailer::where('name','EMSI')->singleOrFail(),$client,(new Address));
|
$this->session($client,(new Address));
|
||||||
$this->client->close();
|
$this->client->close();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ use App\Classes\Sock\Exception\SocketException;
|
|||||||
use App\Classes\Sock\SocketClient;
|
use App\Classes\Sock\SocketClient;
|
||||||
use App\Interfaces\CRC as CRCInterface;
|
use App\Interfaces\CRC as CRCInterface;
|
||||||
use App\Interfaces\Zmodem as ZmodemInterface;
|
use App\Interfaces\Zmodem as ZmodemInterface;
|
||||||
use App\Models\{Address,Mailer};
|
use App\Models\Address;
|
||||||
use App\Traits\CRC as CRCTrait;
|
use App\Traits\CRC as CRCTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -213,7 +213,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
|
|||||||
if (! parent::onConnect($client)) {
|
if (! parent::onConnect($client)) {
|
||||||
Log::withContext(['pid'=>getmypid()]);
|
Log::withContext(['pid'=>getmypid()]);
|
||||||
|
|
||||||
$this->session(Mailer::where('name','ZMODEM')->singleOrFail(),$client);
|
$this->session($client);
|
||||||
$this->client->close();
|
$this->client->close();
|
||||||
|
|
||||||
Log::info(sprintf('%s:= onConnect - Connection closed [%s]',self::LOGKEY,$client->address_remote));
|
Log::info(sprintf('%s:= onConnect - Connection closed [%s]',self::LOGKEY,$client->address_remote));
|
||||||
|
@ -94,13 +94,11 @@ class AddressPoll implements ShouldQueue, ShouldBeUnique
|
|||||||
switch ($o->name) {
|
switch ($o->name) {
|
||||||
case 'BINKP':
|
case 'BINKP':
|
||||||
$s = new Binkp;
|
$s = new Binkp;
|
||||||
$mo = Mailer::where('name','BINKP')->singleOrFail();
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'EMSI':
|
case 'EMSI':
|
||||||
$s = new EMSI;
|
$s = new EMSI;
|
||||||
$mo = Mailer::where('name','EMSI')->singleOrFail();
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -116,7 +114,7 @@ class AddressPoll implements ShouldQueue, ShouldBeUnique
|
|||||||
try {
|
try {
|
||||||
$client = SocketClient::create($this->ao->system->address,$o->pivot->port);
|
$client = SocketClient::create($this->ao->system->address,$o->pivot->port);
|
||||||
|
|
||||||
if (($s->session($mo,$client,$this->ao) & Protocol::S_MASK) === Protocol::S_OK) {
|
if (($s->session($client,$this->ao) & Protocol::S_MASK) === Protocol::S_OK) {
|
||||||
Log::info(sprintf('%s:= Connection ended successfully with [%s] (%s)',self::LOGKEY,$client->address_remote,$this->ao->ftn));
|
Log::info(sprintf('%s:= Connection ended successfully with [%s] (%s)',self::LOGKEY,$client->address_remote,$this->ao->ftn));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user