Some BINKP optimisation, implemented crypt, implemented receiving compressed transfers

This commit is contained in:
2023-07-02 23:40:08 +10:00
parent f9f9fb5345
commit 6f298d778f
28 changed files with 1614 additions and 904 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -32,6 +32,10 @@ final class DNS extends BaseProtocol
{
private const LOGKEY = 'PD-';
/* CONSTS */
public const PORT = 53;
private const DEFAULT_TTL = 86400;
private const TLD = 'ftn';
@@ -249,6 +253,7 @@ final class DNS extends BaseProtocol
* @param int $code
* @param array $answer
* @param array $authority
* @param array $additional
* @return bool
* @throws \Exception
*/

View File

@@ -23,24 +23,27 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
use CRCTrait;
private const EMSI_BEG = '**EMSI_';
private const EMSI_ARGUS1 = '-PZT8AF6-';
private const EMSI_DAT = self::EMSI_BEG.'DAT';
private const EMSI_REQ = self::EMSI_BEG.'REQA77E';
private const EMSI_INQ = self::EMSI_BEG.'INQC816';
private const EMSI_ACK = self::EMSI_BEG.'ACKA490';
private const EMSI_NAK = self::EMSI_BEG.'NAKEEC3';
private const EMSI_HBT = self::EMSI_BEG.'HBTEAEE';
/* CONSTS */
private const CR = "\r";
private const NL = "\n";
private const DEL = "\x08";
public const PORT = 60179;
private const EMSI_BEG = '**EMSI_';
private const EMSI_ARGUS1 = '-PZT8AF6-';
private const EMSI_DAT = self::EMSI_BEG.'DAT';
private const EMSI_REQ = self::EMSI_BEG.'REQA77E';
private const EMSI_INQ = self::EMSI_BEG.'INQC816';
private const EMSI_ACK = self::EMSI_BEG.'ACKA490';
private const EMSI_NAK = self::EMSI_BEG.'NAKEEC3';
private const EMSI_HBT = self::EMSI_BEG.'HBTEAEE';
private const EMSI_BUF = 8192;
private const TMP_LEN = 1024;
private const CR = "\r";
private const NL = "\n";
private const DEL = "\x08";
private const SM_INBOUND = 0;
private const SM_OUTBOUND = 1;
private const EMSI_BUF = 8192;
private const TMP_LEN = 1024;
private const SM_INBOUND = 0;
private const SM_OUTBOUND = 1;
private const EMSI_HSTIMEOUT = 60; /* Handshake timeout */
private const EMSI_SEQ_LEN = 14;
@@ -54,6 +57,8 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
private const EMSI_RESEND_TO = 5;
protected const MO_CHAT = 4;
// Our session status
private int $session;
@@ -84,10 +89,9 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
if (! parent::onConnect($client)) {
Log::withContext(['pid'=>getmypid()]);
// @todo Can this be SESSION_EMSI? if so, set an object class value that in EMSI of SESSION_EMSI, and move this method to the parent class
$this->session(self::SESSION_AUTO,$client,(new Address));
$this->client->close();
Log::info(sprintf('%s:= onConnect - Connection closed [%s]',self::LOGKEY,$client->address_remote));
exit(0);
}
@@ -101,7 +105,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*/
private function emsi_banner(): void
{
Log::debug(sprintf('%s:+ emsi_banner',self::LOGKEY));
Log::debug(sprintf('%s:+ Showing EMSI banner',self::LOGKEY));
$banner = 'This is a mail only system - unless you are a mailer, you should disconnect :)';
$this->client->buffer_add(self::EMSI_REQ.str_repeat(self::DEL,strlen(self::EMSI_REQ)).$banner.self::CR);
@@ -212,7 +216,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
);
// TRAF - netmail/echomail traffic size (bytes)
$makedata .= sprintf('{TRAF}{%lX %lX}',$this->send->mail_size,$this->send->file_size);
$makedata .= sprintf('{TRAF}{%lX %lX}',$this->send->mail_size,$this->send->size);
// MOH# - Mail On Hold - bytes waiting
$makedata .= sprintf('{MOH#}{[%lX]}',$this->send->mail_size);
@@ -955,6 +959,8 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*/
protected function protocol_session(): 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));
$was_req = 0;
@@ -1015,7 +1021,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
// @todo Lock Node AKAs
Log::info(sprintf('%s: - We have %lu%s mail, %lu%s files',self::LOGKEY,$this->send->mail_size,'b',$this->send->file_size,'b'));
Log::info(sprintf('%s: - We have %lu%s mail, %lu%s files',self::LOGKEY,$this->send->mail_size,'b',$this->send->files_size,'b'));
$proto = $this->originate ? $this->node->optionGet(self::P_MASK) : $this->optionGet(self::P_MASK);

View File

@@ -70,11 +70,8 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
private const ZRUB1 = 0x6d; //m /* Translate to rubout 0377 */
/* Return codes -- pseudo-characters */
private const LSZ_OK = self::OK; /* 0 */
private const LSZ_TIMEOUT = self::TIMEOUT; /* -2 */
private const LSZ_RCDO = self::RCDO; /* -3 */
private const LSZ_CAN = self::GCOUNT; /* -4 */
private const LSZ_ERROR = self::ERROR; /* -5 */
private const LSZ_CAN = -4;
private const LSZ_NOHEADER = -6;
private const LSZ_BADCRC = -7;
private const LSZ_XONXOFF = -8;
@@ -312,7 +309,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
Log::debug(sprintf('%s:= zmodem_receive ZFIN after INIT, empty batch',self::LOGKEY));
$this->ls_zdonereceiver();
return self::LSZ_OK;
return self::OK;
case self::ZFILE:
Log::debug(sprintf('%s: = zmodem_receive ZFILE after INIT',self::LOGKEY));
@@ -324,7 +321,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$this->ls_zabort();
$this->ls_zdonereceiver();
return self::LSZ_ERROR;
return self::ERROR;
}
while (TRUE) {
@@ -333,7 +330,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
Log::debug(sprintf('%s:= zmodem_receive ZFIN',self::LOGKEY));
$this->ls_zdonereceiver();
return self::LSZ_OK;
return self::OK;
case self::ZFILE:
if (! $this->recv->to_get) {
@@ -375,7 +372,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
break;
case self::LSZ_OK:
case self::OK:
Log::debug(sprintf('%s: = zmodem_receive OK',self::LOGKEY));
$this->recv->close();
@@ -385,7 +382,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
Log::error(sprintf('%s:! zmodem_receive OTHER [%d]',self::LOGKEY,$rc));
$this->recv->close();
return self::LSZ_ERROR;
return self::ERROR;
}
break;
@@ -400,7 +397,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$this->ls_zabort();
$this->ls_zdonereceiver();
return self::LSZ_ERROR;
return self::ERROR;
default:
Log::error(sprintf('%s:? zmodem_receive Something strange [%d]',self::LOGKEY,$rc));
@@ -408,13 +405,13 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$this->ls_zabort();
$this->ls_zdonereceiver();
return self::LSZ_ERROR;
return self::ERROR;
}
$rc = $this->ls_zrecvfinfo($frame,1);
}
return self::LSZ_OK;
return self::OK;
}
/**
@@ -444,10 +441,10 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$this->client->buffer_add('OO');
$this->client->buffer_flush(5);
return self::LSZ_OK;
return self::OK;
case self::ZNAK:
case self::LSZ_TIMEOUT:
case self::TIMEOUT:
$retransmit = 1;
break;
@@ -512,7 +509,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$rc = $this->ls_zsendfile($send,$this->ls_SerialNum++,$send->total_count,$send->total_size);
switch ($rc) {
case self::LSZ_OK:
case self::OK:
$send->close(TRUE);
break;
@@ -582,7 +579,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
}
if (ord($c) === 0)
return self::LSZ_ERROR;
return self::ERROR;
return $c&0x7f;
}
@@ -865,7 +862,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
/* Ok, GOOD */
case ord('O'):
$rc = $this->client->read_ch(0);
return self::LSZ_OK;
return self::OK;
case self::XON:
case self::XOFF:
@@ -883,7 +880,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
return $rc;
if (self::ZFIN != $rc)
return self::LSZ_OK;
return self::OK;
$retransmit = 1;
@@ -1014,7 +1011,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
return $this->ls_zsendsinit($attstr);
else
return self::LSZ_OK;
return self::OK;
/* Return number to peer, he is paranoid */
case self::ZCHALLENGE:
@@ -1027,7 +1024,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
/* Send ZRQINIT again */
case self::ZNAK:
case self::LSZ_TIMEOUT:
case self::TIMEOUT:
$retransmit = 1;
break;
@@ -1037,7 +1034,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
Log::debug(sprintf('%s: - ls_zinitsender ZFIN [%d]',self::LOGKEY,$zfins));
if (++$zfins === self::LSZ_TRUSTZFINS)
return self::LSZ_ERROR;
return self::ERROR;
break;
@@ -1053,7 +1050,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
/* Abort this session -- we trust in ABORT! */
case self::ZABORT:
Log::debug(sprintf('%s:- ls_zinitsender ZABORT',self::LOGKEY));
return self::LSZ_ERROR;
return self::ERROR;
default:
Log::error(sprintf('%s: ? ls_zinitsender Something strange [%d]',self::LOGKEY,$rc));
@@ -1084,7 +1081,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$got = 0; /* Bytes total got */
$crc = 0; /* Received CRC */
$frametype = self::LSZ_ERROR; /* Type of frame - ZCRC(G|W|Q|E) */
$frametype = self::ERROR; /* Type of frame - ZCRC(G|W|Q|E) */
$rcvdata = 1; /* Data is being received NOW (not CRC) */
while ($rcvdata && (($c = $this->ls_readzdle($timeout)) >= 0)) {
@@ -1163,7 +1160,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$got = 0; /* Bytes total got */
$crc = 0; /* Received CRC */
$frametype = self::LSZ_ERROR; /* Type of frame - ZCRC(G|W|Q|E) */
$frametype = self::ERROR; /* Type of frame - ZCRC(G|W|Q|E) */
$rcvdata = 1; /* Data is being received NOW (not CRC) */
while ($rcvdata && (($c=$this->ls_readzdle($timeout)) >= 0)) {
@@ -1289,7 +1286,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
break;
case self::LSZ_BADCRC:
case self::LSZ_TIMEOUT:
case self::TIMEOUT:
if ($this->ls_rxAttnStr) {
$this->client->buffer_add($this->ls_rxAttnStr);
$this->client->buffer_flush(5);
@@ -1344,7 +1341,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
if (($rc=$this->ls_zsendhhdr(self::ZRINIT,$this->ls_storelong(0))) < 0)
return $rc;
return self::LSZ_OK;
return self::OK;
}
Log::debug(sprintf('%s: - ls_zrecvfile ZDATA',self::LOGKEY));
@@ -1357,7 +1354,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
} while (TRUE);
return self::LSZ_OK;
return self::OK;
}
/**
@@ -1422,8 +1419,8 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
case self::ZNAK:
Log::debug(sprintf('%s: - ls_zrecvfinfo ZNAK',self::LOGKEY));
case self::LSZ_TIMEOUT:
Log::debug(sprintf('%s: - ls_zrecvfinfo LSZ_TIMEOUT',self::LOGKEY));
case self::TIMEOUT:
Log::debug(sprintf('%s: - ls_zrecvfinfo TIMEOUT',self::LOGKEY));
$retransmit = 1;
break;
@@ -1527,7 +1524,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
} while ($trys < 10);
Log::error(sprintf('%s:? ls_zrecvfinfo Something strange or timeout',self::LOGKEY));
return self::LSZ_TIMEOUT;
return self::TIMEOUT;
}
private function ls_zrecvhdr(array &$hdr,int $timeout): int
@@ -1538,7 +1535,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$state = self::rhInit;
$readmode = self::rm7BIT;
static $frametype = self::LSZ_ERROR; /* Frame type */
static $frametype = self::ERROR; /* Frame type */
static $crcl = 2; /* Length of CRC (CRC16 is default) */
static $crcgot = 0; /* Number of CRC bytes already got */
static $incrc = 0; /* Calculated CRC */
@@ -1552,7 +1549,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
if ($this->DEBUG)
Log::debug(sprintf('%s: - ls_zrecvhdr Init State',self::LOGKEY));
$frametype = self::LSZ_ERROR;
$frametype = self::ERROR;
$crc = 0;
$crcl = 2;
$crcgot = 0;
@@ -1858,7 +1855,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
switch (($rc=$this->ls_zrecvdata($buf,$len,$this->ls_DataTimeout,$this->ls_Protocol&self::LSZ_OPTCRC32))) {
/* Ok, here it is */
case self::ZCRCW:
return self::LSZ_OK;
return self::OK;
case self::LSZ_BADCRC:
Log::debug(sprintf('%s: - ls_zrecvcrcw got BADCRC',self::LOGKEY));
@@ -1866,7 +1863,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
return 1;
case self::LSZ_TIMEOUT:
case self::TIMEOUT:
Log::debug(sprintf('%s: - ls_zrecvcrcw got TIMEOUT',self::LOGKEY));
break;
@@ -1913,7 +1910,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
break;
case self::LSZ_TIMEOUT:
case self::TIMEOUT:
break;
case self::LSZ_BADCRC:
@@ -1933,7 +1930,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
} while (++$trys < 10);
Log::error(sprintf('%s:? ls_zrecvnewpos Something strange or timeout [%d]',self::LOGKEY,$rc));
return self::LSZ_TIMEOUT;
return self::TIMEOUT;
}
/**
@@ -1952,7 +1949,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
if (++$this->ls_txReposCount > 10) {
Log::error(sprintf('%s:! ZRPOS to [%ld] limit reached',self::LOGKEY,$newpos));
return self::LSZ_ERROR;
return self::ERROR;
}
} else {
@@ -1966,14 +1963,14 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
if (! $send->seek($newpos)) {
Log::error(sprintf('%s:! ZRPOS to [%ld] seek error',self::LOGKEY,$send->filepos));
return self::LSZ_ERROR;
return self::ERROR;
}
if ($this->ls_txCurBlockSize > 32)
$this->ls_txCurBlockSize >>= 1;
$this->ls_txGoodBlocks = 0;
return self::LSZ_OK;
return self::OK;
}
/**
@@ -2069,7 +2066,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
[($this->ls_Protocol&self::LSZ_OPTVHDR)==self::LSZ_OPTVHDR]
[($this->ls_Protocol&self::LSZ_OPTRLE)==self::LSZ_OPTRLE]) < 0)
{
return self::LSZ_ERROR;
return self::ERROR;
}
/* Send *<DLE> and packet type */
@@ -2145,7 +2142,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
Log::debug(sprintf('%s: - ls_zsendfile ZABORT/ZFIN',self::LOGKEY));
$this->ls_zsendhhdr(self::ZFIN,$this->ls_storelong(0));
return self::LSZ_ERROR;
return self::ERROR;
default:
if ($rc < 0)
@@ -2153,7 +2150,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
Log::debug(sprintf('%s:- ls_zsendfile Strange answer on ZFILE [%d]',self::LOGKEY,$rc));
return self::LSZ_ERROR;
return self::ERROR;
}
/* Send file data */
@@ -2181,7 +2178,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
} catch (\Exception $e) {
Log::error(sprintf('%s:! ls_zsendfile Read error',self::LOGKEY));
return self::LSZ_ERROR;
return self::ERROR;
}
/* Select sub-frame type */
@@ -2266,11 +2263,11 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$this->ls_zsendhhdr(self::ZFIN,$this->ls_storelong(0));
/* Fall through */
case self::LSZ_RCDO:
case self::LSZ_ERROR:
return self::LSZ_ERROR;
case self::RCDO:
case self::ERROR:
return self::ERROR;
case self::LSZ_TIMEOUT: /* Ok! */
case self::TIMEOUT: /* Ok! */
break;
default:
@@ -2289,7 +2286,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
&& ++$trys < 10);
if ($trys >= 10)
return self::LSZ_ERROR;
return self::ERROR;
/* Ok, increase block, if here is MANY good blocks was sent */
if (++$this->ls_txGoodBlocks > 32) {
@@ -2329,7 +2326,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
/* OK! */
case self::ZRINIT:
return self::LSZ_OK;
return self::OK;
/* ACK for data -- it lost! */
case self::ZACK:
@@ -2344,10 +2341,10 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
case self::ZFIN:
/* Abort too */
case self::ZCAN:
return self::LSZ_ERROR;
return self::ERROR;
/* Ok, here is no header */
case self::LSZ_TIMEOUT:
case self::TIMEOUT:
$trys++;
break;
@@ -2366,7 +2363,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
if ($send->feof()) {
Log::error(sprintf('%s:! ls_zsendfile To many tries waiting for ZEOF ACK',self::LOGKEY));
return self::LSZ_ERROR;
return self::ERROR;
}
}
}
@@ -2477,7 +2474,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
break;
case self::ZNAK:
case self::LSZ_TIMEOUT:
case self::TIMEOUT:
$retransmit = 1;
break;
@@ -2587,7 +2584,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
/* Ok */
case self::ZACK:
return self::LSZ_OK;
return self::OK;
/* Return number to peer, he is paranoid */
case self::ZCHALLENGE:
@@ -2605,7 +2602,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
/* Retransmit */
case ZNAK:
case LSZ_TIMEOUT:
case TIMEOUT:
$retransmit = 1;
break;