From e5de4970d1d61e3aa2cb7064fe3e1da654637c7f Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 22 Nov 2023 21:04:58 +1100 Subject: [PATCH] When originating a session, send anything received via the queue --- app/Classes/File/Receive.php | 13 ++++++++----- app/Classes/Protocol.php | 10 ++++++---- app/Classes/Protocol/Binkp.php | 6 ++++-- app/Classes/Protocol/DNS.php | 3 ++- app/Classes/Protocol/EMSI.php | 5 +++-- app/Classes/Protocol/Zmodem.php | 7 ++++--- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/app/Classes/File/Receive.php b/app/Classes/File/Receive.php index a469eb2..8dd2b8c 100644 --- a/app/Classes/File/Receive.php +++ b/app/Classes/File/Receive.php @@ -34,6 +34,7 @@ class Receive extends Base private ?string $comp; /** @var string|null The compressed data received */ private ?string $comp_data; + private $queue = FALSE; public function __construct() { @@ -125,8 +126,8 @@ class Receive extends Base case self::IS_PKT: try { // If packet is greater than a size, lets queue it - if ($this->receiving->size > config('fido.queue_size',0)) { - Log::info(sprintf('%s:- Packet [%s] will be sent to the queue for processing because its [%d] size',self::LOGKEY,$this->receiving->full_name,$this->receiving->size)); + if ($this->queue || ($this->receiving->size > config('fido.queue_size',0))) { + Log::info(sprintf('%s:- Packet [%s] will be sent to the queue for processing because its [%d] size, or queue forced',self::LOGKEY,$this->receiving->full_name,$this->receiving->size)); PacketProcess::dispatch($this->receiving,$this->ao,$rcvd_time); } else @@ -157,11 +158,12 @@ class Receive extends Base /** * Add a new file to receive * - * @param array $file - * @param Address $ao + * @param array $file The name of the receiving file + * @param Address $ao Sender sending a file to us + * @param bool $queue Force sending received items to the queue * @throws \Exception */ - public function new(array $file,Address $ao): void + public function new(array $file,Address $ao,$queue=FALSE): void { Log::debug(sprintf('%s:+ Receiving new file [%s]',self::LOGKEY,join('|',$file))); @@ -169,6 +171,7 @@ class Receive extends Base throw new \Exception('Can only have 1 file receiving at a time'); $this->ao = $ao; + $this->queue = $queue; $this->list->push(new Item($ao,Arr::get($file,'name'),(int)Arr::get($file,'mtime'),(int)Arr::get($file,'size'))); $this->index = $this->list->count()-1; diff --git a/app/Classes/Protocol.php b/app/Classes/Protocol.php index d24636f..a18257e 100644 --- a/app/Classes/Protocol.php +++ b/app/Classes/Protocol.php @@ -132,9 +132,11 @@ abstract class Protocol private array $comms; + protected bool $force_queue = FALSE; + abstract protected function protocol_init(): int; - abstract protected function protocol_session(): int; + abstract protected function protocol_session(bool $force_queue=FALSE): int; public function __construct(Setup $o=NULL) { @@ -381,13 +383,13 @@ abstract class Protocol case self::SESSION_EMSI: Log::debug(sprintf('%s:- Starting EMSI',self::LOGKEY)); - $rc = $this->protocol_session(); + $rc = $this->protocol_session($this->originate); break; case self::SESSION_BINKP: Log::debug(sprintf('%s:- Starting BINKP',self::LOGKEY)); - $rc = $this->protocol_session(); + $rc = $this->protocol_session($this->originate); break; @@ -396,7 +398,7 @@ abstract class Protocol $this->client->speed = self::TCP_SPEED; $this->originate = FALSE; - return $this->protocol_session(); + return $this->protocol_session($this->originate); default: Log::error(sprintf('%s:! Unsupported session type [%d]',self::LOGKEY,$type)); diff --git a/app/Classes/Protocol/Binkp.php b/app/Classes/Protocol/Binkp.php index ff2cb03..bb0271f 100644 --- a/app/Classes/Protocol/Binkp.php +++ b/app/Classes/Protocol/Binkp.php @@ -897,7 +897,7 @@ final class Binkp extends BaseProtocol return TRUE; } - $this->recv->new($file['file'],$this->node->address); + $this->recv->new($file['file'],$this->node->address,$this->force_queue); try { switch ($this->recv->open($file['offs']<0,$file['flags'])) { @@ -1341,14 +1341,16 @@ final class Binkp extends BaseProtocol /** * Set up our BINKP session * + * @param bool $force_queue * @return int * @throws \Exception */ - protected function protocol_session(): int + protected function protocol_session(bool $force_queue=FALSE): int { if ($this->binkp_init() !== self::OK) return self::S_FAILURE; + $this->force_queue = $force_queue; $this->binkp_hs(); while (TRUE) { diff --git a/app/Classes/Protocol/DNS.php b/app/Classes/Protocol/DNS.php index ffe2d61..bc13448 100644 --- a/app/Classes/Protocol/DNS.php +++ b/app/Classes/Protocol/DNS.php @@ -99,10 +99,11 @@ final class DNS extends BaseProtocol * TTL positive values of a signed 32 bit number. * UDP messages 512 octets or less * + * @param bool $force_queue Not used here * @return int * @throws \Exception */ - public function protocol_session(): int + public function protocol_session(bool $force_queue=FALSE): int { Log::debug(sprintf('%s:+ DNS Query',self::LOGKEY)); diff --git a/app/Classes/Protocol/EMSI.php b/app/Classes/Protocol/EMSI.php index 44955a7..b0115e4 100644 --- a/app/Classes/Protocol/EMSI.php +++ b/app/Classes/Protocol/EMSI.php @@ -976,11 +976,12 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface * @return int * @throws \Exception */ - protected function protocol_session(): int + protected function protocol_session(bool $force_queue=FALSE): int { // @todo introduce emsi_init() to perform the job of protocol_init. Only needs to be done when we originate a session Log::debug(sprintf('%s:+ Starting EMSI Protocol SESSION',self::LOGKEY)); + $this->force_queue = $force_queue; $was_req = 0; $got_req = 0; @@ -1189,7 +1190,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface Log::debug(sprintf('%s:+ Start WAZOO Receive',self::LOGKEY)); // @todo If the node is not defined in the DB node->address is NULL. Need to figure out how to handle those nodes. - $rc = (new Zmodem)->zmodem_receive($this->client,$zap,$this->recv,$this->node->address); + $rc = (new Zmodem)->zmodem_receive($this->client,$zap,$this->recv,$this->node->address,$this->force_queue); return ($rc === self::RCDO || $rc === self::ERROR); } diff --git a/app/Classes/Protocol/Zmodem.php b/app/Classes/Protocol/Zmodem.php index 522788a..2222293 100644 --- a/app/Classes/Protocol/Zmodem.php +++ b/app/Classes/Protocol/Zmodem.php @@ -273,10 +273,11 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface /** * Setup our ZMODEM session * + * @param bool $force_queue Not used here * @return int * @throws \Exception */ - public function protocol_session(): int + public function protocol_session(bool $force_queue=FALSE): int { $proto = $this->originate ? $this->node->optionGet(self::P_MASK) : $this->optionGet(self::P_MASK); @@ -301,7 +302,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface * @param int $canzap * @return int */ - public function zmodem_receive(SocketClient $client,int $canzap,Receive $recv,Address $ao): int + public function zmodem_receive(SocketClient $client,int $canzap,Receive $recv,Address $ao,bool $force_queue=FALSE): int { Log::debug(sprintf('%s:+ Starting ZModem Receive [%d]',self::LOGKEY,$canzap)); @@ -1489,7 +1490,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface $filesleft = -1; } else { - $this->recv->new($file,$ao); + $this->recv->new($file,$ao,$this->force_queue); } return self::ZFILE;