New algorithm for calculating packet name, EMSI/BINKP inbound processing tested, Netmail rejection and intransit processing

This commit is contained in:
Deon George
2021-07-24 00:53:35 +10:00
parent 2fdc6eabad
commit ee30ef92c3
12 changed files with 184 additions and 54 deletions

View File

@@ -163,7 +163,7 @@ class Message extends FTNBase
*
* @param string $msg
* @param Domain|null $domain
* @return static
* @return Message
* @throws InvalidPacketException
*/
public static function parseMessage(string $msg,Domain $domain=NULL): self

View File

@@ -62,7 +62,7 @@ class Packet extends FTNBase
{
$this->messages = collect();
$this->domain = NULL;
$this->name = sprintf('%08x',Carbon::now()->timestamp);
$this->name = sprintf('%08x',timew());
// If we are creating an outbound packet, we need to set our header
if ($o)

View File

@@ -19,7 +19,7 @@ abstract class Process
/**
* This function will format text to static::MSG_WIDTH, as well as adding the logo.
*/
protected static function format_msg(string $text): string
public static function format_msg(string $text,array $logo = []): string
{
$msg = utf8_decode(join("\r",static::msg_header()))."\r";
$c = 0;
@@ -29,8 +29,8 @@ abstract class Process
$ll = '';
// Add our logo
if ($c<count(static::$logo)) {
$line = utf8_decode(Arr::get(static::$logo,$c++));
if ($c<count($logo)) {
$line = utf8_decode(Arr::get($logo,$c++));
$ll = $line.' ';
}
@@ -60,8 +60,8 @@ abstract class Process
}
// In case our text is shorter than the loo
for ($c; $c<count(static::$logo);$c++)
$msg .= utf8_decode(Arr::get(static::$logo,$c))."\r";
for ($c; $c<count($logo);$c++)
$msg .= utf8_decode(Arr::get($logo,$c))."\r";
return $msg;
}

View File

@@ -16,7 +16,7 @@ use App\Models\{Netmail,Setup};
*/
final class Ping extends Process
{
protected static array $logo = [
private static array $logo = [
'ÚÄ¿þÚÄ¿ÚÄ¿',
'³ ³Â³ ³Àij',
'ÃÄÙÁÁ ÁÄÄÙ'
@@ -29,7 +29,8 @@ final class Ping extends Process
Log::info(sprintf('Processing PING message from (%s) [%s]',$msg->user_from,$msg->fftn));
$reply = sprintf("Your ping was received here on %s and it took %s to get here.\r",
$reply = sprintf("Your ping was received here on %s and it looks like you sent it on %s. If that is correct, then it took %s to get here.\r",
$msg->date->toDateTimeString(),
Carbon::now()->toDateTimeString(),
$msg->date->diffForHumans(['parts'=>3,'syntax'=>CarbonInterface::DIFF_ABSOLUTE])
);
@@ -46,7 +47,7 @@ final class Ping extends Process
$o->subject = 'Ping Reply';
$o->fftn_id = ($x=$msg->tftn_o) ? $x->id : NULL;
$o->tftn_id = ($x=$msg->fftn_o) ? $x->id : NULL;
$o->msg = static::format_msg($reply);
$o->msg = static::format_msg($reply,self::$logo);
$o->reply = $msg->msgid;
$o->tagline = 'My ping pong opponent was not happy with my serve. He kept returning it.';

View File

@@ -120,6 +120,7 @@ final class Send extends Item
*
* @param string $file
* @throws Exception
* @todo Catch if we add the same file twice
*/
public function add(string $file): void
{
@@ -277,7 +278,8 @@ final class Send extends Item
throw new Exception('No file open for seek');
if ($this->sending instanceof Mail) {
$rc = ($pos < $this->size) ? $pos : $this->size;
$pos = ($pos < $this->size) ? $pos : $this->size;
$rc = TRUE;
} else {
$rc = (fseek($this->f,$pos,SEEK_SET) === 0);

View File

@@ -623,14 +623,6 @@ final class Binkp extends BaseProtocol
// @todo lock nodes
$this->node->ftn = $o;
// Add our mail to the queue if we have authenticated
if ($this->node->aka_authed)
foreach ($this->node->aka_remote as $ao) {
$this->send->mail($ao);
}
Log::info(sprintf('%s: = Node has [%lu] mail and [%lu] files - [%lu] items',__METHOD__,$this->send->mail_size,$this->send->file_size,$this->send->total_count));
$rc = $this->node->aka_num;
}
@@ -653,8 +645,6 @@ final class Binkp extends BaseProtocol
return 0;
}
$this->msgs(self::BPM_NUL,sprintf('TRF %lu %lu',$this->send->mail_size,$this->send->file_size));
if ($this->md_challenge) {
$this->msgs(self::BPM_PWD,sprintf('CRAM-MD5-%s',$this->node->get_md5chal($this->md_challenge)));
@@ -697,6 +687,8 @@ final class Binkp extends BaseProtocol
}
/**
* We received EOB from the remote.
*
* @throws Exception
*/
private function M_eob(string $buf): int
@@ -718,7 +710,7 @@ final class Binkp extends BaseProtocol
}
if ($this->send->total_count)
$this->sessionClear(self::SE_NOFILES);
$this->sessionClear(self::SE_NOFILES|self::SE_SENTEOB);
}
return 1;
@@ -1066,6 +1058,14 @@ final class Binkp extends BaseProtocol
}
}
// Add our mail to the queue if we have authenticated
if ($this->node->aka_authed)
foreach ($this->node->aka_remote as $ao) {
$this->send->mail($ao);
}
$this->msgs(self::BPM_NUL,sprintf('TRF %lu %lu',$this->send->mail_size,$this->send->file_size));
Log::debug(sprintf('%s: = End',__METHOD__));
return $this->binkp_hsdone();
}
@@ -1142,6 +1142,12 @@ final class Binkp extends BaseProtocol
if (strlen($tmp))
$this->msgs(self::BPM_NUL,sprintf('OPT%s',$tmp));
// Add our mail to the queue if we have authenticated
if ($this->node->aka_authed)
foreach ($this->node->aka_remote as $ao) {
$this->send->mail($ao);
}
$this->msgs(self::BPM_NUL,sprintf('TRF %lu %lu',$this->send->mail_size,$this->send->file_size));
$this->msgs(self::BPM_OK,sprintf('%ssecure',$have_pwd ? '' : 'non-'));
@@ -1235,7 +1241,7 @@ final class Binkp extends BaseProtocol
if ($rd && ! $this->binkp_recv())
break;
if (($this->mqueue->count() || $wd) && ! $this->binkp_send())
if (($this->mqueue->count() || $wd) && ! $this->binkp_send() && (! $this->send->total_count))
break;
}

View File

@@ -206,7 +206,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
if (! parent::onConnect($client)) {
$this->session(self::SESSION_ZMODEM,$client);
$this->client->close();
Log::info(sprintf('%s: = End - Connection closed [%s]',__METHOD__,$client->getAddress()));
Log::info(sprintf('%s: = End - Connection closed [%s]',__METHOD__,$client->address_remote));
}
return NULL;

View File

@@ -246,30 +246,6 @@ final class SocketClient {
return new self($socket,$speed);
}
/**
* Return the client's address
*
* @return string
* @todo change to __get()
* @deprecated
*/
public function getAddress(): string
{
return $this->address;
}
/**
* Return the port in use
*
* @return int
* @todo change to __get()
* @deprecated
*/
public function getPort(): int
{
return $this->port;
}
/**
* @param int $timeout
* @return int