From 6d839102b51c99a785c7727b3cfe9025a45273f3 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Wed, 28 Oct 2026 19:58:25 +0100 Subject: [PATCH] Pinned attack flows route at their entry port's own rank, not a cone rank base() now takes the target network; pinned junk has none, so coneOf() called every PNI a cone route and the flood was routed late (behind real traffic) or not at all. Pinned flows use the port's own rank (low preference still last), those ranks join RSET, and the reference allocation in the routing test does the same. --- src/game/80-simulation/30-compute.js | 7 ++++--- tests/ddos-floods.test.js | 17 +++++++++++++++++ tests/helpers/reference-allocation.js | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/ddos-floods.test.js diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index 568b6f6..f02c48a 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -174,8 +174,9 @@ function compute(){ const byRank={},RSET=new Set();for(const id of NET_IDS){const m=byRank[id]={};for(const e of okBy[id]){const r=TR?eff(e,id):base(e,id);RSET.add(r);(m[r]||(m[r]=[])).push(e);} for(const r in m){const L=m[r],key=L.map(e=>e.xi).join(','),o=LIST.get(key);if(o){m[r]=o;continue;} let V=L;if(NCOMP>1){const cs=[];for(const e of L){const k=COMP[e.ci];if(k>=0)(cs[k]||(cs[k]=[])).push(e);}for(const s of cs)if(s)idx(s);V={cs};}else idx(L);LIST.set(key,V);m[r]=V;}} - // Attack flows pinned to their entry port route at its plain rank, which RouteScript may have left with no list. - for(const f of flows)if(f.pin)for(const e of ingressE[f.pin]||[])RSET.add(base(e)); + // Attack flows pinned to their entry port route at the port's own rank: no network to be in a cone of, and RouteScript + // may have left that rank with no list. + const pr=e=>e.pref==='low'?4:e.rank;for(const f of flows)if(f.pin)for(const e of ingressE[f.pin]||[])RSET.add(pr(e)); // The flow being routed, and from its POP: distances, arriving edges and the paths walked so far, by city index. let f=null,Dv=null,Pv=null,PP=null,vis=0;const walked=[],G=[],REST=[],NEG=[]; // An exit the flow can still try: not visited yet, not full when the flow started, and reachable from the POP. @@ -224,7 +225,7 @@ function compute(){ for(let fi=0,FN=flows.length;fi { + for (const net of ['nfx', 'lvl']) { + const { ev, errors } = load(); + ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=5000;S.pops.fra.rgen=RG.length-1;S.pops.fra.routers=8"); + ev(`S.transit=[];S.ixp={};S.peers={};S.grace=null;S.pni=[{id:'pa',net:'${net}',city:'fra',tier:1}];compute()`); + assert.equal(ev(`R.netEg.${net}.p`), 100, 'the 100G PNI is full of real traffic'); + ev("S.ev.ddos={id:'x',city:'fra',vec:'http',gbps:100,start:S.day,until:S.day+5,entries:[{k:'p',id:'pa',city:'fra',share:1}]};compute()"); + assert.equal(ev('R.usePni.pa'), 100); + assert.ok(!(ev(`R.netEg.${net}?.p||0`) > 1), `${net}: the junk is not routed behind the real traffic as if it were a cone route`); + assert.deepEqual(errors, []); + } +}); diff --git a/tests/helpers/reference-allocation.js b/tests/helpers/reference-allocation.js index 4658ced..00da767 100644 --- a/tests/helpers/reference-allocation.js +++ b/tests/helpers/reference-allocation.js @@ -6,7 +6,7 @@ module.exports = ` if(f.rem<=1e-6||(rank===0&&!f.cache)||(pass&&!pass(f)))continue; Dv=SDi[f.ci];Pv=SPi[f.ci];PP=walked[f.ci]||(walked[f.ci]=[]);vis++; const candidates=E.filter(e=>e.used(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||Dv[CIDX[a.city]]-Dv[CIDX[b.city]]); for(let i=0;i1e-6;){ let j=i+1;while(j