When originating a session, send anything received via the queue

This commit is contained in:
Deon George 2023-11-22 21:04:58 +11:00
parent 7847728e52
commit e5de4970d1
6 changed files with 27 additions and 17 deletions

View File

@ -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;

View File

@ -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));

View File

@ -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) {

View File

@ -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));

View File

@ -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);
}

View File

@ -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;