Complete of logging received and sent packet names, and display them in the web ui for each node

This commit is contained in:
2023-07-15 22:10:05 +10:00
parent 61ab0614b6
commit a3302b4012
14 changed files with 257 additions and 121 deletions

View File

@@ -6,7 +6,6 @@ use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
@@ -598,9 +597,9 @@ class Address extends Model
->whereIn('echomail_id',$x->pluck('id'))
->where('address_id',$this->id)
->whereNull('sent_at')
->whereNull('packet')
->whereNull('sent_pkt')
->whereNotNull('echomail_seenby.export_at')
->update(['sent_at'=>Carbon::now(),'packet'=>$pkt->name]);
->update(['sent_pkt'=>$pkt->name]);
}
return $pkt;
@@ -638,21 +637,28 @@ class Address extends Model
* @param bool $update
* @return Packet|null
*/
public function getNetmail(bool $update=TRUE): ?Packet
public function getNetmail(bool $update=FALSE): ?Packet
{
$pkt = NULL;
$s = Setup::findOrFail(config('app.id'));
if (($x=$this->netmailWaiting())
->count())
{
Log::debug(sprintf('%s:= Got [%d] netmails for [%s] for sending',self::LOGKEY,$x->count(),$this->ftn));
if ($x->count() > $s->msgs_pkt) {
$x = $x->take($s->msgs_pkt);
Log::alert(sprintf('%s:= Only sending [%d] netmails for [%s]',self::LOGKEY,$x->count(),$this->ftn));
}
$pkt = $this->getPacket($x);
if ($pkt && $pkt->count() && $update)
DB::table('netmails')
->whereIn('id',$x->pluck('id'))
->update(['sent_at'=>Carbon::now(),'sent_pkt'=>$pkt->name]);
->update(['sent_pkt'=>$pkt->name]);
}
return $pkt;

View File

@@ -22,7 +22,7 @@ final class Echomail extends Model implements Packet
private const LOGKEY = 'ME-';
private Collection $set_seenby;
private Collection $set_path;
private ?string $set_packet = NULL;
private string $set_pkt;
private bool $no_export = FALSE;
protected $casts = [
@@ -50,7 +50,7 @@ final class Echomail extends Model implements Packet
switch ($key) {
case 'no_export':
case 'set_path':
case 'set_packet':
case 'set_pkt':
case 'set_seenby':
$this->{$key} = $value;
break;
@@ -71,17 +71,8 @@ final class Echomail extends Model implements Packet
return;
}
// Our address
$ftns = Setup::findOrFail(config('app.id'))
->system
->match($model->fftn->zone);
// Add our address to the seenby;
$model->set_seenby = $model->set_seenby->merge($ftns->pluck('id'))->unique();
$model->set_path = $model->set_path->merge($ftns->pluck('id'));
// Save the seenby
$model->seenby()->syncWithPivotValues($model->set_seenby,['packet'=>$model->set_packet]);
$model->seenby()->sync($model->set_seenby);
// Save the Path
$ppoid = NULL;
@@ -95,6 +86,15 @@ final class Echomail extends Model implements Packet
$ppoid = $po[0]->id;
}
// Our last node in the path is our sender
if (isset($model->set_pkt)) {
DB::update('UPDATE echomail_path set recv_pkt=? where address_id=? and echomail_id=?',[
$model->set_pkt,
$model->set_path->last(),
$model->id,
]);
}
// See if we need to export this message.
$exportto = $model->echoarea->addresses->pluck('id')->diff($model->set_seenby);
@@ -143,7 +143,6 @@ final class Echomail extends Model implements Packet
{
$this->set_path = collect();
$this->set_seenby = collect();
$this->set_packet = NULL;
}
public function jsonSerialize(): array
@@ -156,7 +155,7 @@ final class Echomail extends Model implements Packet
*/
public function packet(Address $ao): Message
{
Log::debug(sprintf('%s:Bundling [%s]',self::LOGKEY,$this->id));
Log::debug(sprintf('%s:+ Bundling [%s]',self::LOGKEY,$this->id));
// @todo Dont bundle mail to nodes that have been disabled, or addresses that have been deleted
$o = new Message;
@@ -166,7 +165,7 @@ final class Echomail extends Model implements Packet
'dnode' => $ao->node_id,
'onet' => $this->fftn->host_id,
'dnet' => $ao->host_id,
'flags' => 0, // @todo?
'flags' => 0,
'cost' => 0,
'date'=>$this->datetime->format('d M y H:i:s'),
];
@@ -198,8 +197,11 @@ final class Echomail extends Model implements Packet
if ($this->origin)
$o->origin = $this->origin;
$o->seenby = $this->seenby->pluck('ftn2d');
$o->path = $this->pathorder();
$sysaddress = Setup::findOrFail(config('app.id'))->system->match($this->fftn->zone)->first();
$o->seenby = $this->seenby->push($sysaddress)->unique()->pluck('ftn2d');
// Add our address to the path and seenby
$o->path = $this->pathorder()->merge($sysaddress->ftn2d);
$o->packed = TRUE;

View File

@@ -42,7 +42,6 @@ class File extends Model
case 'replaces':
case 'no_export':
case 'set_path':
case 'set_packet':
case 'set_seenby':
$this->{$key} = $value;
break;

View File

@@ -85,11 +85,13 @@ final class Netmail extends Model implements Packet
$ppoid = $po[0]->id;
}
// Our last node in the path is our sender
if (isset($model->set_pkt) && isset($model->set_sender)) {
DB::update('UPDATE netmail_path set recv_pkt=?,recv_id=? where address_id=?',[
DB::update('UPDATE netmail_path set recv_pkt=?,recv_id=? where address_id=? and netmail_id=?',[
$model->set_pkt,
$model->set_sender->id,
Arr::get($model->set_path->last(),'node')->id,
$model->id,
]);
}
}
@@ -130,7 +132,7 @@ final class Netmail extends Model implements Packet
*/
public function packet(Address $ao): Message
{
Log::debug(sprintf('%s:Bundling [%s]',self::LOGKEY,$this->id));
Log::debug(sprintf('%s:+ Bundling [%s]',self::LOGKEY,$this->id));
// @todo Dont bundle mail to nodes that have been disabled, or addresses that have been deleted
$o = new Message;
@@ -169,6 +171,7 @@ final class Netmail extends Model implements Packet
// VIA kludge
$sysaddress = Setup::findOrFail(config('app.id'))->system->match($this->fftn->zone)->first();
$via = $this->via ?: collect();
// Add our address to the VIA line
$via->push(
sprintf('%s @%s.UTC %s %d.%d/%s %s',
$sysaddress->ftn3d,
@@ -185,7 +188,7 @@ final class Netmail extends Model implements Packet
$o->packed = TRUE;
} catch (\Exception $e) {
Log::error(sprintf('%s:Error converting netmail [%s] to a message (%d:%s)',self::LOGKEY,$this->id,$e->getLine(),$e->getMessage()));
Log::error(sprintf('%s:! Error converting netmail [%s] to a message (%d:%s)',self::LOGKEY,$this->id,$e->getLine(),$e->getMessage()));
dump($this);
}

View File

@@ -192,7 +192,7 @@ class System extends Model
*/
public function match(Zone $o,int $type=(Address::NODE_NC|Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT)): Collection
{
return $this->addresses
return $this->akas
->where('zone_id',$o->id)
->filter(function($item) use ($type) {
return $item->role & $type;