Reduce the need for Mailer::class in protocols
This commit is contained in:
@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
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\SocketClient;
|
||||
use App\Models\{Address,Mailer,Setup,System,SystemLog};
|
||||
@@ -98,10 +98,10 @@ abstract class Protocol
|
||||
|
||||
// File transfer status
|
||||
|
||||
public const FOP_OK = 0;
|
||||
public const FOP_CONT = 1;
|
||||
public const FOP_SKIP = 2;
|
||||
public const FOP_ERROR = 3;
|
||||
public const FOP_OK = 0;
|
||||
public const FOP_CONT = 1;
|
||||
public const FOP_SKIP = 2;
|
||||
public const FOP_ERROR = 3;
|
||||
public const FOP_SUSPEND = 4;
|
||||
public const FOP_GOT = 5;
|
||||
|
||||
@@ -123,10 +123,13 @@ abstract class Protocol
|
||||
protected array $capability; // @todo make private
|
||||
/** @var bool Are we originating a connection */
|
||||
protected bool $originate;
|
||||
/** Our comms details */
|
||||
|
||||
/** @var bool Is the application down for maintenance */
|
||||
protected bool $down = FALSE;
|
||||
|
||||
/** @var int Our mailer ID for logging purposes */
|
||||
private int $mailer_id;
|
||||
|
||||
private array $comms;
|
||||
|
||||
protected bool $force_queue = FALSE;
|
||||
@@ -138,6 +141,24 @@ abstract class Protocol
|
||||
public function __construct()
|
||||
{
|
||||
$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
|
||||
*
|
||||
* @return Collection
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function our_addresses(): Collection
|
||||
{
|
||||
@@ -327,13 +349,12 @@ abstract class Protocol
|
||||
/**
|
||||
* Initialise our Session
|
||||
*
|
||||
* @param Mailer $mo
|
||||
* @param SocketClient $client
|
||||
* @param Address|null $o
|
||||
* @return int
|
||||
* @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)
|
||||
Log::withContext(['ftn'=>$o->ftn]);
|
||||
@@ -370,8 +391,8 @@ abstract class Protocol
|
||||
app()->isDownForMaintenance();
|
||||
$this->down = app()->isDownForMaintenance();
|
||||
|
||||
switch ($mo->name) {
|
||||
case 'EMSI':
|
||||
switch (get_class($this)) {
|
||||
case EMSI::class:
|
||||
Log::debug(sprintf('%s:- Starting EMSI',self::LOGKEY));
|
||||
|
||||
$rc = $this->protocol_init();
|
||||
@@ -385,7 +406,7 @@ abstract class Protocol
|
||||
|
||||
break;
|
||||
|
||||
case 'BINKP':
|
||||
case Binkp::class:
|
||||
Log::debug(sprintf('%s:- Starting BINKP',self::LOGKEY));
|
||||
|
||||
$rc = $this->protocol_session($this->originate);
|
||||
@@ -393,13 +414,11 @@ abstract class Protocol
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// @todo Unlock outbounds
|
||||
|
||||
// @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 (($this->node->optionGet(self::O_NRQ) && (! $this->setup->optionGet(EMSI::F_IGNORE_NRQ,'emsi_options'))) || $this->node->optionGet(self::O_HRQ))
|
||||
@@ -430,6 +449,7 @@ abstract class Protocol
|
||||
if ($so && $so->exists) {
|
||||
foreach ($this->node->aka_other as $aka)
|
||||
// @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))) {
|
||||
$oo->validated = TRUE;
|
||||
$oo->save();
|
||||
@@ -441,7 +461,7 @@ abstract class Protocol
|
||||
$slo->items_sent_size = $this->send->total_sent_bytes;
|
||||
$slo->items_recv = $this->recv->total_recv;
|
||||
$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->result = ($rc & self::S_MASK);
|
||||
$slo->originate = $this->originate;
|
||||
@@ -455,12 +475,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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user