Logging updates, some function optimisation
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Classes;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\File\{Receive,Send};
|
||||
@@ -15,6 +16,8 @@ abstract class Protocol
|
||||
// Enable extra debugging
|
||||
protected bool $DEBUG = FALSE;
|
||||
|
||||
private const LOGKEY = 'P--';
|
||||
|
||||
// Return constants
|
||||
protected const OK = 0;
|
||||
protected const EOF = -1;
|
||||
@@ -84,6 +87,7 @@ abstract class Protocol
|
||||
private array $comms; /* Our comms details */
|
||||
|
||||
abstract protected function protocol_init(): int;
|
||||
|
||||
abstract protected function protocol_session(): int;
|
||||
|
||||
public function __construct(Setup $o=NULL)
|
||||
@@ -136,14 +140,14 @@ abstract class Protocol
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function error_close(): void
|
||||
{
|
||||
if ($this->send->fd)
|
||||
$this->send->close(FALSE);
|
||||
protected function error_close(): void
|
||||
{
|
||||
if ($this->send->fd)
|
||||
$this->send->close(FALSE);
|
||||
|
||||
if ($this->recv->fd)
|
||||
$this->recv->close();
|
||||
}
|
||||
if ($this->recv->fd)
|
||||
$this->recv->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Incoming Protocol session
|
||||
@@ -159,7 +163,7 @@ abstract class Protocol
|
||||
if ($pid == -1)
|
||||
throw new SocketException(SocketException::CANT_ACCEPT,'Could not fork process');
|
||||
|
||||
Log::debug(sprintf('%s: = End [%d]',__METHOD__,$pid));
|
||||
Log::debug(sprintf('%s:= End [%d]',self::LOGKEY,$pid));
|
||||
|
||||
// Parent return ready for next connection
|
||||
return $pid;
|
||||
@@ -180,6 +184,31 @@ abstract class Protocol
|
||||
$this->options |= $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Our addresses to send to the remote
|
||||
* @return Collection
|
||||
*/
|
||||
protected function our_addresses(): Collection
|
||||
{
|
||||
if ($this->setup->optionGet(Setup::O_HIDEAKA)) {
|
||||
$addresses = collect();
|
||||
|
||||
foreach ($this->node->aka_remote as $ao)
|
||||
$addresses = $addresses->merge($this->setup->system->match($ao->zone));
|
||||
|
||||
$addresses = $addresses->unique();
|
||||
|
||||
Log::debug(sprintf('%s: - Presenting limited AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
|
||||
|
||||
} else {
|
||||
$addresses = $this->setup->system->addresses;
|
||||
|
||||
Log::debug(sprintf('%s: - Presenting ALL our AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
|
||||
}
|
||||
|
||||
return $addresses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise our Session
|
||||
*
|
||||
@@ -194,7 +223,7 @@ abstract class Protocol
|
||||
if ($o->exists)
|
||||
Log::withContext(['ftn'=>$o->address]);
|
||||
|
||||
Log::debug(sprintf('%s: + Start [%d]',__METHOD__,$type));
|
||||
Log::debug(sprintf('%s:+ Start [%d]',self::LOGKEY,$type));
|
||||
|
||||
// This sessions options
|
||||
$this->options = 0;
|
||||
@@ -226,36 +255,36 @@ abstract class Protocol
|
||||
switch ($type) {
|
||||
/** @noinspection PhpMissingBreakStatementInspection */
|
||||
case self::SESSION_AUTO:
|
||||
Log::debug(sprintf('%s: - Trying EMSI',__METHOD__));
|
||||
Log::debug(sprintf('%s: - Trying EMSI',self::LOGKEY));
|
||||
|
||||
$rc = $this->protocol_init();
|
||||
if ($rc < 0) {
|
||||
Log::error(sprintf('%s: ! Unable to start EMSI [%d]',__METHOD__,$rc));
|
||||
Log::error(sprintf('%s: ! Unable to start EMSI [%d]',self::LOGKEY,$rc));
|
||||
|
||||
return self::S_REDIAL | self::S_ADDTRY;
|
||||
}
|
||||
|
||||
case self::SESSION_EMSI:
|
||||
Log::debug(sprintf('%s: - Starting EMSI',__METHOD__));
|
||||
Log::debug(sprintf('%s: - Starting EMSI',self::LOGKEY));
|
||||
$rc = $this->protocol_session();
|
||||
|
||||
break;
|
||||
|
||||
case self::SESSION_BINKP:
|
||||
Log::debug(sprintf('%s: - Starting BINKP',__METHOD__));
|
||||
Log::debug(sprintf('%s: - Starting BINKP',self::LOGKEY));
|
||||
$rc = $this->protocol_session();
|
||||
|
||||
break;
|
||||
|
||||
case self::SESSION_ZMODEM:
|
||||
Log::debug(sprintf('%s: - Starting ZMODEM',__METHOD__));
|
||||
Log::debug(sprintf('%s: - Starting ZMODEM',self::LOGKEY));
|
||||
$this->client->speed = SocketClient::TCP_SPEED;
|
||||
$this->originate = FALSE;
|
||||
|
||||
return $this->protocol_session();
|
||||
|
||||
default:
|
||||
Log::error(sprintf('%s: ! Unsupported session type [%d]',__METHOD__,$type));
|
||||
Log::error(sprintf('%s: ! Unsupported session type [%d]',self::LOGKEY,$type));
|
||||
|
||||
return self::S_REDIAL | self::S_ADDTRY;
|
||||
}
|
||||
@@ -273,8 +302,8 @@ abstract class Protocol
|
||||
if ($this->optionGet(self::O_HAT))
|
||||
$rc |= self::S_HOLDA;
|
||||
|
||||
Log::info(sprintf('%s: Total: %s - %d:%02d:%02d online, (%d) %lu%s sent, (%d) %lu%s received - %s',
|
||||
__METHOD__,
|
||||
Log::info(sprintf('%s: Total: %s - %d:%02d:%02d online, (%d) %lu%s sent, (%d) %lu%s received - %s',
|
||||
self::LOGKEY,
|
||||
$this->node->address->ftn,
|
||||
$this->node->session_time/3600,
|
||||
$this->node->session_time%3600/60,
|
||||
|
Reference in New Issue
Block a user