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

@@ -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
*