From 6d839102b51c99a785c7727b3cfe9025a45273f3 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Wed, 28 Oct 2026 19:58:25 +0100 Subject: [PATCH 01/12] 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 Date: Wed, 28 Oct 2026 20:09:18 +0100 Subject: [PATCH 02/12] Floods cross the backbone to their victim again, whatever order the POPs were built in Each ingress slice gave its junk the ingress city as source, so a flood only filled the port it came in on: it never loaded the backbone or the victim's router, as it did before distributed ingress. Junk is now created at the victim, pinned to its entry port, before any real traffic and in attack order, so S.pops order no longer decides who gets a full port. A port the victim cannot reach still fills. --- src/game/80-simulation/30-compute.js | 21 +++++++++++++-------- tests/ddos-floods.test.js | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index f02c48a..ccdfa59 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -52,7 +52,17 @@ function compute(){ // Customer demand per city, added up in S.biz order (what filtering S.biz for each city would give). const bizBw={};for(const b of S.biz){const T=BIZ_T[b.type];if(!T.l2&&!T.fiber&&(!T.event||eventLive(b))){const v=bizBw[b.city];bizBw[b.city]=(v===undefined?0:v)+b.bw;}} // Traffic shares by network index, and their sums, for each share table (and with Russia's throttle). - const shArr=new Map(),shSum=new Map(),DEMTO=new Float64Array(NN),loc=scnRule('local'),scrubRoom={},atkBy={},junkGroups=[],bhCities=new Set(ddosAll().filter(a=>a.bh).map(a=>a.city));R2.haul=[];R2.ddos=[];for(const a of ddosAll())for(const part of ddosSlices(a))(atkBy[part.city]||(atkBy[part.city]=[])).push(part); + const shArr=new Map(),shSum=new Map(),DEMTO=new Float64Array(NN),loc=scnRule('local'),scrubRoom={},atkBy={},junkGroups=[],bhCities=new Set(ddosAll().filter(a=>a.bh).map(a=>a.city));R2.haul=[];R2.ddos=[]; + /* Floods first, before any real traffic and in the order the attacks started, so no POP's place in S.pops decides who + gets a full port. Each slice is the flood entering in one city (mitigated and scrubbed there); what leaks is junk at + the victim, pinned to the port it came in on, so it loads that port, the backbone between them and the victim's router. */ + // A port the victim cannot be reached from (down, or no backbone to it) still fills with the junk arriving there. + const VIC={};for(const a of ddosAll()){const v=a.city;(VIC[v]||(VIC[v]=[])).push(a); + for(const part of ddosSlices(a)){const c=part.city;(atkBy[c]||(atkBy[c]=[])).push(part); + const m=ddosMitigation(part,{},bhCities.has(v),false),group={m,flows:[]};R2.ddos.push(m);junkGroups.push(group);if(!popUp(c))m.offline=true; + const src=popUp(v)&&SPD[v][CIDX[c]]0?q.g/m.leak:0});}} + else for(let j=0;jday?1.4:1);const biz=bizBw[c]??0;const d0=eye+biz; // Goggle video is throttled in Russia (#70): people there get half of it, so they ask for half. It is not @@ -64,13 +74,8 @@ function compute(){ // A shaped attack: `rtbh` is the player pulling the plug on the victim IP (junk gone, customer dark too); // `edge` is the crude RouteScript `blackhole ddos` filter (junk gone, 10% of real traffic with it). Flowspec // (a standing licence) and a scrubbing center each knock the flood down before it reaches the sim. - const attacks=atkBy[c]||[],rtbh=bhCities.has(c),edge=!!(attacks.length&&TRX&&TRX.blackhole&&!rtbh); - let dd=0; - for(const atk of attacks){const m=ddosMitigation(atk,{},bhCities.has((atk.parent||atk).city),false);R2.ddos.push(m);dd+=m.leak; - const group={m,flows:[]};junkGroups.push(group); - if(atk.entries?.length){for(const q of m.ingress){const f=flow(c,ci,cn,0,q.g,false,true);f.pin=q.entry.k+':'+q.entry.id;group.flows.push({f,share:m.leak>0?q.g/m.leak:0});}} - else for(let j=0;jm.attack.city===c))m.offline=true;continue;} + const attacks=VIC[c]||[],rtbh=bhCities.has(c),edge=!!(attacks.length&&TRX&&TRX.blackhole&&!rtbh); + if(!popUp(c))continue; const bh=rtbh||edge; if(edge)R2.teBlack+=attacks.reduce((n,a)=>n+a.gbps,0)+d*0.1;if(rtbh)R2.teBlack+=attacks.reduce((n,a)=>n+a.gbps,0)+d; R2.cityBlocked=R2.cityBlocked||{}; diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index 7b6adad..3c26cce 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -15,3 +15,26 @@ test('a flood entering over a PNI with NetChill competes on that PNI at its own assert.deepEqual(errors, []); } }); + +// Frankfurt has the eyeballs and no transit; all transit is in Amsterdam, 100G of wave away. +const remoteIngress = (ev, flip) => { + ev("ACT.start({});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9;ACT.buildPop({city:'ams'});ACT.launchBB({city:'fra'});S.links.push({id:'L',a:'fra',b:'ams',kind:'wave',tier:1,km:400,mo:1,cut:0});ACT.buyTransit({city:'ams',net:NETS.find(n=>sellsAt(n,'ams')).id,tier:1})"); + if (flip) ev("const p=S.pops;S.pops={ams:p.ams,fra:p.fra}"); + ev("compute()"); +}; + +test('a flood entering in another city crosses the backbone to its victim, whatever order the POPs were built in', () => { + const out = []; + for (const flip of [false, true]) { + const { ev, errors } = load({ seed: 5 }); + remoteIngress(ev, flip); + assert.ok(ev("sfOf(R,'fra')") > 0.95, 'fine before the attack'); + ev("S.day=60;S.ev.ddos={id:'a',city:'fra',vec:'http',gbps:300,start:S.day,until:S.day+3,entry:{k:'distributed',lab:''},entries:[{k:'t',id:S.transit[0].id,city:'ams',share:1}]};compute()"); + assert.equal(ev('R.load.L'), 100, 'the junk fills the wave to the victim'); + assert.ok(ev("R.nodeLoad.fra") >= 100, "and the victim's router"); + assert.ok(ev("sfOf(R,'fra')") < 0.05, 'the victim goes dark'); + out.push(ev("JSON.stringify([R.load.L,R.useT[S.transit[0].id],sfOf(R,'fra')])")); + assert.deepEqual(errors, []); + } + assert.equal(out[0], out[1], 'POP build order does not change the outcome'); +}); From 25e3e6db3326d09a7bed3b945e6ce44a2dfc24e1 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Wed, 28 Oct 2026 20:11:06 +0100 Subject: [PATCH 03/12] DDoS attacks are scored and SLA-charged at their victim only ddosSf() took the worst service of every city with an ingress port, so on a big network every attack counted as lost and charged SLA payouts to protected customers anywhere. Held/lost, the SLA check and the far-scrubbing warning now look at the attacked city. --- .../85-incidents/10-incidents-and-ddos.js | 5 +++-- src/game/88-days/10-day-tick.js | 2 +- tests/ddos-floods.test.js | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/game/85-incidents/10-incidents-and-ddos.js b/src/game/85-incidents/10-incidents-and-ddos.js index ec67168..521026e 100644 --- a/src/game/85-incidents/10-incidents-and-ddos.js +++ b/src/game/85-incidents/10-incidents-and-ddos.js @@ -37,7 +37,8 @@ function ddosSlices(a){if(!a.entries?.length)return [a];const groups={}; return Object.entries(groups).map(([city,entries])=>({...a,parent:a,city,entries,gbps:a.gbps*entries.reduce((n,en)=>n+en.share,0)}));} const ddosCities=a=>[...new Set([a.city,...(a.entries||[]).map(en=>en.city)])].filter(c=>S.pops[c]); const ddosHasIx=a=>ddosCities(a).some(hasIxAt); -const ddosSf=a=>Math.min(1,...ddosCities(a).map(c=>sfOf(R,c))); +// An attack is held or lost at its victim: the junk lands there, and other POPs' bad days are not the attacker's doing. +const ddosSf=a=>sfOf(R,a.city); function ddosReport(a){const ms=(R.ddos||[]).filter(m=>m.attack===a||m.attack.parent===a);if(!ms.length)return ddosMitigation(a); const parts={};for(const m of ms)for(const x of m.sp?.parts||[]){const q=parts[x.city]||(parts[x.city]={city:x.city,tier:x.tier,a:0,cleaned:0});q.a+=x.a;q.cleaned+=x.cleaned;} return {attack:a,blackhole:ms.some(m=>m.blackhole),upstream:ms.some(m=>m.upstream),reaching:ms.reduce((n,m)=>n+m.reaching,0),flowspec:ms.reduce((n,m)=>n+m.flowspec,0),fsMissing:ms.some(m=>m.fsMissing),filtered:ms.reduce((n,m)=>n+m.filtered,0),sp:Object.keys(parts).length?{parts:Object.values(parts)}:null,near:ms.find(m=>m.near)?.near||null,leak:ms.reduce((n,m)=>n+m.leak,0)};} @@ -53,7 +54,7 @@ const fsAt=c=>{const p=S.pops[c];return p?(RG[p.rgen||0].fs||0):0;}; function scrubEngaged(atk){return hasScrub()&&(S.scrubMode==='always'||(S.day-(atk.start??S.day))>=SCRUB_DELAY);} // Several centers (#117): the flood goes to the nearest working one, and what it cannot take spills to the next. // A center in another city only helps if the backbone can carry the flood there; routing works that out. -const scrubFar=c=>ddosAll().some(a=>ddosCities(a).includes(c))&&(R.haul||[]).find(q=>q.city===c&&q.ms!==null&&q.ms>=SCRUB_FAR_MS)||null; +const scrubFar=c=>{for(const a of ddosAll())if(a.city===c){const q=(R.haul||[]).find(q=>q.attack===a.id&&q.city===c&&q.ms!==null&&q.ms>=SCRUB_FAR_MS);if(q)return q;}return null;}; function scrubPlan(atk,g=atk.gbps||0,room={},take=null){if(!scrubEngaged(atk))return null;const c=atk.city;const parts=[]; for(const x of S.scrubs.filter(x=>popUp(x.city)&&(x.city===c||pathExists(c,x.city))).sort((a,b)=>(a.city===c?0:kmBetween(c,a.city))-(b.city===c?0:kmBetween(c,b.city)))){if(g<=0)break;const cap=SCRUB_TIERS[x.tier||0].g,a=Math.min(g,room[x.city]??cap);if(a<=0)continue;const cleaned=take?take(x,a):a;room[x.city]=(room[x.city]??cap)-cleaned;parts.push({city:x.city,tier:x.tier||0,a,cleaned});g-=cleaned;} return parts.length?{parts,leak:g}:null;} diff --git a/src/game/88-days/10-day-tick.js b/src/game/88-days/10-day-tick.js index 2630903..3aab042 100644 --- a/src/game/88-days/10-day-tick.js +++ b/src/game/88-days/10-day-tick.js @@ -36,7 +36,7 @@ function dayTick(){ if(l.own&&l.ready>d&&Math.random()<0.012){const extra=10+Math.floor(Math.random()*40);setCableReady(l,l.ready+leadDays(extra));toast(tr('day_tick.construction_delay_n_days_why_a',{n:leadDays(extra),why:pick(l.sub?SEA_DELAYS.map(x=>tr(x)):[tr('day_tick.archaeologists_found_a_roman'),tr('day_tick.a_protected_hamster_species_lives'),tr('day_tick.the_railway_changed_its_mind_about'),tr('day_tick.the_drilling_crew_hit_a_granite'),tr('day_tick.a_town_council_wants_a_public'),tr('day_tick.somebody_else_s_gas_main_was'),tr('day_tick.the_permit_office_lost_your_permit')]),a:CITY[l.a].name,b:CITY[l.b].name}),'bad');}} // DDoS protection SLA: if a protected customer's own city is hit and still goes down, you pay out (once per attack). for(const a of ddosAll()){ - for(const b of S.biz)if(b.type==='scrub'&&ddosCities(a).includes(b.city)&&!(a.sla||[]).includes(b.id)&&(a.id||b.slaFor!==a.start)&&sfOf(R,b.city)<0.85){ + for(const b of S.biz)if(b.type==='scrub'&&b.city===a.city&&!(a.sla||[]).includes(b.id)&&(a.id||b.slaFor!==a.start)&&sfOf(R,b.city)<0.85){ (a.sla||(a.sla=[])).push(b.id);b.slaFor=a.start;S.cash-=SLA_PEN;b.mood=Math.max(0,b.mood-18);S.stats.sla=(S.stats.sla||0)+1; toast(tr('day_tick.sla_breach_name_the_attack_on',{name:esc(b.name),city:CITY[a.city].name,pen:fmt$(SLA_PEN)}),'bad');sfx('err');}} // businesses mood diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index 3c26cce..fc43217 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -38,3 +38,24 @@ test('a flood entering in another city crosses the backbone to its victim, whate } assert.equal(out[0], out[1], 'POP build order does not change the outcome'); }); + +test('an attack is held or lost at its victim; other POPs and their DDoS-protected customers are not charged', () => { + const { ev, errors } = load({ seed: 5 }); + ev("ACT.start({});S.cash=1e9;S.lvl=6;S.nextFail=1e9;S.nextEvent=1e9;ACT.buildPop({city:'nyc'});for(const c of ['fra','nyc']){S.pops[c].bb={d:50};S.pops[c].rgen=3}"); + ev("S.transit=[{id:'tf',city:'fra',net:'cog',tier:2},{id:'tn',city:'nyc',net:'cog',tier:1}];S.scrubs=[{city:'fra',tier:1}];S.scrubMode='always'"); + // New York is struggling on its own (a 10G port for 50G of eyeballs), and has a DDoS-protected customer. + ev("S.pops.nyc.bb.d=200;S.biz.push({id:'sc',type:'scrub',name:'Shield',city:'nyc',bw:1,rate:1000,mood:80,since:0})"); + ev("S.day=60;S.ev.ddos={id:'a',city:'fra',vec:'http',gbps:20,start:S.day,until:S.day+3,entry:{k:'distributed',lab:''},entries:[{k:'t',id:'tf',city:'fra',share:.5},{k:'t',id:'tn',city:'nyc',share:.5}]};compute()"); + assert.ok(ev("sfOf(R,'nyc')") < 0.85, 'New York is under water anyway'); + assert.ok(ev("sfOf(R,'fra')") >= 0.97, 'the victim is fine'); + assert.equal(ev('ddosSf(S.ev.ddos)'), ev("sfOf(R,'fra')")); + const cash = ev('S.cash'); + ev('dayTick()'); + assert.deepEqual(JSON.parse(ev('JSON.stringify(S.ev.ddos.sla||[])')), [], 'no SLA payout for a customer in another city'); + assert.equal(ev('S.stats.sla||0'), 0); + ev('S.day=S.ev.ddos.until;ddosExpire()'); + assert.equal(ev('S.stats.ddosOk||0'), 1, 'held at the victim'); + assert.equal(ev('S.stats.ddosLost||0'), 0); + assert.ok(cash > 0); + assert.deepEqual(errors, []); +}); From 40e4c79139420978c81796d5d6bed0a2ccc5c151 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Wed, 28 Oct 2026 20:16:20 +0100 Subject: [PATCH 04/12] Attacks keep their 12 biggest ingress ports and fold the rest, so saves stay small Every attack stored every ingress port with traffic (over a thousand on a big network), which grew the save from 272 KB to 1.8 MB with 14 attacks. The rest is now one share at the victim, routed like the classic flood over its usual exits; old saves are folded on load. --- src/game/80-simulation/30-compute.js | 3 ++- src/game/80-simulation/50-sanitize.js | 2 +- .../85-incidents/10-incidents-and-ddos.js | 5 ++++ src/game/85-incidents/20-failures.js | 4 +-- tests/ddos-floods.test.js | 25 +++++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index ccdfa59..09cd6ce 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -61,7 +61,8 @@ function compute(){ for(const part of ddosSlices(a)){const c=part.city;(atkBy[c]||(atkBy[c]=[])).push(part); const m=ddosMitigation(part,{},bhCities.has(v),false),group={m,flows:[]};R2.ddos.push(m);junkGroups.push(group);if(!popUp(c))m.offline=true; const src=popUp(v)&&SPD[v][CIDX[c]]0?q.g/m.leak:0});}} + if(part.entries?.length){for(const q of m.ingress){const sh=m.leak>0?q.g/m.leak:0;if(q.entry.k==='rest'){for(let j=0;jday?1.4:1);const biz=bizBw[c]??0;const d0=eye+biz; diff --git a/src/game/80-simulation/50-sanitize.js b/src/game/80-simulation/50-sanitize.js index 5673200..0222376 100644 --- a/src/game/80-simulation/50-sanitize.js +++ b/src/game/80-simulation/50-sanitize.js @@ -66,7 +66,7 @@ function sanitize(s){ // Keep the legacy primary attack so old saves and imports remain compatible; additional floods overlap it. const repairAttack=a=>{if(!a||typeof a!=='object'||!isCity(a.city)||!s.pops[a.city]||!own(DDOS_VEC,a.vec))return null; a.id=sid(a.id);a.gbps=Math.max(0,num(a.gbps,2));a.until=num(a.until,s.day);a.bh=!!a.bh;a.ixbh=!!a.ixbh;a.start=Math.max(0,Math.min(s.day,num(a.start,s.day)));a.until=Math.min(a.until,a.start+7); - if(Array.isArray(a.entries)){a.entries=a.entries.filter(en=>en&&['t','ix','p'].includes(en.k)&&isCity(en.city)&&typeof en.id==='string'&&Number.isFinite(+en.share)&&+en.share>0).slice(0,3000).map(en=>({k:en.k,id:en.id.slice(0,40),city:en.city,lab:String(en.lab||'').slice(0,60),share:+en.share}));const sum=a.entries.reduce((n,en)=>n+en.share,0);if(Number.isFinite(sum)&&sum>0)for(const en of a.entries)en.share/=sum;else delete a.entries;}else delete a.entries; + if(Array.isArray(a.entries)){a.entries=a.entries.slice(0,3000).filter(en=>en&&isCity(en.city)&&Number.isFinite(+en.share)&&+en.share>0&&(en.k==='rest'||['t','ix','p'].includes(en.k)&&typeof en.id==='string')).map(en=>en.k==='rest'?{k:'rest',city:en.city,share:+en.share}:{k:en.k,id:en.id.slice(0,40),city:en.city,lab:String(en.lab||'').slice(0,60),share:+en.share});const sum=a.entries.reduce((n,en)=>n+en.share,0);if(Number.isFinite(sum)&&sum>0){for(const en of a.entries)en.share/=sum;a.entries=ddosFold(a.entries,a.city);}else delete a.entries;}else delete a.entries; a.sla=Array.isArray(a.sla)?a.sla.filter(x=>typeof x==='string').slice(0,s.biz.length):[]; if(!a.entry||typeof a.entry!=='object')a.entry={k:'edge',lab:''};else{a.entry.lab=String(a.entry.lab||'').slice(0,60);a.entry.id=a.entry.id==null?undefined:String(a.entry.id).slice(0,40);}return a;}; const attacks=[s.ev.ddos,...(Array.isArray(s.ev.ddosMore)?s.ev.ddosMore:[])].map(repairAttack).filter(Boolean).slice(0,14); diff --git a/src/game/85-incidents/10-incidents-and-ddos.js b/src/game/85-incidents/10-incidents-and-ddos.js index 521026e..f1e9df7 100644 --- a/src/game/85-incidents/10-incidents-and-ddos.js +++ b/src/game/85-incidents/10-incidents-and-ddos.js @@ -32,6 +32,11 @@ function ddosDrop(a){const left=ddosAll(S,false).filter(x=>x!==a);S.ev.ddos=left function ddosExpire(){for(const a of ddosAll(S,false))if(a.until<=S.day||!S.pops[a.city]){ddosDone(a);ddosDrop(a);}} function ddosEntries(){const ports=Object.values(R.ingressPorts||{}).filter(p=>p.cap>0),busy=ports.some(p=>p.traffic>1e-6),weight=p=>busy?p.traffic:p.cap,total=ports.reduce((n,p)=>n+weight(p),0); return total>0?ports.filter(p=>weight(p)>0).map(p=>({k:p.k,id:p.id,city:p.city,lab:p.lab,share:weight(p)/total})):[];} +// A save keeps the biggest ingress ports by name; the long tail is one share (k:'rest') that arrives over the victim's +// usual exits, so a big network's attacks do not each carry hundreds of ports. +const DDOS_KEEP=12; +function ddosFold(entries,city){const L=entries.slice().sort((a,b)=>b.share-a.share);if(L.length<=DDOS_KEEP+1)return L; + const top=L.slice(0,DDOS_KEEP),rest=L.slice(DDOS_KEEP).reduce((n,en)=>n+en.share,0);if(rest>0)top.push({k:'rest',city,share:rest});return top;} function ddosSlices(a){if(!a.entries?.length)return [a];const groups={}; for(const en of a.entries){const c=S.pops[en.city]?en.city:a.city;(groups[c]||(groups[c]=[])).push(en);} return Object.entries(groups).map(([city,entries])=>({...a,parent:a,city,entries,gbps:a.gbps*entries.reduce((n,en)=>n+en.share,0)}));} diff --git a/src/game/85-incidents/20-failures.js b/src/game/85-incidents/20-failures.js index 49ea71a..3057019 100644 --- a/src/game/85-incidents/20-failures.js +++ b/src/game/85-incidents/20-failures.js @@ -146,10 +146,10 @@ function ddosAttack(recompute=true){const type='ddos',fl=scnRule('ddos');ddosExp const c=pick(Object.keys(S.pops)),vec=pick(ddosVectors()),V=DDOS_VEC[vec]; const gbps=ddosSize(vec); const dur=1+Math.floor(Math.random()*(1+6*ddosPressure())),entry=ddosEntry(c); - const entries=ddosEntries(),a={id:uid(),city:c,vec,gbps,until:S.day+dur,entry:entries.length>1?{k:'distributed',lab:tr('common.distributed_ingress')}:entries[0]||entry,entries,bh:false,start:S.day}; + const ports=ddosEntries(),entries=ddosFold(ports,c),a={id:uid(),city:c,vec,gbps,until:S.day+dur,entry:entries.length>1?{k:'distributed',lab:tr('common.distributed_ingress')}:entries[0]||entry,entries,bh:false,start:S.day}; if(!S.ev.ddos)S.ev.ddos=a;else(S.ev.ddosMore||(S.ev.ddosMore=[])).push(a); const soaked=(V.fs&&fsAt(c))||hasScrub(); - const how=entries.length>1?tr('failures.across_n_transit_and_peering_ports',{n:entries.length}):entry&&entry.lab?tr('failures.in_via_e',{e:entry.lab}):''; + const how=ports.length>1?tr('failures.across_n_transit_and_peering_ports',{n:ports.length}):entry&&entry.lab?tr('failures.in_via_e',{e:entry.lab}):''; const msg=tr('failures.a_size_vec_attack_is_hitting',{size:fmtG(gbps),vec:V.n,city:CITY[c].name,how})+' '+(soaked?tr('failures.your_mitigation_is_eating_most_of'):tr('failures.junk_traffic_is_eating_your_capacity')); if(fl)a.who=pick(FLOOD_WHO); addInc({type,ref:c,atk:a.id,until:S.day+dur,msg:fl?msg+' '+tr('failures.attacker_who',{who:tr(a.who)}):msg,cost:0}); diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index fc43217..f11eb02 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -59,3 +59,28 @@ test('an attack is held or lost at its victim; other POPs and their DDoS-protect assert.ok(cash > 0); assert.deepEqual(errors, []); }); + +test('an attack keeps its biggest ingress ports and folds the long tail, so saves stay small', () => { + const { ev, errors } = load({ seed: 5 }); + ev("ACT.start({});S.cash=1e9;S.lvl=6;for(const c of ['fra','ams','lon','par'])if(!S.pops[c])ACT.buildPop({city:c});for(const c in S.pops){S.pops[c].bb={d:100};S.pops[c].rgen=3}"); + ev("S.transit=[];const nets=NETS.filter(n=>n.type!=='t1').slice(0,40);for(const c in S.pops)for(const n of nets.slice(0,8))S.pni.push({id:n.id+'@'+c,net:n.id,city:c,tier:1});compute()"); + ev("S.day=60;S.ddosStarts=[];ddosAttack()"); + const ports = ev('ddosEntries().length'); + assert.ok(ports > 20, `many ports carry traffic (${ports})`); + const en = JSON.parse(ev('JSON.stringify(S.ev.ddos.entries)')); + assert.equal(en.length, 13, 'twelve named ports and one remainder'); + assert.equal(en.at(-1).k, 'rest'); + assert.equal(en.at(-1).city, ev('S.ev.ddos.city')); + assert.ok(Math.abs(en.reduce((n, x) => n + x.share, 0) - 1) < 1e-9); + assert.match(ev("S.inc.at(-1).msg"), new RegExp(`across ${ports} transit and peering ports`), 'the message still counts every port'); + // The remainder is routed like the rest of the flood, and survives a save. + ev('compute()'); + assert.ok(Math.abs(ev('R.ddos.reduce((n,m)=>n+m.reaching,0)') - ev('S.ev.ddos.gbps')) < 1e-6); + ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()'); + assert.equal(ev('S.ev.ddos.entries.length'), 13); + // An old save with every port is folded on load. + ev("S.ev.ddos.entries=Array.from({length:300},(_,i)=>({k:'p',id:'x'+i,city:'fra',lab:'',share:1}));S=migrate(JSON.parse(JSON.stringify(S)))"); + assert.equal(ev('S.ev.ddos.entries.length'), 13); + assert.equal(ev("S.ev.ddos.entries.find(e=>e.k==='rest').share.toFixed(4)"), (288/300).toFixed(4)); + assert.deepEqual(errors, []); +}); From e80fd0e453bb0f521bc549f0c4865756697b0ca9 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Wed, 28 Oct 2026 20:19:41 +0100 Subject: [PATCH 05/12] Spicy chaos stretches exactly what an incident holds down stretchInc() stretched anything ending on the same day: always the primary attack (even when the incident was about another one, never the overlapping ones) and any unrelated outage that happened to end then. It now finds the attack by i.atk and everything else by the incident's ref, as clearInc() does, and saves allow the longest stretched attack (11 days). --- src/game/40-progress/30-rules.js | 22 ++++++++++++++-------- src/game/80-simulation/50-sanitize.js | 2 +- tests/ddos-floods.test.js | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/game/40-progress/30-rules.js b/src/game/40-progress/30-rules.js index 928a462..c61421b 100644 --- a/src/game/40-progress/30-rules.js +++ b/src/game/40-progress/30-rules.js @@ -31,12 +31,18 @@ function makeRules(preset,o){const p=Object.prototype.hasOwnProperty.call(PRESET // What the HUD and the share card say about the rules. On-call says nothing: it is the game. function ruleTag(){const p=rulePreset();if(S&&S.mode==='sandbox'){const c=CHAOS[rule('chaos')];return tr('common.sandbox')+(c&&rule('chaos')!=='none'?' '+c.i:'');} return p==='oncall'||p==='sandbox'?'':PRESETS[p].i+' '+PRESETS[p].n;} -/* Spicy outages last longer: stretch a fresh incident, and whatever it holds down until the same day, by half. */ +/* Spicy outages last longer: stretch a fresh incident by half, and exactly what it holds down (found by its ref, as + clearInc() finds it), never something else that happens to end the same day. */ function stretchInc(i){if(rule('chaos')!=='spicy'||!i||!(i.until>S.day)||i.start!==S.day)return;const U=i.until,V=S.day+Math.ceil((U-S.day)*SPICY_LONG);if(V===U)return;i.until=V; - const f=(o,k)=>{if(o&&o[k]===U)o[k]=V;},E=S.ev; - for(const l of S.links){f(l,'cut');f(l,'eqDown');f(l,'deg');f(l.loss,'until');f(l.chFail,'until');} - for(const c in S.pops){const p=S.pops[c];f(p,'down');f(p,'ringcut');f(p,'hot');} - for(const t of S.transit){f(t,'down');f(t.lacp,'until');}for(const p of S.pni)f(p.lacp,'until'); - for(const k of ['ixdown','fab'])if(E[k])for(const x in E[k])if(E[k][x]===U)E[k][x]=V; - if(E.ixlacp)for(const x in E.ixlacp)f(E.ixlacp[x],'until'); - for(const k of ['leak','rpki','pmtud','ddos'])f(E[k],'until');} + const f=(o,k)=>{if(o&&o[k]===U)o[k]=V;},E=S.ev,T=i.type,r=i.ref,L=()=>S.links.find(l=>l.id===r); + if(T==='cut'||T==='redsea'){for(const l of S.links)if((l.trench||l.id)===r)f(l,'cut');} + else if(T==='fatwave'||T==='label')f(L(),'cut'); + else if(T==='ctrlplane'){for(const id of Array.isArray(i.links)?i.links:[])f(S.links.find(l=>l.id===id),'cut');} + else if(T==='amp'||T==='roadmff')f(L(),'eqDown');else if(T==='mtu')f(L(),'deg');else if(T==='loss')f(L()?.loss,'until');else if(T==='optic')f(L()?.chFail,'until'); + else if(['crash','power','oops','cleaner','maint','shutdown'].includes(T))f(S.pops[r],'down'); + else if(T==='ring')f(S.pops[r],'ringcut');else if(T==='ac')f(S.pops[r],'hot'); + else if(T==='transit'||T==='prepend')f(S.transit.find(t=>t.id===r),'down'); + else if((T==='ixloop'||T==='maxpfx')&&E.ixdown)f(E.ixdown,r);else if(T==='fabric'&&E.fab)f(E.fab,r); + else if(T==='lacp'){const [k,...x]=String(r).split(':'),id=x.join(':');f(k==='ix'?E.ixlacp&&E.ixlacp[id]:(k==='t'?S.transit:S.pni).find(o=>o.id===id)?.lacp,'until');} + else if(T==='rpki'||T==='hijack')f(E.rpki,'until');else if(T==='leak'||T==='pmtud')f(E[T],'until');else if(T==='krroute'||T==='depeer')f(E,T); + else if(T==='ddos')f(ddosAll(S,false).find(a=>a.id===i.atk),'until');} diff --git a/src/game/80-simulation/50-sanitize.js b/src/game/80-simulation/50-sanitize.js index 0222376..48c6e55 100644 --- a/src/game/80-simulation/50-sanitize.js +++ b/src/game/80-simulation/50-sanitize.js @@ -65,7 +65,7 @@ function sanitize(s){ s.scrubMode=s.scrubMode==='ondemand'?'ondemand':'always'; // Keep the legacy primary attack so old saves and imports remain compatible; additional floods overlap it. const repairAttack=a=>{if(!a||typeof a!=='object'||!isCity(a.city)||!s.pops[a.city]||!own(DDOS_VEC,a.vec))return null; - a.id=sid(a.id);a.gbps=Math.max(0,num(a.gbps,2));a.until=num(a.until,s.day);a.bh=!!a.bh;a.ixbh=!!a.ixbh;a.start=Math.max(0,Math.min(s.day,num(a.start,s.day)));a.until=Math.min(a.until,a.start+7); + a.id=sid(a.id);a.gbps=Math.max(0,num(a.gbps,2));a.until=num(a.until,s.day);a.bh=!!a.bh;a.ixbh=!!a.ixbh;a.start=Math.max(0,Math.min(s.day,num(a.start,s.day)));a.until=Math.min(a.until,a.start+Math.ceil(7*SPICY_LONG)); if(Array.isArray(a.entries)){a.entries=a.entries.slice(0,3000).filter(en=>en&&isCity(en.city)&&Number.isFinite(+en.share)&&+en.share>0&&(en.k==='rest'||['t','ix','p'].includes(en.k)&&typeof en.id==='string')).map(en=>en.k==='rest'?{k:'rest',city:en.city,share:+en.share}:{k:en.k,id:en.id.slice(0,40),city:en.city,lab:String(en.lab||'').slice(0,60),share:+en.share});const sum=a.entries.reduce((n,en)=>n+en.share,0);if(Number.isFinite(sum)&&sum>0){for(const en of a.entries)en.share/=sum;a.entries=ddosFold(a.entries,a.city);}else delete a.entries;}else delete a.entries; a.sla=Array.isArray(a.sla)?a.sla.filter(x=>typeof x==='string').slice(0,s.biz.length):[]; if(!a.entry||typeof a.entry!=='object')a.entry={k:'edge',lab:''};else{a.entry.lab=String(a.entry.lab||'').slice(0,60);a.entry.id=a.entry.id==null?undefined:String(a.entry.id).slice(0,40);}return a;}; diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index f11eb02..33bc30a 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -84,3 +84,25 @@ test('an attack keeps its biggest ingress ports and folds the long tail, so save assert.equal(ev("S.ev.ddos.entries.find(e=>e.k==='rest').share.toFixed(4)"), (288/300).toFixed(4)); assert.deepEqual(errors, []); }); + +test('spicy chaos stretches exactly the attack (or outage) an incident is about, and saves keep it', () => { + const { ev, errors } = load({ seed: 99 }); + ev("beginGame('R','fra',{mode:'normal',preset:'bgp'});if(UI.pendGame)ACT.pitchSkip();S.cash=1e12;ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});ACT.buildPop({city:'ams'});S.links.push({id:'L',a:'fra',b:'ams',kind:'wave',tier:1,km:400,mo:1,cut:0});S.day=50"); + // A link that happens to be cut until the same day as the next attacks must stay as it is. + ev("S.links[0].cut=S.day+2"); + for (let k = 0; k < 4; k++) ev("const old=Math.random;let n=0;Math.random=()=>n++===3?0:old();ddosAttack();Math.random=old"); + const rows = JSON.parse(ev("JSON.stringify(S.inc.filter(i=>i.type==='ddos').map(i=>[i.until,ddosAll(S,false).find(a=>a.id===i.atk).until]))")); + assert.equal(rows.length, 4); + for (const [inc, atk] of rows) { assert.equal(atk, inc, 'the attack lasts as long as its incident'); assert.equal(inc, 52, 'one day, stretched by half'); } + assert.equal(ev('S.links[0].cut'), 52, 'an unrelated cut ending the same day is not stretched'); + // The longest spicy attack (7 days, stretched to 11) survives a reload. + ev("S.ev.ddos.until=S.day+11;S=migrate(JSON.parse(JSON.stringify(S)))"); + assert.equal(ev('S.ev.ddos.until-S.day'), 11); + ev("S.ev.ddos.until=S.day+40;S=migrate(JSON.parse(JSON.stringify(S)))"); + assert.equal(ev('S.ev.ddos.until-S.ev.ddos.start'), 11, 'but not longer'); + // Outages are found by their ref: a fiber cut stretches its own link only. + ev("S.links.push({id:'M',a:'fra',b:'ams',kind:'wave',tier:1,km:400,mo:1,cut:S.day+4});S.links[0].cut=S.day+4;S.links[0].trench='T';addInc({type:'cut',ref:'T',until:S.day+4,msg:'x'})"); + assert.equal(ev("S.links[0].cut-S.day"), 6); + assert.equal(ev("S.links.find(l=>l.id==='M').cut-S.day"), 4); + assert.deepEqual(errors, []); +}); From b5cba3e59168824411eebe0fe789ac0064efafe4 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Wed, 28 Oct 2026 20:23:44 +0100 Subject: [PATCH 06/12] BGP at 3 a.m. brings twice On-call's DDoS, as it says, not twenty times Spicy chaos moved attacks onto the gamers' daily schedule without scaling it, so the preset had about 20x the attacks of On-call. Without gaming customers, attacks stay on the failure schedule (which spicy already runs 1.8x as often, with a slightly heavier DDoS weight to make it 2x); gaming customers still bring their busier one. --- src/game/85-incidents/20-failures.js | 10 ++++++---- tests/ddos-floods.test.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/game/85-incidents/20-failures.js b/src/game/85-incidents/20-failures.js index 3057019..404b912 100644 --- a/src/game/85-incidents/20-failures.js +++ b/src/game/85-incidents/20-failures.js @@ -7,9 +7,10 @@ function fireFailure(){ if(S.transit.some(t=>!(t.down>S.day)))opts.push(['transit',3]); if(Object.keys(S.ixp).length)opts.push(['ixloop',2]); if(S.transit.length&&S.day>60)opts.push(['leak',2]); - // Flood Season brings its own; Change Freeze (calm) has none. Spicy chaos or gaming customers put DDoS on its own, - // busier schedule (ddosTick) instead of this one, so it is never counted twice. - if(S.day>40&&!scnRule('ddos')&&!ddosOff()&&!ddosSpicy())opts.push(['ddos',2]); + // Flood Season brings its own; Change Freeze (calm) has none. Gaming customers put DDoS on its own, busier schedule + // (ddosTick) instead of this one, so it is never counted twice. Spicy failures already come 1.8x as often; a slightly + // heavier weight makes that twice On-call's DDoS, as BGP at 3 a.m. promises. + if(S.day>40&&!scnRule('ddos')&&!ddosOff()&&!gamingCount())opts.push(['ddos',rule('chaos')==='spicy'?2.25:2]); if(fabsUsed.length)opts.push(['fabric',1.5]); const lit=S.links.filter(l=>l.kind==='df'&&dfCap(l)>0&&!linkDown(l));if(lit.length)opts.push(['amp',1.5+lit.length*0.3],['optic',1.5+lit.length*0.3]); opts.push(['funny',4]); @@ -134,12 +135,13 @@ function ddosSize(vec){const fl=scnRule('ddos'),r=Math.random(),roll=fl?1/3+r*2/ // Calm (Change Freeze) and no chaos at all mean no attacks, gamers or not. const ddosOff=()=>{const c=rule('chaos');return c==='calm'||c==='none';}; // More frequent attacks are opt-in: the spicy chaos setting, or hosting gamers (who attract them in real life). +// Outside Flood Season, only gamers move attacks onto ddosTick's daily schedule; spicy alone doubles the usual one. const ddosSpicy=()=>!ddosOff()&&(rule('chaos')==='spicy'||gamingCount()>0); function ddosTick(){if(ddosOff()&&!scnRule('ddos'))return;if(scnRule('ddos')){let next=+S.scn.nextDdos||3,n=0; // Unless spicy, floods take turns as they always did: the next one waits until the last is over. if(!ddosSpicy()&&ddosAll().length)return; while(S.day>=next&&n++<2){ddosAttack(false);next+=floodGap();}S.scn.nextDdos=next40||gamingCount()))for(let i=0;i<2;i++)if(Math.random()d>S.day-7&&d<=S.day);if(S.ddosStarts.length>=14||!Object.keys(S.pops).length)return;S.ddosStarts.push(S.day); diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index 33bc30a..29d1e4b 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -106,3 +106,20 @@ test('spicy chaos stretches exactly the attack (or outage) an incident is about, assert.equal(ev("S.links.find(l=>l.id==='M').cut-S.day"), 4); assert.deepEqual(errors, []); }); + +test('BGP at 3 a.m. brings about twice On-call\'s DDoS; gaming customers bring their own, busier schedule', () => { + const picks = {}; + for (const preset of ['oncall', 'bgp']) { + const { ev, errors } = load({ seed: 7 }); + ev(`beginGame('R','fra',{mode:'normal',preset:'${preset}'});if(UI.pendGame)ACT.pitchSkip();S.cash=1e12;ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});S.day=100;compute()`); + // No daily attacks without gamers, spicy or not. + ev("window.__n=0;const real=ddosAttack;ddosAttack=()=>{window.__n++;};for(let i=0;i<300;i++)ddosTick();window.__tick=window.__n;window.__n=0;for(let i=0;i<4000;i++)fireFailure();ddosAttack=real"); + assert.equal(ev('window.__tick'), 0, `${preset}: no daily DDoS schedule without gaming customers`); + picks[preset] = ev('window.__n') * ev('chaosMul()'); + ev("S.biz.push({id:'g',type:'game',name:'G',city:'fra',bw:1,rate:1,mood:80,since:0});window.__n=0;const real=ddosAttack;ddosAttack=()=>{window.__n++;};for(let i=0;i<300;i++)ddosTick();ddosAttack=real"); + assert.ok(ev('window.__n') > 5, `${preset}: gamers attract attacks on their own schedule`); + assert.deepEqual(errors, []); + } + const ratio = picks.bgp / picks.oncall; + assert.ok(ratio > 1.7 && ratio < 2.3, `about twice the DDoS (${ratio.toFixed(2)}x)`); +}); From d56039695c9174e808a72ec190453240c1341854 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Wed, 28 Oct 2026 20:53:58 +0100 Subject: [PATCH 07/12] Attacks arrive as on 1.36 again: drop the distributed multi-ingress flood model Frederic's call for 2.0: keep #153's fixes, NOC breakdown, new vectors, gaming risk and overlapping attacks, but not the per-port model. It split every flood over each ingress port with traffic (over a thousand on a big network), stored them all in the save, routed one pinned flow per port, and with it came the build-order and victim-scoring bugs found in review. Each attack is again one entry port at the victim (a.entry): upstream clean-pipe, Flowspec on the victim's router, IX blackholing, a sacrificial PNI and RouteScript filter it in that order (ddosMitigation), then scrubbing; what leaks is junk at the victim spread like its traffic, exactly as on main. Saves from 2.0 builds with a.entries load: sanitize drops the shares and a 'distributed' entry becomes 'edge'. Removed: R.ingressPorts, ddosEntries/ddosFold/ddosSlices/ddosCities/ddosHasIx, pinned flows (and the pinned-rank handling in routing and its reference), the mixed-TCAM line and the 'across N ports' message, and their tests; the scrubbing source-city test now uses two victims sharing one center. CHANGELOG #153 bullets describe what ships and credit #153. --- CHANGELOG.md | 20 +-- site/i18n/de.js | 3 - site/i18n/es.js | 3 - site/i18n/fr.js | 3 - site/i18n/it.js | 3 - site/i18n/pt.js | 3 - src/game/80-simulation/30-compute.js | 33 ++--- src/game/80-simulation/50-sanitize.js | 4 +- .../85-incidents/10-incidents-and-ddos.js | 45 ++---- src/game/85-incidents/20-failures.js | 4 +- src/game/90-actions/80-security-and-china.js | 2 +- src/i18n/en.js | 3 - tests/ddos-floods.test.js | 84 +++++------ tests/game.test.js | 134 +++++------------- tests/helpers/reference-allocation.js | 4 +- tests/routing-reference.test.js | 2 +- 16 files changed, 112 insertions(+), 238 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f13ceb4..ebd3011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,16 +18,16 @@ All notable changes to this project are documented here. The project follows - Check a selected link’s redundancy against current demand: see disconnected endpoints, additional service loss and full fallback links without changing the live network. - Links can now use a custom routing metric, set either as a multiplier or as an exact cost. Pick Custom under Routing metric to fine-tune where your traffic goes; it explains how a link's cost is worked out and what each preset comes to on that link. - Prices now follow how connected each city really is, based on PeeringDB and Hurricane Electric data. Transit costs up to 1.8× more in cities where few networks are present, a POP costs 1.25× to 1.5× where there is little or no carrier-neutral data center, and countries with thousands of networks, like Brazil and the US, bring more ISP customers. Big hubs such as Frankfurt, Amsterdam, New York and São Paulo keep their prices. -- Attacks are more varied: sizes, lengths and ingress ports change from one attack to the next, and several can hit at once. Hosting game servers or cloud gaming makes attacks more frequent, as it does in real life. -- The link traffic breakdown now shows the correct source city for scrubbing traffic. Cities using the same center no longer overwrite each other's labels. -- Live attacks now show one scrubbing detour from the attacked city to its nearest active scrubbing center, using the links' one-way latency. -- Game server and cloud gaming customers now carry a “Gaming attracts attacks” note on their offers and customer lists, so you can see the DDoS risk before signing them. -- Live attacks now show how much traffic Flowspec actually drops at the ingress routers. Routers without TCAM no longer claim to filter attacks, mixed router capabilities are called out, and Flowspec drops are counted separately from other edge filters. -- Hosting game servers or cloud gaming brings RackNet and TeamSpooked attacks. Both bypass Flowspec and require dedicated mitigation. -- Flood Season keeps sending ever larger attacks when you keep playing after winning or running out of time. Finishing the challenge no longer switches the floods off. -- Each live attack in the NOC now shows incoming bandwidth, upstream scrubbing, edge filtering, scrubbing-center use and any traffic still leaking through. -- DDoS bandwidth now adds up: upstream scrubbing, edge filters and scrubbing centers work in sequence. The NOC uses the same figures as traffic routing, including floods that cannot reach a remote center. -- Attacks can now use Memcached amplification or an ACK flood. Flowspec catches the former; the latter need mitigation. +- Attacks are more varied: sizes and lengths change from one attack to the next, and several can hit at once, each with its own controls in the NOC. Hosting game servers or cloud gaming makes attacks more frequent, as it does in real life (#153). +- The link traffic breakdown now shows the correct source city for scrubbing traffic. Cities using the same center no longer overwrite each other's labels (#153). +- Live attacks now show one scrubbing detour from the attacked city to its nearest active scrubbing center, using the links' one-way latency (#153). +- Game server and cloud gaming customers now carry a “Gaming attracts attacks” note on their offers and customer lists, so you can see the DDoS risk before signing them (#153). +- Live attacks now show how much traffic Flowspec actually drops. Routers without TCAM no longer claim to filter attacks, and Flowspec drops are counted separately from other edge filters (#153). +- Hosting game servers or cloud gaming brings RackNet and TeamSpooked attacks. Both bypass Flowspec and require dedicated mitigation (#153). +- Flood Season keeps sending ever larger attacks when you keep playing after winning or running out of time. Finishing the challenge no longer switches the floods off (#153). +- Each live attack in the NOC now shows incoming bandwidth, upstream scrubbing, edge filtering, scrubbing-center use and any traffic still leaking through (#153). +- DDoS bandwidth now adds up: upstream scrubbing, edge filters and scrubbing centers work in sequence. The NOC uses the same figures as traffic routing, including floods that cannot reach a remote center (#153). +- Attacks can now use Memcached amplification or an ACK flood. Flowspec catches the former; the latter need mitigation (#153). - Set the number of each optic model directly on land and subsea fiber links. Apply a whole change at once, with its total price shown before buying; removed optics return to the spares shelf. - Order PNIs with one network or every network at all shared POPs from the NOC Traffic tab: choose a port size, review the total cost, and add missing connections or upgrade smaller ones in one go. Each network keeps its own smallest PNI size and delivery time. - Utilities join route servers and request eligible peers across every joined IX, install missing PoP redundancy hardware and balance caches between sites, and request a cache from each eligible provider at each site. diff --git a/site/i18n/de.js b/site/i18n/de.js index c6b6e91..47eb899 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -910,7 +910,6 @@ "common.demand":"Nachfrage", "common.deploy":"Deployen", "common.deployed":"deployt", -"common.distributed_ingress":"Verteilter Eingang", "common.diverse":"redundant", "common.diverse_route":"redundante Route", "common.dns_reflection":"DNS-Reflection", @@ -1635,7 +1634,6 @@ "failures.a_trawler_off_ostend_dragged_its":"Ein Trawler vor Ostende hat sein Netz direkt durch dein Kabel {a}–{b} gezogen. Die Nordsee ist etwa dreißig Meter tief und voller Boote.", "failures.a_visiting_engineer_from_london":"Ein Gast-Ingenieur aus London hat Marmite ins NOC in {city} mitgebracht. Die diplomatischen Beziehungen sind zusammengebrochen, und dein Router auch, während alle stritten.", "failures.a_wind_farm_service_vessel_dropped":"Ein Windpark-Serviceschiff hat auf deinem Kabel {a}–{b} Anker geworfen. Es war da, um eine Turbine zu reparieren.", -"failures.across_n_transit_and_peering_ports":", über {n} Transit- und Peering-Ports", "failures.all_n_links_in_that_trench":"Alle {n} Links in diesem Graben sind mit ausgefallen.", "failures.an_automation_script_in_city_ran":"Ein Automatisierungsskript in {city} hat „sed“ auf die ganze Config losgelassen statt auf eine Zeile. Jedes Interface heißt jetzt „TODO“.", "failures.an_earthquake_shook_your_a_b":"Ein Erdbeben hat deine Glasfaser {a}–{b} irgendwo oberhalb von 4.000 Metern losgerüttelt.", @@ -2009,7 +2007,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Edge-Filter verwerfen: {g}", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec fängt {vec} nicht ab", "incidents_and_ddos.flowspec_dropping_g":"Flowspec verwirft: {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec verwirft: {g}; manche Eingangs-Router haben kein TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} kommen trotzdem durch", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"Es war DNS", diff --git a/site/i18n/es.js b/site/i18n/es.js index 4ab93d8..c5e8b29 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -908,7 +908,6 @@ "common.demand":"Demanda", "common.deploy":"Desplegar", "common.deployed":"desplegado", -"common.distributed_ingress":"Entrada distribuida", "common.diverse":"diversa", "common.diverse_route":"ruta diversa", "common.dns_reflection":"Reflexión DNS", @@ -1633,7 +1632,6 @@ "failures.a_trawler_off_ostend_dragged_its":"Un arrastrero frente a Ostende arrastró sus aparejos directo por tu cable {a}–{b}. El Mar del Norte tiene unos treinta metros de profundidad y está lleno de barcos.", "failures.a_visiting_engineer_from_london":"Un ingeniero visitante de Londres llevó Marmite al NOC de {city}. Se rompieron las relaciones diplomáticas, y tu router también mientras todos discutían.", "failures.a_wind_farm_service_vessel_dropped":"Un barco de servicio de un parque eólico echó el ancla sobre tu cable {a}–{b}. Estaba allí para arreglar una turbina.", -"failures.across_n_transit_and_peering_ports":", por {n} puertos de tránsito y peering", "failures.all_n_links_in_that_trench":"Los {n} enlaces de esa zanja cayeron con ella.", "failures.an_automation_script_in_city_ran":"Un script de automatización en {city} ejecutó «sed» sobre toda la configuración en lugar de una línea. Ahora todas las interfaces se llaman «TODO».", "failures.an_earthquake_shook_your_a_b":"Un terremoto soltó tu fibra {a}–{b} en algún punto por encima de los 4000 metros.", @@ -2007,7 +2005,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Filtros en el borde descartan: {g}", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec no puede atrapar {vec}", "incidents_and_ddos.flowspec_dropping_g":"Flowspec descarta: {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec descarta: {g}; algunos routers de entrada no tienen TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} se cuelan igualmente", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"Era el DNS", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 26a6ad8..30a346d 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -908,7 +908,6 @@ "common.demand":"Demande", "common.deploy":"Déployer", "common.deployed":"déployé", -"common.distributed_ingress":"Arrivée distribuée", "common.diverse":"diversifié", "common.diverse_route":"chemin diversifié", "common.dns_reflection":"réflexion DNS", @@ -1633,7 +1632,6 @@ "failures.a_trawler_off_ostend_dragged_its":"Un chalutier au large d’Ostende a traîné son chalut en plein sur ton câble {a}–{b}. La mer du Nord fait une trentaine de mètres de fond et grouille de bateaux.", "failures.a_visiting_engineer_from_london":"Un ingénieur de passage venu de Londres a apporté de la Marmite au NOC de {city}. Les relations diplomatiques ont rompu, et ton routeur aussi, pendant que tout le monde se disputait.", "failures.a_wind_farm_service_vessel_dropped":"Un navire de maintenance d’un parc éolien a jeté l’ancre sur ton câble {a}–{b}. Il était là pour réparer une éolienne.", -"failures.across_n_transit_and_peering_ports":", via {n} ports de transit et de peering", "failures.all_n_links_in_that_trench":"Les {n} liens de cette tranchée sont tombés avec elle.", "failures.an_automation_script_in_city_ran":"Un script d’automatisation à {city} a lancé « sed » sur toute la config au lieu d’une ligne. Toutes les interfaces s’appellent maintenant « TODO ».", "failures.an_earthquake_shook_your_a_b":"Un séisme a déboîté ta fibre {a}–{b} quelque part au-dessus de 4 000 mètres.", @@ -2007,7 +2005,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Filtres en bordure : {g} supprimés", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec ne peut pas arrêter {vec}", "incidents_and_ddos.flowspec_dropping_g":"Flowspec supprime {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec supprime {g} ; certains routeurs d’entrée n’ont pas de TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} passent encore", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"C’était le DNS", diff --git a/site/i18n/it.js b/site/i18n/it.js index b2547d1..a4b5b11 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -908,7 +908,6 @@ "common.demand":"Domanda", "common.deploy":"Deploy", "common.deployed":"in produzione", -"common.distributed_ingress":"Ingresso distribuito", "common.diverse":"diversificato", "common.diverse_route":"percorso diverso", "common.dns_reflection":"riflessione DNS", @@ -1633,7 +1632,6 @@ "failures.a_trawler_off_ostend_dragged_its":"Un peschereccio al largo di Ostenda ha trascinato le reti dritte sul tuo cavo {a}–{b}. Il Mare del Nord è profondo una trentina di metri e pieno di barche.", "failures.a_visiting_engineer_from_london":"Un ingegnere in visita da Londra ha portato la Marmite nel NOC di {city}. Le relazioni diplomatiche sono saltate, e mentre tutti litigavano è saltato anche il tuo router.", "failures.a_wind_farm_service_vessel_dropped":"Una nave di servizio di un parco eolico ha gettato l'ancora sul tuo cavo {a}–{b}. Era lì per riparare una turbina.", -"failures.across_n_transit_and_peering_ports":", su {n} porte di transit e peering", "failures.all_n_links_in_that_trench":"Tutti i {n} link in quello scavo sono caduti insieme.", "failures.an_automation_script_in_city_ran":"Uno script di automazione a {city} ha lanciato “sed” su tutta la config invece che su una riga. Ora ogni interfaccia si chiama “TODO”.", "failures.an_earthquake_shook_your_a_b":"Un terremoto ha scollegato la tua fibra {a}–{b} da qualche parte sopra i 4.000 metri.", @@ -2007,7 +2005,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Filtri al bordo: {g} scartati", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec non può fermare {vec}", "incidents_and_ddos.flowspec_dropping_g":"Flowspec scarta {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec scarta {g}; alcuni router di ingresso non hanno TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} superano le difese", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"Era il DNS", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index a05f651..4ac6bb9 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -908,7 +908,6 @@ "common.demand":"Demanda", "common.deploy":"Deploy", "common.deployed":"em produção", -"common.distributed_ingress":"Entrada distribuída", "common.diverse":"diverso", "common.diverse_route":"rota diversa", "common.dns_reflection":"reflexão DNS", @@ -1633,7 +1632,6 @@ "failures.a_trawler_off_ostend_dragged_its":"Um barco de arrasto ao largo de Ostende arrastou as redes bem em cima do seu cabo {a}–{b}. O Mar do Norte tem uns trinta metros de profundidade e é cheio de barcos.", "failures.a_visiting_engineer_from_london":"Um engenheiro de Londres em visita levou Marmite para o NOC de {city}. As relações diplomáticas caíram, e seu roteador também, enquanto todo mundo discutia.", "failures.a_wind_farm_service_vessel_dropped":"Um navio de serviço de um parque eólico jogou âncora no seu cabo {a}–{b}. Ele estava lá para consertar uma turbina.", -"failures.across_n_transit_and_peering_ports":", por {n} portas de transit e peering", "failures.all_n_links_in_that_trench":"Todos os {n} links daquela vala caíram junto.", "failures.an_automation_script_in_city_ran":"Um script de automação em {city} rodou “sed” na config inteira em vez de uma linha. Toda interface agora se chama “TODO”.", "failures.an_earthquake_shook_your_a_b":"Um terremoto soltou sua fibra {a}–{b} em algum ponto acima de 4.000 metros.", @@ -2007,7 +2005,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Filtros de borda descartando: {g}", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec não consegue filtrar {vec}", "incidents_and_ddos.flowspec_dropping_g":"Flowspec descarta {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec descarta {g}; alguns roteadores de entrada não têm TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} estão passando", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"Foi o DNS", diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index 09cd6ce..4a0f2eb 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -39,7 +39,7 @@ function compute(){ // ok() cannot change during one compute, so ask each exit once per network, not once per flow and rank. // okBy[net] lists the exits that reach it in E's order, like E.filter(e=>e.ok(net)). const okBy={};for(const id of NET_IDS)okBy[id]=[]; - R2.ingressPorts={};const ekN={};for(const e of E){e.ek=e.k+':'+e.id;if(e.k!=='c'){const p=R2.ingressPorts[e.ek]||(R2.ingressPorts[e.ek]={k:e.k,id:e.id,city:e.city,lab:e.lab,cap:0,traffic:0});p.cap+=e.cap;}ekN[e.ek]=(ekN[e.ek]||0)+1;} + const ekN={};for(const e of E){e.ek=e.k+':'+e.id;ekN[e.ek]=(ekN[e.ek]||0)+1;} // dup: shares its key with another exit (a hand-edited save), so R.egDesc shows whichever pushed last. for(const e of E){e.desc={lab:e.lab,city:e.city,k:e.k};e.dup=ekN[e.ek]>1;e.told=false;e.hp=e.pref==='high'?0:1;e.ci=CIDX[e.city];e.cn=cnCity(e.city);e.vis=0;for(const n of e.nets||NET_IDS){const L=okBy[n];if(L&&L[L.length-1]!==e&&e.ok(n))L.push(e);}} for(const n of NETS){R2.reachable[n.id]=okBy[n.id].some(e=>e.rank>0);if(R2.reachable[n.id])R2.reach+=NSH[n.id];if(okBy[n.id].some(e=>e.rank>0&&e.k!=='t')){R2.nt[n.id]=1;R2.reachNT+=NSH[n.id]; @@ -52,18 +52,8 @@ function compute(){ // Customer demand per city, added up in S.biz order (what filtering S.biz for each city would give). const bizBw={};for(const b of S.biz){const T=BIZ_T[b.type];if(!T.l2&&!T.fiber&&(!T.event||eventLive(b))){const v=bizBw[b.city];bizBw[b.city]=(v===undefined?0:v)+b.bw;}} // Traffic shares by network index, and their sums, for each share table (and with Russia's throttle). - const shArr=new Map(),shSum=new Map(),DEMTO=new Float64Array(NN),loc=scnRule('local'),scrubRoom={},atkBy={},junkGroups=[],bhCities=new Set(ddosAll().filter(a=>a.bh).map(a=>a.city));R2.haul=[];R2.ddos=[]; - /* Floods first, before any real traffic and in the order the attacks started, so no POP's place in S.pops decides who - gets a full port. Each slice is the flood entering in one city (mitigated and scrubbed there); what leaks is junk at - the victim, pinned to the port it came in on, so it loads that port, the backbone between them and the victim's router. */ - // A port the victim cannot be reached from (down, or no backbone to it) still fills with the junk arriving there. - const VIC={};for(const a of ddosAll()){const v=a.city;(VIC[v]||(VIC[v]=[])).push(a); - for(const part of ddosSlices(a)){const c=part.city;(atkBy[c]||(atkBy[c]=[])).push(part); - const m=ddosMitigation(part,{},bhCities.has(v),false),group={m,flows:[]};R2.ddos.push(m);junkGroups.push(group);if(!popUp(c))m.offline=true; - const src=popUp(v)&&SPD[v][CIDX[c]]0?q.g/m.leak:0;if(q.entry.k==='rest'){for(let j=0;ja.bh).map(a=>a.city));R2.haul=[];R2.ddos=[]; + const VIC={};for(const a of ddosAll())(VIC[a.city]||(VIC[a.city]=[])).push(a); for(const c of Object.keys(S.pops)){ const p=S.pops[c],ci=CIDX[c],cn=cnCity(c),SH=cn?NSH_CN:ruCity(c)?NSH_RU:CITY[c].kr&&S.krExit?NSH_KRX:NSH;const eye=(p.bb?p.bb.d:0)*viral*(cn&&ev.golden>day?1.4:1);const biz=bizBw[c]??0;const d0=eye+biz; // Goggle video is throttled in Russia (#70): people there get half of it, so they ask for half. It is not @@ -76,6 +66,10 @@ function compute(){ // `edge` is the crude RouteScript `blackhole ddos` filter (junk gone, 10% of real traffic with it). Flowspec // (a standing licence) and a scrubbing center each knock the flood down before it reaches the sim. const attacks=VIC[c]||[],rtbh=bhCities.has(c),edge=!!(attacks.length&&TRX&&TRX.blackhole&&!rtbh); + // The junk heads for the victim over its usual exits, spread like its traffic. How much is left after the edge + // tools and scrubbing is only known once hauls to remote centers are routed, so the flows are sized after that. + for(const atk of attacks){const m=ddosMitigation(atk,{},rtbh,false),group={m,flows:[]};R2.ddos.push(m);junkGroups.push(group);if(!popUp(c)){m.offline=true;continue;} + for(let j=0;jn+a.gbps,0)+d*0.1;if(rtbh)R2.teBlack+=attacks.reduce((n,a)=>n+a.gbps,0)+d; @@ -145,14 +139,14 @@ function compute(){ for(const m of R2.ddos){const atk=m.attack,A=atk.city,Ai=CIDX[A]; m.sp=!m.offline&&m.leak>0?scrubPlan(atk,m.leak,scrubRoom,(x,want)=>{const B=x.city,Bi=CIDX[B];if(A===B)return want;let h=0,ms=null; if(popUp(A)&&popUp(B)&&SPD[A]&&SPD[A][Bi]0?want*take/total:0;ms=path.reduce((n,e)=>n+e.lat,0)*2; + const v=R2.cityDem[A]*0.1*want/Math.max(m.leak,1)/VIC[A].length,total=want+v,take=Math.max(0,Math.min(total,room));h=total>0?want*take/total:0;ms=path.reduce((n,e)=>n+e.lat,0)*2; // Sources sharing a center need separate labels in link breakdowns and map highlights. const ek='scrub:'+A+'>'+B;R2.egDesc[ek]={lab:labOf(N_('compute.attack_hauled_to_scrubbing_in_city'),'city',CITY[B].name),city:A,k:'l2'}; for(const i of ni)if(HAS[i])nodeTake(i,take);for(const l of path){l.res-=take;l.ld+=take;carry(l,ek,NN,Ai,take);}} R2.haul.push({city:A,to:B,tier:x.tier||0,a:want,h,ms,attack:atk.id});return h;}):null; if(m.sp){m.leak=m.sp.leak; - // The card describes the victim's nearest center, separately from distributed ingress hauling above. - const c=(atk.parent||atk).city;let near=scrubNear.get(c);if(near===undefined){near=null; + // The card describes the victim's nearest center. + const c=atk.city;let near=scrubNear.get(c);if(near===undefined){near=null; for(const x of S.scrubs)if(popUp(x.city)&&SPD[c]&&SPD[c][CIDX[x.city]]n+e.lat,0);if(!near||mse.res<=1e-3||(HAS[v]&&NRES[v]<=1e-3),dst); if(D[dst]===Infinity||D[dst]>2*base+60){teCache.set(key,false);return null;} const Q=walkI(P,src,dst);teCache.set(key,Q);return Q;}; - const ingressE={};for(const e of E)(ingressE[e.ek]||(ingressE[e.ek]=[])).push(e); /* A network in a peer's customer cone, reached through that peer (#85): after every network you peer with directly (its AS path is one hop longer) and before transit. */ const base=(e,n)=>e.pref==='low'?4:e.rank>0&&e.rank<3&&coneOf(e,n)?CONE_RANK:e.rank; @@ -180,9 +173,6 @@ 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 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. @@ -198,7 +188,7 @@ function compute(){ const ek=e.ek,nr=f.nr,ci=f.ci;if(!e.told||e.dup){R2.egDesc[ek]=e.desc;e.told=true;} for(const l of path){l.res-=amt;l.ld+=amt;carry(l,ek,nr,ci,amt);} e.used+=amt;f.rem-=amt; - if(!f.junk){if(e.k!=='c')R2.ingressPorts[ek].traffic+=amt;let ok=amt;const cf=f.cn,ce=e.cn,cn=f.ncn; + if(!f.junk){let ok=amt;const cf=f.cn,ce=e.cn,cn=f.ncn; if(cf!==ce||(cf&&!cn)||(!cf&&cn&&e.k==='t')){const prem=(e.k==='t'&&e.prem)||(e.k==='p'&&e.pnc)||path.some(x=>x.links&&x.links.some(y=>y.premium));const loss=prem?0.03:(ev.gfw>day?0.35:0.2);R2.gfwLost+=amt*loss;R2.gfwCross+=amt;ok=amt*(1-loss);} SRV[f.ci]+=ok;R2.served+=ok;if(f.bz)R2.bizSrv[f.c]+=ok;if(e.rank<=2)R2.peered+=ok;if(e.k==='t'){const m=R2.tNet[e.id]||(R2.tNet[e.id]={});m[f.n]=(m[f.n]||0)+ok; // Backhaul to transit: users notice the round trip to the exit. Up to 20 ms (about 1,500 km) is free, then @@ -231,7 +221,6 @@ function compute(){ for(let fi=0,FN=flows.length;fi{if(!a||typeof a!=='object'||!isCity(a.city)||!s.pops[a.city]||!own(DDOS_VEC,a.vec))return null; a.id=sid(a.id);a.gbps=Math.max(0,num(a.gbps,2));a.until=num(a.until,s.day);a.bh=!!a.bh;a.ixbh=!!a.ixbh;a.start=Math.max(0,Math.min(s.day,num(a.start,s.day)));a.until=Math.min(a.until,a.start+Math.ceil(7*SPICY_LONG)); - if(Array.isArray(a.entries)){a.entries=a.entries.slice(0,3000).filter(en=>en&&isCity(en.city)&&Number.isFinite(+en.share)&&+en.share>0&&(en.k==='rest'||['t','ix','p'].includes(en.k)&&typeof en.id==='string')).map(en=>en.k==='rest'?{k:'rest',city:en.city,share:+en.share}:{k:en.k,id:en.id.slice(0,40),city:en.city,lab:String(en.lab||'').slice(0,60),share:+en.share});const sum=a.entries.reduce((n,en)=>n+en.share,0);if(Number.isFinite(sum)&&sum>0){for(const en of a.entries)en.share/=sum;a.entries=ddosFold(a.entries,a.city);}else delete a.entries;}else delete a.entries; + delete a.entries; // 2.0 betas spread attacks over every ingress port; they arrive on one again a.sla=Array.isArray(a.sla)?a.sla.filter(x=>typeof x==='string').slice(0,s.biz.length):[]; - if(!a.entry||typeof a.entry!=='object')a.entry={k:'edge',lab:''};else{a.entry.lab=String(a.entry.lab||'').slice(0,60);a.entry.id=a.entry.id==null?undefined:String(a.entry.id).slice(0,40);}return a;}; + if(!a.entry||typeof a.entry!=='object'||!['t','ix','p','edge'].includes(a.entry.k))a.entry={k:'edge',lab:''};else{a.entry.lab=String(a.entry.lab||'').slice(0,60);a.entry.id=a.entry.id==null?undefined:String(a.entry.id).slice(0,40);}return a;}; const attacks=[s.ev.ddos,...(Array.isArray(s.ev.ddosMore)?s.ev.ddosMore:[])].map(repairAttack).filter(Boolean).slice(0,14); if(attacks.length)s.ev.ddos=attacks[0];else delete s.ev.ddos;s.ev.ddosMore=attacks.slice(1); s.ddosStarts=(Array.isArray(s.ddosStarts)?s.ddosStarts:attacks.map(a=>a.start)).filter(d=>typeof d==='number'||typeof d==='string').map(Number).filter(d=>Number.isFinite(d)&&d>s.day-7&&d<=s.day).sort((a,b)=>a-b).slice(-14); diff --git a/src/game/85-incidents/10-incidents-and-ddos.js b/src/game/85-incidents/10-incidents-and-ddos.js index f1e9df7..a7a9624 100644 --- a/src/game/85-incidents/10-incidents-and-ddos.js +++ b/src/game/85-incidents/10-incidents-and-ddos.js @@ -24,35 +24,21 @@ const HARMLESS=[ function lagsN(){const o=[];for(const t of S.transit)if((t.n||1)>=2&&!(t.down>S.day))o.push({k:'t',id:t.id,o:t,n:t.n,lab:tr('incidents_and_ddos.name_transit_lag_in_city',{name:NET[t.net].name,city:CITY[t.city].name})}); for(const p of S.pni)if((p.n||1)>=2)o.push({k:'p',id:p.id,o:p,n:p.n,lab:tr('incidents_and_ddos.pni_lag_with_name_in_city',{name:NET[p.net].name,city:CITY[p.city].name})}); for(const x in S.ixp){const n=(S.ixn||{})[x]||1;if(n>=2&&!S.myIx[x])o.push({k:'ix',id:x,n,lab:ixNamesCity(x)?tr('incidents_and_ddos.ix_lag',{ix:ixName(x)}):tr('incidents_and_ddos.ix_lag_in_city',{ix:ixName(x),city:CITY[ixCity(x)].name})});}return o;} -// Where the junk comes in: one of the city's live uplinks, or just "the edge" if it has none yet. -// The primary slot remains compatible with older saves; every system uses the full live set. +// Several attacks can be live at once: the primary slot keeps older saves compatible, the rest overlap it. function ddosAll(s=S,live=true){return [s.ev.ddos,...(s.ev.ddosMore||[])].filter(a=>a&&(!live||a.until>s.day));} const ddosFind=id=>ddosAll().find(a=>id===undefined||a.id===id); function ddosDrop(a){const left=ddosAll(S,false).filter(x=>x!==a);S.ev.ddos=left[0]||null;S.ev.ddosMore=left.slice(1);} function ddosExpire(){for(const a of ddosAll(S,false))if(a.until<=S.day||!S.pops[a.city]){ddosDone(a);ddosDrop(a);}} -function ddosEntries(){const ports=Object.values(R.ingressPorts||{}).filter(p=>p.cap>0),busy=ports.some(p=>p.traffic>1e-6),weight=p=>busy?p.traffic:p.cap,total=ports.reduce((n,p)=>n+weight(p),0); - return total>0?ports.filter(p=>weight(p)>0).map(p=>({k:p.k,id:p.id,city:p.city,lab:p.lab,share:weight(p)/total})):[];} -// A save keeps the biggest ingress ports by name; the long tail is one share (k:'rest') that arrives over the victim's -// usual exits, so a big network's attacks do not each carry hundreds of ports. -const DDOS_KEEP=12; -function ddosFold(entries,city){const L=entries.slice().sort((a,b)=>b.share-a.share);if(L.length<=DDOS_KEEP+1)return L; - const top=L.slice(0,DDOS_KEEP),rest=L.slice(DDOS_KEEP).reduce((n,en)=>n+en.share,0);if(rest>0)top.push({k:'rest',city,share:rest});return top;} -function ddosSlices(a){if(!a.entries?.length)return [a];const groups={}; - for(const en of a.entries){const c=S.pops[en.city]?en.city:a.city;(groups[c]||(groups[c]=[])).push(en);} - return Object.entries(groups).map(([city,entries])=>({...a,parent:a,city,entries,gbps:a.gbps*entries.reduce((n,en)=>n+en.share,0)}));} -const ddosCities=a=>[...new Set([a.city,...(a.entries||[]).map(en=>en.city)])].filter(c=>S.pops[c]); -const ddosHasIx=a=>ddosCities(a).some(hasIxAt); // An attack is held or lost at its victim: the junk lands there, and other POPs' bad days are not the attacker's doing. const ddosSf=a=>sfOf(R,a.city); -function ddosReport(a){const ms=(R.ddos||[]).filter(m=>m.attack===a||m.attack.parent===a);if(!ms.length)return ddosMitigation(a); - const parts={};for(const m of ms)for(const x of m.sp?.parts||[]){const q=parts[x.city]||(parts[x.city]={city:x.city,tier:x.tier,a:0,cleaned:0});q.a+=x.a;q.cleaned+=x.cleaned;} - return {attack:a,blackhole:ms.some(m=>m.blackhole),upstream:ms.some(m=>m.upstream),reaching:ms.reduce((n,m)=>n+m.reaching,0),flowspec:ms.reduce((n,m)=>n+m.flowspec,0),fsMissing:ms.some(m=>m.fsMissing),filtered:ms.reduce((n,m)=>n+m.filtered,0),sp:Object.keys(parts).length?{parts:Object.values(parts)}:null,near:ms.find(m=>m.near)?.near||null,leak:ms.reduce((n,m)=>n+m.leak,0)};} +function ddosReport(a){return (R.ddos||[]).find(m=>m.attack===a)||ddosMitigation(a);} +// Where the junk comes in: one of the city's live uplinks, or just "the edge" if it has none yet. function ddosEntry(c){const o=[]; for(const t of S.transit)if(t.city===c&&!(t.down>S.day))o.push({k:'t',id:t.id,lab:tr('common.net_transit',{net:NET[t.net].name})}); for(const x of ixIdsIn(c))if(S.ixp[x]!==undefined)o.push({k:'ix',id:x,lab:tr('common.ix_peering',{ix:ixName(x)})}); for(const p of S.pni)if(p.city===c)o.push({k:'p',id:p.id,lab:tr('common.pni_with_net',{net:NET[p.net].name})}); return o.length?pick(o):{k:'edge',lab:''};} -// Flowspec capability at each ingress POP: 0 none, 1 basic, 2 full. +// Flowspec capability of a POP's router: 0 none, 1 basic, 2 full. const fsAt=c=>{const p=S.pops[c];return p?(RG[p.rgen||0].fs||0):0;}; // Scrubbing removes attack traffic up to the center's capacity; overflow leaks. On-demand // does nothing for the first couple of days while traffic is being diverted. @@ -63,18 +49,16 @@ const scrubFar=c=>{for(const a of ddosAll())if(a.city===c){const q=(R.haul||[]). function scrubPlan(atk,g=atk.gbps||0,room={},take=null){if(!scrubEngaged(atk))return null;const c=atk.city;const parts=[]; for(const x of S.scrubs.filter(x=>popUp(x.city)&&(x.city===c||pathExists(c,x.city))).sort((a,b)=>(a.city===c?0:kmBetween(c,a.city))-(b.city===c?0:kmBetween(c,b.city)))){if(g<=0)break;const cap=SCRUB_TIERS[x.tier||0].g,a=Math.min(g,room[x.city]??cap);if(a<=0)continue;const cleaned=take?take(x,a):a;room[x.city]=(room[x.city]??cap)-cleaned;parts.push({city:x.city,tier:x.tier||0,a,cleaned});g-=cleaned;} return parts.length?{parts,leak:g}:null;} -// One accounting pipeline for routing and the NOC: upstream -> edge -> scrubbing -> leakage. -function ddosMitigation(a,room={},blackhole=a.bh,plan=true){const entries=a.entries?.length?a.entries:[{...(a.entry||{}),share:1}],total=entries.reduce((n,en)=>n+en.share,0),ingress=[]; - let upstream=false,reaching=0,g=0,flowspec=0,fsMissing=false; - for(const en of entries){const t=en.k==='t'?S.transit.find(x=>x.id===en.id):null,p=en.k==='p'?S.pni.find(x=>x.id===en.id):null,clean=!!(t&&t.clean); - upstream=upstream||clean;let part=blackhole?0:a.gbps*en.share/total*(clean?0.1:1);reaching+=part; - if(DDOS_VEC[a.vec]?.fs){const cap=fsAt(S.pops[en.city]?en.city:a.city),before=part;part*=FS_RES[cap];flowspec+=before-part;if(cap===0&&before>0)fsMissing=true;} - if(a.ixbh&&hasIxAt(a.city))part*=0.5; - if(p&&p.sacrif)part=Math.min(part,liveCap(pniG(p),p.city,p.site,p.n)*0.9); - if(teRules()?.blackhole&&!blackhole)part=0; - g+=part;ingress.push({entry:en,g:part});} +// One accounting pipeline for routing and the NOC: upstream -> edge -> scrubbing -> leakage. The junk comes in on one +// port of the victim (a.entry) and is filtered by the victim's own router. +function ddosMitigation(a,room={},blackhole=a.bh,plan=true){const en=a.entry||{},t=en.k==='t'?S.transit.find(x=>x.id===en.id):null,p=en.k==='p'?S.pni.find(x=>x.id===en.id):null,upstream=!!(t&&t.clean); + const reaching=blackhole?0:a.gbps*(upstream?0.1:1);let g=reaching,flowspec=0; + if(DDOS_VEC[a.vec]?.fs){g*=FS_RES[fsAt(a.city)];flowspec=reaching-g;} + if(a.ixbh&&hasIxAt(a.city))g*=0.5; + if(p&&p.sacrif)g=Math.min(g,liveCap(pniG(p),p.city,p.site,p.n)*0.9); + if(teRules()?.blackhole&&!blackhole)g=0; const filtered=reaching-g,sp=plan&&g>0?scrubPlan(a,g,room):null; - return {attack:a,blackhole,upstream,reaching,flowspec,fsMissing,filtered,ingress,sp,leak:sp?sp.leak:g};} + return {attack:a,blackhole,upstream,reaching,flowspec,filtered,sp,leak:sp?sp.leak:g};} // The NOC's live attack view: what is hitting you, what each tool would do about it right now, and the buttons. function ddosPanel(){return S?ddosAll().filter(a=>S.pops[a.city]).map(ddosOne).join(''):'';} function ddosOne(a){ @@ -85,7 +69,6 @@ function ddosOne(a){ :m.upstream?'✓ '+tr('incidents_and_ddos.after_upstream_scrubbing_g',{g:fmtG(m.reaching)}):''; const fsLine=!V.fs?'— '+tr('incidents_and_ddos.flowspec_cannot_catch_vec',{vec:esc(V.n)}) :m.flowspec<=1e-6?'— '+tr('incidents_and_ddos.no_flowspec_filtering_ingress') - :m.fsMissing?'~ '+tr('incidents_and_ddos.flowspec_dropping_g_some_ingress',{g:fmtG(m.flowspec)}) :'✓ '+tr('incidents_and_ddos.flowspec_dropping_g',{g:fmtG(m.flowspec)}); const used=c=>(R.ddos||[m]).reduce((n,q)=>n+(q.sp?.parts||[]).filter(x=>x.city===c).reduce((t,x)=>t+x.cleaned,0),0); const scrOne=x=>{const T=SCRUB_TIERS[x.tier],q=hl(x),total=used(x.city); @@ -107,6 +90,6 @@ function ddosOne(a){
${scrLine}
${haulLine?`
${haulLine}
`:''}
${m.leak>1e-6?'~ '+tr('incidents_and_ddos.g_is_leaking_through',{g:fmtG(m.leak)}):'✓ '+tr('incidents_and_ddos.attack_fully_mitigated')}
`} -
${m.blackhole?btn(tr('common.stop_blackholing'),'unrtbh',{id:a.id},'ghost sm'):btn(tr('incidents_and_ddos.blackhole_the_target_rtbh'),'rtbh',{id:a.id},'red sm')}${ddosHasIx(a)&&!m.blackhole?btn(a.ixbh?tr('incidents_and_ddos.ix_blackhole_on'):tr('incidents_and_ddos.ix_blackhole_half_honour_it'),'ixbh',{id:a.id},a.ixbh?'green sm':'sm'):''}${btn(tr('incidents_and_ddos.hackback_3000tm_20k'),'hackback',{id:a.id},'sm',S.cash<20000)}
+
${m.blackhole?btn(tr('common.stop_blackholing'),'unrtbh',{id:a.id},'ghost sm'):btn(tr('incidents_and_ddos.blackhole_the_target_rtbh'),'rtbh',{id:a.id},'red sm')}${hasIxAt(a.city)&&!m.blackhole?btn(a.ixbh?tr('incidents_and_ddos.ix_blackhole_on'):tr('incidents_and_ddos.ix_blackhole_half_honour_it'),'ixbh',{id:a.id},a.ixbh?'green sm':'sm'):''}${btn(tr('incidents_and_ddos.hackback_3000tm_20k'),'hackback',{id:a.id},'sm',S.cash<20000)}

${tr('incidents_and_ddos.rtbh_is_free_and_instant_but')}

`; return h;} diff --git a/src/game/85-incidents/20-failures.js b/src/game/85-incidents/20-failures.js index 404b912..d688fe6 100644 --- a/src/game/85-incidents/20-failures.js +++ b/src/game/85-incidents/20-failures.js @@ -148,10 +148,10 @@ function ddosAttack(recompute=true){const type='ddos',fl=scnRule('ddos');ddosExp const c=pick(Object.keys(S.pops)),vec=pick(ddosVectors()),V=DDOS_VEC[vec]; const gbps=ddosSize(vec); const dur=1+Math.floor(Math.random()*(1+6*ddosPressure())),entry=ddosEntry(c); - const ports=ddosEntries(),entries=ddosFold(ports,c),a={id:uid(),city:c,vec,gbps,until:S.day+dur,entry:entries.length>1?{k:'distributed',lab:tr('common.distributed_ingress')}:entries[0]||entry,entries,bh:false,start:S.day}; + const a={id:uid(),city:c,vec,gbps,until:S.day+dur,entry,bh:false,start:S.day}; if(!S.ev.ddos)S.ev.ddos=a;else(S.ev.ddosMore||(S.ev.ddosMore=[])).push(a); const soaked=(V.fs&&fsAt(c))||hasScrub(); - const how=ports.length>1?tr('failures.across_n_transit_and_peering_ports',{n:ports.length}):entry&&entry.lab?tr('failures.in_via_e',{e:entry.lab}):''; + const how=entry&&entry.lab?tr('failures.in_via_e',{e:entry.lab}):''; const msg=tr('failures.a_size_vec_attack_is_hitting',{size:fmtG(gbps),vec:V.n,city:CITY[c].name,how})+' '+(soaked?tr('failures.your_mitigation_is_eating_most_of'):tr('failures.junk_traffic_is_eating_your_capacity')); if(fl)a.who=pick(FLOOD_WHO); addInc({type,ref:c,atk:a.id,until:S.day+dur,msg:fl?msg+' '+tr('failures.attacker_who',{who:tr(a.who)}):msg,cost:0}); diff --git a/src/game/90-actions/80-security-and-china.js b/src/game/90-actions/80-security-and-china.js index 9e7fd87..3cba21f 100644 --- a/src/game/90-actions/80-security-and-china.js +++ b/src/game/90-actions/80-security-and-china.js @@ -7,7 +7,7 @@ Object.assign(ACT,{ rmScrub:({city})=>{if(!S.scrubs.some(x=>x.city===city))return;if(UI.confirm!=='scrub:'+city){UI.confirm='scrub:'+city;renderAll();return;}S.scrubs=S.scrubs.filter(x=>x.city!==city);if(!hasScrub())S.scrubMode='always';UI.confirm=null;after();}, cleanPipe:({id})=>{const t=S.transit.find(x=>x.id===id);if(!t)return;t.clean=!t.clean;toast(t.clean?tr('security_and_china.clean_pipe_add_on_enabled_on',{net:NET[t.net].name,mo:fmt$(cleanMo(t))}):tr('security_and_china.clean_pipe_add_on_removed_from',{net:NET[t.net].name}),t.clean?'good':'');after();}, sacrif:({id})=>{const p=S.pni.find(x=>x.id===id);if(!p)return;p.sacrif=!p.sacrif;toast(p.sacrif?tr('security_and_china.net_pni_is_now_a_sacrificial',{net:NET[p.net].name}):tr('security_and_china.net_pni_is_back_to_normal',{net:NET[p.net].name}),p.sacrif?'good':'');after();}, - ixbh:({id}={})=>{const a=ddosFind(id);if(!a){toast(tr('security_and_china.no_attack_to_blackhole_right_now'),'');return;}if(!ddosHasIx(a)){toast(tr('security_and_china.no_ix_in_city_to_announce',{city:CITY[a.city].name}),'bad');sfx('err');return;}a.ixbh=!a.ixbh;toast(a.ixbh?tr('security_and_china.ix_blackhole_announced_in_city_about',{city:ddosCities(a).filter(hasIxAt).map(c=>CITY[c].name).join(', ')}):tr('security_and_china.ix_blackhole_withdrawn'),a.ixbh?'good':'');sfx('alert');after();}, + ixbh:({id}={})=>{const a=ddosFind(id);if(!a){toast(tr('security_and_china.no_attack_to_blackhole_right_now'),'');return;}if(!hasIxAt(a.city)){toast(tr('security_and_china.no_ix_in_city_to_announce',{city:CITY[a.city].name}),'bad');sfx('err');return;}a.ixbh=!a.ixbh;toast(a.ixbh?tr('security_and_china.ix_blackhole_announced_in_city_about',{city:CITY[a.city].name}):tr('security_and_china.ix_blackhole_withdrawn'),a.ixbh?'good':'');sfx('alert');after();}, rtbh:({id}={})=>{const a=ddosFind(id);if(!a){toast(tr('security_and_china.no_attack_to_blackhole_right_now'),'');return;}a.bh=true;S.stats.rtbh=(S.stats.rtbh||0)+1;toast(tr('security_and_china.rtbh_announced_you_blackholed_the',{city:CITY[a.city].name}),'bad');sfx('alert');after();}, unrtbh:({id}={})=>{const a=ddosFind(id);if(!a)return;for(const x of ddosAll())if(x.city===a.city)x.bh=false;toast(tr('security_and_china.blackhole_withdrawn_city_is',{city:CITY[a.city].name}),'');after();}, hackback:({id}={})=>{const a=ddosFind(id);if(!a||a.until<=S.day){toast(tr('security_and_china.nothing_to_hack_back_right_now'),'');return;}if(!spend(20000))return;S.stats.hackback=(S.stats.hackback||0)+1; diff --git a/src/i18n/en.js b/src/i18n/en.js index 9e5308b..309e046 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -909,7 +909,6 @@ "common.demand":"Demand", "common.deploy":"Deploy", "common.deployed":"deployed", -"common.distributed_ingress":"Distributed ingress", "common.diverse":"diverse", "common.diverse_route":"diverse route", "common.dns_reflection":"DNS reflection", @@ -1634,7 +1633,6 @@ "failures.a_trawler_off_ostend_dragged_its":"A trawler off Ostend dragged its gear straight through your {a}–{b} cable. The North Sea is about thirty metres deep and full of boats.", "failures.a_visiting_engineer_from_london":"A visiting engineer from London brought Marmite to the {city} NOC. Diplomatic relations broke down, and so did your router while everyone argued.", "failures.a_wind_farm_service_vessel_dropped":"A wind-farm service vessel dropped anchor on your {a}–{b} cable. It was there to fix a turbine.", -"failures.across_n_transit_and_peering_ports":", across {n} transit and peering ports", "failures.all_n_links_in_that_trench":"All {n} links in that trench went down with it.", "failures.an_automation_script_in_city_ran":"An automation script in {city} ran “sed” on the whole config instead of one line. Every interface is now named “TODO”.", "failures.an_earthquake_shook_your_a_b":"An earthquake shook your {a}–{b} fiber loose somewhere above 4,000 metres.", @@ -2008,7 +2006,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Edge filters dropping: {g}", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec cannot catch {vec}", "incidents_and_ddos.flowspec_dropping_g":"Flowspec dropping: {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec dropping: {g}; some ingress routers have no TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} is leaking through", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"It was DNS", diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index 29d1e4b..98efc9f 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -3,85 +3,75 @@ const test = require('node:test'); const assert = require('node:assert/strict'); const { load } = require('./harness'); -test('a flood entering over a PNI with NetChill competes on that PNI at its own rank, as real traffic does', () => { - 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, []); - } -}); - // Frankfurt has the eyeballs and no transit; all transit is in Amsterdam, 100G of wave away. -const remoteIngress = (ev, flip) => { +const remoteTransit = (ev, flip) => { ev("ACT.start({});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9;ACT.buildPop({city:'ams'});ACT.launchBB({city:'fra'});S.links.push({id:'L',a:'fra',b:'ams',kind:'wave',tier:1,km:400,mo:1,cut:0});ACT.buyTransit({city:'ams',net:NETS.find(n=>sellsAt(n,'ams')).id,tier:1})"); if (flip) ev("const p=S.pops;S.pops={ams:p.ams,fra:p.fra}"); ev("compute()"); }; -test('a flood entering in another city crosses the backbone to its victim, whatever order the POPs were built in', () => { +test('a flood loads the backbone and the victim as on main, whatever order the POPs were built in', () => { const out = []; for (const flip of [false, true]) { const { ev, errors } = load({ seed: 5 }); - remoteIngress(ev, flip); + remoteTransit(ev, flip); assert.ok(ev("sfOf(R,'fra')") > 0.95, 'fine before the attack'); - ev("S.day=60;S.ev.ddos={id:'a',city:'fra',vec:'http',gbps:300,start:S.day,until:S.day+3,entry:{k:'distributed',lab:''},entries:[{k:'t',id:S.transit[0].id,city:'ams',share:1}]};compute()"); - assert.equal(ev('R.load.L'), 100, 'the junk fills the wave to the victim'); - assert.ok(ev("R.nodeLoad.fra") >= 100, "and the victim's router"); + ev("S.day=60;ddosAttack();Object.assign(S.ev.ddos,{city:'fra',vec:'http',gbps:300});compute()"); + assert.equal(ev('S.ev.ddos.entries'), undefined, 'no per-port shares'); + assert.equal(ev('R.load.L'), 100, 'the junk fills the wave between the transit and the victim'); + assert.ok(ev('R.nodeLoad.fra') >= 100, "and the victim's router"); assert.ok(ev("sfOf(R,'fra')") < 0.05, 'the victim goes dark'); - out.push(ev("JSON.stringify([R.load.L,R.useT[S.transit[0].id],sfOf(R,'fra')])")); + assert.equal(ev("sfOf(R,'ams')"), 1); + out.push(ev("JSON.stringify([R.load.L,Object.values(R.useT)[0],sfOf(R,'fra'),R.ddos.length])")); assert.deepEqual(errors, []); } assert.equal(out[0], out[1], 'POP build order does not change the outcome'); }); +test('the same flood lands exactly as it does on main (one entry port, the victim\'s router filters it)', () => { + const { ev, errors } = load({ seed: 5 }); + remoteTransit(ev, false); + ev("S.pops.fra.rgen=RG.findIndex(r=>r.fs===2);S.day=60;S.ev.ddos={id:'a',city:'fra',vec:'dns',gbps:200,start:S.day,until:S.day+3,entry:{k:'t',id:S.transit[0].id,lab:''},bh:false};compute()"); + // Full Flowspec leaves 15%: 30G of junk on the 100G wave, next to Frankfurt's own traffic. + assert.ok(Math.abs(ev('R.ddos[0].leak') - 30) < 1e-9); + assert.ok(Math.abs(ev("R.ef[edgeKey(S.links[0])].net.junk") - 30) < 1e-6); + assert.deepEqual(errors, []); +}); + test('an attack is held or lost at its victim; other POPs and their DDoS-protected customers are not charged', () => { const { ev, errors } = load({ seed: 5 }); ev("ACT.start({});S.cash=1e9;S.lvl=6;S.nextFail=1e9;S.nextEvent=1e9;ACT.buildPop({city:'nyc'});for(const c of ['fra','nyc']){S.pops[c].bb={d:50};S.pops[c].rgen=3}"); - ev("S.transit=[{id:'tf',city:'fra',net:'cog',tier:2},{id:'tn',city:'nyc',net:'cog',tier:1}];S.scrubs=[{city:'fra',tier:1}];S.scrubMode='always'"); - // New York is struggling on its own (a 10G port for 50G of eyeballs), and has a DDoS-protected customer. + ev("S.transit=[{id:'tf',city:'fra',net:'cog',tier:2},{id:'tn',city:'nyc',net:'cog',tier:0}];S.scrubs=[{city:'fra',tier:1}];S.scrubMode='always'"); + // New York is struggling on its own (a 10G port for 200G of eyeballs), and has a DDoS-protected customer. ev("S.pops.nyc.bb.d=200;S.biz.push({id:'sc',type:'scrub',name:'Shield',city:'nyc',bw:1,rate:1000,mood:80,since:0})"); - ev("S.day=60;S.ev.ddos={id:'a',city:'fra',vec:'http',gbps:20,start:S.day,until:S.day+3,entry:{k:'distributed',lab:''},entries:[{k:'t',id:'tf',city:'fra',share:.5},{k:'t',id:'tn',city:'nyc',share:.5}]};compute()"); + ev("S.day=60;S.ev.ddos={id:'a',city:'fra',vec:'http',gbps:20,start:S.day,until:S.day+3,entry:{k:'t',id:'tf',lab:''}};compute()"); assert.ok(ev("sfOf(R,'nyc')") < 0.85, 'New York is under water anyway'); assert.ok(ev("sfOf(R,'fra')") >= 0.97, 'the victim is fine'); assert.equal(ev('ddosSf(S.ev.ddos)'), ev("sfOf(R,'fra')")); - const cash = ev('S.cash'); ev('dayTick()'); assert.deepEqual(JSON.parse(ev('JSON.stringify(S.ev.ddos.sla||[])')), [], 'no SLA payout for a customer in another city'); assert.equal(ev('S.stats.sla||0'), 0); ev('S.day=S.ev.ddos.until;ddosExpire()'); assert.equal(ev('S.stats.ddosOk||0'), 1, 'held at the victim'); assert.equal(ev('S.stats.ddosLost||0'), 0); - assert.ok(cash > 0); assert.deepEqual(errors, []); }); -test('an attack keeps its biggest ingress ports and folds the long tail, so saves stay small', () => { - const { ev, errors } = load({ seed: 5 }); - ev("ACT.start({});S.cash=1e9;S.lvl=6;for(const c of ['fra','ams','lon','par'])if(!S.pops[c])ACT.buildPop({city:c});for(const c in S.pops){S.pops[c].bb={d:100};S.pops[c].rgen=3}"); - ev("S.transit=[];const nets=NETS.filter(n=>n.type!=='t1').slice(0,40);for(const c in S.pops)for(const n of nets.slice(0,8))S.pni.push({id:n.id+'@'+c,net:n.id,city:c,tier:1});compute()"); - ev("S.day=60;S.ddosStarts=[];ddosAttack()"); - const ports = ev('ddosEntries().length'); - assert.ok(ports > 20, `many ports carry traffic (${ports})`); - const en = JSON.parse(ev('JSON.stringify(S.ev.ddos.entries)')); - assert.equal(en.length, 13, 'twelve named ports and one remainder'); - assert.equal(en.at(-1).k, 'rest'); - assert.equal(en.at(-1).city, ev('S.ev.ddos.city')); - assert.ok(Math.abs(en.reduce((n, x) => n + x.share, 0) - 1) < 1e-9); - assert.match(ev("S.inc.at(-1).msg"), new RegExp(`across ${ports} transit and peering ports`), 'the message still counts every port'); - // The remainder is routed like the rest of the flood, and survives a save. - ev('compute()'); - assert.ok(Math.abs(ev('R.ddos.reduce((n,m)=>n+m.reaching,0)') - ev('S.ev.ddos.gbps')) < 1e-6); - ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()'); - assert.equal(ev('S.ev.ddos.entries.length'), 13); - // An old save with every port is folded on load. - ev("S.ev.ddos.entries=Array.from({length:300},(_,i)=>({k:'p',id:'x'+i,city:'fra',lab:'',share:1}));S=migrate(JSON.parse(JSON.stringify(S)))"); - assert.equal(ev('S.ev.ddos.entries.length'), 13); - assert.equal(ev("S.ev.ddos.entries.find(e=>e.k==='rest').share.toFixed(4)"), (288/300).toFixed(4)); +test('fourteen attacks on a big network keep the save small, and 2.0 beta saves with per-port shares still load', () => { + const fs = require('node:fs'), path = require('node:path'); + const fx = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8')); + const { ev, errors } = load({ seed: 3 }); + ev(`S=migrate(JSON.parse(${JSON.stringify(JSON.stringify(fx.S || fx))}));UI.started=true;compute()`); + const before = ev('JSON.stringify(S).length'); + ev("S.day=Math.max(S.day,50);for(let i=0;i<14;i++){S.ddosStarts=[];ddosAttack(false);}compute()"); + assert.equal(ev('ddosAll().length'), 14); + assert.ok(ev('JSON.stringify(S).length') - before < 10000, 'a few hundred bytes per attack'); + // A beta save spread each attack over every port: the shares are dropped and the attack carries on. + ev("S.ev.ddos.entries=Array.from({length:300},(_,i)=>({k:'p',id:'x'+i,city:S.ev.ddos.city,lab:'',share:1}));S.ev.ddos.entry={k:'distributed',lab:'Distributed ingress'};S=migrate(JSON.parse(JSON.stringify(S)));compute()"); + assert.equal(ev('S.ev.ddos.entries'), undefined); + assert.equal(ev('S.ev.ddos.entry.k'), 'edge'); + assert.equal(ev('ddosAll().length'), 14); + assert.match(ev('ddosPanel()'), /Live attack/); assert.deepEqual(errors, []); }); diff --git a/tests/game.test.js b/tests/game.test.js index ad9c729..5102de3 100644 --- a/tests/game.test.js +++ b/tests/game.test.js @@ -4,8 +4,8 @@ const { load, seed } = require('./harness'); test('daily DDoS spawns share one routing calculation and score their first active day', () => { const { ev, errors } = load(); - // The busier DDoS schedule needs spicy chaos (BGP at 3 a.m.) or gaming customers. - ev("ACT.start({});S.rules=makeRules('bgp');S.cash=1e9;S.day=50;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=200;ACT.buyTransit({city:'fra',net:'cog',tier:1});compute();window.__compute=compute;window.__random=Math.random;window.__computes=0;compute=()=>{window.__computes++;window.__compute()};Math.random=()=>0;dayTick();compute=window.__compute;Math.random=window.__random"); + // The busier daily DDoS schedule comes with gaming customers. + ev("ACT.start({});S.biz=[{type:'game',id:'g',name:'G',city:'fra',bw:1,rate:1,reqs:[]}];S.cash=1e9;S.day=50;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=200;ACT.buyTransit({city:'fra',net:'cog',tier:1});compute();window.__compute=compute;window.__random=Math.random;window.__computes=0;compute=()=>{window.__computes++;window.__compute()};Math.random=()=>0;dayTick();compute=window.__compute;Math.random=window.__random"); assert.equal(ev('ddosAll().length'), 2, 'both daily spawn opportunities were used'); assert.equal(ev('window.__computes'), 1, 'daily spawns do not reroute the whole network individually'); assert.ok(ev('ddosAll().every(a=>a.worst===ddosSf(a))'), 'first-day service is recorded after routing'); @@ -209,7 +209,7 @@ test('Flowspec is a router-model capability, and each tool answers a flood', () test('a distributed SYN flood reports actual Flowspec drops and sends only the remainder to scrubbing', () => { const { ev, errors } = load(); - ev("ACT.start({});S.scrubs=[{city:'fra',tier:0}];S.scrubMode='always';S.ev.ddos={id:'syn',city:'fra',vec:'syn',gbps:30.2,start:0,until:7,entries:[{k:'edge',city:'fra',share:1}]};compute()"); + ev("ACT.start({});S.scrubs=[{city:'fra',tier:0}];S.scrubMode='always';S.ev.ddos={id:'syn',city:'fra',vec:'syn',gbps:30.2,start:0,until:7,entry:{k:'edge',lab:''}};compute()"); assert.equal(ev('ddosReport(S.ev.ddos).flowspec'), 0); assert.equal(ev('ddosReport(S.ev.ddos).sp.parts[0].cleaned'), 30.2); assert.match(ev('ddosPanel()'), /— No Flowspec filtering: ingress routers have no TCAM/); @@ -230,29 +230,22 @@ test('a distributed SYN flood reports actual Flowspec drops and sends only the r assert.deepEqual(errors, []); }); -test('Flowspec accounts for each ingress router, upstream cleaning and other edge filters separately', () => { +test('Flowspec, upstream cleaning and other edge filters are each accounted for separately', () => { const { ev, errors } = load(); - ev("ACT.start({});S.cash=1e9;S.lvl=6;ACT.buildPop({city:'nyc'});S.pops.nyc.rgen=3;S.transit=[{id:'tf',city:'fra',net:'cog',tier:1},{id:'tn',city:'nyc',net:'cog',tier:1}];S.scrubs=[{city:'fra',tier:0},{city:'nyc',tier:0}];S.ev.ddos={id:'syn',city:'fra',vec:'syn',gbps:30.2,start:0,until:7,entries:[{k:'t',id:'tf',city:'fra',share:0.5},{k:'t',id:'tn',city:'nyc',share:0.5}]};compute()"); - assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-12.835)<1e-9); - assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).sp.parts.reduce((n,x)=>n+x.cleaned,0)')-17.365)<1e-9); - assert.match(ev('ddosPanel()'), /~ Flowspec dropping: 12\.8 Gbps; some ingress routers have no TCAM/); - assert.match(ev('ddosPanel()'), /Scrubbing in Frankfurt: 15\.1 Gbps \/ 100G/); - assert.match(ev('ddosPanel()'), /Scrubbing in New York: 2\.3 Gbps \/ 100G/); - assert.equal(ev('ddosMitigation(S.ev.ddos).flowspec'), ev('ddosReport(S.ev.ddos).flowspec'), 'uncached reports also filter at the ingress instead of the target'); - ev('S.transit[1].clean=true;compute()'); - assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).reaching')-16.61)<1e-9); - assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-1.2835)<1e-9); - assert.match(ev('ddosPanel()'), /✓ After upstream scrubbing: 16\.6 Gbps/); - assert.match(ev('ddosPanel()'), /~ Flowspec dropping: 1\.3 Gbps/); - ev("S.pops.fra.rgen=3;S.ixp={fra:1,nyc:1};S.ev.ddos.ixbh=true;compute()"); - assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-14.1185)<1e-9); - assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).filtered-ddosReport(S.ev.ddos).flowspec')-1.24575)<1e-9); - assert.match(ev('ddosPanel()'), /✓ Flowspec dropping: 14\.1 Gbps/); - assert.match(ev('ddosPanel()'), /✓ Edge filters dropping: 1\.2 Gbps/); + ev("ACT.start({});S.cash=1e9;S.lvl=6;S.pops.fra.rgen=1;S.transit=[{id:'tf',city:'fra',net:'cog',tier:1}];S.scrubs=[{city:'fra',tier:0}];S.ev.ddos={id:'syn',city:'fra',vec:'syn',gbps:30.2,start:0,until:7,entry:{k:'t',id:'tf'}};compute()"); + assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-18.12)<1e-9); + assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).sp.parts[0].cleaned')-12.08)<1e-9); + assert.match(ev('ddosPanel()'), /✓ Flowspec dropping: 18\.1 Gbps/); + ev('S.transit[0].clean=true;compute()'); + assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).reaching')-3.02)<1e-9, 'clean pipe leaves a tenth'); + assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-1.812)<1e-9); + assert.match(ev('ddosPanel()'), /✓ After upstream scrubbing: 3\.0 Gbps/); + ev("S.ixp={fra:1};S.ev.ddos.ixbh=true;compute()"); + assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).filtered-ddosReport(S.ev.ddos).flowspec')-0.604)<1e-9); + assert.match(ev('ddosPanel()'), /✓ Edge filters dropping: 0\.6 Gbps/); assert.ok(ev('Math.abs(ddosReport(S.ev.ddos).reaching-ddosReport(S.ev.ddos).filtered-ddosReport(S.ev.ddos).sp.parts.reduce((n,x)=>n+x.cleaned,0)-ddosReport(S.ev.ddos).leak)<1e-9')); assert.deepEqual(errors, []); }); - test('RTBH blackholes the victim, and HackBack 3000 is a gamble', () => { const { ev } = load(); ev("ACT.start({});S.cash=1e8;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=120;ACT.buyTransit({city:'fra',net:'cog',tier:1});compute()"); @@ -793,8 +786,8 @@ test('DDoS frequency rises with level and signed gaming customers, with a rollin assert.ok(base < early && early < level && level < gaming && gaming <= 7); ev("S.offers=Array.from({length:50},()=>({type:'game'}));S.biz=[];S.lvl=1"); assert.equal(ev('ddosRate()'), base, 'unsigned offers do not attract attacks'); - // Force every random spawn opportunity (with spicy chaos on), then verify each rolling seven-day window. - ev("S.rules=makeRules('bgp');"); + // Force every random spawn opportunity (gamers on board), then verify each rolling seven-day window. + ev("S.biz=[{type:'game',city:'fra'}];"); ev('window.__starts=[];window.__oldRandom=Math.random;Math.random=()=>0'); for (let day = 50; day < 66; day++) { ev(`S.day=${day};ddosTick();window.__starts.push(...ddosAll().filter(a=>a.start===S.day).map(a=>a.start))`); @@ -832,39 +825,6 @@ test('DDoS sizes use a smaller non-gaming baseline and preserve unbounded Flood assert.deepEqual(errors, []); }); -test('distributed attacks follow normal transit and peering traffic across regions', () => { - const { ev, errors } = load(); - ev("ACT.start({});S.cash=1e9;S.lvl=6;ACT.buildPop({city:'nyc'});for(const c of ['fra','nyc']){S.pops[c].rgen=3;S.pops[c].bb={d:c==='fra'?100:300}}S.transit=[{id:'tf',city:'fra',net:'cog',tier:2},{id:'tn',city:'nyc',net:'cog',tier:2}];S.pni=[{id:'pf',city:'fra',net:'ggl',tier:1}];S.ixp={nyc:1};S.rs={nyc:true};compute();window.__normal=JSON.stringify(R.ingressPorts);ddosAttack()"); - const normal = JSON.parse(ev('window.__normal')); - const entries = JSON.parse(ev('JSON.stringify(ddosAll()[0].entries)')); - const total = Object.values(normal).reduce((n,p)=>n+p.traffic,0); - assert.ok(entries.some(p=>p.k==='t') && entries.some(p=>p.k==='p') && entries.some(p=>p.k==='ix')); - assert.deepEqual([...new Set(entries.map(p=>p.city))].sort(), ['fra','nyc']); - for (const en of entries) assert.ok(Math.abs(en.share-normal[en.k+':'+en.id].traffic/total)<1e-9); - assert.ok(Math.abs(entries.reduce((n,en)=>n+en.share,0)-1)<1e-9); - assert.match(ev('ddosPanel()'), /Live attack:/); - assert.doesNotMatch(ev('ddosPanel()'), /ports: .*regions:/, 'keep regional detail out of the live attack card'); - ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()'); - assert.equal(ev('S.ev.ddos.entries.length'), entries.length, 'distributed shares survive a save round trip'); - assert.deepEqual(errors, []); -}); - -test('distributed ingress applies upstream scrubbing only to its own port and uses regional centers', () => { - const { ev, errors } = load(); - ev("ACT.start({});S.cash=1e9;S.lvl=6;ACT.buildPop({city:'nyc'});for(const c of ['fra','nyc']){S.pops[c].rgen=3;S.pops[c].bb={d:100}}S.transit=[{id:'tf',city:'fra',net:'cog',tier:2,clean:true},{id:'tn',city:'nyc',net:'cog',tier:2}];S.scrubs=[{city:'fra',tier:0}];S.ev.ddos={id:'spread',city:'fra',vec:'http',gbps:1000,start:0,until:7,entries:[{k:'t',id:'tf',city:'fra',share:0.25},{k:'t',id:'tn',city:'nyc',share:0.75}]};compute()"); - assert.equal(ev('ddosReport(S.ev.ddos).reaching'), 775); - assert.equal(ev('ddosReport(S.ev.ddos).leak'), 750); - assert.equal(ev('R.useT.tn'), 400, 'the uncleaned flood fills its own ingress port'); - assert.ok(ev('R.useT.tf') < 200, 'it cannot spill into the cleaned port'); - assert.match(ev('ddosPanel()'), /✓ After upstream scrubbing: 775 Gbps/); - assert.match(ev('ddosPanel()'), /~ 750 Gbps is leaking through/); - ev("S.scrubs.push({city:'nyc',tier:1});compute()"); - assert.equal(ev('ddosReport(S.ev.ddos).leak'), 0); - assert.match(ev('ddosPanel()'), /✓ Scrubbing in Frankfurt: 25\.0 Gbps \/ 100G/); - assert.match(ev('ddosPanel()'), /✓ Scrubbing in New York: 750 Gbps \/ 1T/); - assert.deepEqual(errors, []); -}); - test('scrubbing hauls retain their real source on each link when several cities use one center', () => { const { ev, errors, dom } = load(); ev(`ACT.start({});S.cash=1e9;S.lvl=6;for(const c of ['prg','ber'])ACT.buildPop({city:c}); @@ -875,8 +835,8 @@ test('scrubbing hauls retain their real source on each link when several cities {id:'pb',a:'prg',b:'ber',kind:'wave',tier:2,km:280,mo:100}]; S.transit=[{id:'tp',city:'prg',net:'cog',tier:2},{id:'tb',city:'ber',net:'cog',tier:2}]; S.scrubs=[{city:'fra',tier:1}]; - S.ev.ddos={id:'spread',city:'ber',vec:'ack',gbps:100,start:0,until:7, - entries:[{k:'t',id:'tp',city:'prg',share:.5},{k:'t',id:'tb',city:'ber',share:.5}]};compute()`); + S.ev.ddos={id:'b',city:'ber',vec:'ack',gbps:50,start:0,until:7,entry:{k:'t',id:'tb'}}; + S.ev.ddosMore=[{id:'p',city:'prg',vec:'ack',gbps:50,start:0,until:7,entry:{k:'t',id:'tp'}}];compute()`); const sources = id => JSON.parse(ev(`JSON.stringify(Object.entries(R.ef[edgeKey(S.links.find(l=>l.id==='${id}'))].eg) .filter(([key])=>key.startsWith('scrub:')).map(([key,g])=>({city:R.egDesc[key].city,g})).sort((a,b)=>a.city.localeCompare(b.city)))`)); assert.equal(ev('R.load.pb||0'), 0, 'Berlin does not feed the Prague link'); @@ -892,8 +852,8 @@ test('scrubbing hauls retain their real source on each link when several cities assert.deepEqual(JSON.parse(ev('JSON.stringify([...UI.feed])')), ['prg'], 'the map highlights the same source as the inspected link'); row.querySelector('[data-act="goEgress"]').click(); assert.equal(ev('UI.sel.id'), 'prg', 'Open goes to the actual source city'); - // Reordering ingress and adding an overlapping flood must not change the attribution. - ev("S.ev.ddos.entries.reverse();S.ev.ddosMore=[{...S.ev.ddos,id:'overlap',gbps:20,entries:S.ev.ddos.entries.slice().reverse()}];compute()"); + // Swapping the attacks' order and adding an overlapping flood must not change the attribution. + ev("S.ev.ddosMore.push(S.ev.ddos,{...S.ev.ddos,id:'overlap',gbps:20});S.ev.ddos=S.ev.ddosMore.shift();compute()"); assert.deepEqual(sources('fp1').map(x=>x.city), ['prg']); assert.deepEqual(sources('fb').map(x=>x.city), ['ber']); // When Berlin's direct link fails, its haul really does join Prague's route. @@ -914,29 +874,9 @@ function setupScrubLatency(ev) { S.transit=[{id:'tf',city:'fra',net:'cog',tier:2},{id:'tn',city:'nyc',net:'cog',tier:2}]; S.scrubs=[{city:'fra',tier:0},{city:'par',tier:0}]; S.ev.ddos={id:'par-flood',city:'par',vec:'dns',gbps:33.8,start:0,until:7, - entries:[{k:'t',id:'tf',city:'fra',share:0.65},{k:'t',id:'tn',city:'nyc',share:0.35}]};compute()`); + entry:{k:'edge',lab:''}};compute()`); } -test('distributed ingress does not give a locally protected victim a remote scrubbing latency', () => { - const { ev, errors, dom } = load(); - setupScrubLatency(ev); - assert.ok(ev("R.haul.some(q=>q.city==='nyc'&&q.to==='par'&&q.ms>60)"), 'the remote ingress still travels to its scrubbing center'); - assert.equal(ev('ddosReport(S.ev.ddos).sp.parts.length'), 2, 'both centers clean the distributed flood'); - assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-20.28)<1e-9); - assert.equal(ev('ddosReport(S.ev.ddos).leak'), 0); - Object.defineProperty(dom.window, 'innerWidth', { value: 360, configurable: true }); - ev("UI.left='noc';UI.leftOpen=true;renderLeft()"); - const text = dom.window.document.getElementById('left').textContent; - assert.match(text, /Live attack: Paris/); - assert.match(text, /Scrubbing in Frankfurt: 8\.8 Gbps/); - assert.match(text, /Scrubbing in Paris: 4\.7 Gbps/); - assert.doesNotMatch(text, /Scrubbing traffic hauled over your backbone|\+\d+(\.\d+)? ms/); - // A local center is still nearest when it is full and other centers take overflow. - ev("S.ev.ddos.vec='ack';S.ev.ddos.gbps=300;compute()"); - assert.doesNotMatch(ev('ddosOne(S.ev.ddos)'), /Scrubbing traffic hauled over your backbone/); - assert.deepEqual(errors, []); -}); - test('each attack shows only the nearest scrubbing detour using precise one-way link latency', () => { const { ev, errors } = load(); setupScrubLatency(ev); @@ -946,11 +886,11 @@ test('each attack shows only the nearest scrubbing detour using precise one-way assert.equal((card.match(/Scrubbing traffic hauled over your backbone/g)||[]).length, 1); assert.match(card, /✓ Scrubbing traffic hauled over your backbone: Paris → Frankfurt \(\+3\.1 ms\)/); // An overlapping attack has its own victim and nearest center. - ev("S.ev.ddosMore=[{id:'other',city:'ams',vec:'ack',gbps:10,start:0,until:7,entries:[{k:'t',id:'tn',city:'nyc',share:1}]}];compute()"); + ev("S.ev.ddosMore=[{id:'other',city:'ams',vec:'ack',gbps:10,start:0,until:7,entry:{k:'edge',lab:''}}];compute()"); assert.doesNotMatch(ev('ddosOne(S.ev.ddosMore[0])'), /Scrubbing traffic hauled over your backbone/); assert.match(ev('ddosOne(S.ev.ddos)'), /Paris → Frankfurt \(\+3\.1 ms\)/); // Ignore a failed nearby center and use the live path to Amsterdam. - ev("S.pops.fra.down=10;S.links.push({id:'pa',a:'par',b:'ams',kind:'wave',tier:3,km:2000,mo:100});S.ev.ddos.entries=[{k:'edge',city:'par',share:1}];compute()"); + ev("S.pops.fra.down=10;S.links.push({id:'pa',a:'par',b:'ams',kind:'wave',tier:3,km:2000,mo:100});compute()"); assert.match(ev('ddosOne(S.ev.ddos)'), /Paris → Amsterdam \(\+13\.0 ms\)/); ev('S.ev.ddos.bh=true;compute()'); assert.doesNotMatch(ev('ddosOne(S.ev.ddos)'), /Scrubbing traffic hauled over your backbone/); @@ -970,17 +910,6 @@ test('a constrained remote haul leaves scrubbing capacity for the next overlappi assert.deepEqual(errors, []); }); -test('distributed attack statistics survive an ingress outage and corrupted saved shares', () => { - const { ev, errors } = load(); - ev("ACT.start({});S.cash=1e9;S.lvl=6;ACT.buildPop({city:'nyc'});S.ev.ddos={id:'spread',city:'fra',vec:'http',gbps:1000,start:0,until:7,entries:[{k:'t',id:'a',city:'fra',share:0.25},{k:'t',id:'b',city:'nyc',share:0.75}]};S.pops.nyc.down=5;compute()"); - assert.equal(ev('ddosReport(S.ev.ddos).reaching'), 1000); - assert.equal(ev('ddosReport(S.ev.ddos).leak'), 1000); - ev("S.ev.ddos.entries.push({k:'t',id:'bad',city:'unknown',share:5},{k:'t',id:'bad2',city:'fra',share:-1});S=migrate(JSON.parse(JSON.stringify(S)));compute()"); - assert.equal(ev('S.ev.ddos.entries.length'), 2); - assert.equal(ev('S.ev.ddos.entries.reduce((n,en)=>n+en.share,0)'), 1); - assert.deepEqual(errors, []); -}); - test('RackNet and TeamSpooked require signed gaming customers, bypass Flowspec, and stay within a third of the current size range', () => { const { ev, errors } = load(); ev("ACT.start({});S.cash=1e9;S.lvl=13;S.pops.fra.bb={d:150000};ACT.buyTransit({city:'fra',net:'cog',tier:2});compute()"); @@ -1004,7 +933,7 @@ test('RackNet and TeamSpooked require signed gaming customers, bypass Flowspec, assert.deepEqual(errors, []); }); -test('normal DDoS starts average half an attack per week without gaming and never exceed a seven-per-week expected rate', () => { +test('gamers\' DDoS starts rise gradually from half an attack per week and never exceed a seven-per-week expected rate', () => { const { ev, errors } = load(); ev("ACT.start({});S.rules=makeRules('bgp');S.day=50"); const checks = JSON.parse(ev(` @@ -1020,9 +949,9 @@ test('normal DDoS starts average half an attack per week without gaming and neve JSON.stringify(out) `)); for(const row of checks){ + if(row.games===0){assert.equal(row.observed,0,'without gamers attacks stay on the failure schedule');continue;} assert.ok(Math.abs(row.observed-row.expected)<=0.0011, JSON.stringify(row)); - if(row.games===0)assert.equal(row.observed,0.5); - else assert.ok(row.expected>0.5&&row.expected<=7); + assert.ok(row.expected>0.5&&row.expected<=7); } assert.ok(checks[3].expected>checks[2].expected, 'level increases gaming frequency'); assert.ok(checks[4].expected>checks[3].expected, 'more gaming customers increase frequency'); @@ -1116,7 +1045,7 @@ test('Flood Season retains its existing size quantiles and escalation when norma assert.deepEqual(errors, []); }); -test('the busier DDoS schedule needs spicy chaos or gaming customers; otherwise attacks come as before', () => { +test('the busier DDoS schedule needs gaming customers; otherwise attacks come with the other incidents', () => { const { ev, errors } = load(); ev("ACT.start({});S.cash=1e9;S.day=50;S.lvl=13;S.biz=[];S.nextFail=1e9;S.nextEvent=1e9"); const ticks = () => ev("(()=>{const old=Math.random,oa=ddosAttack;let n=0;ddosAttack=()=>{n++};Math.random=()=>0;try{for(let i=0;i<30;i++)ddosTick();}finally{Math.random=old;ddosAttack=oa;}return n;})()"); @@ -1127,14 +1056,15 @@ test('the busier DDoS schedule needs spicy chaos or gaming customers; otherwise ev("S.biz=[{type:'game',city:'fra',bw:5,rate:1,reqs:[]}]"); assert.ok(ticks() > 0, 'gaming customers bring their own attacks'); ev("S.biz=[];S.rules=makeRules('bgp')"); - assert.ok(ticks() > 0, 'spicy chaos brings more attacks'); + assert.equal(ticks(), 0, 'spicy chaos alone has no daily schedule: it doubles the incident one'); ev("S.rules=makeRules('freeze')"); assert.equal(ticks(), 0, 'Change Freeze has no attacks on either schedule'); ev("S.biz=[{type:'game',city:'fra',bw:5,rate:1,reqs:[]}]"); assert.equal(ticks(), 0, 'not even with gamers'); assert.ok(ev("(()=>{const old=Math.random;try{for(let i=0;i<200;i++){const r=i/200;Math.random=()=>r;S.ev.ddos=null;S.ev.ddosMore=[];S.ddosStarts=[];fireFailure();if(ddosAll().length)return false;}return true;}finally{Math.random=old;S.inc=[];}})()"), 'and fireFailure never rolls one'); - ev("S.rules=makeRules('bgp');S.biz=[]"); - assert.ok(ev("(()=>{const old=Math.random;try{for(let i=0;i<200;i++){const r=i/200;Math.random=()=>r;S.ev.ddos=null;S.ev.ddosMore=[];S.ddosStarts=[];fireFailure();if(ddosAll().length)return false;}return true;}finally{Math.random=old;S.inc=[];}})()"), 'spicy attacks come from their own schedule only, never twice'); + ev("S.rules=makeRules('oncall');S.biz=[{type:'game',city:'fra',bw:5,rate:1,reqs:[]}]"); + assert.ok(ev("(()=>{const old=Math.random;try{for(let i=0;i<200;i++){const r=i/200;Math.random=()=>r;S.ev.ddos=null;S.ev.ddosMore=[];S.ddosStarts=[];fireFailure();if(ddosAll().length)return false;}return true;}finally{Math.random=old;S.inc=[];}})()"), 'gamers\' attacks come from their own schedule only, never twice'); + ev("S.biz=[]"); ev("S.rules=makeRules('oncall')"); // Flood Season, not spicy: one flood at a time, 3 to 7 days apart, however old the scenario is. ev("ACT.startScn({id:'flood',sure:1});S.biz=[]"); diff --git a/tests/helpers/reference-allocation.js b/tests/helpers/reference-allocation.js index 00da767..a69d199 100644 --- a/tests/helpers/reference-allocation.js +++ b/tests/helpers/reference-allocation.js @@ -5,8 +5,8 @@ module.exports = ` for(f of flows){ 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.usede.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 Date: Thu, 29 Oct 2026 07:01:18 +0100 Subject: [PATCH 08/12] Saves get the rules of their mode, whatever their rules say sanitize() trusted any preset and override in a save, so an edited or imported save could run a Normal game on puzzle rules (no clock, ever), On-call with infinite money and open gates, sandbox powers without the sandbox tag, or a scenario off On-call. Rules now follow the mode: scenarios and the weekly are On-call, a sandbox keeps only its chaos, a Normal game one of the three Normal presets unchanged. --- src/game/80-simulation/50-sanitize.js | 7 +++-- tests/rules-locked.test.js | 45 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/rules-locked.test.js diff --git a/src/game/80-simulation/50-sanitize.js b/src/game/80-simulation/50-sanitize.js index 44e8205..bdb268a 100644 --- a/src/game/80-simulation/50-sanitize.js +++ b/src/game/80-simulation/50-sanitize.js @@ -77,8 +77,11 @@ function sanitize(s){ for(const k of Object.keys(s.ach))s.ach[k]=num(s.ach[k],0); {const p=s.achP&&typeof s.achP==='object'&&!Array.isArray(s.achP)?s.achP:{};s.achP={};for(const k of Object.keys(s.ach))s.achP[k]=BVAR[p[k]]?p[k]:'oncall';} if(s.merged){const o={};if(typeof s.merged==='object')for(const m of MERGERS)if(isFinite(s.merged[m.id]))o[m.id]=+s.merged[m.id];s.merged=Object.keys(o).length?o:undefined;} - // The rules (2.0): a save without them is the classic game, On-call (or a sandbox or puzzle, if it was one). Locked after the start. - {const r=s.rules&&typeof s.rules==='object'&&!Array.isArray(s.rules)?s.rules:{},p=s.mode==='sandbox'?'sandbox':s.mode==='puzzle'?'puzzle':own(PRESETS,r.preset)?r.preset:'oncall';s.rules=makeRules(p,own(PRESETS,r.preset)?r:{});} + /* The rules (2.0) follow from the mode, as the doors set them, and nothing else: a save without them is the classic + game, On-call. Scenarios and the weekly run on On-call; a sandbox keeps only its chaos; a Normal game one of the + three Normal presets, unchanged (its validated mods kept). So an edited or imported save cannot stop the clock or print money. */ + {const r=s.rules&&typeof s.rules==='object'&&!Array.isArray(s.rules)?s.rules:{}; + const m={mods:r.mods};s.rules=s.scn&&typeof s.scn==='object'?makeRules('oncall',m):s.mode==='sandbox'?makeRules('sandbox',{...m,chaos:r.chaos}):makeRules(NORMAL_PRESETS.includes(r.preset)?r.preset:'oncall',m);} if(s.te){if(typeof s.te!=='object')s.te=null;else{s.te.on=!!s.te.on;s.te.script=typeof s.te.script==='string'?s.te.script.slice(0,4000):'';}} return s;} function migrate(s){sanitize(s); diff --git a/tests/rules-locked.test.js b/tests/rules-locked.test.js new file mode 100644 index 0000000..61d3941 --- /dev/null +++ b/tests/rules-locked.test.js @@ -0,0 +1,45 @@ +// The rules follow from the mode when a save loads: an edited or imported save cannot change them (2.0). +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); + +test('a loaded save gets the rules of its mode, whatever its rules say', () => { + const { ev, errors } = load(); + ev("beginGame('T','fra',{mode:'normal'});if(UI.pendGame)ACT.pitchSkip()"); + const base = JSON.parse(ev('JSON.stringify(packSave(S))')); + const loadAs = (mut) => { const s = JSON.parse(JSON.stringify(base)); mut(s); ev(`S=migrate(JSON.parse(${JSON.stringify(JSON.stringify(s))}))`); return JSON.parse(ev('JSON.stringify(S.rules)')); }; + const preset = (p, o) => JSON.parse(ev(`JSON.stringify(makeRules('${p}'${o ? ',' + JSON.stringify(o) : ''}))`)); + // Normal games keep one of the three Normal presets, with nothing changed. + for (const p of ['freeze', 'oncall', 'bgp']) assert.deepEqual(loadAs(s => { s.rules = { preset: p }; }), preset(p)); + assert.deepEqual(loadAs(s => { s.rules = { preset: 'oncall', money: 'infinite', gates: 'open', chaos: 'none', lead: 'quick' }; }), preset('oncall'), 'no free money or open gates in On-call'); + assert.deepEqual(loadAs(s => { s.rules = { preset: 'freeze', clock: false }; }), preset('freeze'), 'the clock always runs'); + assert.deepEqual(loadAs(s => { s.rules = { preset: 'puzzle' }; }), preset('oncall'), 'no puzzle rules (clock off for ever) in a Normal game'); + assert.deepEqual(loadAs(s => { s.rules = { preset: 'sandbox' }; }), preset('oncall'), 'no sandbox powers without the sandbox tag'); + assert.deepEqual(loadAs(s => { delete s.rules; }), preset('oncall'), 'a save from before 2.0 is On-call'); + // Sandboxes keep only their chaos. + assert.deepEqual(loadAs(s => { s.mode = 'sandbox'; s.rules = { preset: 'sandbox', chaos: 'spicy', clock: false, money: 'normal' }; }), preset('sandbox', { chaos: 'spicy' })); + assert.deepEqual(loadAs(s => { s.mode = 'sandbox'; s.rules = { preset: 'bgp' }; }), preset('sandbox')); + // Scenarios and the weekly run on On-call. + const scn = { id: 'pac', rules: {}, days: 1095, name: 'x', mods: [] }; + for (const r of [{ preset: 'bgp' }, { preset: 'oncall', chaos: 'none' }, { preset: 'sandbox' }, { preset: 'freeze' }]) + assert.deepEqual(loadAs(s => { s.mode = 'scenario'; s.scn = scn; s.rules = r; }), preset('oncall'), JSON.stringify(r)); + assert.deepEqual(loadAs(s => { s.mode = 'scenario'; s.scn = { ...scn, id: 'weekly', key: '2026-W44' }; s.rules = { preset: 'freeze' }; }), preset('oncall'), 'the weekly too'); + assert.deepEqual(errors, []); +}); + +test('a save that claims to be a puzzle loads as a Normal On-call game with the clock running', () => { + const { ev, errors } = load(); + ev("beginGame('T','fra',{mode:'normal'});if(UI.pendGame)ACT.pitchSkip()"); + const s = JSON.parse(ev('JSON.stringify(packSave(S))')); + s.mode = 'puzzle'; s.rules = { preset: 'puzzle' }; + ev(`S=migrate(JSON.parse(${JSON.stringify(JSON.stringify(s))}));UI.started=true;compute()`); + assert.equal(ev('S.mode'), 'normal'); + assert.equal(ev('pzOn()'), false); + assert.equal(ev("rule('clock')"), true); + ev('for(let i=0;i<3;i++)dayTick()'); + assert.equal(ev('S.day'), 3, 'days pass'); + ev(`UI.importing=JSON.parse(${JSON.stringify(JSON.stringify(s))});ACT.importGo()`); + assert.equal(ev('S.mode'), 'normal'); + assert.equal(ev('rulePreset()'), 'oncall'); + assert.deepEqual(errors, []); +}); From 1692217549f4f81697ed22a9a16c4c6163a7eeb3 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Thu, 29 Oct 2026 07:03:39 +0100 Subject: [PATCH 09/12] Flood Season attacker names come only from the game's own list An imported save could put raw HTML in an attack's attacker name, which reached the end-of-flood toast unescaped. sanitize() keeps only names from the list, and the toast escapes the name and city anyway. --- src/game/80-simulation/50-sanitize.js | 1 + src/game/85-incidents/20-failures.js | 2 +- tests/ddos-floods.test.js | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/game/80-simulation/50-sanitize.js b/src/game/80-simulation/50-sanitize.js index bdb268a..c5bc597 100644 --- a/src/game/80-simulation/50-sanitize.js +++ b/src/game/80-simulation/50-sanitize.js @@ -67,6 +67,7 @@ function sanitize(s){ const repairAttack=a=>{if(!a||typeof a!=='object'||!isCity(a.city)||!s.pops[a.city]||!own(DDOS_VEC,a.vec))return null; a.id=sid(a.id);a.gbps=Math.max(0,num(a.gbps,2));a.until=num(a.until,s.day);a.bh=!!a.bh;a.ixbh=!!a.ixbh;a.start=Math.max(0,Math.min(s.day,num(a.start,s.day)));a.until=Math.min(a.until,a.start+Math.ceil(7*SPICY_LONG)); delete a.entries; // 2.0 betas spread attacks over every ingress port; they arrive on one again + if(a.who!==undefined&&!FLOOD_WHO.includes(a.who))delete a.who; // a label from the list, never text from the file a.sla=Array.isArray(a.sla)?a.sla.filter(x=>typeof x==='string').slice(0,s.biz.length):[]; if(!a.entry||typeof a.entry!=='object'||!['t','ix','p','edge'].includes(a.entry.k))a.entry={k:'edge',lab:''};else{a.entry.lab=String(a.entry.lab||'').slice(0,60);a.entry.id=a.entry.id==null?undefined:String(a.entry.id).slice(0,40);}return a;}; const attacks=[s.ev.ddos,...(Array.isArray(s.ev.ddosMore)?s.ev.ddosMore:[])].map(repairAttack).filter(Boolean).slice(0,14); diff --git a/src/game/85-incidents/20-failures.js b/src/game/85-incidents/20-failures.js index d688fe6..33d4843 100644 --- a/src/game/85-incidents/20-failures.js +++ b/src/game/85-incidents/20-failures.js @@ -162,7 +162,7 @@ function ddosAttack(recompute=true){const type='ddos',fl=scnRule('ddos');ddosExp // When an attack is over: was it held? Held means the city under attack got at least 97% of its traffic every day. function ddosDone(a){if(!a||a.done)return;a.done=1;if(a.worst===undefined&&S.pops[a.city])a.worst=ddosSf(a);const ok=(a.worst===undefined?1:a.worst)>=0.97; if(ok){S.stats.ddosOk=(S.stats.ddosOk||0)+1;if(a.gbps>=1000)S.stats.ddosOkBig=(S.stats.ddosOkBig||0)+1;}else S.stats.ddosLost=(S.stats.ddosLost||0)+1; - if(scnRule('ddos')){const who=tr(a.who||FLOOD_WHO[0]);toast(ok?tr('failures.flood_held_g_who_gave_up',{g:fmtG(a.gbps),who:who.charAt(0).toUpperCase()+who.slice(1)}):tr('failures.that_one_got_through_g_city',{g:fmtG(a.gbps),city:CITY[a.city]?CITY[a.city].name:tr('common.your_network'),p:pct(a.worst||0),who}),ok?'goal':'bad');}} + if(scnRule('ddos')){const w=tr(FLOOD_WHO.includes(a.who)?a.who:FLOOD_WHO[0]),who=esc(w.charAt(0).toUpperCase()+w.slice(1));toast(ok?tr('failures.flood_held_g_who_gave_up',{g:fmtG(a.gbps),who}):tr('failures.that_one_got_through_g_city',{g:fmtG(a.gbps),city:esc(CITY[a.city]?CITY[a.city].name:tr('common.your_network')),p:pct(a.worst||0),who:esc(w)}),ok?'goal':'bad');}} // Flood Season: 3 to 7 days apart as before, shrinking with age, level and gamers only when attacks are spicy. const floodGap=()=>!ddosSpicy()?3+Math.floor(Math.random()*5):Math.max(0.05,(3+Math.random()*5)/(Math.sqrt(1+S.day/180)*(1+gamingCount()/10+Math.max(0,(S.lvl||1)-1)/12))); const FLOOD_WHO=[N_('failures.a_botnet_of_40_000_smart'),N_('failures.every_unpatched_baby_monitor_in'),N_('failures.a_gaming_clan_that_lost_one'),N_('failures.a_fridge_that_achieved_sentience_and'),N_('failures.a_crypto_bro_shorting_your_stock'),N_('failures.a_teenager_with_a_stolen_credit'),N_('failures.a_rival_isp_s_stress_test'),N_('failures.ten_thousand_smart_light_bulbs'),N_('failures.a_printer_just_one_printer_nobody'),N_('failures.a_botnet_run_from_a_cloud'),N_('failures.somebody_who_did_not_like_your'),N_('failures.the_internet_connected_kettles_of_a')]; diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index 98efc9f..d6b0d40 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -113,3 +113,13 @@ test('BGP at 3 a.m. brings about twice On-call\'s DDoS; gaming customers bring t const ratio = picks.bgp / picks.oncall; assert.ok(ratio > 1.7 && ratio < 2.3, `about twice the DDoS (${ratio.toFixed(2)}x)`); }); + +test('an imported save cannot put HTML in a Flood Season attacker\'s name', () => { + const { ev, dom, errors } = load({ seed: 5 }); + ev("ACT.startScn({id:'flood',sure:1});S.day=10;ddosAttack();S.ev.ddos.who='';S=migrate(JSON.parse(JSON.stringify(S)))"); + assert.equal(ev('S.ev.ddos.who'), undefined, 'only names from the list survive a load'); + ev('S.ev.ddos.who="";ddosDone(S.ev.ddos)'); + assert.equal(dom.window.document.getElementById('pwn'), null); + assert.equal(dom.window.document.getElementById('pwn2'), null, 'and the toast escapes it anyway'); + assert.deepEqual(errors, []); +}); From 4bb5e07c2847c7ae0e33c1043370e172c915e621 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Thu, 29 Oct 2026 07:04:45 +0100 Subject: [PATCH 10/12] The China licence follows quick lead times: about 5 days instead of 45 Change Freeze and Sandbox deliver everything in a tenth of the time, but the licence still took 45 days and the button said so. It now waits leadDays(45), and the button shows that number. --- site/i18n/de.js | 2 +- site/i18n/es.js | 2 +- site/i18n/fr.js | 2 +- site/i18n/it.js | 2 +- site/i18n/pt.js | 2 +- src/game/90-actions/80-security-and-china.js | 2 +- src/game/93-ui/70-link-panels.js | 2 +- src/i18n/en.js | 2 +- tests/ddos-floods.test.js | 11 +++++++++++ 9 files changed, 19 insertions(+), 8 deletions(-) diff --git a/site/i18n/de.js b/site/i18n/de.js index 47eb899..b710e76 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -2128,7 +2128,7 @@ "link_panels.add_parallel_link":"Parallelen Link hinzufügen", "link_panels.additional_traffic_lost":"Zusätzlich verlorener Traffic", "link_panels.an_alternate_path_exists_but_current":"Es gibt einen anderen Weg, aber mit dem jetzigen Routing und der Kapazität kommt weniger Traffic an.", -"link_panels.apply_for_a_license_price_mo":"Lizenz beantragen {price} + {mo}/Monat · ~45 Tage", +"link_panels.apply_for_a_license_price_mo_n_days":"Lizenz beantragen {price} + {mo}/Monat · ~{n} Tage", "link_panels.back_in_n_days":"Zurück in {n} Tagen.", "link_panels.behind_the_great_firewall":"Hinter der Großen Firewall", "link_panels.biggest_fabric_money_can_buy":"Die größte Fabric, die man für Geld kaufen kann.", diff --git a/site/i18n/es.js b/site/i18n/es.js index c5e8b29..e670864 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -2126,7 +2126,7 @@ "link_panels.add_parallel_link":"Añadir enlace paralelo", "link_panels.additional_traffic_lost":"Tráfico perdido adicional", "link_panels.an_alternate_path_exists_but_current":"Hay un camino alternativo, pero con el routing y la capacidad actuales llega menos tráfico.", -"link_panels.apply_for_a_license_price_mo":"Solicitar una licencia {price} + {mo}/mes · ~45 días", +"link_panels.apply_for_a_license_price_mo_n_days":"Solicitar una licencia {price} + {mo}/mes · ~{n} días", "link_panels.back_in_n_days":"De vuelta en {n} días.", "link_panels.behind_the_great_firewall":"Tras el Gran Cortafuegos", "link_panels.biggest_fabric_money_can_buy":"La fabric más grande que el dinero puede comprar.", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 30a346d..63f3195 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -2126,7 +2126,7 @@ "link_panels.add_parallel_link":"Ajouter un lien parallèle", "link_panels.additional_traffic_lost":"Trafic perdu en plus", "link_panels.an_alternate_path_exists_but_current":"Un autre chemin existe, mais avec le routage et la capacité actuels, moins de trafic arrive.", -"link_panels.apply_for_a_license_price_mo":"Demander une licence {price} + {mo}/mois · ~45 jours", +"link_panels.apply_for_a_license_price_mo_n_days":"Demander une licence {price} + {mo}/mois · ~{n} jours", "link_panels.back_in_n_days":"Retour dans {n} jours.", "link_panels.behind_the_great_firewall":"Derrière le Grand Pare-feu", "link_panels.biggest_fabric_money_can_buy":"Le plus gros fabric que l’argent puisse acheter.", diff --git a/site/i18n/it.js b/site/i18n/it.js index a4b5b11..c183fe3 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2126,7 +2126,7 @@ "link_panels.add_parallel_link":"Aggiungi link parallelo", "link_panels.additional_traffic_lost":"Ulteriore traffico perso", "link_panels.an_alternate_path_exists_but_current":"Esiste un percorso alternativo, ma con routing e capacità attuali viene consegnato meno traffico.", -"link_panels.apply_for_a_license_price_mo":"Richiedi una licenza {price} + {mo}/mese · ~45 giorni", +"link_panels.apply_for_a_license_price_mo_n_days":"Richiedi una licenza {price} + {mo}/mese · ~{n} giorni", "link_panels.back_in_n_days":"Torna tra {n} giorni.", "link_panels.behind_the_great_firewall":"Dietro il Great Firewall", "link_panels.biggest_fabric_money_can_buy":"Il fabric più grosso che si possa comprare.", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index 4ac6bb9..e5b091c 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -2126,7 +2126,7 @@ "link_panels.add_parallel_link":"Adicionar link paralelo", "link_panels.additional_traffic_lost":"Tráfego perdido a mais", "link_panels.an_alternate_path_exists_but_current":"Existe um caminho alternativo, mas com o roteamento e a capacidade atuais chega menos tráfego.", -"link_panels.apply_for_a_license_price_mo":"Pedir licença {price} + {mo}/mês · ~45 dias", +"link_panels.apply_for_a_license_price_mo_n_days":"Pedir licença {price} + {mo}/mês · ~{n} dias", "link_panels.back_in_n_days":"Volta em {n} dias.", "link_panels.behind_the_great_firewall":"Atrás do Great Firewall", "link_panels.biggest_fabric_money_can_buy":"O maior fabric que o dinheiro pode comprar.", diff --git a/src/game/90-actions/80-security-and-china.js b/src/game/90-actions/80-security-and-china.js index 3cba21f..b909a8c 100644 --- a/src/game/90-actions/80-security-and-china.js +++ b/src/game/90-actions/80-security-and-china.js @@ -1,5 +1,5 @@ Object.assign(ACT,{ - applyCn:()=>{if(S.cnLic.state!=='none')return;if(!spend(CN_LIC))return;S.cnLic={state:'pending',ready:S.day+45};toast(tr('security_and_china.application_filed_your_local_partner'),'goal');after();}, + applyCn:()=>{if(S.cnLic.state!=='none')return;if(!spend(CN_LIC))return;S.cnLic={state:'pending',ready:S.day+leadDays(45)};toast(tr('security_and_china.application_filed_your_local_partner'),'goal');after();}, togglePrem:({id})=>{const t=S.transit.find(x=>x.id===id);if(!t||!premCity(NET[t.net],t.city)||premOnlyAt(NET[t.net],t.city))return;t.premium=!t.premium;sfx('click');after();}, buildScrub:({city,tier})=>{if(!S.pops[city]||S.scrubs.some(x=>x.city===city))return;const T=SCRUB_TIERS[tier||0];if(!T)return;if((lvl()||1){const x=S.scrubs.find(q=>q.city===city);tier=+tier;if(!x||!SCRUB_TIERS[tier]||tier<=(x.tier||0))return;const T=SCRUB_TIERS[tier];if((lvl()||1)`;} function chinaSection(c){const st=S.cnLic?S.cnLic.state:'none',loss=S.ev.gfw>S.day?0.35:0.2; let h=`

${tr('link_panels.behind_the_great_firewall')}

${tr('link_panels.mainland_china_plays_by_its_own',{list:CN_BLOCKED.slice(0,4).map(esc).join(', '),pct:pct(loss)})}

`; - if(st==='none')h+=`

${tr('link_panels.foreign_networks_need_a_local_joint')}

${btn(tr('link_panels.apply_for_a_license_price_mo',{price:fmt$(CN_LIC),mo:fmt$(CN_JV_MO)}),'applyCn',{},'pink',S.cash${tr('link_panels.foreign_networks_need_a_local_joint')}

${btn(tr('link_panels.apply_for_a_license_price_mo_n_days',{price:fmt$(CN_LIC),mo:fmt$(CN_JV_MO),n:leadDays(45)}),'applyCn',{},'pink',S.cash${tr('link_panels.license_paperwork_in_progress_n_days',{n:Math.max(0,S.cnLic.ready-S.day)})}

`; else h+=`

${tr('link_panels.your_joint_venture_holds_an')}

`; if(R.gfwCross>0.5)h+=`
${tr('link_panels.your_traffic_crossing_the_border')}${fmtG(R.gfwCross)}
${tr('link_panels.lost_on_the_way')}${fmtG(R.gfwLost)}
`; diff --git a/src/i18n/en.js b/src/i18n/en.js index 309e046..2b6cf52 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -2127,7 +2127,7 @@ "link_panels.add_parallel_link":"Add parallel link", "link_panels.additional_traffic_lost":"Additional traffic lost", "link_panels.an_alternate_path_exists_but_current":"An alternate path exists, but current routing and capacity deliver less traffic.", -"link_panels.apply_for_a_license_price_mo":"Apply for a license {price} + {mo}/mo · ~45 days", +"link_panels.apply_for_a_license_price_mo_n_days":"Apply for a license {price} + {mo}/mo · ~{n} days", "link_panels.back_in_n_days":"Back in {n} days.", "link_panels.behind_the_great_firewall":"Behind the Great Firewall", "link_panels.biggest_fabric_money_can_buy":"Biggest fabric money can buy.", diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index d6b0d40..4415ad9 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -123,3 +123,14 @@ test('an imported save cannot put HTML in a Flood Season attacker\'s name', () = assert.equal(dom.window.document.getElementById('pwn2'), null, 'and the toast escapes it anyway'); assert.deepEqual(errors, []); }); + +test('the China licence arrives in a tenth of the time with quick lead times, and the button says so', () => { + for (const [preset, days] of [['oncall', 45], ['freeze', 5]]) { + const { ev, errors } = load(); + ev(`beginGame('C','fra',{mode:'normal',preset:'${preset}'});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9`); + assert.match(ev("tr('link_panels.apply_for_a_license_price_mo_n_days',{price:'$1',mo:'$1',n:leadDays(45)})"), new RegExp(`~${days} days`)); + ev('ACT.applyCn()'); + assert.equal(ev('S.cnLic.ready-S.day'), days, preset); + assert.deepEqual(errors, []); + } +}); From 31e44440e8045f1199201cb12c2506c38611a300 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Thu, 29 Oct 2026 07:17:08 +0100 Subject: [PATCH 11/12] Flood Season escalates again, and empty POPs no longer hold floods for free Every flood was 700G or more from day 1, so the scenario no longer built up. Sizes are 1.36's again (a third terabit monsters, the rest ordinary floods sized to the city), growing by the year as #153 had it. Floods go for POPs that serve someone, and a city with nobody to serve only holds a flood its tools soak up. Seeded runs over a year: no defence or one 1T center cannot win; one 1T center with full Flowspec and clean pipe wins around day 100 (main needed two centers, day 164). --- CHANGELOG.md | 1 + .../85-incidents/10-incidents-and-ddos.js | 3 ++- src/game/85-incidents/20-failures.js | 25 +++++++++++-------- tests/ddos-floods.test.js | 19 ++++++++++++++ tests/game.test.js | 17 ++++++------- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebd3011..9e50d6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ All notable changes to this project are documented here. The project follows - Live attacks now show how much traffic Flowspec actually drops. Routers without TCAM no longer claim to filter attacks, and Flowspec drops are counted separately from other edge filters (#153). - Hosting game servers or cloud gaming brings RackNet and TeamSpooked attacks. Both bypass Flowspec and require dedicated mitigation (#153). - Flood Season keeps sending ever larger attacks when you keep playing after winning or running out of time. Finishing the challenge no longer switches the floods off (#153). +- Flood Season escalates again: ordinary floods mixed with terabit monsters, all growing through the year, and floods go for the POPs that serve customers, so empty POPs no longer hold them for free. - Each live attack in the NOC now shows incoming bandwidth, upstream scrubbing, edge filtering, scrubbing-center use and any traffic still leaking through (#153). - DDoS bandwidth now adds up: upstream scrubbing, edge filters and scrubbing centers work in sequence. The NOC uses the same figures as traffic routing, including floods that cannot reach a remote center (#153). - Attacks can now use Memcached amplification or an ACK flood. Flowspec catches the former; the latter need mitigation (#153). diff --git a/src/game/85-incidents/10-incidents-and-ddos.js b/src/game/85-incidents/10-incidents-and-ddos.js index a7a9624..a28a5dc 100644 --- a/src/game/85-incidents/10-incidents-and-ddos.js +++ b/src/game/85-incidents/10-incidents-and-ddos.js @@ -30,7 +30,8 @@ const ddosFind=id=>ddosAll().find(a=>id===undefined||a.id===id); function ddosDrop(a){const left=ddosAll(S,false).filter(x=>x!==a);S.ev.ddos=left[0]||null;S.ev.ddosMore=left.slice(1);} function ddosExpire(){for(const a of ddosAll(S,false))if(a.until<=S.day||!S.pops[a.city]){ddosDone(a);ddosDrop(a);}} // An attack is held or lost at its victim: the junk lands there, and other POPs' bad days are not the attacker's doing. -const ddosSf=a=>sfOf(R,a.city); +// A city with nobody to serve holds only if its tools soak up the flood (or there is nothing to judge but that). +const ddosSf=a=>((R.cityDem||{})[a.city]||0)>1e-6||!a.gbps?sfOf(R,a.city):clamp(1-ddosReport(a).leak/a.gbps,0,1); function ddosReport(a){return (R.ddos||[]).find(m=>m.attack===a)||ddosMitigation(a);} // Where the junk comes in: one of the city's live uplinks, or just "the edge" if it has none yet. function ddosEntry(c){const o=[]; diff --git a/src/game/85-incidents/20-failures.js b/src/game/85-incidents/20-failures.js index 33d4843..c7eaebf 100644 --- a/src/game/85-incidents/20-failures.js +++ b/src/game/85-incidents/20-failures.js @@ -120,18 +120,21 @@ const ddosVectors=()=>Object.keys(DDOS_VEC).filter(k=>!DDOS_VEC[k].gaming||gamin // Spread gaming exposure over dozens of customers, including the first, rather than switching baselines. const ddosRate=()=>0.5+6.5*(1-Math.exp(-gamingCount()/50*(1+Math.max(1,S.lvl||1)/LEVELS.length))); const ddosPressure=()=>1-Math.exp(-(.01+Math.max(0,(S.lvl||1)-1)/12+gamingCount()/10+(scnRule('ddos')?.2+S.day/365:0))); -// Normalize the vector mix so smaller gaming-only floods do not lower the advertised overall mean. -function ddosSizeMean(){const stage=Math.max(1,S.lvl||1)/LEVELS.length,games=gamingCount(),fl=scnRule('ddos'); - const base=Math.max(10,(R.demand||0)*4/3*stage,fl?1400:0); - if(fl)return base*(1+0.2*games/(games+10))*(1+S.day/365); +// Normalize the vector mix so smaller gaming-only floods do not lower the advertised overall mean (Flood Season sizes its own). +function ddosSizeMean(){const stage=Math.max(1,S.lvl||1)/LEVELS.length,games=gamingCount(); + const base=Math.max(10,(R.demand||0)*4/3*stage); // Relative to no gaming: 3x at one customer, 8x at 50, approaching the existing 12x balance. const mean=base*(games?1.2-0.9*Math.pow(4/9,(games-1)/49):0.1),vectors=ddosVectors(),weight=vectors.reduce((n,k)=>n+(DDOS_VEC[k].gaming?1/3:1),0)/vectors.length; return mean/weight;} // Normal rolls: 98% uniform 0.2–2, 2% uniform 8–12. Their mean is 1.278, so spikes do not inflate the balance. -const ddosSizeMax=()=>ddosSizeMean()*(scnRule('ddos')?1.5:12/1.278); -function ddosSize(vec){const fl=scnRule('ddos'),r=Math.random(),roll=fl?1/3+r*2/3:(r<.98?.2+1.8*r/.98:8+4*(r-.98)/.02)/12; - const raw=ddosSizeMax()*(DDOS_VEC[vec].gaming?1/3:1)*roll; - return fl?Math.max(2,Math.floor(raw)):Math.max(0.001,Math.floor(raw*1000)/1000);} +const ddosSizeMax=()=>ddosSizeMean()*12/1.278; +/* Flood Season (as in 1.36): a third are terabit monsters, the rest ordinary floods sized to the city; all of it grows + through the year, and on after it. One draw picks both, so fixed draws give fixed sizes. */ +function ddosSize(vec,c){const fl=scnRule('ddos'),r=Math.random(); + if(fl){const games=gamingCount(),grow=(1+S.day/365)*(1+0.2*games/(games+10))*(DDOS_VEC[vec].gaming?1/3:1); + const raw=r<1/3?800+2600*r*3:2+(r-1/3)*1.5*Math.max(18,((R.cityDem||{})[c]||0)*0.9);return Math.max(2,Math.floor(raw*grow));} + const roll=(r<.98?.2+1.8*r/.98:8+4*(r-.98)/.02)/12,raw=ddosSizeMax()*(DDOS_VEC[vec].gaming?1/3:1)*roll; + return Math.max(0.001,Math.floor(raw*1000)/1000);} // Calm (Change Freeze) and no chaos at all mean no attacks, gamers or not. const ddosOff=()=>{const c=rule('chaos');return c==='calm'||c==='none';}; // More frequent attacks are opt-in: the spicy chaos setting, or hosting gamers (who attract them in real life). @@ -145,8 +148,10 @@ function ddosTick(){if(ddosOff()&&!scnRule('ddos'))return;if(scnRule('ddos')){le // Size, duration and starts are randomized independently; overlapping floods never replace each other. function ddosAttack(recompute=true){const type='ddos',fl=scnRule('ddos');ddosExpire(); S.ddosStarts=(S.ddosStarts||[]).filter(d=>d>S.day-7&&d<=S.day);if(S.ddosStarts.length>=14||!Object.keys(S.pops).length)return;S.ddosStarts.push(S.day); - const c=pick(Object.keys(S.pops)),vec=pick(ddosVectors()),V=DDOS_VEC[vec]; - const gbps=ddosSize(vec); + // Flood Season goes for the POPs that serve someone, so empty ones cannot soak up floods for a free win. + const all=Object.keys(S.pops),served=fl?all.filter(x=>(R.cityDem||{})[x]>1e-6):[]; + const c=pick(served.length?served:all),vec=pick(ddosVectors()),V=DDOS_VEC[vec]; + const gbps=ddosSize(vec,c); const dur=1+Math.floor(Math.random()*(1+6*ddosPressure())),entry=ddosEntry(c); const a={id:uid(),city:c,vec,gbps,until:S.day+dur,entry,bh:false,start:S.day}; if(!S.ev.ddos)S.ev.ddos=a;else(S.ev.ddosMore||(S.ev.ddosMore=[])).push(a); diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index 4415ad9..dfabb02 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -134,3 +134,22 @@ test('the China licence arrives in a tenth of the time with quick lead times, an assert.deepEqual(errors, []); } }); + +test('Flood Season escalates from ordinary floods to monsters, and empty POPs or no customers do not hold floods for free', () => { + const { ev, errors } = load({ seed: 5 }); + ev("ACT.startScn({id:'flood',sure:1});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'ams'});ACT.buyTransit({city:'ams',net:NETS.find(n=>sellsAt(n,'ams')).id,tier:1});compute()"); + const sizes = JSON.parse(ev("const o=[];for(let i=0;i<60;i++){dayTick();for(const a of ddosAll())if(a.start===S.day)o.push(a.gbps);}JSON.stringify(o)")); + assert.ok(sizes.some(g => g < 100), `some ordinary floods early on (${sizes.join(' ')})`); + assert.ok(sizes.some(g => g >= 1000), 'and some terabit monsters'); + // Ten empty POPs: floods still go for Amsterdam, where the customers are. + ev("for(const c of ['lon','par','fra','mad','mil','vie','waw','sto','osl','hel'])ACT.buildPop({city:c});compute();S.ev.ddos=null;S.ev.ddosMore=[];S.ddosStarts=[]"); + ev("for(let i=0;i<10;i++){S.ddosStarts=[];ddosAttack(false);}"); + assert.deepEqual(JSON.parse(ev('JSON.stringify([...new Set(ddosAll().map(a=>a.city))])')), ['ams']); + // A flood on a city with nobody to serve only holds if the tools soak it up. + ev("S.ev.ddosMore=[];S.ev.ddos={id:'e',city:'lon',vec:'http',gbps:500,start:S.day,until:S.day+2,entry:{k:'edge',lab:''}};compute()"); + assert.equal(ev("R.cityDem.lon||0"), 0); + assert.ok(ev('ddosSf(S.ev.ddos)') < 0.97, 'unmitigated: not held'); + ev("S.scrubs=[{city:'lon',tier:1}];S.scrubMode='always';compute()"); + assert.equal(ev('ddosSf(S.ev.ddos)'), 1, 'scrubbed: held'); + assert.deepEqual(errors, []); +}); diff --git a/tests/game.test.js b/tests/game.test.js index 5102de3..13e085a 100644 --- a/tests/game.test.js +++ b/tests/game.test.js @@ -806,11 +806,7 @@ test('DDoS sizes use a smaller non-gaming baseline and preserve unbounded Flood const { ev, errors } = load(); ev('ACT.start({});S.lvl=13;R.demand=150000;S.biz=[]'); assert.equal(ev('ddosSizeMean()'), 20000); - ev("S.scn={id:'flood',rules:{ddos:true}};S.day=365"); - assert.equal(ev('ddosSizeMean()'), 400000); - ev('S.day=730'); - assert.equal(ev('ddosSizeMean()'), 600000, 'Flood Season keeps growing after completion'); - ev('S.scn=null;R.demand=300000'); + ev('R.demand=300000'); assert.equal(ev('ddosSizeMean()'), 40000, 'larger networks can draw still larger attacks'); ev('S.lvl=1'); const early = ev('ddosSizeMax()'); @@ -1034,13 +1030,14 @@ test('normal attack sizes cover a broad ordinary range and a two-percent large t assert.deepEqual(errors, []); }); -test('Flood Season retains its existing size quantiles and escalation when normal attacks gain rare spikes', () => { +test('Flood Season mixes terabit monsters with ordinary floods, and all of it grows through the year and after', () => { const { ev, errors } = load(); - ev("ACT.start({});S.scn={id:'flood',rules:{ddos:true}};S.lvl=3;S.biz=[];R.demand=1850"); - for (const [day,expected] of [[0,[700,1400,2099]],[365,[1400,2800,4199]],[730,[2100,4200,6299]]]) { + ev("ACT.start({});S.scn={id:'flood',rules:{ddos:true}};S.lvl=3;S.biz=[];R.cityDem={fra:100}"); + // One draw: below a third a monster (800 to 3,400G), above it an ordinary flood up to 90% of the city's traffic. + for (const [day,expected] of [[0,[800,3399,2,91]],[365,[1600,6799,4,183]],[730,[2400,10199,6,275]]]) { ev(`S.day=${day}`); - const actual = JSON.parse(ev("const old=Math.random;let sizes;try{sizes=[0,0.5,0.999999].map(r=>{Math.random=()=>r;return ddosSize('syn')})}finally{Math.random=old}JSON.stringify(sizes)")); - assert.deepEqual(actual, expected); + const actual = JSON.parse(ev("const old=Math.random;let sizes;try{sizes=[0,1/3-1e-9,1/3,0.999999].map(r=>{Math.random=()=>r;return ddosSize('syn','fra')})}finally{Math.random=old}JSON.stringify(sizes)")); + assert.deepEqual(actual, expected, `day ${day}`); } assert.deepEqual(errors, []); }); From c5142046ed2a2a04a2e3f8d7b98ca8df23341acf Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Thu, 29 Oct 2026 07:17:15 +0100 Subject: [PATCH 12/12] CHANGELOG: China licence lead time, locked rules and attacker names in saves --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e50d6c..dcb95df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ All notable changes to this project are documented here. The project follows - Hosting game servers or cloud gaming brings RackNet and TeamSpooked attacks. Both bypass Flowspec and require dedicated mitigation (#153). - Flood Season keeps sending ever larger attacks when you keep playing after winning or running out of time. Finishing the challenge no longer switches the floods off (#153). - Flood Season escalates again: ordinary floods mixed with terabit monsters, all growing through the year, and floods go for the POPs that serve customers, so empty POPs no longer hold them for free. +- The China licence follows quick lead times: about 5 days instead of 45 under Change Freeze and in Sandbox. +- Imported saves can no longer change a network's rules or slip HTML into a Flood Season attacker's name. - Each live attack in the NOC now shows incoming bandwidth, upstream scrubbing, edge filtering, scrubbing-center use and any traffic still leaking through (#153). - DDoS bandwidth now adds up: upstream scrubbing, edge filters and scrubbing centers work in sequence. The NOC uses the same figures as traffic routing, including floods that cannot reach a remote center (#153). - Attacks can now use Memcached amplification or an ACK flood. Flowspec catches the former; the latter need mitigation (#153).