More complete rework of packet parsing and packet generation with f279d85
- and testing passes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ use Symfony\Component\HttpFoundation\File\File;
|
||||
|
||||
use App\Classes\FTN as FTNBase;
|
||||
use App\Exceptions\InvalidPacketException;
|
||||
use App\Models\{Address,Domain,Echomail,Netmail,Software,Zone};
|
||||
use App\Models\{Address,Domain,Echomail,Netmail,Software,System,Zone};
|
||||
use App\Notifications\Netmails\EchomailBadAddress;
|
||||
|
||||
/**
|
||||
@@ -206,7 +206,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
Log::debug(sprintf('%s:/ Requesting key for Packet::class [%s]',self::LOGKEY,$key));
|
||||
//Log::debug(sprintf('%s:/ Requesting key for Packet::class [%s]',self::LOGKEY,$key));
|
||||
|
||||
switch ($key) {
|
||||
// From Addresses
|
||||
@@ -418,15 +418,13 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
|
||||
$msg = Message::parseMessage($message,$this->zone);
|
||||
|
||||
// @todo If the message from domain (eg: $msg->fftn->zone->domain) is different to the packet address domain ($pkt->fftn->zone->domain), we'll skip this message
|
||||
Log::debug(sprintf('%s:^ Message [%s] - Packet from domain [%d], Message domain [%d]',self::LOGKEY,$msg->msgid,$this->fftn->zone->domain_id,$msg->fftn->zone->domain_id));
|
||||
|
||||
// If the message is invalid, we'll ignore it
|
||||
if ($msg->errors) {
|
||||
Log::info(sprintf('%s:- Message [%s] has errors',self::LOGKEY,$msg->msgid));
|
||||
if ($msg->errors->count()) {
|
||||
Log::info(sprintf('%s:- Message [%s] has [%d] errors',self::LOGKEY,$msg->msgid ?: 'No ID',$msg->errors->count()));
|
||||
|
||||
|
||||
// If the messages is not for the right zone, we'll ignore it
|
||||
if ($msg->errors->messages()->has('invalid-zone')) {
|
||||
if ($msg->errors->has('invalid-zone')) {
|
||||
Log::alert(sprintf('%s:! Message [%s] is from an invalid zone [%s], packet is from [%s] - ignoring it',self::LOGKEY,$msg->msgid,$msg->fftn->zone->zone_id,$this->fftn->zone->zone_id));
|
||||
|
||||
if (! $msg->rescanned->count())
|
||||
@@ -435,81 +433,60 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
return;
|
||||
}
|
||||
|
||||
// @todo If the $msg->fftn doesnt exist, we'll need to create it
|
||||
// @todo If the $msg->tftn doesnt exist (netmail), we'll need to create it (ergo intransit)
|
||||
/*
|
||||
// If the to address doenst exist, we'll create a new entry
|
||||
if ($msg->errors->messages()->has('to') && $msg->tzone) {
|
||||
try {
|
||||
// @todo Need to work out the correct region for the host_id
|
||||
Address::unguard();
|
||||
$ao = Address::firstOrNew([
|
||||
'zone_id' => $msg->tzone->id,
|
||||
//'region_id' => 0,
|
||||
'host_id' => $msg->tn,
|
||||
'node_id' => $msg->tf,
|
||||
'point_id' => $msg->tp,
|
||||
'active' => TRUE, // @todo This should be false, as it hasnt been assigned to the node
|
||||
]);
|
||||
Address::reguard();
|
||||
// If the $msg->fftn doesnt exist, we'll need to create it
|
||||
if ($msg->errors->has('from') && $this->fftn && $this->fftn->zone_id) {
|
||||
Log::debug(sprintf('%s:^ From address [%s] doesnt exist, it needs to be created',self::LOGKEY,$msg->set->get('set_fftn')));
|
||||
|
||||
if (is_null($ao->region_id))
|
||||
$ao->region_id = $ao->host_id;
|
||||
$ao = Address::findFTN($msg->set->get('set_fftn'),TRUE);
|
||||
|
||||
if ($ao?->exists && ($ao->zone?->domain_id !== $this->fftn->zone->domain_id)) {
|
||||
Log::alert(sprintf('%s:! From address [%s] domain [%d] doesnt match packet domain [%d]?',self::LOGKEY,$msg->set->get('set_fftn'),$ao->zone?->domain_id,$this->fftn->zone->domain_id));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error(sprintf('%s:! Error finding/creating TO address [%s] for message',self::LOGKEY,$msg->tboss),['error'=>$e->getMessage()]);
|
||||
$this->errors->push($msg);
|
||||
return;
|
||||
}
|
||||
|
||||
$so = System::createUnknownSystem();
|
||||
if (! $ao) {
|
||||
$so = System::createUnknownSystem();
|
||||
$ao = Address::createFTN($msg->set->get('set_fftn'),$so);
|
||||
}
|
||||
|
||||
$so->addresses()->save($ao);
|
||||
|
||||
Log::alert(sprintf('%s:- To FTN is not defined, creating new entry for [%s] (%d)',self::LOGKEY,$msg->tboss,$ao->id));
|
||||
$msg->fftn_id = $ao->id;
|
||||
Log::alert(sprintf('%s:- From FTN [%s] is not defined, created new entry for (%d)',self::LOGKEY,$msg->set->get('set_fftn'),$ao->id));
|
||||
}
|
||||
|
||||
// If the from address doenst exist, we'll create a new entry
|
||||
if ($msg->errors->messages()->has('from') && $msg->tzone) {
|
||||
try {
|
||||
// @todo Need to work out the correct region for the host_id
|
||||
Address::unguard();
|
||||
$ao = Address::firstOrNew([
|
||||
'zone_id' => $msg->fzone->id,
|
||||
//'region_id' => 0,
|
||||
'host_id' => $msg->fn,
|
||||
'node_id' => $msg->ff,
|
||||
'point_id' => $msg->fp,
|
||||
'active'=> TRUE, // @todo This should be FALSE as it hasnt been assigned to the node
|
||||
]);
|
||||
Address::reguard();
|
||||
// If the $msg->tftn doesnt exist, we'll need to create it
|
||||
if ($msg->errors->has('to') && $this->tftn && $this->tftn->zone_id) {
|
||||
Log::debug(sprintf('%s:^ To address [%s] doesnt exist, it needs to be created',self::LOGKEY,$msg->set->get('set_tftn')));
|
||||
|
||||
if (is_null($ao->region_id))
|
||||
$ao->region_id = $ao->host_id;
|
||||
$ao = Address::findFTN($msg->set->get('set_tftn'),TRUE);
|
||||
|
||||
if ($ao?->exists && ($ao->zone?->domain_id !== $this->tftn->zone->domain_id)) {
|
||||
Log::alert(sprintf('%s:! To address [%s] domain [%d] doesnt match packet domain [%d]?',self::LOGKEY,$msg->set->get('set_tftn'),$ao->zone?->domain_id,$this->fftn->zone->domain_id));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error(sprintf('%s:! Error finding/creating FROM address [%s] for message',self::LOGKEY,$msg->fboss),['error'=>$e->getMessage()]);
|
||||
$this->errors->push($msg);
|
||||
return;
|
||||
}
|
||||
|
||||
$so = System::createUnknownSystem();
|
||||
if (! $ao) {
|
||||
$so = System::createUnknownSystem();
|
||||
$ao = Address::createFTN($msg->set->get('set_fftn'),$so);
|
||||
}
|
||||
|
||||
$so->addresses()->save($ao);
|
||||
|
||||
Log::alert(sprintf('%s:- From FTN is not defined, creating new entry for [%s] (%d)',self::LOGKEY,$msg->fboss,$ao->id));
|
||||
$msg->tftn_id = $ao->id;
|
||||
Log::alert(sprintf('%s:- To FTN [%s] is not defined, created new entry for (%d)',self::LOGKEY,$msg->set->get('set_tftn'),$ao->id));
|
||||
}
|
||||
*/
|
||||
|
||||
// If the from/to user is missing
|
||||
if ($msg->errors->messages()->has('from') || $msg->errors->messages()->has('to')) {
|
||||
Log::error(sprintf('%s:! Skipping message [%s] due to errors (%s)...',self::LOGKEY,$msg->msgid,join(',',$msg->errors->messages()->keys())));
|
||||
$this->errors->push($msg);
|
||||
// If there is no fftn, then its from a system that we dont know about
|
||||
if (! $this->fftn) {
|
||||
Log::alert(sprintf('%s:! No further message processing, packet is from a system we dont know about [%s]',self::LOGKEY,$this->fftn_t));
|
||||
|
||||
$this->messages->push($msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// @todo If the message from domain (eg: $msg->fftn->zone->domain) is different to the packet address domain ($pkt->fftn->zone->domain), we'll skip this message
|
||||
Log::debug(sprintf('%s:^ Message [%s] - Packet from domain [%d], Message domain [%d]',self::LOGKEY,$msg->msgid,$this->fftn->zone->domain_id,$msg->fftn->zone->domain_id));
|
||||
|
||||
$this->messages->push($msg);
|
||||
}
|
||||
|
||||
|
@@ -63,34 +63,36 @@ final class FSC39 extends Packet
|
||||
*/
|
||||
protected function header(): string
|
||||
{
|
||||
$oldest = $this->messages->sortBy('datetime')->last();
|
||||
|
||||
try {
|
||||
return pack(collect(self::HEADER)->pluck(1)->join(''),
|
||||
$this->ff, // Orig Node
|
||||
$this->tf, // Dest Node
|
||||
Arr::get($this->header,'y'), // Year
|
||||
Arr::get($this->header,'m'), // Month
|
||||
Arr::get($this->header,'d'), // Day
|
||||
Arr::get($this->header,'H'), // Hour
|
||||
Arr::get($this->header,'M'), // Minute
|
||||
Arr::get($this->header,'S'), // Second
|
||||
0, // Baud
|
||||
2, // Packet Version (should be 2)
|
||||
$this->fn, // Orig Net
|
||||
$this->tn, // Dest Net
|
||||
(Setup::PRODUCT_ID & 0xff), // Product Code Lo
|
||||
Setup::PRODUCT_VERSION_MAJ, // Product Version Major
|
||||
$this->password, // Packet Password
|
||||
$this->fz, // Orig Zone
|
||||
$this->tz, // Dest Zone
|
||||
'', // Reserved
|
||||
$this->fftn_p->node_id, // Orig Node
|
||||
$this->tftn_p->node_id, // Dest Node
|
||||
$oldest->datetime->format('Y'), // Year
|
||||
$oldest->datetime->format('m')-1, // Month
|
||||
$oldest->datetime->format('d'), // Day
|
||||
$oldest->datetime->format('H'), // Hour
|
||||
$oldest->datetime->format('i'), // Minute
|
||||
$oldest->datetime->format('s'), // Second
|
||||
0, // Baud
|
||||
2, // Packet Version (should be 2)
|
||||
$this->fftn_p->host_id, // Orig Net
|
||||
$this->tftn_p->host_id, // Dest Net
|
||||
(Setup::PRODUCT_ID & 0xff), // Product Code Lo
|
||||
Setup::PRODUCT_VERSION_MAJ, // Product Version Major
|
||||
$this->pass_p ?: $this->tftn_p->session('pktpass'), // Packet Password
|
||||
$this->fftn_p->zone->zone_id, // Orig Zone
|
||||
$this->tftn_p->zone->zone_id, // Dest Zone
|
||||
'', // Reserved
|
||||
Arr::get($this->header,'capvalid',1<<0), // fsc-0039.004 (copy of 0x2c)
|
||||
((Setup::PRODUCT_ID >> 8) & 0xff), // Product Code Hi
|
||||
Setup::PRODUCT_VERSION_MIN, // Product Version Minor
|
||||
Arr::get($this->header,'capword',1<<0), // Capability Word
|
||||
$this->fz, // Orig Zone
|
||||
$this->tz, // Dest Zone
|
||||
$this->fp, // Orig Point
|
||||
$this->tp, // Dest Point
|
||||
((Setup::PRODUCT_ID >> 8) & 0xff), // Product Code Hi
|
||||
Setup::PRODUCT_VERSION_MIN, // Product Version Minor
|
||||
1<<0, // Capability Word
|
||||
$this->fftn_p->zone->zone_id, // Orig Zone
|
||||
$this->tftn_p->zone->zone_id, // Dest Zone
|
||||
$this->fftn_p->point_id, // Orig Point
|
||||
$this->tftn_p->point_id, // Dest Point
|
||||
strtoupper(hexstr(Setup::PRODUCT_ID)), // ProdData
|
||||
);
|
||||
|
||||
|
@@ -44,22 +44,22 @@ final class FSC45 extends Packet
|
||||
{
|
||||
try {
|
||||
return pack(collect(self::HEADER)->pluck(1)->join(''),
|
||||
$this->ff, // Orig Node
|
||||
$this->tf, // Dest Node
|
||||
$this->fp, // Orig Point
|
||||
$this->tp, // Dest Point
|
||||
'', // Reserved
|
||||
2, // Sub Version (should be 2)
|
||||
2, // Packet Version (should be 2)
|
||||
$this->fn, // Orig Net
|
||||
$this->tn, // Dest Net
|
||||
(Setup::PRODUCT_ID & 0xff), // Product Code
|
||||
Setup::PRODUCT_VERSION_MAJ, // Product Version
|
||||
$this->password, // Packet Password
|
||||
$this->fz, // Orig Zone
|
||||
$this->tz, // Dest Zone
|
||||
$this->fd, // Orig Domain
|
||||
$this->td, // Dest Domain
|
||||
$this->fftn_p->node_id, // Orig Node
|
||||
$this->tftn_p->node_id, // Dest Node
|
||||
$this->fp, // Orig Point
|
||||
$this->tp, // Dest Point
|
||||
'', // Reserved
|
||||
2, // Sub Version (should be 2)
|
||||
2, // Packet Version (should be 2)
|
||||
$this->fftn_p->host_id, // Orig Net
|
||||
$this->tftn_p->host_id, // Dest Net
|
||||
(Setup::PRODUCT_ID & 0xff), // Product Code
|
||||
Setup::PRODUCT_VERSION_MAJ, // Product Version
|
||||
$this->pass_p ?: $this->tftn_p->session('pktpass'), // Packet Password
|
||||
$this->fftn_p->zone->zone_id, // Orig Zone
|
||||
$this->tftn_p->zone->zone_id, // Dest Zone
|
||||
$this->fftn_p->zone->domain->name, // Orig Domain
|
||||
$this->tftn_p->zone->domain->name, // Dest Domain
|
||||
strtoupper(hexstr(Setup::PRODUCT_ID)), // ProdData
|
||||
);
|
||||
|
||||
|
@@ -43,26 +43,28 @@ final class FTS1 extends Packet
|
||||
*/
|
||||
protected function header(): string
|
||||
{
|
||||
$oldest = $this->messages->sortBy('datetime')->last();
|
||||
|
||||
try {
|
||||
return pack(collect(self::HEADER)->pluck(1)->join(''),
|
||||
$this->ff, // Orig Node
|
||||
$this->tf, // Dest Node
|
||||
Arr::get($this->header,'y'), // Year
|
||||
Arr::get($this->header,'m'), // Month
|
||||
Arr::get($this->header,'d'), // Day
|
||||
Arr::get($this->header,'H'), // Hour
|
||||
Arr::get($this->header,'M'), // Minute
|
||||
Arr::get($this->header,'S'), // Second
|
||||
0, // Baud
|
||||
2, // Packet Version (should be 2)
|
||||
$this->fn, // Orig Net
|
||||
$this->tn, // Dest Net
|
||||
(Setup::PRODUCT_ID & 0xff), // Product Code Lo
|
||||
Setup::PRODUCT_VERSION_MAJ, // Product Version Major
|
||||
$this->password, // Packet Password
|
||||
$this->fz, // Orig Zone
|
||||
$this->tz, // Dest Zone
|
||||
'', // Reserved
|
||||
$this->fftn_p->node_id, // Orig Node
|
||||
$this->tftn_p->node_id, // Dest Node
|
||||
$oldest->datetime->format('Y'), // Year
|
||||
$oldest->datetime->format('m')-1, // Month
|
||||
$oldest->datetime->format('d'), // Day
|
||||
$oldest->datetime->format('H'), // Hour
|
||||
$oldest->datetime->format('i'), // Minute
|
||||
$oldest->datetime->format('s'), // Second
|
||||
0, // Baud
|
||||
2, // Packet Version (should be 2)
|
||||
$this->fftn_p->host_id, // Orig Net
|
||||
$this->tftn_p->host_id, // Dest Net
|
||||
(Setup::PRODUCT_ID & 0xff), // Product Code Lo
|
||||
Setup::PRODUCT_VERSION_MAJ, // Product Version Major
|
||||
$this->pass_p ?: $this->tftn_p->session('pktpass'), // Packet Password
|
||||
$this->fftn_p->zone->zone_id, // Orig Zone
|
||||
$this->tftn_p->zone->zone_id, // Dest Zone
|
||||
'', // Reserved
|
||||
);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
Reference in New Issue
Block a user