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, []); });