Start of processing packets - implemented PING Responce to Netmail
This commit is contained in:
@@ -6,6 +6,7 @@ use Exception;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use App\Classes\FTN\Packet;
|
||||
use App\Http\Controllers\DomainController;
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
@@ -28,13 +29,35 @@ class Address extends Model
|
||||
|
||||
/**
|
||||
* Find children dependant on this record
|
||||
*
|
||||
* @todo While this is finding children of hubs, we are not currently finding children of Hosts or Regions.
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function children()
|
||||
{
|
||||
return $this->belongsTo(self::class,'id','hub_id');
|
||||
switch (strtolower($this->role)) {
|
||||
case 'region':
|
||||
return $this->hasMany(self::class,'region_id','region_id')
|
||||
->where('zone_id',$this->zone_id)
|
||||
->where(function($q) {
|
||||
return $q->where('host_id',0)
|
||||
->orWhere('role',DomainController::NODE_NC);
|
||||
})
|
||||
->where('id','<>',$this->id);
|
||||
|
||||
case 'host':
|
||||
return $this->hasMany(self::class,'host_id','host_id')
|
||||
->where('zone_id',$this->zone_id)
|
||||
->where('region_id',$this->region_id)
|
||||
->whereNull('hub_id')
|
||||
->where('id','<>',$this->id);
|
||||
|
||||
case 'hub':
|
||||
return $this->hasMany(self::class,'hub_id','id');
|
||||
|
||||
case 'node':
|
||||
return NULL;
|
||||
|
||||
default:
|
||||
throw new Exception('Unknown role: '.$this->role);
|
||||
}
|
||||
}
|
||||
|
||||
public function system()
|
||||
@@ -54,17 +77,17 @@ class Address extends Model
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFTNAttribute()
|
||||
public function getFTNAttribute(): string
|
||||
{
|
||||
return sprintf('%s@%s',$this->getFTN4DAttribute(),$this->zone->domain->name);
|
||||
}
|
||||
|
||||
public function getFTN3DAttribute()
|
||||
public function getFTN3DAttribute(): string
|
||||
{
|
||||
return sprintf('%d:%d/%d',$this->zone->zone_id,$this->host_id ?: $this->region_id,$this->node_id);
|
||||
}
|
||||
|
||||
public function getFTN4DAttribute()
|
||||
public function getFTN4DAttribute(): string
|
||||
{
|
||||
return sprintf('%s.%d',$this->getFTN3DAttribute(),$this->point_id);
|
||||
}
|
||||
@@ -91,7 +114,7 @@ class Address extends Model
|
||||
}
|
||||
}
|
||||
|
||||
/* GENERAL METHODS */
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
* Find a record in the DB for a node string, eg: 10:1/1.0
|
||||
@@ -126,6 +149,22 @@ class Address extends Model
|
||||
return ($o && $o->system->active) ? $o : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get netmail for this node (including it's children)
|
||||
*/
|
||||
public function getNetmail(): Packet
|
||||
{
|
||||
$o = new Packet($this);
|
||||
|
||||
foreach (Netmail::whereIn('tftn_id',$this->children->pluck('id')->push($this->id))->get() as $oo) {
|
||||
$o->addNetmail($oo->packet());
|
||||
|
||||
// @todo We need to mark the netmail as sent
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string and split it out as an FTN array
|
||||
*
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -37,6 +37,11 @@ class Setup extends Model
|
||||
public const O_EMSI = 1<<2; /* Listen for EMSI connections */
|
||||
public const O_HIDEAKA = 1<<3; /* Hide AKAs to different Zones */
|
||||
|
||||
public const PRODUCT_NAME = 'Clearing Houz';
|
||||
public const PRODUCT_ID = 0xAB8D;
|
||||
public const PRODUCT_VERSION_MAJ = 0;
|
||||
public const PRODUCT_VERSION_MIN = 0;
|
||||
|
||||
// Our non model attributes and values
|
||||
private array $internal = [];
|
||||
|
||||
|
@@ -56,7 +56,18 @@ class System extends Model
|
||||
return $this->hasManyThrough(Zone::class,Address::class,'system_id','id','id','zone_id');
|
||||
}
|
||||
|
||||
/* GENERAL METHODS */
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
* Return the system's address in the same zone
|
||||
*
|
||||
* @param Address $o
|
||||
* @return Address
|
||||
*/
|
||||
public function match(Address $o): Address
|
||||
{
|
||||
return $this->addresses->where('zone_id',$o->zone_id)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the system name, or role name for the zone
|
||||
|
Reference in New Issue
Block a user