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

@@ -357,6 +357,9 @@ class Message extends FTNBase
case 'errors':
return $this->{$key};
case 'dbid':
return $this->kludge->get($key);
default:
throw new \Exception('Unknown key: '.$key);
}

View File

@@ -36,9 +36,9 @@ class Item
protected const I_RECV = (1<<0);
protected const I_SEND = (1<<1);
protected string $file_name = '';
protected int $file_size = 0;
protected int $file_mtime = 0;
protected string $file_name;
protected int $file_size;
protected int $file_mtime;
/** Current read/write pointer */
protected int $file_pos = 0;
/** File descriptor */
@@ -113,8 +113,27 @@ class Item
{
switch($key) {
case 'mtime':
if ($this instanceof Mail)
$this->youngest()->timestamp;
if ($this->action & self::I_RECV|self::I_SEND)
return $this->{'file_'.$key};
throw new \Exception('Invalid request for key: '.$key);
case 'name':
if ($this instanceof Mail)
return sprintf('%08x',timew($this->youngest()));
if ($this->action & self::I_RECV|self::I_SEND)
return $this->{'file_'.$key};
throw new \Exception('Invalid request for key: '.$key);
case 'size':
if ($this instanceof Mail)
return strlen($this->file);
if ($this->action & self::I_RECV|self::I_SEND)
return $this->{'file_'.$key};
@@ -124,6 +143,9 @@ class Item
return $this->file_name;
case 'sendas':
if ($this instanceof Mail)
return sprintf('%s.pkt',$this->name);
return $this->file_name ? basename($this->file_name) : $this->filemodel->name;
default:

View File

@@ -31,6 +31,7 @@ class Mail extends Item
public function __get($key) {
switch ($key) {
case 'file': return $this->file;
case 'messages': return $this->file->messages;
default:
return parent::__get($key);
}

View File

@@ -41,6 +41,9 @@ final class Send extends Item
public function __get($key)
{
switch ($key) {
case 'dbids':
return $this->sending->messages->pluck('echoarea','dbid');
case 'fd':
return is_resource($this->f) ?: $this->f;
@@ -242,13 +245,15 @@ final class Send extends Item
*/
public function open(string $compress=''): bool
{
Log::debug(sprintf('%s:+ open',self::LOGKEY));
Log::debug(sprintf('%s:+ Opening file to send',self::LOGKEY));
// If we have mail, we'll send that first
if ($this->sending = $this->packets
->filter(function($item) { return ($item->action & self::I_SEND) && $item->sent === FALSE; })
->first())
{
Log::debug(sprintf('%s:- Sending [%s]',self::LOGKEY,$this->sending->name));
$this->file_pos = 0;
$this->start = time();
$this->f = TRUE;

View File

@@ -5,11 +5,13 @@ namespace App\Classes\Protocol;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use League\Flysystem\UnreadableFileEncountered;
use App\Classes\Crypt;
use App\Classes\Protocol as BaseProtocol;
use App\Classes\FTN\Message;
use App\Classes\Sock\SocketClient;
use App\Classes\Sock\SocketException;
use App\Exceptions\FileGrewException;
@@ -991,8 +993,30 @@ final class Binkp extends BaseProtocol
Log::error(sprintf('%s:! M_got[skip] for unknown file [%s]',self::LOGKEY,$buf));
} else {
Log::info(sprintf('%s:= Packet/File [%s] sent.',self::LOGKEY,$this->send->name));
Log::info(sprintf('%s:= Packet/File [%s] sent with [%s].',self::LOGKEY,$this->send->name,$this->send->dbids->join(',')));
$this->sessionClear(self::SE_WAITGOT|self::SE_SENDFILE);
// Update netmail table
if ($x=$this->send->dbids->filter(function($item) { return (! $item); })->keys()->filter())
DB::table('netmails')
->whereIn('id',$x)
->update([
'sent_at'=>Carbon::now(),
'sent_pkt'=>$this->send->name,
'sent_id'=>$this->node->address->id,
'flags'=>DB::raw('flags | '.Message::FLAG_SENT),
]);
// Update echomails table
if ($x=$this->send->dbids->filter(function($item) { return $item; })->keys()->filter())
DB::table('echomail_seenby')
->whereIn('echomail_id',$x)
->where('address_id',$this->node->address->id)
->update([
'sent_at'=>Carbon::now(),
'sent_pkt'=>$this->send->name,
]);
$this->send->close(TRUE);
}
}

View File

@@ -103,6 +103,13 @@ class MessageProcess implements ShouldQueue
$o->flags |= Message::FLAG_RECD;
$o->save();
Log::info(sprintf('%s:! Netmail [%s] from (%s:%s) - was processed by us [%d]',
self::LOGKEY,
$this->msg->msgid,
$this->msg->user_from,
$this->msg->fftn,
$o->id,
));
break;
}
}
@@ -112,7 +119,7 @@ class MessageProcess implements ShouldQueue
$o->flags |= Message::FLAG_RECD;
$o->save();
Log::alert(sprintf('%s:! Ignoring Netmail [%s] to the Hub from (%s:%s) - its from a bot [%d].',
Log::alert(sprintf('%s:! Ignoring Netmail [%s] to the Hub from (%s:%s) - its from a bot [%d]',
self::LOGKEY,
$this->msg->msgid,
$this->msg->user_from,
@@ -289,6 +296,7 @@ class MessageProcess implements ShouldQueue
$o->set_path = $this->msg->pathaddress;
$o->set_seenby = $this->msg->seenaddress;
// Record receiving packet and sender
$o->set_pkt = $this->packet;
$o->save();

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;