Leverage Redis and queue to handle large packets
This commit is contained in:
@@ -106,7 +106,7 @@ class Message extends FTNBase
|
||||
private array $dst; // Address the message is to
|
||||
|
||||
private Collection $path; // FTS-0004.001 The message PATH lines
|
||||
private Collection $pathaddress; // Collection of Addresses after parsing seenby
|
||||
private Collection $pathaddress; // Collection of Addresses after parsing seenby
|
||||
private Collection $rogue_path; // Collection of FTNs in the Seen-by that are not defined
|
||||
private Collection $seenby; // FTS-0004.001 The message SEEN-BY lines
|
||||
private Collection $seenaddress; // Collection of Addresses after parsing seenby
|
||||
@@ -553,6 +553,11 @@ class Message extends FTNBase
|
||||
*/
|
||||
private function parseAddresses(string $type,Collection $addresses,Collection &$rogue): Collection
|
||||
{
|
||||
static $aos = NULL;
|
||||
|
||||
if (! $aos)
|
||||
$aos = collect();
|
||||
|
||||
$nodes = collect();
|
||||
|
||||
$net = NULL;
|
||||
@@ -567,7 +572,11 @@ class Message extends FTNBase
|
||||
};
|
||||
|
||||
$ftn = sprintf('%d:%d/%d',$this->fz,$net&0x7fff,$node&0x7fff);
|
||||
$ao = Address::findFTN($ftn);
|
||||
// @todo This should be enhanced to include the address at the time of the message.
|
||||
if ($aos->has($ftn))
|
||||
$ao = $aos->get($ftn);
|
||||
else
|
||||
$aos->put($ftn,$ao=(bool)Address::findFTN($ftn));
|
||||
|
||||
if (! $ao) {
|
||||
Log::alert(sprintf('%s:! Undefined Node [%s] in %s.',self::LOGKEY,$ftn,$type));
|
||||
|
@@ -6,12 +6,13 @@ use Carbon\Carbon;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
||||
use App\Classes\FTN as FTNBase;
|
||||
use App\Models\{Address,Domain,Setup,Software};
|
||||
|
||||
class Packet extends FTNBase
|
||||
class Packet extends FTNBase implements \Iterator, \Countable
|
||||
{
|
||||
private const LOGKEY = 'PKT';
|
||||
|
||||
@@ -57,6 +58,41 @@ class Packet extends FTNBase
|
||||
public Collection $messages; // Messages in the Packet
|
||||
public Collection $errors; // Messages that fail validation
|
||||
private string $name; // Packet name
|
||||
public bool $use_redis = TRUE; // Use redis for messages.
|
||||
private int $index; // Our array index
|
||||
|
||||
/**
|
||||
* Number of messages in this packet
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return $this->messages->count();
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return $this->use_redis ? unserialize(Redis::get($this->key())) : $this->messages->get($this->index);
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return $this->messages->get($this->index);
|
||||
}
|
||||
|
||||
public function next(): void
|
||||
{
|
||||
$this->index++;
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
$this->index = 0;
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return $this->use_redis ? ($this->key() && Redis::exists($this->key())) : $this->key();
|
||||
}
|
||||
|
||||
public function __construct(Address $o=NULL)
|
||||
{
|
||||
@@ -359,7 +395,7 @@ class Packet extends FTNBase
|
||||
* @param Domain|null $domain
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
public function parseMessage(string $message,Domain $domain=NULL): void
|
||||
private function parseMessage(string $message,Domain $domain=NULL): void
|
||||
{
|
||||
$msg = Message::parseMessage($message,$domain);
|
||||
|
||||
@@ -369,7 +405,13 @@ class Packet extends FTNBase
|
||||
Log::error(sprintf('%s:! %s Skipping...',self::LOGKEY,join('|',$msg->errors->messages()->get('from'))));
|
||||
|
||||
} else {
|
||||
$this->messages->push($msg);
|
||||
if ($this->use_redis) {
|
||||
Redis::set($msg->msgid,serialize($msg));
|
||||
$this->messages->push($msg->msgid);
|
||||
|
||||
} else {
|
||||
$this->messages->push($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user