Start of processing packets - implemented PING Responce to Netmail

This commit is contained in:
Deon George
2021-07-16 00:54:23 +10:00
parent fe2784f98f
commit a0d3c8d8ab
22 changed files with 1256 additions and 442 deletions

View File

@@ -2,21 +2,92 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
use Jenssegers\Mongodb\Eloquent\Model;
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
use App\Classes\FTN\Message;
class Netmail extends Model
{
protected $dates = ['date'];
protected $fillable = ['date','msgid','from_ftn'];
public $timestamps = FALSE; // @todo Remove, seems an issue with cockroach updating tables.
use SoftDeletes;
public function kludges()
protected $connection = 'mongodb';
protected $dates = ['datetime'];
/* RELATIONS */
public function fftn()
{
return $this->belongsToMany(Kludge::class);
return $this
->setConnection('pgsql')
->belongsTo(Address::class);
}
public function paths()
public function tftn()
{
return $this->belongsToMany(Path::class,NULL,NULL,'node_id');
return $this
->setConnection('pgsql')
->belongsTo(Address::class);
}
/* ATTRIBUTES */
public function getMsgAttribute($value): string
{
return utf8_decode($value);
}
public function setMsgAttribute($value): void
{
$this->attributes['msg'] = utf8_encode($value);
}
/* METHODS */
/**
* Return this model as a packet
*/
public function packet(): Message
{
$o = new Message;
$o->header = [
'onode' => $this->fftn->node_id,
'dnode' => $this->tftn->node_id,
'onet' => $this->fftn->host_id,
'dnet' => $this->tftn->host_id,
'flags' => 0, // @todo?
'cost' => 0,
'date'=>$this->created_at->format('d M y H:i:s'),
];
$o->user_to = $this->to;
$o->user_from = $this->from;
$o->subject = $this->subject;
$o->message = $this->msg;
$o->msgid = sprintf('%s %08x',$this->fftn->ftn3d,crc32($this->id));
// VIA kludge
$via = $this->via ?: collect();
$via->push(
sprintf('%s @%s.UTC %s %d.%d/%s %s',
$this->fftn->ftn3d,
Carbon::now()->utc()->format('Ymd.His'),
Setup::PRODUCT_NAME,
Setup::PRODUCT_VERSION_MAJ,
Setup::PRODUCT_VERSION_MIN,
(new Setup)->version,
Carbon::now()->format('Y-m-d'),
));
$o->via = $via;
// INTL kludge
// @todo Point handling FMPT/TOPT
$o->intl = sprintf('%s %s',$this->tftn->ftn3d,$this->fftn->ftn3d);
return $o;
}
}