Enable duplicates to update seen-by's before being discarded

This commit is contained in:
Deon George 2021-11-24 22:34:40 +11:00
parent 02c23f047c
commit ebd1cf8732
6 changed files with 41 additions and 14 deletions

View File

@ -59,6 +59,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
public Collection $messages; // Messages in the Packet public Collection $messages; // Messages in the Packet
public Collection $errors; // Messages that fail validation public Collection $errors; // Messages that fail validation
private string $name; // Packet name private string $name; // Packet name
private ?System $system; // System the packet is from
public bool $use_redis = TRUE; // Use redis for messages. public bool $use_redis = TRUE; // Use redis for messages.
private int $index; // Our array index private int $index; // Our array index
@ -116,7 +117,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
* @return Packet * @return Packet
* @throws InvalidPacketException * @throws InvalidPacketException
*/ */
public static function open(File $file,Zone $zone=NULL,bool $use_redis=TRUE): self public static function open(File $file,System $system=NULL,bool $use_redis=TRUE): self
{ {
Log::debug(sprintf('%s:+ Opening Packet [%s]',self::LOGKEY,$file)); Log::debug(sprintf('%s:+ Opening Packet [%s]',self::LOGKEY,$file));
@ -136,7 +137,6 @@ class Packet extends FTNBase implements \Iterator, \Countable
throw new InvalidPacketException('Not a type 2 packet: '.$version); throw new InvalidPacketException('Not a type 2 packet: '.$version);
$o = new self; $o = new self;
$o->zone = $zone;
$o->use_redis = $use_redis; $o->use_redis = $use_redis;
$o->name = (string)$file; $o->name = (string)$file;
$o->header = unpack(self::unpackheader(self::v2header),$header); $o->header = unpack(self::unpackheader(self::v2header),$header);
@ -155,6 +155,8 @@ class Packet extends FTNBase implements \Iterator, \Countable
else if (! strlen($x)) else if (! strlen($x))
throw new InvalidPacketException('No message in packet: '.bin2hex($x)); throw new InvalidPacketException('No message in packet: '.bin2hex($x));
$o->zone = $system?->zones->firstWhere('zone_id',$o->fz);
// If zone is null, we'll take the zone from the packet // If zone is null, we'll take the zone from the packet
if (! $o->zone) if (! $o->zone)
$o->zone = Zone::where('zone_id',$o->fz)->where('default',TRUE)->single(); $o->zone = Zone::where('zone_id',$o->fz)->where('default',TRUE)->single();

View File

@ -112,7 +112,7 @@ final class Receive extends Item
Log::info(sprintf('%s: - Processing mail packet [%s]',self::LOGKEY,$this->file)); Log::info(sprintf('%s: - Processing mail packet [%s]',self::LOGKEY,$this->file));
try { try {
$po = Packet::open(new File($this->file),$this->ao->zone); $po = Packet::open(new File($this->file),$this->ao->system);
} catch (InvalidPacketException $e) { } catch (InvalidPacketException $e) {
Log::error(sprintf('%s: - Not deleting packet [%s], as it generated an exception',self::LOGKEY,$this->file)); Log::error(sprintf('%s: - Not deleting packet [%s], as it generated an exception',self::LOGKEY,$this->file));

View File

@ -6,7 +6,7 @@ use Illuminate\Console\Command;
use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\File;
use App\Classes\FTN\Packet; use App\Classes\FTN\Packet;
use App\Models\Zone; use App\Models\System;
class PacketInfo extends Command class PacketInfo extends Command
{ {
@ -17,7 +17,7 @@ class PacketInfo extends Command
*/ */
protected $signature = 'packet:info' protected $signature = 'packet:info'
.' {pkt : Packet to process}' .' {pkt : Packet to process}'
.' {zone? : Zone the packet is from}'; .' {system? : Zone the packet is from}';
/** /**
* The console command description. * The console command description.
@ -35,9 +35,9 @@ class PacketInfo extends Command
public function handle() public function handle()
{ {
$f = new File($this->argument('pkt')); $f = new File($this->argument('pkt'));
$z = $this->argument('zone') ? Zone::where('zone_id',$this->argument('zone'))->singleOrFail() : NULL; $s = $this->argument('system') ? System::where('name',$this->argument('zone'))->singleOrFail() : NULL;
$pkt = Packet::open($f,$z); $pkt = Packet::open($f,$s);
$this->info(sprintf('Packet Type: %s',$pkt->type)); $this->info(sprintf('Packet Type: %s',$pkt->type));
$this->info(sprintf('From: %s to %s',$pkt->fftn,$pkt->tftn)); $this->info(sprintf('From: %s to %s',$pkt->fftn,$pkt->tftn));

View File

@ -19,7 +19,7 @@ class PacketProcess extends Command
protected $signature = 'packet:process' protected $signature = 'packet:process'
.' {pkt : Packet to process}' .' {pkt : Packet to process}'
.' {--N|nobot : Dont process bots}' .' {--N|nobot : Dont process bots}'
.' {zone? : Zone the packet is from}'; .' {system? : Zone the packet is from}';
/** /**
* The console command description. * The console command description.
@ -37,9 +37,9 @@ class PacketProcess extends Command
public function handle() public function handle()
{ {
$f = new File($this->argument('pkt')); $f = new File($this->argument('pkt'));
$z = $this->argument('zone') ? Zone::where('zone_id',$this->argument('zone'))->singleOrFail() : NULL; $s = $this->argument('system') ? Zone::where('name',$this->argument('system'))->singleOrFail() : NULL;
foreach (Packet::open($f,$z) as $msg) { foreach (Packet::open($f,$s) as $msg) {
// @todo Quick check that the packet should be processed by us. // @todo Quick check that the packet should be processed by us.
// @todo validate that the packet's zone is in the domain. // @todo validate that the packet's zone is in the domain.

View File

@ -142,16 +142,20 @@ class MessageProcess implements ShouldQueue
->where('domain_id',$this->msg->fboss_o->zone->domain_id) ->where('domain_id',$this->msg->fboss_o->zone->domain_id)
->single(); ->single();
Log::debug(sprintf('%s: - Processing echomail [%s].',self::LOGKEY,$this->msg->msgid));
// Check for duplicate messages // Check for duplicate messages
// FTS-0009.001 // FTS-0009.001
if ($this->msg->msgid) { if ($this->msg->msgid) {
$o = Echomail::where('msgid',$this->msg->msgid) $o = Echomail::where('msgid',$this->msg->msgid)
->where('fftn_id',($x=$this->msg->fboss_o) ? $x->id : NULL) ->where('fftn_id',($x=$this->msg->fboss_o) ? $x->id : NULL)
->where('datetime',Carbon::now()->subYears(3)) ->where('datetime','>',Carbon::now()->subYears(3))
->single(); ->single();
Log::debug(sprintf('%s: - Checking for duplicate from host id [%d].',self::LOGKEY,($x=$this->msg->fboss_o) ? $x->id : NULL));
if ($o) { if ($o) {
Log::alert(sprintf('%s:! Ignoring duplicate echomail [%s] in [%s] from (%s) [%s] to (%s).', Log::alert(sprintf('%s:! Duplicate echomail [%s] in [%s] from (%s) [%s] to (%s) - updating seenby.',
self::LOGKEY, self::LOGKEY,
$this->msg->msgid, $this->msg->msgid,
$this->msg->echoarea, $this->msg->echoarea,
@ -159,10 +163,31 @@ class MessageProcess implements ShouldQueue
$this->msg->user_from, $this->msg->user_from,
)); ));
if (! $o->msg_crc)
$o->msg_crc = md5($this->msg->message);
$o->seenby = collect($o->getRawOriginal('seenby'))->merge($this->msg->seenaddress)->filter()->toArray();
$o->save();
return; return;
} }
} }
// Find another message with the same msg_crc
if ($this->msg->message) {
$o = Echomail::where('msg_crc',$xx=md5($this->msg->message))
->where('fftn_id',($x=$this->msg->fboss_o) ? $x->id : NULL)
->where('datetime','>',Carbon::now()->subWeek())
->get();
if ($o->count())
Log::alert(sprintf('%s:! Duplicate message CRC [%s] in [%s].',
self::LOGKEY,
$xx,
$o->pluck('id')->join('|')
));
}
// @todo Can the sender create it if it doesnt exist? // @todo Can the sender create it if it doesnt exist?
// @todo Can the sender send messages to this area? // @todo Can the sender send messages to this area?
// - Create it, or // - Create it, or

View File

@ -67,7 +67,7 @@ class PacketTest extends TestCase
// This packet has an incorrect zone in the Origin // This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_nomsgid_noorigin.pkt'); $f = new File(__DIR__.'/data/test_nomsgid_noorigin.pkt');
$pkt = Packet::open($f,$zo,FALSE); $pkt = Packet::open($f,$this->so,FALSE);
$this->assertEquals(1,$pkt->count()); $this->assertEquals(1,$pkt->count());
@ -96,7 +96,7 @@ class PacketTest extends TestCase
// This packet has an incorrect zone in the Origin // This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_msgid_origin.pkt'); $f = new File(__DIR__.'/data/test_msgid_origin.pkt');
$pkt = Packet::open($f,$zo,FALSE); $pkt = Packet::open($f,$this->so,FALSE);
$this->assertEquals(1,$pkt->count()); $this->assertEquals(1,$pkt->count());