Added downstream(), and fixed failing tests in RoutingTest
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 42s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m48s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s

This commit is contained in:
Deon George 2024-05-10 21:33:02 +10:00
parent edee0643ec
commit cd2efbd1d4
3 changed files with 52 additions and 15 deletions

View File

@ -24,6 +24,7 @@ class AddressCheck extends Command
$this->info(sprintf('Address: %s (%s)',$o->ftn,$o->role_name));
$this->info(sprintf("Children: \n- %s",$o->children()->pluck('ftn4d')->join("\n- ")));
$this->info(sprintf("Downstream: \n- %s",$o->downstream()->pluck('ftn4d')->join("\n- ")));
$this->info(sprintf('Uplink: %s (Parent: %s)',$o->uplink()?->ftn,$o->parent()?->ftn));
$this->info(sprintf('Our Address: %s',our_address($o)?->ftn));
$this->info(sprintf('- Domain Addresses: %s',our_address($o->zone->domain)->pluck('ftn4d')->join(',')));

View File

@ -873,6 +873,19 @@ class Address extends Model
return $children->filter(function($item) use ($exclude) { return ! $exclude->pluck('id')->contains($item->id);});
}
/**
* List of all our nodes and their children
*
* @return \Illuminate\Support\Collection
* @throws \Exception
*/
public function downstream(): \Illuminate\Support\Collection
{
return $this->downlinks()->transform(function($item) {
return $item->nodes()->push($item);
})->flatten();
}
/**
* Files waiting to be sent to this system
*
@ -1149,6 +1162,29 @@ class Address extends Model
return Netmail::whereIn('id',$netmails->pluck('id'))->get();
}
public function nodes(): Collection
{
switch ($this->role_id) {
case self::NODE_NN:
return $this->nodes_point;
case self::NODE_HC:
return $this->nodes_hub;
case self::NODE_NC:
return $this->nodes_net;
case self::NODE_RC:
return $this->nodes_region;
case self::NODE_ZC:
return $this->nodes_zone;
default:
return new Collection;
}
}
/**
* Find the immediate parent for this node.
*

View File

@ -107,7 +107,7 @@ class RoutingTest extends TestCase
$ao = Address::findFTN('101:0/0@a');
$this->assertEquals($ao->role_id,Address::NODE_ZC);
$this->assertCount(0,$ao->downlinks());
$this->assertCount(0,$ao->downstream());
$this->assertNull($ao->uplink());
}
@ -117,7 +117,7 @@ class RoutingTest extends TestCase
$this->session_zc();
$ao = Address::findFTN('101:0/0@a');
$this->assertCount(935,$ao->downlinks());
$this->assertCount(935,$ao->downstream());
}
// An RC's parent should be the ZC, when we have session details with parent
@ -136,7 +136,7 @@ class RoutingTest extends TestCase
$this->session_rc();
$ao = Address::findFTN('100:1/0@a');
$this->assertEquals(185,$ao->downlinks()->count());
$this->assertCount(185,$ao->downstream());
}
// An RCs node still collects mail from the RC
@ -199,7 +199,7 @@ class RoutingTest extends TestCase
$this->session_nc();
$ao = Address::findFTN('100:1/0@a');
$this->assertCount(185-36,$ao->downlinks());
$this->assertCount(185-36,$ao->downstream());
}
// If we also have session details for an Hub, then there are less RC nodes
@ -211,7 +211,7 @@ class RoutingTest extends TestCase
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:1/0@a');
$this->assertCount(185-6,$ao->downlinks());
$this->assertCount(185,$ao->downstream());
$ao = Address::findFTN('100:10/22@a');
$this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn);
@ -232,7 +232,7 @@ class RoutingTest extends TestCase
$this->session_nc();
$ao = Address::findFTN('100:10/0@a');
$this->assertCount(35,$ao->downlinks());
$this->assertCount(35,$ao->downstream());
}
public function test_complex_rc_nc_hc()
@ -242,26 +242,26 @@ class RoutingTest extends TestCase
$this->session_hub();
$ao = Address::findFTN('100:1/100.0@a');
$this->assertCount(0,$ao->downlinks());
$this->assertCount(0,$ao->downstream());
$this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn);
// RC
$ao = Address::findFTN('100:1/0.0@a');
$this->assertCount(186-1-30-6,$ao->downlinks());
$this->assertCount(186-1-30-6,$ao->downstream());
$ao = Address::findFTN('100:11/0.0@a');
$this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn);
// NC
$ao = Address::findFTN('100:10/0.0@a');
$this->assertCount(36-1-6,$ao->downlinks());
$this->assertCount(36-1-6,$ao->downstream());
$ao = Address::findFTN('100:10/10.0@a');
$this->assertEquals('100:10/0.0@a',$ao->uplink()->ftn);
// HC
$ao = Address::findFTN('100:10/20.0@a');
$this->assertCount(6-1,$ao->downlinks());
$this->assertCount(6-1,$ao->downstream());
$ao = Address::findFTN('100:10/22.0@a');
$this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn);
@ -283,26 +283,26 @@ class RoutingTest extends TestCase
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:1/100.0@a');
$this->assertCount(0,$ao->downlinks());
$this->assertCount(0,$ao->downstream());
$this->assertEquals('100:1/0.0@a',$ao->uplink()?->ftn);
// RC
$ao = Address::findFTN('100:1/0.0@a');
$this->assertCount(186-36-36-1,$ao->downlinks());
$this->assertCount(186-36-36-1,$ao->downstream());
$ao = Address::findFTN('100:11/0.0@a');
$this->assertEquals('100:11/0.0@a',$ao->uplink()->ftn);
// NC
$ao = Address::findFTN('100:10/0.0@a');
$this->assertCount(36-6-1,$ao->downlinks());
$this->assertCount(36-6-1,$ao->downstream());
$ao = Address::findFTN('100:10/10.0@a');
$this->assertNull($ao->uplink()?->ftn);
// HC
$ao = Address::findFTN('100:10/20.0@a');
$this->assertCount(6-1,$ao->downlinks());
$this->assertCount(6-1,$ao->downstream());
$ao = Address::findFTN('100:10/22.0@a');
$this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn);
@ -333,6 +333,6 @@ class RoutingTest extends TestCase
$this->assertEquals('100:10/21.0@a',$ao->uplink()?->ftn);
$ao = Address::findFTN('100:10/21@a');
$this->assertCount(1,$ao->downlinks());
$this->assertCount(1,$ao->downstream());
}
}