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 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]);
|
||||
@ -366,12 +387,10 @@ abstract class Protocol
|
||||
// We are an IP node
|
||||
$this->optionSet(self::O_TCP);
|
||||
$this->client = $client;
|
||||
// @todo This appears to be a bug in laravel? Need to call app()->isDownForMaintenance() twice?
|
||||
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 +404,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 +412,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 +447,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 +459,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 +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;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ use App\Classes\Protocol as BaseProtocol;
|
||||
use App\Classes\Sock\Exception\SocketException;
|
||||
use App\Classes\Sock\SocketClient;
|
||||
use App\Exceptions\{FileGrewException,InvalidFTNException};
|
||||
use App\Models\{Address,Mailer,Setup};
|
||||
use App\Models\{Address,Setup};
|
||||
|
||||
final class Binkp extends BaseProtocol
|
||||
{
|
||||
@ -155,7 +155,7 @@ final class Binkp extends BaseProtocol
|
||||
if (! parent::onConnect($client)) {
|
||||
Log::withContext(['pid'=>getmypid()]);
|
||||
|
||||
$this->session(Mailer::where('name','BINKP')->singleOrFail(),$client,(new Address));
|
||||
$this->session($client,(new Address));
|
||||
$this->client->close();
|
||||
exit(0);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use App\Classes\Sock\SocketClient;
|
||||
use App\Exceptions\InvalidFTNException;
|
||||
use App\Interfaces\CRC as CRCInterface;
|
||||
use App\Interfaces\Zmodem as ZmodemInterface;
|
||||
use App\Models\{Address,Mailer,Setup};
|
||||
use App\Models\{Address,Setup};
|
||||
use App\Traits\CRC as CRCTrait;
|
||||
|
||||
// http://ftsc.org/docs/fsc-0056.001
|
||||
@ -95,7 +95,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
|
||||
if (! parent::onConnect($client)) {
|
||||
Log::withContext(['pid'=>getmypid()]);
|
||||
|
||||
$this->session(Mailer::where('name','EMSI')->singleOrFail(),$client,(new Address));
|
||||
$this->session($client,(new Address));
|
||||
$this->client->close();
|
||||
exit(0);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use App\Classes\Sock\Exception\SocketException;
|
||||
use App\Classes\Sock\SocketClient;
|
||||
use App\Interfaces\CRC as CRCInterface;
|
||||
use App\Interfaces\Zmodem as ZmodemInterface;
|
||||
use App\Models\{Address,Mailer};
|
||||
use App\Models\Address;
|
||||
use App\Traits\CRC as CRCTrait;
|
||||
|
||||
/**
|
||||
@ -213,7 +213,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
|
||||
if (! parent::onConnect($client)) {
|
||||
Log::withContext(['pid'=>getmypid()]);
|
||||
|
||||
$this->session(Mailer::where('name','ZMODEM')->singleOrFail(),$client);
|
||||
$this->session($client);
|
||||
$this->client->close();
|
||||
|
||||
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) {
|
||||
case 'BINKP':
|
||||
$s = new Binkp;
|
||||
$mo = Mailer::where('name','BINKP')->singleOrFail();
|
||||
|
||||
break;
|
||||
|
||||
case 'EMSI':
|
||||
$s = new EMSI;
|
||||
$mo = Mailer::where('name','EMSI')->singleOrFail();
|
||||
|
||||
break;
|
||||
|
||||
@ -116,7 +114,7 @@ class AddressPoll implements ShouldQueue, ShouldBeUnique
|
||||
try {
|
||||
$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));
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user