More complete rework of packet parsing and packet generation with f279d85 - and testing passes

This commit is contained in:
2024-05-20 21:31:21 +10:00
parent b30ab2f999
commit ab2e288f06
14 changed files with 227 additions and 210 deletions

View File

@@ -154,7 +154,7 @@ class Address extends Model
$o = new self;
$o->active = TRUE;
$o->zone_id = $zo->id;
$o->region_id = 0; // @todo Automatically determine region
$o->region_id = $ftn['r'];
$o->host_id = $ftn['n'];
$o->node_id = $ftn['f'];
$o->point_id = $ftn['p'];
@@ -307,8 +307,39 @@ class Address extends Model
if ((! empty($matches[4])) AND ((! is_numeric($matches[$i])) || ($matches[4] > self::ADDRESS_FIELD_MAX)))
throw new InvalidFTNException(sprintf('Invalid FTN: [%s] - point address invalid [%d]',$ftn,$matches[4]));
// Work out region
$region_id = 0;
$zone_id = NULL;
// We can only work out region if we have a domain
if ($matches[5] ?? NULL) {
$o = new self;
$o->host_id = $matches[2];
$o->node_id = $matches[3];
$o->point_id = empty($matches[4]) ? 0 : (int)$matches[4];
$zo = Zone::select('zones.*')->where('zone_id',$matches[1])->join('domains',['domains.id'=>'zones.domain_id'])->where('domains.name',$matches[5])->single();
$o->zone_id = $zo?->id;
$parent = $o->parent();
$zone_id = $parent?->zone->zone_id;
// For flattened domains
if ($zo->domain->flatten && is_null($zone_id))
foreach ($zo->domain->zones as $zoo) {
$o->zone_id = $zoo->id;
$parent = $o->parent();
if ($parent)
break;
}
$region_id = $parent?->region_id;
$zone_id = $parent?->zone->zone_id;
}
return [
'z'=>(int)$matches[1],
'z'=>(int)$zone_id ?: $matches[1],
'r'=>(int)$region_id,
'n'=>(int)$matches[2],
'f'=>(int)$matches[3],
'p'=>empty($matches[4]) ? 0 : (int)$matches[4],