Scrubbing tiers, clean-pipe, sacrificial PNI, IX blackhole, SLA (1.18.0)

Rounds out the DDoS toolbox. Scrubbing centers come in 100G/1T/10T tiers and
clean only up to their capacity; always-on or cheaper on-demand (which lags a
couple of days). A transit clean-pipe add-on scrubs a flood upstream before it
reaches you. A Chinese PNI can be marked sacrificial: a flood over it dies on
the small port instead of the core, at the cost of half its legit capacity. A
new IX-blackhole mitigation drops about half the junk while keeping the victim
up. Selling DDoS protection now carries an SLA penalty when a protected
customer still goes down. Italian and tests included.
This commit is contained in:
Frederic Jung 2026-10-25 07:02:17 +00:00
parent bc9d2baee1
commit a2ab478386
No known key found for this signature in database
6 changed files with 180 additions and 36 deletions

View file

@ -6,12 +6,29 @@ All notable changes to this project are documented here. The project follows
## [Unreleased]
## [1.18.0] — 2026-10-25
- Overland waves between continents (Europe to the Middle East and Asia) now cost
45× the normal price, about ten times the subsea route or more, as in real life.
Dark fiber pairs aren't sold on those routes at all (#40). Links you already
lease keep their price.
- No more limit of four cache boxes per CDN in a POP: each box takes a router
port, and free ports are now the only limit (#39).
- Scrubbing centers now come in tiers — 100G, 1T and 10T of clean bandwidth.
A center cleans an attack only up to its capacity; a bigger flood leaks the
rest past. Centers can run always-on, or cheaper on-demand, which takes a
couple of days to engage once an attack starts.
- Transit clean-pipe add-on. Turn it on for a transit port and the provider
scrubs a flood entering there before it ever reaches you, for a monthly fee
per port.
- Sacrificial PNI. Mark a Chinese PNI as a deliberate choke point: a flood
arriving over it dies on the small port instead of flooding your core, but
legitimate traffic across it runs at half capacity.
- IX blackhole. A new mitigation on the live attack panel: announce the
victim to the exchange and about half the members drop the junk — the
customer stays up, unlike a full RTBH.
- Selling DDoS protection now carries an SLA: if a protected customer's city
is hit and still goes down, you pay out an SLA credit and they get unhappy.
## [1.17.1] — 2026-10-25

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "seriesoftubes",
"version": "1.17.1",
"version": "1.18.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "seriesoftubes",
"version": "1.17.1",
"version": "1.18.0",
"devDependencies": {
"jsdom": "24.1.3"
},

View file

@ -1,6 +1,6 @@
{
"name": "seriesoftubes",
"version": "1.17.1",
"version": "1.18.0",
"description": "A cartoon browser game about building the internet.",
"private": true,
"license": "MIT",

View file

@ -929,7 +929,17 @@
"{size} · {vec}{entry} · {n}d left":"{size} · {vec}{entry} · {n}g rimasti",
"Blackholed: the junk is gone, and so is {city}. The attack got what it wanted.":"In buco nero: la spazzatura è sparita, e anche {city}. L’attacco ha ottenuto ciò che voleva.",
"Reaching your network: {g}":"Arriva alla tua rete: {g}",
"Scrubbing in {city} is cleaning it":"Lo scrubbing a {city} lo sta pulendo",
"On-demand scrubbing diverting, live in {n}d":"Scrubbing on-demand in deviazione, attivo tra {n}g",
"{tier} scrubbing in {city} is cleaning it":"Lo scrubbing {tier} a {city} lo sta pulendo",
"{tier} scrubbing is over capacity: {g} leaks past":"Lo scrubbing {tier} è oltre capacità: {g} passano comunque",
"{net} is scrubbing it upstream (clean-pipe)":"{net} lo sta ripulendo a monte (clean-pipe)",
"Contained on your sacrificial {net} PNI":"Contenuto sulla tua PNI sacrificale {net}",
"IX blackhole on ✓":"Blackhole IX attivo ✓",
"IX blackhole <small>~half honour it</small>":"Blackhole IX <small>~metà lo rispetta</small>",
"Clean-pipe on ✓":"Clean-pipe attivo ✓",
"+ Clean-pipe <small>{mo}/mo · scrubs DDoS upstream</small>":"+ Clean-pipe <small>{mo}/mese · ripulisce i DDoS a monte</small>",
"Sacrificial choke ✓":"Strozzatura sacrificale ✓",
"Make sacrificial <small>contains floods · ½ capacity</small>":"Rendi sacrificale <small>contiene i flood · ½ capacità</small>",
"No scrubbing center":"Nessun centro di scrubbing",
"Flowspec on your {model} is dropping {vec} at the edge":"Il Flowspec sul tuo {model} sta scartando {vec} all’edge",
"Flowspec on your {model} trims {vec}, but its TCAM is small":"Il Flowspec sul tuo {model} lima {vec}, ma la sua TCAM è piccola",
@ -938,7 +948,7 @@
"Stop blackholing":"Togli il buco nero",
"Blackhole the target (RTBH)":"Metti il bersaglio in buco nero (RTBH)",
"HackBack 3000™ <small>$20k</small>":"HackBack 3000™ <small>$20k</small>",
"RTBH is free and instant, but it drops everything to the victim, attack and customer alike. HackBack 3000™ by Skynot AI sometimes ends it, and sometimes flattens an innocent and earns you a fine.":"L’RTBH è gratis e immediato, ma scarta tutto ciò che va alla vittima: attacco e cliente insieme. HackBack 3000™ di Skynot AI a volte lo ferma, e a volte travolge un innocente e ti becca una multa.",
"RTBH is free and instant, but it drops everything to the victim, attack and customer alike. An IX blackhole keeps the customer up but only about half the members honour it. HackBack 3000™ by Skynot AI sometimes ends it, and sometimes flattens an innocent and earns you a fine.":"L’RTBH è gratis e immediato, ma scarta tutto ciò che va alla vittima: attacco e cliente insieme. Un blackhole IX tiene su il cliente ma solo circa metà dei membri lo rispetta. HackBack 3000™ di Skynot AI a volte lo ferma, e a volte travolge un innocente e ti becca una multa.",
"Flowspec-capable POPs":"POP con Flowspec",
"Flowspec drop rules live in router TCAM, so only capable routers filter known UDP floods (DNS, NTP, CLDAP, SYN) at the edge. The used Rusty has none, merchant-silicon and whitebox models do a little, the big chassis do it in full. Upgrade a POP’s router from its Infra tab.":"Le regole di scarto Flowspec vivono nella TCAM del router, quindi solo i router capaci filtrano i flood UDP noti (DNS, NTP, CLDAP, SYN) all’edge. La Rusty usata non ne ha, i modelli merchant-silicon e whitebox un po’, i grandi chassis in pieno. Aggiorna il router di un POP dalla sua scheda Infra.",
"<b>No attack to blackhole right now.</b>":"<b>Nessun attacco da mettere in buco nero adesso.</b>",
@ -1246,7 +1256,17 @@
"Now grab an IX port there for remote peering.":"Ora prendi lì una porta IX per il peering remoto.",
"<b>Fabric port in {city} is full.</b>":"<b>La porta fabric a {city} è piena.</b>",
"<b>Application filed.</b><br>Your local partner says about 45 days. Probably.":"<b>Domanda presentata.</b><br>Il tuo partner locale dice circa 45 giorni. Forse.",
"<b>Scrubbing center online in {city}.</b><br>DDoS attacks are now absorbed, and you can sell DDoS protection to businesses.":"<b>Scrubbing center attivo a {city}.</b><br>Ora gli attacchi DDoS vengono assorbiti, e puoi vendere protezione DDoS alle aziende.",
"<b>{tier} scrubbing unlocks at customer level {lv}.</b>":"<b>Lo scrubbing {tier} si sblocca al livello cliente {lv}.</b>",
"<b>{tier} scrubbing center online in {city}.</b><br>Attacks up to {g} are cleaned, and you can sell DDoS protection.":"<b>Centro di scrubbing {tier} attivo a {city}.</b><br>Gli attacchi fino a {g} vengono ripuliti, e puoi vendere protezione DDoS.",
"<b>Scrubbing upgraded to {tier}.</b>":"<b>Scrubbing aggiornato a {tier}.</b>",
"<b>Clean-pipe add-on enabled on {net}.</b><br>They scrub a flood before it reaches your port here, for {mo}/mo.":"<b>Add-on clean-pipe attivato su {net}.</b><br>Ripuliscono un flood prima che raggiunga la tua porta qui, per {mo}/mese.",
"<b>Clean-pipe add-on removed from {net}.</b>":"<b>Add-on clean-pipe rimosso da {net}.</b>",
"<b>{net} PNI is now a sacrificial choke point.</b><br>A flood from there dies on the small port instead of inside your network, but legit traffic over it runs at half capacity.":"<b>La PNI {net} è ora un punto di strozzatura sacrificale.</b><br>Un flood da lì muore sulla porta piccola invece che dentro la tua rete, ma il traffico legittimo ci passa a metà capacità.",
"<b>{net} PNI is back to normal.</b>":"<b>La PNI {net} è tornata normale.</b>",
"<b>No IX in {city} to announce a blackhole to.</b>":"<b>Nessun IX a {city} a cui annunciare un blackhole.</b>",
"<b>IX blackhole announced in {city}.</b><br>About half the members honour the /32 and drop the junk. The customer stays up.":"<b>Blackhole IX annunciato a {city}.</b><br>Circa metà dei membri rispetta il /32 e scarta la spazzatura. Il cliente resta online.",
"<b>IX blackhole withdrawn.</b>":"<b>Blackhole IX ritirato.</b>",
"<b>SLA breach: {name}.</b><br>The attack on {city} got through and your protected customer went down. You owe {pen} in SLA credits.":"<b>Violazione SLA: {name}.</b><br>L’attacco su {city} è passato e il tuo cliente protetto è andato giù. Devi {pen} in crediti SLA.",
"Router added":"Router aggiunto",
"<b>Unplug something first.</b><br>{used} ports are in use, and one router fewer only has {max}.":"<b>Prima stacca qualcosa.</b><br>Ci sono {used} porte in uso, e con un router in meno ne avresti solo {max}.",
"<b>The {model} won't fit.</b><br>{why}":"<b>Il {model} non ci sta.</b><br>{why}",
@ -1487,12 +1507,17 @@
"Power cuts are covered.":"I blackout sono coperti.",
"Install generator <small>{cost} + {mo}/mo</small>":"Installa generatore <small>{cost} + {mo}/mese</small>",
"DDoS scrubbing center":"Centro di scrubbing DDoS",
"Online here. Attack traffic anywhere on your network is cleaned before it hurts, and you can sell DDoS protection to businesses.":"Attivo qui. Il traffico d’attacco ovunque sulla tua rete viene ripulito prima che faccia danni, e puoi vendere protezione DDoS alle aziende.",
"Cleans attacks for your whole network, up to its clean-bandwidth capacity, and unlocks DDoS protection contracts. Clean traffic returns over GRE, which can re-open the MSS black hole.":"Ripulisce gli attacchi per tutta la tua rete, fino alla sua capacità di banda pulita, e sblocca i contratti di protezione DDoS. Il traffico pulito torna via GRE, che può riaprire il buco nero MSS.",
"On-demand (engages in {n}d)":"On-demand (si attiva tra {n}g)",
"Always-on":"Sempre attivo",
"Switch to always-on":"Passa a sempre attivo",
"Switch to on-demand <small>cheaper</small>":"Passa a on-demand <small>più economico</small>",
"Upgrade to {tier} <small>{cost}</small>":"Aggiorna a {tier} <small>{cost}</small>",
"Really shut it down?":"Spegnerlo davvero?",
"Shut down":"Spegni",
"You already run one in {city}.":"Ne hai già uno a {city}.",
"Absorbs DDoS attacks for your whole network and unlocks DDoS protection contracts for businesses.":"Assorbe gli attacchi DDoS per tutta la tua rete e sblocca i contratti di protezione DDoS per le aziende.",
"Build scrubbing center <small>{cost} + {mo}/mo</small>":"Costruisci centro di scrubbing <small>{cost} + {mo}/mese</small>",
"Cleans DDoS attacks for your whole network, up to its clean-bandwidth capacity, and unlocks DDoS protection contracts for businesses.":"Ripulisce gli attacchi DDoS per tutta la tua rete, fino alla sua capacità di banda pulita, e sblocca i contratti di protezione DDoS per le aziende.",
"Build {tier} <small>{cost} + {mo}/mo</small>":"Costruisci {tier} <small>{cost} + {mo}/mese</small>",
"Interconnection fabrics (NNI)":"Fabric di interconnessione (NNI)",
"Buy a port on a fabric, then order virtual circuits to your other POPs or to a remote IX. Fast and flexible, but you share their fabric.":"Compra una porta su un fabric, poi ordina circuiti virtuali verso gli altri tuoi POP o verso un IX remoto. Veloce e flessibile, ma condividi il loro fabric.",
"{port} port · {price}/mo":"Porta {port} · {price}/mese",

View file

@ -581,7 +581,14 @@ const SITE2_COST=45000,SITE2_MO=3000,TE_COST=60000,TE_MO=4000;
const SITE2_N=[tr('The Other Building'),tr('Campus B (the one with parking)'),tr('Across-the-River DC'),tr('The Annex'),tr('Suburban Mega-shed'),tr('The Cheaper One'),tr('Formerly a Shopping Mall'),tr('Bunker Two')];
const siteName=(c,s)=>s==='b'?SITE2_N[hstr(c)%SITE2_N.length]:CITY[c].dc;
const popCost=c=>POP_COST+(c&&CITY[c]&&CITY[c].ru?RU_BOX:0)+(c&&CITY[c]&&CITY[c].uae?UAE_LIC:0)+(c&&CITY[c]&&CITY[c].saudi?KSA_LIC:0);
const CN_LIC=150000, CN_JV_MO=6000, SCRUB_COST=60000, SCRUB_MO=5000;
const CN_LIC=150000, CN_JV_MO=6000;
// Scrubbing centers come in tiers by clean bandwidth. Always-on diverts instantly; on-demand is cheaper
// but takes a couple of days to engage. A clean-pipe add-on on a transit scrubs upstream, per port.
const SCRUB_TIERS=[{n:'100G',g:100,cost:60000,mo:5000,lvl:1},{n:'1T',g:1000,cost:180000,mo:15000,lvl:3},{n:'10T',g:10000,cost:500000,mo:40000,lvl:4}];
const SCRUB_DELAY=2, SLA_PEN=20000;
const scrubG=()=>SCRUB_TIERS[S.scrubTier||0].g;
const scrubMo=()=>Math.round(SCRUB_TIERS[S.scrubTier||0].mo*(S.scrubMode==='ondemand'?0.6:1));
const cleanMo=t=>Math.round(PORT[t.tier].g*(t.n||1)*5);
// DDoS has a shape now: a vector, a size and an entry point. A vector's `fs` is whether Flowspec can drop
// it at the edge — it catches the known volumetric UDP floods, but an application-layer HTTP flood sails
// through. Whether a POP can run Flowspec at all is a router-model property (`fs` on RG): the rules live in
@ -1383,7 +1390,7 @@ function scenarioModal(){const wk=weekly(),h=scnHof();let best=null;try{best=JSO
function newGame(name,home){
S={v:1,name,asn:200000+Math.floor(_rand()*15000),home,day:0,cash:START_CASH,
ltv:2,t1v:2,pops:{[home]:{day:0,bb:null,boost:0,down:0,routers:1,gen:false}},links:[],nni:[],transit:[],ixp:{},rs:{},peers:{},pni:[],caches:[],biz:[],offers:[],myIx:{},
done:{},inc:[],ev:{},priceMul:1,nextFail:45,nextEvent:40,usedNames:[],stats:{survived:0,incidents:0,peak:0},cnLic:{state:'none'},scrubAt:null,won:false,lost:false,neg:0,loans:[],loanOffers:[],loanStrikes:0};
done:{},inc:[],ev:{},priceMul:1,nextFail:45,nextEvent:40,usedNames:[],stats:{survived:0,incidents:0,peak:0},cnLic:{state:'none'},scrubAt:null,scrubTier:0,scrubMode:'always',won:false,lost:false,neg:0,loans:[],loanOffers:[],loanStrikes:0};
}
/* ================= HELPERS ================= */
@ -1586,7 +1593,7 @@ function compute(){
E.push({k:'t',prem:!!t.premium&&t.city==='hkg',pref:t.pref||'normal',lab:tr('{net} transit',{net:NET[t.net].name}),id:t.id,city:t.city,cap:Math.min(liveCap(PORT[t.tier].g,t.city,t.site,t.n)*lagF(t),TRX&&TRX.cap[t.net]!==undefined?TRX.cap[t.net]:Infinity),used:0,rank:3,ok:n=>!(depeer&&t.net==='cog'&&n==='ggl')&&n!==leak});}
for(const c in S.ixp){const ct=ixCity(c);if(!(popUp(ct)||remote.includes(ct))||(S.ev.ixdown&&S.ev.ixdown[c]>day)||!liveN(ct,(S.ixSite||{})[c],(S.ixn||{})[c]))continue;const set=ixSessions(c);R2.sessions+=set.size;
E.push({k:'ix',pref:(S.ixPref&&S.ixPref[c])||'normal',lab:tr('{ix} peering',{ix:ixName(c)}),id:c,city:ct,cap:ixCap(c),used:0,rank:2,ok:n=>set.has(n)});}
for(const p of S.pni){if(!popUp(p.city)||!liveN(p.city,p.site,p.n))continue;R2.sessions++;E.push({k:'p',pnc:!!NET[p.net].cn,pref:p.pref||'normal',lab:tr('PNI with {net}',{net:NET[p.net].name}),id:p.id,city:p.city,cap:liveCap(PORT[p.tier].g,p.city,p.site,p.n)*lagF(p),used:0,rank:1,ok:n=>n===p.net});}
for(const p of S.pni){if(!popUp(p.city)||!liveN(p.city,p.site,p.n))continue;R2.sessions++;E.push({k:'p',pnc:!!NET[p.net].cn,pref:p.pref||'normal',lab:tr('PNI with {net}',{net:NET[p.net].name}),id:p.id,city:p.city,cap:liveCap(PORT[p.tier].g,p.city,p.site,p.n)*lagF(p)*(p.sacrif?0.5:1),used:0,rank:1,ok:n=>n===p.net});}
for(const c of S.caches){if(!popUp(c.city)||siteDown(c.city,'a'))continue;E.push({k:'c',pref:'normal',lab:tr('{name} cache',{name:NET[c.net].cache.name}),id:c.id,city:c.city,cap:CACHE_CAP,used:0,rank:0,ok:n=>n===c.net});}
{const rp=ev.rpki&&ev.rpki.until>day?new Set(ev.rpki.nets):null;if(rp)for(const e of E){if(e.k==='c')continue;const o=e.ok;e.ok=n=>!rp.has(n)&&o(n);}}
for(const n of NETS){R2.reachable[n.id]=E.some(e=>e.rank>0&&e.ok(n.id));if(R2.reachable[n.id])R2.reach+=NSH[n.id];}
@ -1604,7 +1611,14 @@ function compute(){
const atk=ev.ddos&&ev.ddos.city===c&&ev.ddos.until>day?ev.ddos:null;
const rtbh=!!(atk&&atk.bh), edge=!!(atk&&TRX&&TRX.blackhole&&!rtbh);
let dd=0;
if(atk&&!rtbh){let mult=1;if(DDOS_VEC[atk.vec]&&DDOS_VEC[atk.vec].fs){const cap=fsAt(atk.city);if(cap)mult=Math.min(mult,FS_RES[cap]);}if(S.scrubAt)mult=Math.min(mult,0.15);if(edge)mult=0;dd=atk.gbps*mult;}
if(atk&&!rtbh){let mult=1;const en=atk.entry||{};
if(DDOS_VEC[atk.vec]&&DDOS_VEC[atk.vec].fs){const cap=fsAt(atk.city);if(cap)mult=Math.min(mult,FS_RES[cap]);}
mult=Math.min(mult,scrubMult(atk));
if(en.k==='t'){const t=S.transit.find(x=>x.id===en.id);if(t&&t.clean)mult=Math.min(mult,0.1);}
if(atk.ixbh&&hasIxAt(atk.city))mult=Math.min(mult,0.5);
if(edge)mult=0;
dd=atk.gbps*mult;
if(en.k==='p'){const p=S.pni.find(x=>x.id===en.id);if(p&&p.sacrif)dd=Math.min(dd,liveCap(PORT[p.tier].g,p.city,p.site,p.n)*0.9);}}
const bh=rtbh||edge;
if(dd>0)for(const n of NETS)flows.push({c,n:n.id,rem:dd*NSH[n.id],junk:true});
if(edge)R2.teBlack+=atk.gbps*0.15+d*0.1;if(rtbh)R2.teBlack+=atk.gbps+d;
@ -1704,12 +1718,12 @@ function compute(){
C.optical=S.links.filter(l=>l.kind==='df').reduce((a,l)=>a+(l.ready>S.day?0:ampCount(l.km)*AMP_MO+(l.regen|0)*REGEN_MO)+(l.spares?Math.round(150+(l.ch||[]).length*80):0),0);
C.links=S.links.reduce((a,l)=>a+(l.mo||0),0);
C.nni=(S.nni||[]).reduce((a,x)=>a+NNI[x.tier].mo,0);
C.transit=S.transit.reduce((a,t)=>{const q=p95(t,R2.useT[t.id]||0);R2.p95[t.id]=q;const n=t.n||1;return a+Math.max(q,PORT[t.tier].g*n*0.2)*NET[t.net].price*(t.premium&&t.city==='hkg'?NET[t.net].premium:1)*pm*regionMult(t.city)+PORT[t.tier].tmo*n;},0);
C.transit=S.transit.reduce((a,t)=>{const q=p95(t,R2.useT[t.id]||0);R2.p95[t.id]=q;const n=t.n||1;return a+Math.max(q,PORT[t.tier].g*n*0.2)*NET[t.net].price*(t.premium&&t.city==='hkg'?NET[t.net].premium:1)*pm*regionMult(t.city)+PORT[t.tier].tmo*n+(t.clean?cleanMo(t):0);},0);
C.ix=Object.keys(S.ixp).reduce((a,c)=>a+(S.myIx[c]?myFab(c).mo:ixPortMo(c,S.ixp[c])*((S.ixn||{})[c]||1)+dkAddonMo(c)),0);
C.pni=S.pni.reduce((a,p)=>a+PORT[p.tier].pni*(p.n||1)+(NET[p.net].pol==='paid'?NET[p.net].paidFee:0)+(NET[p.net].perG?Math.round(NET[p.net].perG*(R2.usePni[p.id]||0)):0),0);
C.caches=S.caches.length*CACHE_MO;
C.loans=(S.loans||[]).reduce((a,l)=>a+(BANKS[l.bank].equity?0:l.pay),0);
C.extras=(S.cnLic&&S.cnLic.state==='ok'?CN_JV_MO:0)+(S.scrubAt?SCRUB_MO:0)+Object.keys(S.pops).filter(ruCity).length*RU_BOX_MO+Object.values(S.pops).filter(p=>p.site2).length*SITE2_MO+(S.te?TE_MO:0);
C.extras=(S.cnLic&&S.cnLic.state==='ok'?CN_JV_MO:0)+(S.scrubAt?scrubMo():0)+Object.keys(S.pops).filter(ruCity).length*RU_BOX_MO+Object.values(S.pops).filter(p=>p.site2).length*SITE2_MO+(S.te?TE_MO:0);
V.eyeballs=0;V.business=0;V.ix=0;
for(const c in S.pops){const sf=sfOf(R2,c);V.eyeballs+=R2.cityEye[c]*sf*EYE_RATE*(CITY[c].arpu||1);}
for(const b of S.biz){const sf=BIZ_T[b.type].fiber?(fiberOk(b)?1:0):BIZ_T[b.type].l2?clamp((R2.l2[b.id]||0)/b.bw,0,1):sfOf(R2,b.city);V.business+=b.bw*b.rate*Math.min(1,sf/0.95);}
@ -1743,8 +1757,8 @@ function sanitize(s){
const tier=v=>int(v,0,PORT.length-1,0),lag=v=>int(v,1,LAG_MAX,1),sid=v=>String(v==null?uid():v).slice(0,40);
s.links=s.links.filter(l=>l&&isCity(l.a)&&isCity(l.b)&&l.a!==l.b).map(l=>{l.id=sid(l.id);l.km=num(l.km,kmBetween(l.a,l.b));l.mo=num(l.mo,0);l.cut=num(l.cut,0);if(l.kind!=='df'&&l.kind!=='vxc')l.kind='wave';if(l.kind==='wave')l.tier=int(l.tier,0,LT.length-1,0);if(l.cable&&!own(CAB,l.cable))l.cable=null;if(l.kind==='vxc'&&!own(VXC,l.vt))l.vt=0;if(l.kind==='df'){if(!own(DF_SYS,l.sys))l.sys='lite';l.ch=Array.isArray(l.ch)?l.ch.filter(o=>own(OPT,o)):[];l.ready=num(l.ready,0);l.regen=int(l.regen,0,REGEN_MAX,0);}const deg=v=>v&&typeof v==='object'?{until:num(v.until,0),f:Math.min(1,Math.max(0,num(v.f,1)))}:null;if(l.loss)l.loss=deg(l.loss);if(l.metric&&!own(MET,l.metric))l.metric='normal';return l;});
const degO=v=>v&&typeof v==='object'?{until:num(v.until,0),f:Math.min(1,Math.max(0,num(v.f,1)))}:null;
s.transit=s.transit.filter(t=>t&&isCity(t.city)&&isNet(t.net)).map(t=>(t.lacp=degO(t.lacp),t.site=['a','b','ab'].includes(t.site)?t.site:'a',t.id=sid(t.id),t.tier=tier(t.tier),t.n=lag(t.n),t.down=num(t.down,0),t));
s.pni=s.pni.filter(x=>x&&isCity(x.city)&&isNet(x.net)).map(x=>(x.lacp=degO(x.lacp),x.site=['a','b','ab'].includes(x.site)?x.site:'a',x.id=sid(x.id),x.tier=tier(x.tier),x.n=lag(x.n),x));
s.transit=s.transit.filter(t=>t&&isCity(t.city)&&isNet(t.net)).map(t=>(t.lacp=degO(t.lacp),t.site=['a','b','ab'].includes(t.site)?t.site:'a',t.id=sid(t.id),t.tier=tier(t.tier),t.n=lag(t.n),t.down=num(t.down,0),t.clean=!!t.clean,t));
s.pni=s.pni.filter(x=>x&&isCity(x.city)&&isNet(x.net)).map(x=>(x.lacp=degO(x.lacp),x.site=['a','b','ab'].includes(x.site)?x.site:'a',x.id=sid(x.id),x.tier=tier(x.tier),x.n=lag(x.n),x.sacrif=!!x.sacrif,x));
s.caches=s.caches.filter(x=>x&&isCity(x.city)&&isNet(x.net)&&NET[x.net].cache).map(x=>(x.id=sid(x.id),x));
for(const c of Object.keys(s.ixp)){if(!isIx(c))delete s.ixp[c];else s.ixp[c]=tier(s.ixp[c]);}
for(const k of ['rs','ixn','ixPref','ixSite'])for(const c of Object.keys(s[k]))if(!isIx(c))delete s[k][c];if(s.ixCut&&typeof s.ixCut==='object'){for(const c of Object.keys(s.ixCut))if(!isIx(c))delete s.ixCut[c];else s.ixCut[c]=Math.min(1,Math.max(0.6,num(s.ixCut[c],1)));}else delete s.ixCut;
@ -1758,10 +1772,11 @@ function sanitize(s){
s.loans=s.loans.filter(l=>l&&own(BANKS,l.bank));s.loanOffers=s.loanOffers.filter(l=>l&&own(BANKS,l.bank));
s.usedNames=s.usedNames.filter(x=>typeof x==='string');s.log=s.log.filter(e=>e&&typeof e.t==='string').slice(0,30);
if(s.scrubAt&&!isCity(s.scrubAt))s.scrubAt=null;
s.scrubTier=int(s.scrubTier,0,SCRUB_TIERS.length-1,0);s.scrubMode=s.scrubMode==='ondemand'?'ondemand':'always';
if(s.ev&&s.ev.ddos){const a=s.ev.ddos;
if(!a||typeof a!=='object'||!isCity(a.city)||!own(DDOS_VEC,a.vec))delete s.ev.ddos;
else{a.gbps=num(a.gbps,2);a.until=num(a.until,s.day);a.bh=!!a.bh;a.start=num(a.start,s.day);
if(!a.entry||typeof a.entry!=='object')a.entry={k:'edge',lab:''};else a.entry.lab=String(a.entry.lab||'').slice(0,60);}}
else{a.gbps=num(a.gbps,2);a.until=num(a.until,s.day);a.bh=!!a.bh;a.ixbh=!!a.ixbh;a.start=num(a.start,s.day);
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);}}}
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);for(const b of [...s.biz,...s.offers])if(Array.isArray(b.reqs))b.reqs=b.reqs.filter(k=>!REQS[k]||!REQS[k].can||(isCity(b.city)&&(!b.city2||isCity(b.city2))&&REQS[k].can(b)));if(s.ltv!==2){for(const l of s.links)if(l.kind==='wave'&&l.tier>=3)l.tier=Math.min(LT.length-1,l.tier+1);s.ltv=2;}if(s.dk){s.dk.m=s.dk.m||{};s.dk.add=s.dk.add||{};s.dk.ret=s.dk.ret||{};s.dk.retUsed=s.dk.retUsed||{};}s.hist=s.hist||[];s.loans=s.loans||[];s.loanOffers=s.loanOffers||[];s.loanStrikes=s.loanStrikes||0;for(const l of s.links||[])if(!l.kind)l.kind='wave';
@ -1925,32 +1940,49 @@ function lagsN(){const o=[];for(const t of S.transit)if((t.n||1)>=2&&!(t.down>S.
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:tr('{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.
function ddosEntry(c){const o=[];
for(const t of S.transit)if(t.city===c&&!(t.down>S.day))o.push({k:'t',lab:tr('{net} transit',{net:NET[t.net].name})});
for(const x of ixIdsIn(c))if(S.ixp[x]!==undefined)o.push({k:'ix',lab:tr('{ix} peering',{ix:ixName(x)})});
for(const p of S.pni)if(p.city===c)o.push({k:'p',lab:tr('PNI with {net}',{net:NET[p.net].name})});
for(const t of S.transit)if(t.city===c&&!(t.down>S.day))o.push({k:'t',id:t.id,lab:tr('{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('{ix} peering',{ix:ixName(x)})});
for(const p of S.pni)if(p.city===c)o.push({k:'p',id:p.id,lab:tr('PNI with {net}',{net:NET[p.net].name})});
return o.length?pick(o):{k:'edge',lab:''};}
// Flowspec capability of the router in a city: 0 none, 1 basic, 2 full. The flood is filtered where the
// victim POP's own router has the TCAM for it.
const fsAt=c=>{const p=S.pops[c];return p?(RG[p.rgen||0].fs||0):0;};
// Scrubbing residual for an attack: clean up to the center's capacity (to 15%), overflow leaks. On-demand
// does nothing for the first couple of days while traffic is being diverted.
function scrubEngaged(atk){return !!S.scrubAt&&(S.scrubMode==='always'||(S.day-(atk.start||S.day))>=SCRUB_DELAY);}
function scrubMult(atk){if(!scrubEngaged(atk))return 1;const cap=scrubG(),g=atk.gbps||0;if(g<=0)return 1;return g<=cap?0.15:(cap*0.15+(g-cap))/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(){
const a=S&&S.ev&&S.ev.ddos;if(!a||a.until<=S.day||!S.pops[a.city])return '';
const V=DDOS_VEC[a.vec]||{n:'?',fs:false},cap=fsAt(a.city),scrOn=!!S.scrubAt;
const fsRes=V.fs&&cap?FS_RES[cap]:1;
let mult=1;if(fsRes<1)mult=Math.min(mult,fsRes);if(scrOn)mult=Math.min(mult,0.15);
const land=a.bh?0:Math.round(a.gbps*mult),model=RG[(S.pops[a.city].rgen||0)].n;
const V=DDOS_VEC[a.vec]||{n:'?',fs:false},cap=fsAt(a.city),model=RG[(S.pops[a.city].rgen||0)].n,en=a.entry||{};
const cleanT=en.k==='t'?S.transit.find(x=>x.id===en.id):null, sacP=en.k==='p'?S.pni.find(x=>x.id===en.id):null;
let mult=1;
if(V.fs&&cap)mult=Math.min(mult,FS_RES[cap]);
mult=Math.min(mult,scrubMult(a));
if(cleanT&&cleanT.clean)mult=Math.min(mult,0.1);
if(a.ixbh&&hasIxAt(a.city))mult=Math.min(mult,0.5);
let land=a.bh?0:a.gbps*mult;
if(sacP&&sacP.sacrif)land=Math.min(land,liveCap(PORT[sacP.tier].g,sacP.city,sacP.site,sacP.n)*0.9);
land=Math.round(land);
const fsLine=!V.fs?'— '+tr('Flowspec cannot catch an {vec} (application layer)',{vec:esc(V.n)})
:cap>=2?'✓ '+tr('Flowspec on your {model} is dropping {vec} at the edge',{model:esc(model),vec:esc(V.n)})
:cap===1?'~ '+tr('Flowspec on your {model} trims {vec}, but its TCAM is small',{model:esc(model),vec:esc(V.n)})
:'— '+tr('Your {model} here has no Flowspec TCAM',{model:esc(model)});
const T=SCRUB_TIERS[S.scrubTier||0];
const scrLine=!S.scrubAt?'— '+tr('No scrubbing center')
:!scrubEngaged(a)?'… '+tr('On-demand scrubbing diverting, live in {n}d',{n:Math.max(1,SCRUB_DELAY-(S.day-(a.start||S.day)))})
:a.gbps<=T.g?'✓ '+tr('{tier} scrubbing in {city} is cleaning it',{tier:T.n,city:esc(CITY[S.scrubAt].name)})
:'~ '+tr('{tier} scrubbing is over capacity: {g} leaks past',{tier:T.n,g:fmtG(a.gbps-T.g)});
const entryLine=cleanT&&cleanT.clean?'✓ '+tr('{net} is scrubbing it upstream (clean-pipe)',{net:esc(NET[cleanT.net].name)})
:sacP&&sacP.sacrif?'✓ '+tr('Contained on your sacrificial {net} PNI',{net:esc(NET[sacP.net].name)}):'';
let h=`<div class="inc" style="background:#FFE2E6;border:1px solid #FF8A9A">
<div class="nm">🚨 ${tr('Live attack: {city}',{city:esc(CITY[a.city].name)})}</div>
<div class="meta">${tr('{size} · {vec}{entry} · {n}d left',{size:fmtG(a.gbps),vec:esc(V.n),entry:a.entry&&a.entry.lab?' · '+esc(a.entry.lab):'',n:a.until-S.day})}</div>
<div class="meta"><b>${a.bh?tr('Blackholed: the junk is gone, and so is {city}. The attack got what it wanted.',{city:esc(CITY[a.city].name)}):tr('Reaching your network: {g}',{g:fmtG(land)})}</b></div>
<div class="meta">${scrOn?'✓ '+tr('Scrubbing in {city} is cleaning it',{city:esc(CITY[S.scrubAt].name)}):'— '+tr('No scrubbing center')}</div>
<div class="meta">${fsLine}</div>
<div class="btns">${a.bh?btn(tr('Stop blackholing'),'unrtbh',{},'ghost sm'):btn(tr('Blackhole the target (RTBH)'),'rtbh',{},'red sm')}${btn(tr('HackBack 3000™ <small>$20k</small>'),'hackback',{},'sm',S.cash<20000)}</div>
<p class="meta">${tr('RTBH is free and instant, but it drops everything to the victim, attack and customer alike. HackBack 3000™ by Skynot AI sometimes ends it, and sometimes flattens an innocent and earns you a fine.')}</p></div>`;
<div class="meta">${scrLine}</div>
<div class="meta">${fsLine}</div>${entryLine?`\n <div class="meta">${entryLine}</div>`:''}
<div class="btns">${a.bh?btn(tr('Stop blackholing'),'unrtbh',{},'ghost sm'):btn(tr('Blackhole the target (RTBH)'),'rtbh',{},'red sm')}${hasIxAt(a.city)&&!a.bh?btn(a.ixbh?tr('IX blackhole on ✓'):tr('IX blackhole <small>~half honour it</small>'),'ixbh',{},a.ixbh?'green sm':'sm'):''}${btn(tr('HackBack 3000™ <small>$20k</small>'),'hackback',{},'sm',S.cash<20000)}</div>
<p class="meta">${tr('RTBH is free and instant, but it drops everything to the victim, attack and customer alike. An IX blackhole keeps the customer up but only about half the members honour it. HackBack 3000™ by Skynot AI sometimes ends it, and sometimes flattens an innocent and earns you a fine.')}</p></div>`;
return h;}
function fireFailure(){
const opts=[];
@ -2186,6 +2218,11 @@ function dayTick(){
for(const l of S.links){if(l.kind!=='df')continue;
if(l.ready===d){toast(`<b>${l.own?tr('Your fiber is finished: {a}–{b}',{a:CITY[l.a].name,b:CITY[l.b].name}):tr('Dark fiber handed over: {a}–{b}',{a:CITY[l.a].name,b:CITY[l.b].name})}</b><br>${(l.ch||[]).length?tr('Channels are lighting up now.'):tr('It is dark. Add optics to light it up.')}`,'goal',[{l:tr('Open'),act:'selLink',args:{id:l.id}}]);sfx('coin');}
if(l.own&&l.ready>d&&Math.random()<0.012){const extra=10+Math.floor(Math.random()*40);l.ready+=extra;toast(tr('<b>Construction delay: +{n} days</b><br>{why} ({a}–{b})',{n:extra,why:pick([tr('Archaeologists found a Roman bathhouse on your route.'),tr('A protected hamster species lives along the right-of-way.'),tr('The railway changed its mind about the easement.'),tr('The drilling crew hit a granite boulder the size of a bus.'),tr('A town council wants a public hearing. About the color of the manhole covers.'),tr('Somebody else’s gas main was exactly where the map said it was not.'),tr('The permit office lost your permit. And then the replacement.')]),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).
if(S.ev.ddos&&S.ev.ddos.until>d){const a=S.ev.ddos;
for(const b of S.biz)if(b.type==='scrub'&&b.city===a.city&&b.slaFor!==a.start&&sfOf(R,b.city)<0.85){
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('<b>SLA breach: {name}.</b><br>The attack on {city} got through and your protected customer went down. You owe {pen} in SLA credits.',{name:esc(b.name),city:CITY[a.city].name,pen:fmt$(SLA_PEN)}),'bad');sfx('err');}}
// businesses mood
for(const b of S.biz.slice()){if(eventTick(b,d))continue;const sf=bizSf(b),reachOk=BIZ_T[b.type].l2||BIZ_T[b.type].fiber||R.reach>0.99,scrubOk=b.type!=='scrub'||!!S.scrubAt,divOk=reqOk(b);
if(sf>=0.95&&reachOk&&scrubOk&&divOk)b.mood=Math.min(100,b.mood+2);
@ -2466,7 +2503,13 @@ const ACT={
goEgress:({city,k})=>{ACT.focusCity({city});UI.tab=k==='t'?'up':k==='l2'?'cust':'peer';renderPanel();},
applyCn:()=>{if(S.cnLic.state!=='none')return;if(!spend(CN_LIC))return;S.cnLic={state:'pending',ready:S.day+45};toast(tr('<b>Application filed.</b><br>Your local partner says about 45 days. Probably.'),'goal');after();},
togglePrem:({id})=>{const t=S.transit.find(x=>x.id===id);if(!t)return;t.premium=!t.premium;sfx('click');after();},
scrub:({city})=>{if(S.scrubAt){if(UI.confirm!=='scrub'){UI.confirm='scrub';renderAll();return;}S.scrubAt=null;UI.confirm=null;after();return;}if(!spend(SCRUB_COST))return;S.scrubAt=city;toast(tr('<b>Scrubbing center online in {city}.</b><br>DDoS attacks are now absorbed, and you can sell DDoS protection to businesses.',{city:CITY[city].name}),'good');after();},
buildScrub:({city,tier})=>{if(S.scrubAt)return;const T=SCRUB_TIERS[tier||0];if((lvl()||1)<T.lvl){toast(tr('<b>{tier} scrubbing unlocks at customer level {lv}.</b>',{tier:T.n,lv:T.lvl}),'bad');sfx('err');return;}if(!spend(T.cost))return;S.scrubAt=city;S.scrubTier=tier||0;S.scrubMode='always';toast(tr('<b>{tier} scrubbing center online in {city}.</b><br>Attacks up to {g} are cleaned, and you can sell DDoS protection.',{tier:T.n,city:CITY[city].name,g:fmtG(T.g)}),'good');after();},
scrubUp:({tier})=>{if(!S.scrubAt||tier<=(S.scrubTier||0))return;const T=SCRUB_TIERS[tier];if((lvl()||1)<T.lvl){toast(tr('<b>{tier} scrubbing unlocks at customer level {lv}.</b>',{tier:T.n,lv:T.lvl}),'bad');sfx('err');return;}if(!spend(Math.round(T.cost*0.6)))return;S.scrubTier=tier;toast(tr('<b>Scrubbing upgraded to {tier}.</b>',{tier:T.n}),'good');after();},
scrubMode:()=>{if(!S.scrubAt)return;S.scrubMode=S.scrubMode==='ondemand'?'always':'ondemand';sfx('click');after();},
rmScrub:()=>{if(!S.scrubAt)return;if(UI.confirm!=='scrub'){UI.confirm='scrub';renderAll();return;}S.scrubAt=null;S.scrubTier=0;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('<b>Clean-pipe add-on enabled on {net}.</b><br>They scrub a flood before it reaches your port here, for {mo}/mo.',{net:NET[t.net].name,mo:fmt$(cleanMo(t))}):tr('<b>Clean-pipe add-on removed from {net}.</b>',{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('<b>{net} PNI is now a sacrificial choke point.</b><br>A flood from there dies on the small port instead of inside your network, but legit traffic over it runs at half capacity.',{net:NET[p.net].name}):tr('<b>{net} PNI is back to normal.</b>',{net:NET[p.net].name}),p.sacrif?'good':'');after();},
ixbh:()=>{const a=S.ev.ddos;if(!a){toast(tr('<b>No attack to blackhole right now.</b>'),'');return;}if(!hasIxAt(a.city)){toast(tr('<b>No IX in {city} to announce a blackhole to.</b>',{city:CITY[a.city].name}),'bad');sfx('err');return;}a.ixbh=!a.ixbh;toast(a.ixbh?tr('<b>IX blackhole announced in {city}.</b><br>About half the members honour the /32 and drop the junk. The customer stays up.',{city:CITY[a.city].name}):tr('<b>IX blackhole withdrawn.</b>'),a.ixbh?'good':'');sfx('alert');after();},
rtbh:()=>{const a=S.ev.ddos;if(!a){toast(tr('<b>No attack to blackhole right now.</b>'),'');return;}a.bh=true;S.stats.rtbh=(S.stats.rtbh||0)+1;toast(tr('<b>RTBH announced.</b><br>You blackholed the target in {city}. The flood stops, and so does everyone there.',{city:CITY[a.city].name}),'bad');sfx('alert');after();},
unrtbh:()=>{const a=S.ev.ddos;if(!a||!a.bh)return;a.bh=false;toast(tr('<b>Blackhole withdrawn.</b><br>{city} is reachable again. Brace for the junk.',{city:CITY[a.city].name}),'');after();},
hackback:()=>{const a=S.ev.ddos;if(!a||a.until<=S.day){toast(tr('<b>Nothing to hack back right now.</b>'),'');return;}if(!spend(20000))return;S.stats.hackback=(S.stats.hackback||0)+1;
@ -2751,7 +2794,7 @@ function cityPanel(c){
h+=`<div class="row">${logo(n)}<div class="grow"><div class="nm">${esc(n.name)} <span class="tag ${n.type}">${TYPE_L[n.type]}</span></div><div class="meta">${tr('${price} per Gbps / month · billed on 95th percentile',{price:pr.toFixed(2)})}</div>`;
if(t){const u=R.useT[t.id]||0,cap=lagCap(PORT[t.tier].g,t.n),tdown=t.down>S.day;
h+=`<div class="kv"><span>${lagName(t.tier,t.n)}${tdown?' · <b style="color:var(--bad)">'+tr('OUTAGE')+'</b>':''}</span><b>${fmtG(u)}</b></div><div class="bar ${barCls(u/cap)}"><i style="width:${u/cap*100}%"></i></div>${prefCtl('t',t.id,t.pref)}${siteCtl('t',t.id,c,t.site)}${n.premium&&c==='hkg'?`<div class="btns">${btn(t.premium?tr('CN-Too premium on ✓'):tr('Switch to CN-Too premium <small>{x}× price · ~3% loss into China</small>',{x:n.premium}),'togglePrem',{id:t.id},t.premium?'green sm':'sm')}</div>`:''}${(()=>{const top=transitTop([t.id],4);return top.length?`<div class="ttop"><div class="meta"><b>${tr('Top destinations on this port')}</b></div>${top.map(([id,v])=>`<div class="meta">${esc(NET[id].name)} · ${fmtG(v)} · <i>${esc(offTransitHint(id,c))}</i></div>`).join('')}</div>`:'';})()}<div class="meta">${tr('95th pct {p95} · commit {commit} · bill {bill}/mo',{p95:fmtG(R.p95[t.id]||0),commit:fmtG(cap*.2),bill:fmt$(Math.max(R.p95[t.id]||0,PORT[t.tier].g*(t.n||1)*.2)*pr+PORT[t.tier].tmo*(t.n||1))})}</div>
<div class="btns">${PORT.map((P2,i)=>i>t.tier?btn((t.n||1)>1?tr('Upgrade all to {port} <small>{cost} + {mo}/mo</small>',{port:P2.n,cost:fmt$(P2.setup*(t.n||1)),mo:fmt$(P2.tmo*(t.n||1))}):tr('Upgrade {port} <small>{cost} + {mo}/mo</small>',{port:P2.n,cost:fmt$(P2.setup*(t.n||1)),mo:fmt$(P2.tmo*(t.n||1))}),'buyTransit',{city:c,net:n.id,tier:i},'sm',S.cash<P2.setup*(t.n||1)||!portOk(c,i)):'').join('')}${(t.n||1)<LAG_MAX?btn(tr('+ LAG member <small>{cost} + {mo}/mo</small>',{cost:fmt$(PORT[t.tier].setup),mo:fmt$(PORT[t.tier].tmo)}),'lagT',{id:t.id,d:1},'sm',S.cash<PORT[t.tier].setup||!portOk(c,t.tier)):''}${(t.n||1)>1?btn(tr('− member'),'lagT',{id:t.id,d:-1},'ghost sm'):''}${btn(UI.confirm===t.id?tr('Really cancel?'):tr('Cancel'),'cancelTransit',{id:t.id},'ghost sm')}</div>`;}
<div class="btns">${PORT.map((P2,i)=>i>t.tier?btn((t.n||1)>1?tr('Upgrade all to {port} <small>{cost} + {mo}/mo</small>',{port:P2.n,cost:fmt$(P2.setup*(t.n||1)),mo:fmt$(P2.tmo*(t.n||1))}):tr('Upgrade {port} <small>{cost} + {mo}/mo</small>',{port:P2.n,cost:fmt$(P2.setup*(t.n||1)),mo:fmt$(P2.tmo*(t.n||1))}),'buyTransit',{city:c,net:n.id,tier:i},'sm',S.cash<P2.setup*(t.n||1)||!portOk(c,i)):'').join('')}${(t.n||1)<LAG_MAX?btn(tr('+ LAG member <small>{cost} + {mo}/mo</small>',{cost:fmt$(PORT[t.tier].setup),mo:fmt$(PORT[t.tier].tmo)}),'lagT',{id:t.id,d:1},'sm',S.cash<PORT[t.tier].setup||!portOk(c,t.tier)):''}${(t.n||1)>1?btn(tr('− member'),'lagT',{id:t.id,d:-1},'ghost sm'):''}${btn(t.clean?tr('Clean-pipe on ✓'):tr('+ Clean-pipe <small>{mo}/mo · scrubs DDoS upstream</small>',{mo:fmt$(cleanMo(t))}),'cleanPipe',{id:t.id},t.clean?'green sm':'sm')}${btn(UI.confirm===t.id?tr('Really cancel?'):tr('Cancel'),'cancelTransit',{id:t.id},'ghost sm')}</div>`;}
else h+=`<div class="btns">${PORT.map((P2,i)=>btn(tr('{port} <small>{cost} + {mo}/mo</small>',{port:P2.n,cost:fmt$(P2.setup),mo:fmt$(P2.tmo)}),'buyTransit',{city:c,net:n.id,tier:i},'sm',S.cash<P2.setup||!portOk(c,i))).join('')}</div>`;
h+=`</div></div>`;}
h+=`</section>`;
@ -2762,7 +2805,7 @@ function cityPanel(c){
const here=NETS.filter(n=>n.pops.includes(c));
for(const n of here){const pn=S.pni.find(x=>x.city===c&&x.net===n.id),chk=peerOk(n.id,'pni',c);
h+=`<div class="row">${logo(n)}<div class="grow"><div class="nm">${esc(n.name)} <span class="tag ${n.pol}">${n.pol}</span></div>`;
if(pn){const u=R.usePni[pn.id]||0,cap=lagCap(PORT[pn.tier].g,pn.n);h+=`<div class="kv"><span>${(pn.n||1)>1?`${pn.n}×${PORT[pn.tier].n} LAG`:PORT[pn.tier].n} PNI</span><b>${fmtG(u)}</b></div><div class="bar ${barCls(u/cap)}"><i style="width:${u/cap*100}%"></i></div>${prefCtl('p',pn.id,pn.pref)}${siteCtl('p',pn.id,c,pn.site)}<div class="btns">${PORT.map((P2,i)=>i>pn.tier?btn((pn.n||1)>1?tr('Upgrade all to {port} <small>{cost}</small>',{port:P2.n,cost:fmt$((1500+P2.setup/2)*(pn.n||1))}):tr('Upgrade {port} <small>{cost}</small>',{port:P2.n,cost:fmt$((1500+P2.setup/2)*(pn.n||1))}),'pni',{city:c,net:n.id,tier:i},'sm',!portOk(c,i)||S.cash<(1500+P2.setup/2)*(pn.n||1)):'').join('')}${(pn.n||1)<LAG_MAX?btn(tr('+ LAG member <small>{cost} + {mo}/mo</small>',{cost:fmt$(1500+PORT[pn.tier].setup/2),mo:fmt$(PORT[pn.tier].pni)}),'lagP',{id:pn.id,d:1},'sm',S.cash<1500+PORT[pn.tier].setup/2):''}${(pn.n||1)>1?btn(tr('− member'),'lagP',{id:pn.id,d:-1},'ghost sm'):''}${btn(UI.confirm===pn.id?tr('Really remove?'):tr('Remove'),'cancelPni',{id:pn.id},'ghost sm')}</div>`;}
if(pn){const u=R.usePni[pn.id]||0,cap=lagCap(PORT[pn.tier].g,pn.n);h+=`<div class="kv"><span>${(pn.n||1)>1?`${pn.n}×${PORT[pn.tier].n} LAG`:PORT[pn.tier].n} PNI</span><b>${fmtG(u)}</b></div><div class="bar ${barCls(u/cap)}"><i style="width:${u/cap*100}%"></i></div>${prefCtl('p',pn.id,pn.pref)}${siteCtl('p',pn.id,c,pn.site)}<div class="btns">${PORT.map((P2,i)=>i>pn.tier?btn((pn.n||1)>1?tr('Upgrade all to {port} <small>{cost}</small>',{port:P2.n,cost:fmt$((1500+P2.setup/2)*(pn.n||1))}):tr('Upgrade {port} <small>{cost}</small>',{port:P2.n,cost:fmt$((1500+P2.setup/2)*(pn.n||1))}),'pni',{city:c,net:n.id,tier:i},'sm',!portOk(c,i)||S.cash<(1500+P2.setup/2)*(pn.n||1)):'').join('')}${(pn.n||1)<LAG_MAX?btn(tr('+ LAG member <small>{cost} + {mo}/mo</small>',{cost:fmt$(1500+PORT[pn.tier].setup/2),mo:fmt$(PORT[pn.tier].pni)}),'lagP',{id:pn.id,d:1},'sm',S.cash<1500+PORT[pn.tier].setup/2):''}${(pn.n||1)>1?btn(tr('− member'),'lagP',{id:pn.id,d:-1},'ghost sm'):''}${NET[n.id].cn?btn(pn.sacrif?tr('Sacrificial choke ✓'):tr('Make sacrificial <small>contains floods · ½ capacity</small>'),'sacrif',{id:pn.id},pn.sacrif?'green sm':'sm'):''}${btn(UI.confirm===pn.id?tr('Really remove?'):tr('Remove'),'cancelPni',{id:pn.id},'ghost sm')}</div>`;}
else{h+=chk.ok?`<div class="btns">${PORT.map((P2,i)=>btn(`${P2.n} <small>${fmt$(1500+P2.setup/2)}</small>`,'pni',{city:c,net:n.id,tier:i},'sm',S.cash<1500+P2.setup/2||!portOk(c,i))).join('')}</div>${chk.fee?`<div class="meta">${tr('Paid peering: {price}/mo on top',{price:fmt$(chk.fee)})}</div>`:''}`:`<div class="why">${esc(chk.why)}</div>`;}
h+=`</div></div>`;}
h+=`</section><section><h3>${tr('Embedded caches')}</h3><p class="lead">${tr('CDNs put free cache servers inside your POP. Most of their traffic is then served right here, with no transit and no IX port.')}</p>`;
@ -2788,7 +2831,15 @@ function cityPanel(c){
return `<p class="lead">${tr('Two buildings joined by your own metro ring. A power cut or cleaner in one leaves the other running at half capacity. Uplinks only work while their site is up, unless you split them: choose <b>Both</b> on a port to put LAG members in each building.')}</p>${row('a')}${row('b')}${up('b').length&&up('a').length?'':`<p class="why">${tr('Everything is in one building. Move some uplinks to the other site from the Transit and Peering tabs.')}</p>`}<div class="kv"><span>${tr('Second site and metro ring')}</span><b>${tr('{price}/mo',{price:fmt$(SITE2_MO)})}</b></div><div class="btns">${btn(UI.confirm==='site'+c?tr('Really close it?'):tr('Close site B'),'rmSite',{city:c},'ghost sm')}</div>`;})()
:`<p class="lead">${tr('Right now {city} is one building. A power cut, an A/C failure or a cleaner with a vacuum takes the whole city dark, and a second router does not help with that. A second data center across town, joined by your own metro ring, keeps half the POP up.',{city:esc(CITY[c].name)})}</p><div class="btns">${btn(tr('Add a second site <small>{cost} + {mo}/mo</small>',{cost:fmt$(SITE2_COST),mo:fmt$(SITE2_MO)}),'addSite',{city:c},'pink',S.cash<SITE2_COST)}</div>`}</section>
<section><h3>${tr('Power')}</h3><div class="kv"><span>${tr('Backup generator')}</span><b>${p.gen?tr('Installed'):tr('None')}</b></div>${p.gen?'<p class="note">'+tr('Power cuts are covered.')+'</p>':`<div class="btns">${btn(tr('Install generator <small>{cost} + {mo}/mo</small>',{cost:fmt$(GEN_COST),mo:fmt$(GEN_MO)}),'addGen',{city:c},'',S.cash<GEN_COST)}</div>`}</section>`;
h+=`<section><h3>${tr('DDoS scrubbing center')}</h3>${S.scrubAt===c?`<p class="lead">${tr('Online here. Attack traffic anywhere on your network is cleaned before it hurts, and you can sell DDoS protection to businesses.')}</p>${btn(UI.confirm==='scrub'?tr('Really shut it down?'):tr('Shut down'),'scrub',{city:c},'ghost sm')}`:S.scrubAt?`<p class="lead">${tr('You already run one in {city}.',{city:CITY[S.scrubAt].name})}</p>`:`<p class="lead">${tr('Absorbs DDoS attacks for your whole network and unlocks DDoS protection contracts for businesses.')}</p>${btn(tr('Build scrubbing center <small>{cost} + {mo}/mo</small>',{cost:fmt$(SCRUB_COST),mo:fmt$(SCRUB_MO)}),'scrub',{city:c},'',S.cash<SCRUB_COST)}`}</section>`;
h+=`<section><h3>${tr('DDoS scrubbing center')}</h3>`;
if(S.scrubAt===c){const T=SCRUB_TIERS[S.scrubTier||0];
h+=`<p class="lead">${tr('Cleans attacks for your whole network, up to its clean-bandwidth capacity, and unlocks DDoS protection contracts. Clean traffic returns over GRE, which can re-open the MSS black hole.')}</p>
<div class="kv"><span>${tr('Capacity')}</span><b>${T.n} · ${fmtG(T.g)}</b></div>
<div class="kv"><span>${tr('Mode')}</span><b>${S.scrubMode==='ondemand'?tr('On-demand (engages in {n}d)',{n:SCRUB_DELAY}):tr('Always-on')} · ${fmt$(scrubMo())}/mo</b></div>
<div class="btns">${btn(S.scrubMode==='ondemand'?tr('Switch to always-on'):tr('Switch to on-demand <small>cheaper</small>'),'scrubMode',{},'sm')}${SCRUB_TIERS.map((X,i)=>i>(S.scrubTier||0)?btn(tr('Upgrade to {tier} <small>{cost}</small>',{tier:X.n,cost:fmt$(Math.round(X.cost*0.6))}),'scrubUp',{tier:i},'sm',(lvl()||1)<X.lvl||S.cash<X.cost*0.6):'').join('')}${btn(UI.confirm==='scrub'?tr('Really shut it down?'):tr('Shut down'),'rmScrub',{},'ghost sm')}</div>`;}
else if(S.scrubAt)h+=`<p class="lead">${tr('You already run one in {city}.',{city:CITY[S.scrubAt].name})}</p>`;
else{h+=`<p class="lead">${tr('Cleans DDoS attacks for your whole network, up to its clean-bandwidth capacity, and unlocks DDoS protection contracts for businesses.')}</p><div class="btns">${SCRUB_TIERS.map((X,i)=>btn(tr('Build {tier} <small>{cost} + {mo}/mo</small>',{tier:X.n,cost:fmt$(X.cost),mo:fmt$(X.mo)}),'buildScrub',{city:c,tier:i},i===0?'':'sm',(lvl()||1)<X.lvl||S.cash<X.cost)).join('')}</div>`;}
h+=`</section>`;
const fabs=FABS.filter(f=>f.cities.includes(c));
if(fabs.length){h+=`<section><h3>${tr('Interconnection fabrics (NNI)')}</h3><p class="lead">${tr('Buy a port on a fabric, then order virtual circuits to your other POPs or to a remote IX. Fast and flexible, but you share their fabric.')}</p>`;
for(const f of fabs){const pt=nniPort(c,f.id),used=nniUsed(c,f.id);

View file

@ -191,8 +191,8 @@ test('Flowspec is a router-model capability, and each tool answers a flood', ()
// It cannot touch an application-layer HTTP flood, however big the TCAM.
const http = ev("RG[0].fs=2;S.ev.ddos.vec='http';compute();const s=R.served;RG[0].fs=0;s");
assert.ok(Math.abs(http - none) < 1, 'Flowspec is useless against HTTP');
// Scrubbing cleans any vector, regardless of router.
ev("S.ev.ddos.vec='dns';S.scrubAt='fra';compute()");
// Scrubbing cleans any vector, regardless of router. A 1T center swallows this 300 Gbps flood whole.
ev("S.ev.ddos.vec='dns';S.scrubAt='fra';S.scrubTier=1;S.scrubMode='always';compute()");
assert.ok(ev('R.served') > none, 'scrubbing recovers real traffic');
assert.deepEqual(errors, []);
});
@ -223,3 +223,54 @@ test('old saves load, and a stale flat DDoS object is repaired away', () => {
const kept = ev("const s=JSON.parse(JSON.stringify(S));s.ev={ddos:{city:'fra',vec:'dns',gbps:'80',until:9}};sanitize(s);JSON.stringify([s.ev.ddos&&s.ev.ddos.vec, s.ev.ddos&&s.ev.ddos.gbps])");
assert.deepEqual(JSON.parse(kept), ['dns', 80], 'a shaped attack is kept, numbers coerced');
});
test('scrubbing tiers: capacity caps what a center can clean, and on-demand lags', () => {
const { ev } = load();
ev("ACT.start({});S.cash=1e8;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=200;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.ev.ddos={city:'fra',vec:'dns',gbps:300,until:S.day+3,entry:{k:'t',lab:'x'},bh:false,start:S.day};compute()");
const none = ev('R.served');
// A 100G center cannot swallow a 300 Gbps flood; a 10T center can.
const small = ev("S.scrubAt='fra';S.scrubTier=0;S.scrubMode='always';compute();R.served");
const big = ev("S.scrubTier=2;compute();R.served");
assert.ok(big > small, 'a bigger scrubbing tier cleans more');
assert.ok(big > none, 'the 10T center recovers the flood');
// On-demand does nothing until it engages (SCRUB_DELAY days in).
const notYet = ev("S.scrubMode='ondemand';S.ev.ddos.start=S.day;compute();R.served");
const engaged = ev("S.ev.ddos.start=S.day-SCRUB_DELAY;compute();R.served");
assert.ok(engaged > notYet, 'on-demand scrubbing kicks in only after the delay');
});
test('clean-pipe on the entry transit, a sacrificial PNI, and an IX blackhole each blunt a flood', () => {
const { ev } = load();
ev("ACT.start({});S.cash=1e8;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=200;ACT.buyTransit({city:'fra',net:'cog',tier:1})");
const tid = ev("S.transit[0].id");
ev(`S.ev.ddos={city:'fra',vec:'dns',gbps:400,until:S.day+3,entry:{k:'t',id:'${tid}'},bh:false,start:S.day};compute()`);
const raw = ev('R.served');
// Clean-pipe on the transit the attack enters: the provider scrubs it upstream.
const clean = ev(`S.transit[0].clean=true;compute();const s=R.served;S.transit[0].clean=false;s`);
assert.ok(clean > raw, 'clean-pipe on the entry transit recovers traffic');
// A sacrificial CN PNI contains a flood entering over it (capped at the small port).
ev("S.pni.push({id:'pn1',city:'fra',net:'ctc',tier:1,n:1,site:'a',sacrif:true});S.ev.ddos.entry={k:'p',id:'pn1'}");
const contained = ev("compute();R.served");
const uncontained = ev("S.pni[0].sacrif=false;compute();const s=R.served;S.pni[0].sacrif=true;s");
assert.ok(contained > uncontained, 'a sacrificial PNI contains the flood');
// IX blackhole: ~half the junk gone, victim stays up. Shrink the flood so the drop shows in served.
ev("ACT.buyIx({city:'fra',tier:1,signed:true});S.ev.ddos.entry={k:'t',id:S.transit[0].id};S.ev.ddos.gbps=180");
const before = ev("compute();R.served");
ev("ACT.ixbh()");
assert.equal(ev('S.ev.ddos.ixbh'), true, 'blackhole announced');
assert.equal(ev('S.ev.ddos.bh'), false, 'the customer is not taken dark');
assert.ok(ev("compute();R.served") > before, 'the IX blackhole drops some junk');
});
test('SLA: a protected customer that still goes down costs an SLA credit, once', () => {
const { ev } = load();
ev("ACT.start({});S.cash=1e8;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=200;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.nextFail=1e9;S.nextEvent=1e9");
// A DDoS protection customer, an overwhelming flood, a 100G center that can't cope.
ev("S.scrubAt='fra';S.scrubTier=0;S.biz.push({id:'b1',city:'fra',type:'scrub',bw:5,rate:900,mood:80,since:0,reqs:[]});S.ev.ddos={city:'fra',vec:'dns',gbps:6000,until:S.day+5,entry:{k:'t',lab:'x'},bh:false,start:S.day}");
ev("dayTick()");
assert.equal(ev('S.stats.sla'), 1, 'one SLA breach recorded');
assert.ok(ev('S.biz[0].mood') < 70, 'the SLA breach dented their mood');
// The same attack does not bill twice.
ev("dayTick()");
assert.equal(ev('S.stats.sla'), 1, 'the same attack is only billed once');
});