More complete rework of packet parsing and packet generation with f279d85 - and testing passes

This commit is contained in:
2024-05-20 21:31:21 +10:00
parent b30ab2f999
commit ab2e288f06
14 changed files with 227 additions and 210 deletions

View File

@@ -242,25 +242,28 @@ class Message extends FTNBase
$o->mo->msg_crc = md5($o->mo->msg_src);
$o->mo->fftn_id = $o->fftn?->id;
if ($o->fftn)
$o->mo->fftn_id = $o->fftn->id;
else
$o->mo->set_fftn = $o->fftn_t;
switch (get_class($o->mo)) {
case Echomail::class:
// Echomails dont have a to address
break;
case Netmail::class:
$o->mo->tftn_id = $o->tftn?->id;
if ($o->tftn)
$o->mo->tftn_id = $o->tftn->id;
else
$o->mo->set_tftn = $o->tftn_t;
break;
default:
throw new InvalidPacketException('Unknown message class: '.get_class($o->mo));
}
if (($x=$o->validate())->fails()) {
$o->mo->errors = $x;
Log::debug(sprintf('%s:! Message fails validation (%s@%s->%s@%s)',self::LOGKEY,$o->mo->from,$o->fftn_t,$o->mo->to,$o->tftn_t),['result'=>$o->mo->errors->errors()]);
}
$o->validate();
return $o->mo;
}
@@ -300,7 +303,7 @@ class Message extends FTNBase
public function __get($key)
{
// @todo Do we need all these key values?
Log::debug(sprintf('%s:/ Requesting key for Message::class [%s]',self::LOGKEY,$key));
//Log::debug(sprintf('%s:/ Requesting key for Message::class [%s]',self::LOGKEY,$key));
switch ($key) {
// From Addresses
@@ -556,7 +559,7 @@ class Message extends FTNBase
foreach ($this->mo->kludges as $k=>$v)
$return .= sprintf("\01%s %s\r",$k,$v);
$return .= $this->mo->content;
$return .= $this->mo->content."\r";
if ($this->mo instanceof Netmail) {
foreach ($this->mo->path as $ao)
@@ -830,14 +833,16 @@ class Message extends FTNBase
$validator->errors()->add('invalid-zone',sprintf('Message zone [%d] doesnt match packet zone [%d].',$this->fz,$this->zone->zone_id));
}
if (! $this->fboss_o)
$validator->errors()->add('from',sprintf('Undefined Node [%s] sent message.',$this->fboss));
if (! $this->tboss_o)
$validator->errors()->add('to',sprintf('Undefined Node [%s] for destination.',$this->tboss));
if (! $this->fftn)
$validator->errors()->add('from',sprintf('Undefined Node [%s] sent message.',$this->fftn_t));
if ($this->isNetmail() && (! $this->tftn))
$validator->errors()->add('to',sprintf('Undefined Node [%s] for destination.',$this->tftn_t));
});
$this->mo->errors = $validator->errors();
if ($validator->fails())
$this->mo->errors = $validator;
Log::debug(sprintf('%s:! Message fails validation (%s@%s->%s@%s)',self::LOGKEY,$this->mo->from,$this->fftn_t,$this->mo->to,$this->tftn_t),['result'=>$validator->errors()]);
return $validator;
}