Grow sideways in the late game: localised eyeball traffic, spread AI campuses, PNIs by router, spill tiers

Traffic to networks that sell to homes now starts where their users live (#48),
giant AI circuits come from campuses in 34 metros and less often from crowded
ones (#61), a PNI bundles eight members per router up to 32 (#323), and
RouteScript spill tiers move overflow onto detours within a latency budget (#136).
This commit is contained in:
Frederic Jung 2026-11-10 07:25:21 +00:00
parent 80baa970e7
commit 69cdb3e372
No known key found for this signature in database
29 changed files with 340 additions and 36 deletions

View file

@ -101,7 +101,7 @@ const API_CMD={
cancelPni:{args:[['id','entityId']],confirm:'arg',pass:a=>({id:a.id,ok:1}),
doc:'Cancel a PNI or its pending augment.'},
lagP:{args:[['id','entityId'],['d','step']],watch:['pni.#id'],
doc:'Add or remove a LAG member on a PNI. Adding is an augment with a lead time.'},
doc:'Add or remove a LAG member on a PNI, up to 8 per router at the POP (pniLagMax, at most PNI_LAG_MAX). Adding is an augment with a lead time.'},
sacrif:{args:[['id','entityId']],watch:['pni.#id'],
doc:'Mark a PNI sacrificial, so attack traffic is steered into it.'},
peerPol:{args:[['p','peerPolicy']],watch:['ppol'],

View file

@ -26,7 +26,7 @@ function apiJson(v){
carries the keys confGo/confSponsor need, which exist in no field of S; TE_RECIPES renders
each recipe's script, because the source is a function and some read the live network. The
recipes' relevance score is not exposed: judging which one fits is the agent's job. */
const API_TABLES={ROCKETS,CRUSTS,PIE_RD,PIE_SPAT_DEF,SALES,CITIES,NETS,CABLES,XIX,PORT,LT,NNI,VXC,RG,OPT,DF_SYS,FAB,SCRUB_TIERS,BIZ_T,LEVELS,GOALS,BROKER_GOALS,SCN,BANKS,REQS,NSH,MET,PREF,RT,PPOL,CONFS,LAG_MAX,RMAX,REGEN_MAX,START_CASH,CONF_COST,CONF_SP,CAP_COST,CAP_LV,CONF_DAYS,SUB_UPGRADES,SEA_DESIGNS,TE_COST,TE_MO,MYIX_COST,CN_LIC,SITE2_COST,MYIX_FAB,INTERNS,OPSK,CHARTERS,SEAT_N,CORE_LV,CORE_COST,CORE_REQ,CORE_LAB,INTERN_MO,PZ_TIERS,AR_TIERS,PZ_RG};
const API_TABLES={ROCKETS,CRUSTS,PIE_RD,PIE_SPAT_DEF,SALES,CITIES,NETS,CABLES,XIX,PORT,LT,NNI,VXC,RG,OPT,DF_SYS,FAB,SCRUB_TIERS,BIZ_T,LEVELS,GOALS,BROKER_GOALS,SCN,BANKS,REQS,NSH,MET,PREF,RT,PPOL,CONFS,LAG_MAX,PNI_LAG_MAX,PNI_LAG_RT,RMAX,REGEN_MAX,START_CASH,CONF_COST,CONF_SP,CAP_COST,CAP_LV,CONF_DAYS,SUB_UPGRADES,SEA_DESIGNS,TE_COST,TE_MO,MYIX_COST,CN_LIC,SITE2_COST,MYIX_FAB,INTERNS,OPSK,CHARTERS,SEAT_N,CORE_LV,CORE_COST,CORE_REQ,CORE_LAB,INTERN_MO,PZ_TIERS,AR_TIERS,PZ_RG};
const API_MADE={
BADGES:()=>!S?[]:BADGES.map(b=>{const on=S.ach&&S.ach[b.id]!==undefined,ever=!!hof()[b.id];
return b.secret&&!on&&!ever?{id:b.id,i:'❔',t:'???',d:tr('badges.a_secret_badge'),r:b.r,secret:true}:{...b,ever};}),

View file

@ -0,0 +1,26 @@
/* Where each network's users live (#48). A network that sells to homes lists its home markets (cc, see W2), and that is
where its eyeballs are. People mostly talk to people near them, so a POP's traffic to the networks that sell to homes
goes mostly to the ones at home: a New York POP sends a lot to Comecast and little to Doitsche Telekomm, Frankfurt
the other way round. Together those networks keep the share the city's table gives them; only how it splits between
them follows geography. Content and carriers without home markets are everywhere and keep their shares.
Routing is unchanged: traffic leaves at the nearest exit (hot potato), so an eyeball peered with in the cities its
users are in takes that traffic off your backbone where it starts, and one peered with in two cities has it hauled
there from everywhere else. */
const LOC_HOME=1,LOC_REG=0.3,LOC_FAR=0.08;
const LOC_NIX=new Map(NETS.map((n,j)=>[n.id,j]));
// Per network index: its home countries and the regions they are in, or null (no home market: everywhere).
let LOC_NET=null;
function locNets(){if(LOC_NET)return LOC_NET;const ccReg=new Map();
for(const c of CITIES){let s=ccReg.get(c.cc);if(!s)ccReg.set(c.cc,s=new Set());s.add(c.reg);}
LOC_NET=NETS.map(n=>{if(!n.cc)return null;const cc=new Set(Array.isArray(n.cc)?n.cc:[n.cc]),reg=new Set();for(const k of cc)for(const r of ccReg.get(k)||[])reg.add(r);return {cc,reg};});
return LOC_NET;}
// How near a city is to a network's users: at home, on the same continent, or far away.
const locW=(h,C)=>h.cc.has(C.cc)?LOC_HOME:h.reg.has(C.reg)?LOC_REG:LOC_FAR;
/* A city's shares in table T (by network index), localised. The tables and the map never change after load, so each
city's array is made once per table and kept. */
const LOC_SH=new Map();
function locSh(T,c){let m=LOC_SH.get(T);if(!m)LOC_SH.set(T,m=new Map());let a=m.get(c);if(a)return a;
const L=locNets(),C=CITY[c],NN=NETS.length;a=new Float64Array(NN);let g=0,gw=0;
for(let j=0;j<NN;j++){const s=T[NETS[j].id]||0;if(!s)continue;const h=L[j];if(!h){a[j]=s;continue;}const v=s*locW(h,C);g+=s;gw+=v;a[j]=v;}
if(gw>0){const f=g/gw;for(let j=0;j<NN;j++)if(L[j]&&a[j])a[j]*=f;}
m.set(c,a);return a;}

View file

@ -194,7 +194,7 @@ const OPS_RUN={
// Each port: cap() now, use today, lag() and ups() the jobs it could have as {cost, cap after, w for the log, go}, sig() to see a job took.
for(const p of S.pni){const c=p.city,use=(R.usePni[p.id]||0)*opsAhead(),cap=()=>lagCap(pniG(p),p.n),n=()=>p.n||1;if(!pniOn(p)||p.up||!(use>0)||cap()>=N*use||!opsHere('ports',c))continue;
L.push({city:c,at:c,use,u:use/cap(),cap,n,rt:(S.pops[c]||{}).routers||1,busy:()=>!!p.up,sig:()=>[p.tier,n(),!!p.g1,!!p.up].join(),
lag:()=>n()<LAG_MAX&&!msfNope(p.net,c)&&PORT_SLOT(p.tier)<=room(c)?{cost:1500+PORT[p.tier].setup/2,cap:lagCap(pniG(p),n()+1),w:'+1×'+pniPN(p),go:()=>ACT.lagP({id:p.id,d:1})}:null,
lag:()=>n()<pniLagMax(c)&&!msfNope(p.net,c)&&PORT_SLOT(p.tier)<=room(c)?{cost:1500+PORT[p.tier].setup/2,cap:lagCap(pniG(p),n()+1),w:'+1×'+pniPN(p),go:()=>ACT.lagP({id:p.id,d:1})}:null,
ups:()=>{const out=[];for(let t=p.g1?0:p.tier+1;t<PORT.length&&portShown(t);t++){const q=pniQuote(c,p.net,t,resv(c));if(q&&!q.why)out.push({cost:q.cost,cap:lagCap(PORT[t].g,n()),w:pniPN(p)+'→'+PORT[t].n,go:()=>ACT.pni({city:c,net:p.net,tier:t})});}return out;}});}
// Nominal capacity, not ixCap(): a LACP fault or one building down halves a LAG for a day or two, not worth a bigger port.
for(const x in S.ixp){const c=ixCity(x),use=(R.useIx[x]||0)*opsAhead(),n=()=>(S.ixn||{})[x]||1,cap=()=>lagCap(PORT[S.ixp[x]].g,n())*(isRemote(x)?REMOTE_CAP:1),pop=S.pops[c];if(S.myIx[x]||!(use>0)||!(cap()>0)||cap()>=N*use||!opsHere('ports',c))continue;

View file

@ -23,6 +23,11 @@ function ixMembers(c){if(XIXM[c])return XIXM[c].members.slice();if(S.myIx[c])ret
const IX_MEM={};
// LAG: several identical ports bundled into one logical link. Flow hashing is never perfectly even, so a bundle carries ~95% of the sum.
const LAG_MAX=8;
/* A PNI bundle grows with the routers it lands on (#323): eight members per router at the POP, so a PNI fatter than eight
ports costs another router (its price and its port slots), up to 32 members, the most the big LAG implementations
bundle. Only PNIs: transit, exchange and fabric ports stay at LAG_MAX. */
const PNI_LAG_RT=8,PNI_LAG_MAX=32;
function pniLagMax(c){const p=S.pops[c];return Math.min(PNI_LAG_MAX,PNI_LAG_RT*((p&&p.routers)||1));}
function lagCap(g,n){n=n||1;return g*n*(n>1?0.95:1);}
function lagName(tier,n){return (n||1)>1?`${n}×${PORT[tier].n} LAG`:tr('common.port_port',{port:PORT[tier].n});}
function ixCap(c){return ixLagF(c)*(S.myIx[c]?myFab(c).g*(myIxLive(c)?1:0):liveCap(PORT[S.ixp[c]].g,ixCity(c),(S.ixSite||{})[c],(S.ixn||{})[c])*(isRemote(c)?REMOTE_CAP:1));}

View file

@ -14,7 +14,7 @@ function utilityCacheMoves(city){if(!S||!S.pops[city])return [];const groups=new
// list of networks, and Goggle is throttled to half in Russia. The world shares (NSH) would size boxes for networks the
// city cannot even reach, and too few for the ones it uses most.
const cityShTab=c=>cnCity(c)?NSH_CN:ruCity(c)?NSH_RU:CITY[c].kr&&S.krExit?NSH_KRX:NSH;
const cityNetSh=(c,id)=>(cityShTab(c)[id]||0)*(id==='ggl'&&ruCity(c)?0.5:1);
const cityNetSh=(c,id)=>{const j=LOC_NIX.get(id);return (j===undefined?0:locSh(cityShTab(c),c)[j])*(id==='ggl'&&ruCity(c)?0.5:1);};
// A city's total share only depends on its table and on the Russian throttle, and the tables never change after load:
// summed once per kind of city, not once per network asked about (that was cities × networks² every shift).
const CSH_SUM=new Map();

View file

@ -9,6 +9,9 @@ cap transit cogentle at 20 gbps
avoid transit for goggle
# Move traffic before links are completely full
spill at 85%
# Hot links spill early onto detours that cost little latency
# spill at 80% within 10 ms
# spill at 90% within 20 ms
# Local-pref: use the cheap upstream first, the pricey one last
# prefer transit cogentle
# avoid transit level tree
@ -27,9 +30,11 @@ function teFind(word,list,label){const w=slug(word);if(!w)return {err:tr('routes
const pre=list.filter(x=>w.length>=3&&slug(x.name).startsWith(w));if(pre.length===1)return {v:pre[0].id};
const best=list.map(x=>({x,d:Math.min(lev(w,slug(x.name)),lev(w,x.id))})).sort((a,b)=>a.d-b.d)[0];
return {err:tr('routescript.unknown_what_word',{what:label,word})+(best&&best.d<=3?tr('routescript.did_you_mean_name',{name:best.x.name}):'')};}
function teParse(src){const out={spill:null,cap:{},net:{},up:{},prep:{},protect:false,drain:new Set(),avoid:new Set(),blackhole:false,errors:[],n:0};
function teParse(src){const out={spill:null,tiers:[],cap:{},net:{},up:{},prep:{},protect:false,drain:new Set(),avoid:new Set(),blackhole:false,errors:[],n:0};
const lines=String(src||'').split('\n').slice(0,60);
lines.forEach((raw,i)=>{const line=raw.replace(/#.*/,'').trim().toLowerCase();if(!line)return;const L=i+1;let m;
// A spill tier (#136): from this load on, detours that add at most this many milliseconds.
if(m=line.match(/^spill\s+at\s+(\d{1,3})\s*%\s+within\s+(\d{1,3})\s*ms$/)){const v=+m[1],ms=+m[2];if(v<20||v>100)out.errors.push(tr('routescript.line_n_spill_must_be_between',{n:L}));else if(ms<1||ms>100)out.errors.push(tr('routescript.line_n_within_1_to_100_ms',{n:L}));else{out.tiers.push({at:v/100,ms});out.tiers.sort((a,b)=>a.at-b.at||a.ms-b.ms);out.n++;}return;}
if(m=line.match(/^spill\s+at\s+(\d{1,3})\s*%$/)){const v=+m[1];if(v<20||v>100)out.errors.push(tr('routescript.line_n_spill_must_be_between',{n:L}));else{out.spill=v/100;out.n++;}return;}
if(m=line.match(/^(prefer|avoid)\s+(pni|ix|transit)\s+for\s+(.+)$/)){const r=teFind(m[3],NETS,tr('common.network'));if(r.err){out.errors.push(tr('routescript.line_n_err',{n:L,err:r.err}));return;}const o=out.net[r.v]=out.net[r.v]||{};o[m[1]]=TE_KINDS[m[2]];out.n++;return;}
if(m=line.match(/^cap\s+transit\s+(.+?)\s+at\s+(\d+(?:\.\d+)?)\s*(gbps|tbps|g|t)$/)){const r=teFind(m[1],NETS.filter(n=>n.price),tr('common.transit_provider'));if(r.err){out.errors.push(tr('routescript.line_n_err',{n:L,err:r.err}));return;}out.cap[r.v]=+m[2]*(m[3][0]==='t'?1000:1);out.n++;return;}
@ -103,6 +108,7 @@ function teHelpModal(){const rule=(code,what)=>`<dt><code>${code}</code></dt><dd
<li>${tr('routescript.deploy_makes_it_live_for_the')}</li></ul>
<h3>${tr('common.rules')}</h3><dl>
${rule('spill at 85%',tr('routescript.move_traffic_to_the_next_exit'))}
${rule('spill at 80% within 10 ms',tr('routescript.from_this_load_on_spill_onto'))}
${rule('prefer pni for goggle',tr('routescript.send_one_network_s_traffic_over'))}
${rule('avoid transit for netchill',tr('routescript.use_that_kind_of_exit_for'))}
${rule('cap transit cogentle at 20 gbps',tr('routescript.a_ceiling_on_one_provider_so'))}
@ -122,7 +128,7 @@ function teModal(msg){const src=UI.teDraft!==undefined?UI.teDraft:(S.te.script||
<p class="tagline">${tr('routescript.write_rules_check_them_against_live')}</p>
<textarea id="teSrc" class="tecode" spellcheck="false" autocapitalize="off" autocomplete="off" rows="12">${esc(src)}</textarea>
${msg||''}<div class="btns" style="margin-top:8px">${btn(tr('routescript.check_dry_run'),'teCheck',{},'')}${btn(tr('common.deploy'),'teDeploy',{},'pink')}${S.te.script?btn(tr('common.remove_script'),'teClear',{},'ghost sm'):''}${btn(tr('common.optimize'),'teOpt',{},'ghost sm')}${btn(tr('routescript.reset_to_example'),'teExample',{},'ghost sm')}</div><div class="btns" style="margin-top:6px">${btn('✨ '+tr('routescript.slop_it_with_ai'),'teSlop',{},'aibtn')}${btn(tr('routescript.help_and_ready_made_scripts'),'teHelp',{},'ghost sm')}</div>
<p class="meta" style="margin-top:8px"><b>${tr('common.rules_7b18')}</b> <code>spill at 80%</code> · <code>prefer pni|ix|transit for NETWORK</code> · <code>avoid pni|ix|transit for NETWORK</code> · <code>cap transit PROVIDER at 20 gbps</code> · <code>prefer|avoid transit PROVIDER</code> · <code>prepend transit PROVIDER 1-3</code> · <code>protect customers</code> · <code>drain CITY</code> · <code>avoid link CITY-CITY</code> · <code>blackhole ddos</code></p>
<p class="meta" style="margin-top:8px"><b>${tr('common.rules_7b18')}</b> <code>spill at 80%</code> · <code>spill at 80% within 10 ms</code> · <code>prefer pni|ix|transit for NETWORK</code> · <code>avoid pni|ix|transit for NETWORK</code> · <code>cap transit PROVIDER at 20 gbps</code> · <code>prefer|avoid transit PROVIDER</code> · <code>prepend transit PROVIDER 1-3</code> · <code>protect customers</code> · <code>drain CITY</code> · <code>avoid link CITY-CITY</code> · <code>blackhole ddos</code></p>
${S.te.script?`<p class="meta">${tr('routescript.live_state_rules',{state:S.te.on?tr('common.deployed'):tr('routescript.controller_is_off'),rules:teRules()?tr('routescript.n_rules_active',{n:teRules().n}):tr('common.not_active')})}</p>`:''}`);}
function teTrial(src){const keep=S.te.script,on=S.te.on,before={served:R.served,tc:R.cost.transit||0,moved:R.teMoved||0};
S.te.script=src;S.te.on=true;compute();const after={served:R.served,tc:R.cost.transit||0,moved:R.teMoved||0,bh:R.teBlack||0};

View file

@ -9,7 +9,7 @@ function routeCore(){
// The day's state, set by nodes() and run(). (TR, base and eff, the ranks, are for the reference loop of the tests.)
let NRES,NSEEN,NORD,NLOAD,EL,NKN,SEN,ACN,NC,SED,ACD,
E,HAS,PASS,R2,FREM,FNJ,FCI,FCA,FBZ,NF,CNB,NCN,ev,day,SRV,TNS,NN,TNK,TORD,TNA,snd,LATP,FARL,EGT,EGO,NEG,NEO,NEA,FGT,FTI,FGI,FII,FGH,FGP,
TE,SPILL,teCache,adj,CORE,OUT,REACH,DSEL,PREFC,BRJ,COMP,SDi,SPi,ALONE,TR,base,eff,
TE,SPILL,TT,teCache,adj,CORE,OUT,REACH,DSEL,PREFC,BRJ,COMP,SDi,SPi,ALONE,TR,base,eff,
NX=0,USED=null,CAPX=null,CIX=null,HPX=null,DTX=null,VISX=null,TEF=null,EP=0;
// The flow being routed, and from its POP: distances, arriving edges and the paths walked so far, by city index.
// F: its index; fci, fnj: its city and network index. BRX: BRJ with each list as a list object of one shape (lx()).
@ -98,9 +98,35 @@ function routeCore(){
// with free capacity, as long as they are no more than twice as long.
const send=(x,want)=>{
let room=Math.min(want,FREM[F],CAPX[x]-USED[x]);if(room<=1e-6)return;const ci=CIX[x];
const P=PP[ci]||(PP[ci]=walkP(Pv,fci,ci));if(!P.dead)room-=push(x,P,room,TE&&SPILL<1?1-SPILL:0);
const P=PP[ci]||(PP[ci]=walkP(Pv,fci,ci));if(TT&&ci!==fci){room=tiers(x,P,room,ci);if(room<=1e-6)return;}
if(!P.dead)room-=push(x,P,room,TE&&SPILL<1?1-SPILL:0);
if(TE&&room>1e-6&&FREM[F]>1e-6&&USED[x]<CAPX[x]&&ci!==fci)for(let k=0;k<2&&room>1e-6;k++){const P=altPath(fci,ci,Dv[ci]);if(!P)break;const m=push(x,P,Math.min(room,CAPX[x]-USED[x]));if(m<=1e-6)break;room-=m;R2.teMoved+=m;}
};
/* Spill tiers (#136, `spill at 80% within 10 ms`): the shortest path fills up to a tier's line, then what does not fit
takes the fastest detour whose links are all still under that line, if it adds no more than the tier's milliseconds;
the next tier lets links run hotter and detours longer. After the last tier the usual rules above take over. A detour
is searched by latency over the links under the line (tierSearch), and kept per pair and tier while it still is:
links only fill up while routing, so a pair with no detour under a line never gets one. */
const pathMs=P=>{let ms=P.ms;if(ms<0){ms=0;const p=P.path;for(let k=0;k<p.length;k++)ms+=p[k].lat;P.ms=ms;}return ms;};
let TC=null,TSD=null,TSP=null,TSS=null,TSG=0,TH=[],THU=[];
const tierSearch=(src,dst,keep,lim)=>{const n=TEO.length-1,core=CORE;if(!TSD||TSD.length!==n){TSD=new Float64Array(n);TSP=new Array(n);TSS=new Int32Array(n);TSG=0;}
const g=++TSG,D=TSD,P=TSP,ST=TSS;let m=0;D[src]=0;ST[src]=g;TH[0]=0;THU[0]=src;m=1;
while(m){let best=0;for(let i=1;i<m;i++)if(TH[i]<TH[best])best=i;const d=TH[best],u=THU[best];m--;TH[best]=TH[m];THU[best]=THU[m];
if(d>D[u])continue;if(u===dst)break;
for(let k=TEO[u],K=TEO[u+1];k<K;k++){const v=TEN[k],e=TEE[k];if(!(e.res>e.cap*keep+1e-3)||(HAS[v]&&NRES[v]<=1e-3)||(core&&OUT[v]&&v!==dst))continue;
const nd=d+e.lat;if(nd>lim||!(nd<(ST[v]===g?D[v]:Infinity)))continue;D[v]=nd;ST[v]=g;P[v]=e;TH[m]=nd;THU[m]=v;m++;}}
return ST[dst]===g?walkP(P,src,dst):null;};
const tierPath=(t,keep,src,dst,lim)=>{const key=(src*NC+dst)*TT.length+t,c=TC.get(key);if(c===false)return null;
if(c){let ok=true;const p=c.path,ni=c.ni;for(let k=0;k<p.length;k++)if(!(p[k].res>p[k].cap*keep+1e-3)){ok=false;break;}
if(ok)for(let k=0;k<ni.length;k++){const i=ni[k];if(HAS[i]&&!(NRES[i]>1e-3)){ok=false;break;}}
if(ok)return pathMs(c)<=lim?c:null;}
const Q=tierSearch(src,dst,keep,Infinity);TC.set(key,Q||false);return Q&&pathMs(Q)<=lim?Q:null;};
const tiers=(x,P,room,ci)=>{for(let t=0;t<TT.length&&room>1e-6;t++){const T=TT[t],keep=1-T.at;
room-=push(x,P,room,keep);
if(room<=1e-6||FREM[F]<=1e-6||!(USED[x]<CAPX[x]))break;
const Q=tierPath(t,keep,fci,ci,pathMs(P)+T.ms);if(!Q||Q.path===P.path)continue;
const m=push(x,Q,Math.min(room,CAPX[x]-USED[x]),keep);if(m>1e-6){room-=m;R2.teMoved+=m;}}
return room;};
// Exits with the same preference and the same IGP distance form an ECMP group: spread the flow over
// them by free capacity (like several transits in one city), then top up in order if one fills.
// The group is g[i0..i1): plain loops and one scratch array, since this runs for most flows (same sums, same order).
@ -204,10 +230,11 @@ function routeCore(){
return {nodeTake,carry,
nodes(o){({NRES,NSEEN,NORD,NLOAD,EL,NKN,SEN,ACN,NC,SED,ACD}=o);},
run(o,PASSES,RANKS,RSET){({E,HAS,PASS,R2,FREM,FNJ,FCI,FCA,FBZ,NF,CNB,NCN,ev,day,SRV,TNS,NN,TNK,TORD,TNA,snd,LATP,FARL,EGT,EGO,NEG,NEO,NEA,FGT,FTI,FGI,FII,FGH,FGP,
TE,SPILL,teCache,adj,CORE,OUT,REACH,DSEL,PREFC,BRJ,COMP,SDi,SPi,ALONE,TR,base,eff}=o);
TE,SPILL,TT,teCache,adj,CORE,OUT,REACH,DSEL,PREFC,BRJ,COMP,SDi,SPi,ALONE,TR,base,eff}=o);
NX=E.length;USED=new Float64Array(NX);CAPX=new Float64Array(NX);CIX=new Int32Array(NX);HPX=new Uint8Array(NX);DTX=new Float64Array(NX);VISX=new Int32Array(NX);
for(let x=0;x<NX;x++){const e=E[x];USED[x]=e.used;CAPX[x]=e.cap;CIX[x]=e.ci;HPX[x]=e.hp;DTX[x]=e.dt;}
F=0;fci=0;fnj=0;Dv=null;Pv=null;PP=null;vis=0;GN=0;walked=[];EP=0;LRs=-1;LRD=null;
TC=TT?new Map():null;
if(TE){const n=adj.length;TEO=new Int32Array(n+1);let k=0;for(let u=0;u<n;u++){TEO[u]=k;const a=adj[u];if(a)k+=a.length;}TEO[n]=k;
TEN=new Int32Array(k);TEE=new Array(k);k=0;for(let u=0;u<n;u++){const a=adj[u];if(a)for(let j=0;j<a.length;j++){TEN[k]=a[j][0];TEE[k]=a[j][1];k++;}}}TEF=TE?new Uint8Array(NC*NC):null;
const W=new Map();BRX=new Array(BRJ.length);for(let j=0;j<BRJ.length;j++){const m=BRJ[j],b={};for(const r in m)b[r]=lx(m[r],W);BRX[j]=b;}
@ -218,7 +245,7 @@ function routeCore(){
}
for(let x=0;x<NX;x++)E[x].used=USED[x];
// Nothing of this day is kept: the next run() sets its own.
E=R2=BRJ=BRX=SDi=SPi=teCache=TEF=TEE=null;walked=[];}};
E=R2=BRJ=BRX=SDi=SPi=teCache=TEF=TEE=TC=null;TSD=TSP=null;walked=[];}};
}
// The core in use (a test can put the plain one in its place: tests/speed.test.js).
let ROUTE=routeCore();

View file

@ -102,13 +102,15 @@ function compute(){RW.gen++;
// Goggle video is throttled in Russia (#70): people there get half of it, so they ask for half. It is not
// traffic you failed to deliver, and it does not cross your links only to be thrown away.
const ru=ruCity(c),thr=n=>n==='ggl'&&ru?0.5:1;let sa=shArr.get(SH),sm=shSum.get(SH);if(!sa){shArr.set(SH,sa=NETS.map(n=>SH[n.id]||0));shSum.set(SH,sm=[]);}
const tt=sm[+ru]||(sm[+ru]=[NETS.reduce((t,n,j)=>t+sa[j]*thr(n.id),0),NETS.reduce((t,n,j)=>t+sa[j],0)]),lf=loc?NETS.reduce((t,n,j)=>t+(R2.reachable[n.id]?sa[j]*thr(n.id):0),0)/(tt[0]||1):1,d=d0*tt[0]/(tt[1]||1)*lf;
// This city's own split: its traffic to networks that sell to homes goes mostly to the ones whose users are near (#48).
const ls=locSh(SH,c);
const tt=sm[+ru]||(sm[+ru]=[NETS.reduce((t,n,j)=>t+sa[j]*thr(n.id),0),NETS.reduce((t,n,j)=>t+sa[j],0)]),lf=loc?NETS.reduce((t,n,j)=>t+(R2.reachable[n.id]?ls[j]*thr(n.id):0),0)/(tt[0]||1):1,d=d0*tt[0]/(tt[1]||1)*lf;
R2.cityEye[c]=eye;R2.cityDem[c]=d;R2.citySrv[c]=0;R2.demand+=d;
for(let j=0;j<NN;j++)DEMTO[j]=(DEMTO[j]||0)+d0*sa[j]*thr(NETS[j].id);
for(let j=0;j<NN;j++)DEMTO[j]=(DEMTO[j]||0)+d0*ls[j]*thr(NETS[j].id);
if(!popUp(c))continue;CNB[ci]=cn;
R2.cityBlocked=R2.cityBlocked||{};
const mtuH=ev.pmtud&&ev.pmtud.until>day?ev.pmtud:null,kr=CITY[c].kr;
for(let j=0;j<NN;j++){const n=NETS[j],a=(loc&&!R2.reachable[n.id]?0:d0)*sa[j]*thr(n.id)*(mtuH&&mtuH.net===n.id?mtuH.f:1)*(kr&&ev.krroute>day&&n.id==='fbk'?0.8:1);if(a<=0)continue;
for(let j=0;j<NN;j++){const n=NETS[j],a=(loc&&!R2.reachable[n.id]?0:d0)*ls[j]*thr(n.id)*(mtuH&&mtuH.net===n.id?mtuH.f:1)*(kr&&ev.krroute>day&&n.id==='fbk'?0.8:1);if(a<=0)continue;
// With `protect customers`, the business part first, then the rest (no arrays: this runs per city and network).
const bf=d0>0?biz/d0:0,sp=!!(TRX&&TRX.protect&&bf>0),cn2=cacheNets.has(n.id);
for(let q=0;q<(sp?2:1);q++){const x=sp?(q?a*(1-bf):a*bf):a,bz=sp&&!q;if(x<=0)continue;if(cn2){flow(ci,j,x*0.85,true,bz);flow(ci,j,x*0.15,false,bz);}
@ -186,7 +188,7 @@ function compute(){RW.gen++;
if(!R2.egDesc[ek])R2.egDesc[ek]={lab:clean?labOf(N_('compute.scrubbed_traffic_from_city'),'city',CITY[A].name):labOf(N_('compute.attack_entering_in_city'),'city',CITY[from].name),city:B,k:'l2'};
for(const i of ni)if(HAS[i])nodeTake(i,amt);for(const l of path){l.res-=amt;l.ld+=amt;if(!clean){l.jk=(l.jk||0)+amt;JK=1;}carry(l,ek,clean?NN+2:NN,Bi,amt);}return amt;};
const DD=ddosLoad({E,okBy,R2,autoBh:!!(TRX&&TRX.blackhole),haul,ms:msOf});
const TE=!!(S.te&&S.te.on)&&coreTE(),TR=TE?teRules():null,REACH=coreTeReach();R2.teMoved=0;const teCache=new Map(),SPILL=TR&&TR.spill?TR.spill:1;
const TE=!!(S.te&&S.te.on)&&coreTE(),TR=TE?teRules():null,REACH=coreTeReach();R2.teMoved=0;const teCache=new Map(),SPILL=TR&&TR.spill?TR.spill:1,TT=TR&&TR.tiers.length?TR.tiers:null;
/* 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;
@ -216,7 +218,7 @@ function compute(){RW.gen++;
R.egT and R.netEg list them in; both are written back after routing. NEG: each network's R.netEg record. */
const EGT=new Float64Array(4),EGO=[],NEA=new Float64Array(NN*4),NEO=[],NEG=[];
ROUTE.run({E,HAS,PASS,R2,FREM,FNJ,FCI,FCA,FBZ,NF,CNB,NCN,ev,day,SRV,TNS,NN,TNK,TORD,TNA,snd,LATP,FARL,EGT,EGO,NEG,NEO,NEA,FGT,FTI,FGI,FII,FGH,FGP,
TE,SPILL,teCache,adj,CORE,OUT,REACH,DSEL,PREFC,BRJ,COMP,SDi,SPi,ALONE,TR,base,eff},PASSES,RANKS,RSET);
TE,SPILL,TT,teCache,adj,CORE,OUT,REACH,DSEL,PREFC,BRJ,COMP,SDi,SPi,ALONE,TR,base,eff},PASSES,RANKS,RSET);
for(const i of NORD)R2.nodeLoad[CITIES[i].id]=NLOAD[i];
for(const k of EGO)R2.egT[EXK[k]]=EGT[k];for(const j of NEO){const ne=NEG[j];for(let k=0;k<4;k++)ne[EXK[k]]=NEA[j*4+k];}
(()=>{

View file

@ -20,7 +20,7 @@ function sanitize(s){
for(const c of Object.keys(s.pops)){const p=s.pops[c];if(!isCity(c)||!p||typeof p!=='object'){delete s.pops[c];continue;}p.routers=int(p.routers,1,RMAX,1);if(p.rupDay!==undefined)p.rupDay=num(p.rupDay,-1);if(p.rgen!==undefined)p.rgen=int(p.rgen,0,RG.length-1,0);p.down=num(p.down,0);if(p.bb&&typeof p.bb==='object')p.bb.d=num(p.bb.d,0);else p.bb=null;}
if(!isCity(s.home))s.home=Object.keys(s.pops)[0]||'fra';
opsSanitize(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);
const tier=v=>int(v,0,PORT.length-1,0),lag=v=>int(v,1,LAG_MAX,1),plag=v=>int(v,1,PNI_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);if(l.list!==undefined){const L=l.kind==='df'?cmClean(l.list):null;if(L)l.list=L;else delete l.list;}l.km=num(l.km,kmBetween(l.a,l.b));l.mo=num(l.mo,0);l.cut=num(l.cut,0);if(l.cname!=null)l.cname=String(l.cname).slice(0,60);if(l.pairs!==undefined)l.pairs=Math.min(l.sub?SUB_PAIRS_MAX:s.lvl>=PAIRS_LV?PAIRS_BIG:PAIRS_MAX,Math.max(1,Math.floor(+l.pairs)||1));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)||!cablePair(l.cable,l.a,l.b)))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);if(l.day!==undefined)l.day=Math.min(s.day,Math.max(0,num(l.day,s.day)));for(const k of Object.keys(SUB_UPGRADES)){const f='sub'+k;if(l[f]!==undefined){if(l.own&&l.sub&&Number.isFinite(l[f])&&l[f]>=0)l[f]=Math.round(l[f]);else delete l[f];}}if(l.seaPath!==undefined){if(l.own&&l.sub&&Array.isArray(l.seaPath)&&l.seaPath.length>=2&&l.seaPath.length<=2048&&l.seaPath.every(p=>Array.isArray(p)&&p.length===2&&p.every(Number.isFinite)&&Math.abs(p[0])<=180&&Math.abs(p[1])<=90))l.seaPath=l.seaPath.map(p=>p.slice());else delete l.seaPath;}if(l.paid!==undefined){if(l.own&&l.sub&&Number.isFinite(l.paid)&&l.paid>=0)l.paid=Math.round(l.paid);else delete l.paid;}if(l.own&&l.sub&&!own(SEA_DESIGNS,l.seaDesign))l.seaDesign='standard';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);return l;});
for(const l of s.links)repairSubUpgradeDates(l,s.day);
/* Metrics moved from each link to its city pair (#122). Older saves routed a pair at the lowest metric of its
@ -32,9 +32,9 @@ function sanitize(s){
if(!ks.has(k)||typeof v!=='string'||!own(MET,v)||v==='normal')delete pm[k];}}
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.clean=!!t.clean,t.carry===true||delete t.carry,t.premium=premOnlyAt(NET[t.net],t.city)||!!t.premium&&premCity(NET[t.net],t.city),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.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=plag(x.n),x.sacrif=!!x.sacrif,x));
// PNIs on order (#…): delivery day, a pending augment, and 1G for the one network that sells it
for(const x of s.pni){if(x.ready!==undefined)x.ready=num(x.ready,0);if(x.g1)x.g1=x.tier===0&&x.net==='dtk'?true:undefined;else delete x.g1;if(x.up){const u=x.up;x.up=u&&typeof u==='object'?{tier:tier(u.tier),n:lag(u.n),ready:num(u.ready,0),g1:!!u.g1&&x.net==='dtk'&&tier(u.tier)===0,...(u.site==='ab'?{site:'ab'}:{})}:undefined;if(!x.up)delete x.up;}}
for(const x of s.pni){if(x.ready!==undefined)x.ready=num(x.ready,0);if(x.g1)x.g1=x.tier===0&&x.net==='dtk'?true:undefined;else delete x.g1;if(x.up){const u=x.up;x.up=u&&typeof u==='object'?{tier:tier(u.tier),n:plag(u.n),ready:num(u.ready,0),g1:!!u.g1&&x.net==='dtk'&&tier(u.tier)===0,...(u.site==='ab'?{site:'ab'}:{})}:undefined;if(!x.up)delete x.up;}}
// Supply chain: a shortage and a price lock, both optional.
{const H=s.hw&&typeof s.hw==='object'&&!Array.isArray(s.hw)?s.hw:{},o={};const sh=H.shock,lk=H.lock;
if(sh&&typeof sh==='object'&&own(HW_SHOCK,sh.k))o.shock={k:sh.k,until:num(sh.until,0),mul:clamp(num(sh.mul,1),1,2)};

View file

@ -16,16 +16,60 @@ function eventTick(b,d){if(!BIZ_T[b.type].event)return false;if(d<b.start)return
if(d<b.start+b.dur){b.srv=(b.srv||0)+sfOf(R,b.city);b.srvDays=(b.srvDays||0)+1;if(d===b.start)toast(tr('customers_and_events.name_starts_today_bw_of_extra',{name:esc(b.name),bw:fmtG(b.bw),city:CITY[b.city].name,d:b.dur}),'goal',[{l:tr('common.show_me'),act:'focusCity',args:{city:b.city}}]);return true;}
const avg=b.srvDays?b.srv/b.srvDays:0;if(avg>=0.95)S.stats.evFull=(S.stats.evFull||0)+1;const pay=avg>=0.95?b.fee:avg>=0.7?Math.round(b.fee*avg):-Math.round(b.fee*0.2);S.cash+=pay;S.biz=S.biz.filter(x=>x!==b);
toast(pay>=0?tr('customers_and_events.name_is_over_pay_you_delivered',{name:esc(b.name),pay:fmt$(pay),pct:pct(avg)})+(avg>=0.95?' '+tr('common.flawless'):''):tr('customers_and_events.name_was_a_disaster_only_pct',{name:esc(b.name),pct:pct(avg),pay:fmt$(-pay)}),pay>=0?'good':'bad');sfx(pay>=0?'coin':'err');return true;}
/* Where the giants actually build: gigawatt AI campuses and cloud regions, mapped to the nearest city on the map. */
const MEGA=[{c:'ash',n:'Data Center Alley'},{c:'ash',n:'Prome-the-mess Ohio'},{c:'dal',n:'Star-Gait Abilene'},{c:'dal',n:'Hyperbole Louisiana'},{c:'dal',n:'Colossus of Blues Memphis'},{c:'chi',n:'Fairweather Wisconsin'},{c:'chi',n:'Project Rainy-er Indiana'},{c:'chi',n:'Cornfield Cluster Iowa'},{c:'nyc',n:'Neocloud New Jersey'},{c:'sto',n:'Star-Gait Fjord-way'},{c:'mad',n:'Aragón Mega-shed'},{c:'dub',n:'Bring-Your-Own-Power Dublin'},{c:'auh',n:'Star-Gait UAE'},{c:'ruh',n:'Desert Kingdom AI Campus'},{c:'doh',n:'Lusail Data Oasis'},{c:'kul',n:'Johor Overflow'},{c:'hyd',n:'Vizag AI Hub'},{c:'icn',n:'Ulsan AI Campus'},{c:'tok',n:'Hokkaido Snow DC'},{c:'syd',n:'Star-Gait Down Under'},{c:'syd',n:'AirDrunk Western Sydney'},{c:'mel',n:'AirDrunk Melbourne West'},{c:'mex',n:'Querétaro Cluster'},{c:'for',n:'Short-Video Ceará Campus'},{c:'scl',n:'Quilicura Region'}];
/* Where the giants actually build: gigawatt AI campuses and cloud regions, mapped to the nearest city on the map (#61:
not just five metros; real campuses sit all over, from Oregon to Wyoming to Querétaro). w: a hub that draws more. */
const MEGA=[
{c:'ash',n:'Data Center Alley',w:2},
{c:'atn',n:'Peach-flops Georgia'},
{c:'auh',n:'Star-Gait UAE'},
{c:'aus',n:'Taylor-Made Texas Campus'},
{c:'chi',n:'Fairweather Wisconsin'},
{c:'chi',n:'Project Rainy-er Indiana'},
{c:'cmh',n:'Prome-the-mess Ohio'},
{c:'csn',n:'Biggest Little Cluster Reno'},
{c:'cys',n:'Wind Chill Wyoming Campus'},
{c:'dal',n:'Star-Gait Abilene'},
{c:'doh',n:'Lusail Data Oasis'},
{c:'dsm',n:'Cornfield Cluster Iowa'},
{c:'dub',n:'Bring-Your-Own-Power Dublin'},
{c:'for',n:'Short-Video Ceará Campus'},
{c:'hyd',n:'Vizag AI Hub'},
{c:'icn',n:'Ulsan AI Campus'},
{c:'jan',n:'Hyperbole Louisiana'},
{c:'kcy',n:'Burnt Ends Bit Barn'},
{c:'kul',n:'Johor Overflow'},
{c:'lit',n:'Colossus of Blues Memphis'},
{c:'mad',n:'Aragón Mega-shed'},
{c:'mel',n:'AirDrunk Melbourne West'},
{c:'mty',n:'Norteño Nodes Nuevo León'},
{c:'nyc',n:'Neocloud New Jersey'},
{c:'phx',n:'Mesa-ive Compute Arizona'},
{c:'qro',n:'Querétaro Cluster'},
{c:'ric',n:'Henrico Hyperscale Hustle'},
{c:'ruh',n:'Desert Kingdom AI Campus'},
{c:'scl',n:'Quilicura Region'},
{c:'sea',n:'Quincy-dence Washington'},
{c:'sle',n:'Dilly-Dalles Oregon'},
{c:'sto',n:'Star-Gait Fjord-way'},
{c:'syd',n:'AirDrunk Western Sydney'},
{c:'syd',n:'Star-Gait Down Under'},
{c:'tok',n:'Hokkaido Snow DC'},
{c:'yqb',n:'Hydro-Chill Québec'},
];
/* A campus is picked by its weight, less where giant circuits already crowd the city (#61): a metro that carries as much
as the average busy one draws half as often, three times as much a quarter. Hubs stay a bit busier, never the only ones. */
function megaLoad(){const m=new Map(),add=(c,v)=>{if(c)m.set(c,(m.get(c)||0)+v);};
for(const o of S.biz.concat(S.offers||[])){const T=BIZ_T[o.type];if(!T||!T.mega||!T.l2)continue;for(const c of bCities(o))add(c,o.bw||0);}return m;}
function megaPick(list,ld){let tot=0,k=0;for(const v of ld.values()){tot+=v;k++;}const avg=k?tot/k:0,w=list.map(m=>(m.w||1)/(1+(avg>0?(ld.get(m.c)||0)/avg:0)));
let r=Math.random()*w.reduce((a,b)=>a+b,0);for(let i=0;i<list.length;i++){r-=w[i];if(r<0)return list[i];}return list[list.length-1];}
function spawnMega(t,T,nm,mine){
const megaMine=MEGA.filter(m=>mine.includes(m.c));if(!megaMine.length)return;
if(t==='ingest'){const m=pick(megaMine),bw=pick(T.opts),dur=3+Math.floor(Math.random()*4),start=S.day+10+Math.floor(Math.random()*12);
const megaMine=MEGA.filter(m=>mine.includes(m.c));if(!megaMine.length)return;const ld=megaLoad();
if(t==='ingest'){const m=megaPick(megaMine,ld),bw=pick(T.opts),dur=3+Math.floor(Math.random()*4),start=S.day+10+Math.floor(Math.random()*12);
S.offers.push({id:uid(),city:m.c,city2:null,name:tr('customers_and_events.name_at_site',{name:nm(),site:m.n}),type:t,bw,rate:0,reqs:[],start,dur,fee:Math.round(bw*dur*55),exp:start-2,mega:true});return;}
if(t==='aiwan'||t==='agi'){const a=pick(megaMine),others=MEGA.filter(m=>m.c!==a.c&&(Math.random()<0.7?mine.includes(m.c):true));if(!others.length)return;const b=pick(others);if(!reqCan('diverse',{city:a.c,city2:b.c}))return;const km=kmBetween(a.c,b.c),bw=pick(T.opts);
if(t==='aiwan'||t==='agi'){const a=megaPick(megaMine,ld),others=MEGA.filter(m=>m.c!==a.c&&(Math.random()<0.7?mine.includes(m.c):true));if(!others.length)return;const b=megaPick(others,ld);if(!reqCan('diverse',{city:a.c,city2:b.c}))return;const km=kmBetween(a.c,b.c),bw=pick(T.opts);
const reqs=['diverse'];if(Math.random()<0.4)reqs.push('metro');
S.offers.push({id:uid(),city:a.c,city2:b.c,name:`${nm()}: ${a.n} ⇄ ${b.n}`,type:t,bw,rate:Math.round((150+km*0.08)*T.km),reqs,exp:S.day+45,mega:true});return;}
if(t==='mtrain'){const hub=pick(megaMine),reg=CITY[hub.c].reg,pool=[...new Set(MEGA.filter(m=>m.c!==hub.c&&CITY[m.c].reg===reg).map(m=>m.c))];if(pool.length<2)return;
if(t==='mtrain'){const hub=megaPick(megaMine,ld),reg=CITY[hub.c].reg,pool=[...new Set(MEGA.filter(m=>m.c!==hub.c&&CITY[m.c].reg===reg).map(m=>m.c))];if(pool.length<2)return;
const sites=[hub.c];while(sites.length<Math.min(4,pool.length+1)&&pool.length)sites.push(pool.splice(Math.floor(Math.random()*pool.length),1)[0]);
const avg=sites.slice(1).reduce((x,c)=>x+kmBetween(hub.c,c),0)/(sites.length-1),bw=pick(T.opts);
S.offers.push({id:uid(),city:hub.c,city2:null,sites,name:tr('customers_and_events.name_hub_site',{name:nm(),site:hub.n}),type:t,bw,rate:Math.round((150+avg*0.08)*0.6),reqs:[],exp:S.day+45,mega:true});return;}

View file

@ -4,7 +4,7 @@ Object.assign(ACT,{
ad:({city})=>{const p=S.pops[city];if(!p||!p.bb)return;if(!spend(8000))return;p.boost=S.day+30;floater(CITY[city].x,CITY[city].y-30,tr('common.ad_campaign'),'#FF8A3D');after();},
buyTransit:({city,net,tier})=>{tier=+tier;if(scnRule('noTransit')){toast(tr('pops_transit_ix.no_transit_in_this_scenario_peering'),'bad');sfx('err');return;}if(!S.pops[city]||!NET[net]||!sellsAt(NET[net],city)||!PORT[tier])return;if(!portOk(city,tier)){toast(tr('actions.your_router_can_t_take_a',{port:PORT[tier].n}),'bad');sfx('err');return;}const ex=S.transit.find(t=>t.city===city&&t.net===net);if(ex&&tier<=ex.tier)return;if(!portGate(city,ex?(PORT_SLOT(tier)-PORT_SLOT(ex.tier))*(ex.n||1):PORT_SLOT(tier)))return;if(!spend(PORT[tier].setup*(ex&&ex.n||1)))return;if(ex)ex.tier=tier;else S.transit.push({id:uid(),city,net,tier,down:0,...(premOnlyAt(NET[net],city)?{premium:true}:{})});toast(tr('pops_transit_ix.net_transit_is_live_in_city',{net:esc(NET[net].name),city:CITY[city].name}),'good');after();},
lagT:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const t=S.transit.find(x=>x.id===id);if(!t)return;const n=(t.n||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0){if(!portOk(t.city,t.tier)||!portGate(t.city,PORT_SLOT(t.tier)))return;if(!spend(PORT[t.tier].setup))return;}t.n=n;if(n<2&&t.site==='ab')t.site='a';toast(+d>0?tr('pops_transit_ix.lag_member_added_net_in_city',{net:esc(NET[t.net].name),city:CITY[t.city].name,lag:lagName(t.tier,n)}):tr('pops_transit_ix.lag_member_removed'),'good');after();},
lagP:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const p=S.pni.find(x=>x.id===id);if(!p)return;const n=(p.n||1)+(+d);if(n<1||n>LAG_MAX)return;if(d>0&&(!pniOn(p)||p.up||msfNope(p.net,p.city)))return;if(+d>0&&(!portGate(p.city,PORT_SLOT(p.tier))||!spend(1500+PORT[p.tier].setup/2)))return;
lagP:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const p=S.pni.find(x=>x.id===id);if(!p)return;const n=(p.n||1)+(+d);if(n<1||n>PNI_LAG_MAX)return;if(d>0&&n>pniLagMax(p.city)){toast(tr('pops_transit_ix.this_pni_already_bundles_n_ports',{n:n-1,more:PNI_LAG_RT,max:PNI_LAG_MAX}),'bad');sfx('err');return;}if(d>0&&(!pniOn(p)||p.up||msfNope(p.net,p.city)))return;if(+d>0&&(!portGate(p.city,PORT_SLOT(p.tier))||!spend(1500+PORT[p.tier].setup/2)))return;
// A LAG member is an augment: the big networks take months for that too.
if(d>0){const lead=pniLead(p.net);p.up={tier:p.tier,n,ready:S.day+lead,g1:!!p.g1};if(!lead)pniUpDone(p);toast(lead?tr('pops_transit_ix.augment_ordered_with_net_eta',{net:esc(NET[p.net].name),eta:pniWhen(lead)}):tr('pops_transit_ix.augment_with_net_is_up',{net:esc(NET[p.net].name),port:p.n+'×'+pniPN(p)}),'good');after();return;}p.n=n;if(n<2&&p.site==='ab')p.site='a';sfx('build');after();},
lagIx:({city,d})=>{d=+d;if(d!==1&&d!==-1)return;if(!isIx(city)||S.ixp[city]===undefined||S.myIx[city]||!S.pops[ixCity(city)])return;S.ixn=S.ixn||{};const n=(S.ixn[city]||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0&&(!portGate(ixCity(city),PORT_SLOT(S.ixp[city]))||!spend(ixPortMo(city,S.ixp[city]))))return;S.ixn[city]=n;if(n<2&&S.ixSite&&S.ixSite[city]==='ab')S.ixSite[city]='a';sfx('build');after();},

View file

@ -16,7 +16,7 @@ Object.assign(ACT,{
popStdClear:()=>{S.popStd=null;sfx('click');after();},
addRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)>=RMAX)return;if(!spend(routerCost(p.rgen||0,p.routers||1)))return;p.routers=(p.routers||1)+1;floater(CITY[city].x,CITY[city].y-30,tr('common.router_added'),'#FF4F9A');after();},
models:()=>{UI.models=!UI.models;renderPanel();},
rmRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)<=1)return;if(portsUsed(city)>portsMax(city,undefined,p.routers-1)){toast(tr('routing_and_routers.unplug_something_first_used_ports',{used:fmtPorts(portsUsed(city)),max:portsMax(city,undefined,p.routers-1)}),'bad');sfx('err');return;}p.routers--;{const back=tradeIn(p.rgen||0,1);if(back>0){S.cash+=back;toast(tr('routing_and_routers.sold_a_model_on_ebuy_price',{model:esc(RG[p.rgen||0].n),price:fmt$(back)}),'good');}}after();},
rmRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)<=1)return;{const m=Math.min(PNI_LAG_MAX,PNI_LAG_RT*(p.routers-1)),big=S.pni.find(x=>x.city===city&&Math.max(x.n||1,(x.up&&x.up.n)||1)>m);if(big){toast(tr('routing_and_routers.a_pni_here_bundles_n_ports',{net:esc(NET[big.net].name),n:Math.max(big.n||1,(big.up&&big.up.n)||1),m}),'bad');sfx('err');return;}}if(portsUsed(city)>portsMax(city,undefined,p.routers-1)){toast(tr('routing_and_routers.unplug_something_first_used_ports',{used:fmtPorts(portsUsed(city)),max:portsMax(city,undefined,p.routers-1)}),'bad');sfx('err');return;}p.routers--;{const back=tradeIn(p.rgen||0,1);if(back>0){S.cash+=back;toast(tr('routing_and_routers.sold_a_model_on_ebuy_price',{model:esc(RG[p.rgen||0].n),price:fmt$(back)}),'good');}}after();},
upRouter:({city,g})=>{const p=S.pops[city];if(!p)return;g=g===undefined?mainRG(RG[p.rgen||0].cls+1):+g;if(!RG[g]||g===(p.rgen||0))return;{const why=modelFits(city,g);if(why){toast(tr('routing_and_routers.the_model_won_t_fit_why',{model:esc(RG[g].n),why:esc(why)}),'bad');sfx('err');return;}}if(!techOk('rg',g,RG[g].lvl)){toast(tr('routing_and_routers.model_unlocks_at_customer_level_lv',{model:esc(RG[g].n),lv:RG[g].lvl}),'bad');sfx('err');return;}
const rt=p.routers||1,old=p.rgen||0;if(p.rupDay===S.day){toast(tr('routing_and_routers.the_new_routers_in_city_are',{city:CITY[city].name}),'bad');sfx('err');return;}const back=tradeIn(old,rt);if(!spend(swapCost(city,g)))return;p.rgen=g;p.rupDay=S.day;if(back>0)toast(tr('routing_and_routers.sold_the_old_model_on_ebuy',{model:esc(RG[old].n),price:fmt$(back)}),'good');
if(rt===1&&popIdle(city))toast(tr('routing_and_routers.new_router_in_city_swapped_before',{city:CITY[city].name}),'good');

View file

@ -11,7 +11,7 @@ function pniValLine(n,c,v){
return `<div class="meta pval" title="${esc(tr('pni_list.saves_minus_cost',{saved:fmt$(Math.round(v.saved)),cost:fmt$(Math.round(v.cost))}))}">${tr('pni_list.n_here',{g:fmtG(v.want)})}: ${via} → ${tr('pni_list.with_port',{port:PORT[v.tier].n,val})}</div>`;}
function pniRow(c,n,pn,v,chk){let h=`<div class="row prow">${logo(n)}<div class="grow"><div class="nm">${esc(n.name)} <span class="tag ${n.pol}">${n.pol}</span>${v&&v.worth?` <span class="tag worth">⭐ ${tr('pni_list.worth_it')}</span>`:''}</div><div class="pchips">${pniChip(n.id,c)}</div>${v?pniValLine(n,c,v):''}`;
if(pn&&!pniOn(pn))h+=pniWait(pn,c);
else if(pn){const u=R.usePni[pn.id]||0,cap=lagCap(pniG(pn),pn.n);h+=`<div class="kv"><span>${(pn.n||1)>1?`${pn.n}×${pniPN(pn)} LAG`:pniPN(pn)} PNI</span><b>${fmtG(u)}</b></div>${pn.up?`<div class="meta">${tr('city_panel.augment_on_order_port_about_n',{port:(pn.up.n>1?pn.up.n+'×':'')+(pn.up.g1?'1G':PORT[pn.up.tier].n),n:Math.max(0,pn.up.ready-S.day)})} ${btn(tr('common.chase_it'),'pniChase',{id:pn.id},'ghost sm')}</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.up&&pn.up.site==='ab'?'ab':pn.site)}<div class="btns">${PORT.map((P2,i)=>!pn.up&&!msfNope(n.id,c)&&(i>pn.tier||(pn.g1&&i===0))?btn((a=>(pn.n||1)>1?tr('common.upgrade_all_to_port_cost_mo',a):tr('common.upgrade_port_cost_mo_mo',a))({port:P2.n,cost:fmt$((1500+P2.setup/2)*(pn.n||1)),mo:fmt$(P2.pni*(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.up&&!pn.g1&&pn.tier>pniMin(n.id)&&!msfNope(n.id,c)?btn(tr('link_panels.downgrade_port_price',{port:PORT[pn.tier-1].n,price:portMo(PORT[pn.tier-1].pni*(pn.n||1))}),'downP',{id:pn.id},'ghost sm'):''}${(pn.n||1)<LAG_MAX&&!pn.up&&!msfNope(n.id,c)?btn(tr('common.lag_member_cost_mo_mo',{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('common.member'),'lagP',{id:pn.id,d:-1},'ghost sm'):''}${NET[n.id].cn?btn(pn.sacrif?tr('common.sacrificial_choke'):tr('city_panel.make_sacrificial_contains_floods_1_2'),'sacrif',{id:pn.id},pn.sacrif?'green sm':'sm'):''}${btn(UI.confirm===pn.id?tr('common.really_remove'):tr('common.remove'),'cancelPni',{id:pn.id},'ghost sm')}</div>`;}
else if(pn){const u=R.usePni[pn.id]||0,cap=lagCap(pniG(pn),pn.n);h+=`<div class="kv"><span>${(pn.n||1)>1?`${pn.n}×${pniPN(pn)} LAG`:pniPN(pn)} PNI</span><b>${fmtG(u)}</b></div>${pn.up?`<div class="meta">${tr('city_panel.augment_on_order_port_about_n',{port:(pn.up.n>1?pn.up.n+'×':'')+(pn.up.g1?'1G':PORT[pn.up.tier].n),n:Math.max(0,pn.up.ready-S.day)})} ${btn(tr('common.chase_it'),'pniChase',{id:pn.id},'ghost sm')}</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.up&&pn.up.site==='ab'?'ab':pn.site)}${(pn.n||1)>=pniLagMax(c)&&(pn.n||1)<PNI_LAG_MAX&&!pn.up?`<div class="meta">${tr('pni_list.lag_full_add_a_router',{n:pn.n||1,more:PNI_LAG_RT,max:PNI_LAG_MAX})}</div>`:''}<div class="btns">${PORT.map((P2,i)=>!pn.up&&!msfNope(n.id,c)&&(i>pn.tier||(pn.g1&&i===0))?btn((a=>(pn.n||1)>1?tr('common.upgrade_all_to_port_cost_mo',a):tr('common.upgrade_port_cost_mo_mo',a))({port:P2.n,cost:fmt$((1500+P2.setup/2)*(pn.n||1)),mo:fmt$(P2.pni*(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.up&&!pn.g1&&pn.tier>pniMin(n.id)&&!msfNope(n.id,c)?btn(tr('link_panels.downgrade_port_price',{port:PORT[pn.tier-1].n,price:portMo(PORT[pn.tier-1].pni*(pn.n||1))}),'downP',{id:pn.id},'ghost sm'):''}${(pn.n||1)<pniLagMax(c)&&!pn.up&&!msfNope(n.id,c)?btn(tr('common.lag_member_cost_mo_mo',{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('common.member'),'lagP',{id:pn.id,d:-1},'ghost sm'):''}${NET[n.id].cn?btn(pn.sacrif?tr('common.sacrificial_choke'):tr('city_panel.make_sacrificial_contains_floods_1_2'),'sacrif',{id:pn.id},pn.sacrif?'green sm':'sm'):''}${btn(UI.confirm===pn.id?tr('common.really_remove'):tr('common.remove'),'cancelPni',{id:pn.id},'ghost sm')}</div>`;}
else{h+=chk.ok?`<div class="btns">${pniG1(n.id)?btn(tr('city_panel.port_cost_mo_mo',{port:'1G',cost:fmt$(PNI_G1_COST),mo:fmt$(Math.round(PORT[0].pni/2))}),'pni',{city:c,net:n.id,tier:-1},'sm',S.cash<PNI_G1_COST||!portOk(c,0)):''}${PORT.map((P2,i)=>portShown(i)&&i>=pniMin(n.id)?btn(tr('city_panel.port_cost_mo_mo',{port:P2.n,cost:fmt$(1500+P2.setup/2),mo:fmt$(P2.pni)}),'pni',{city:c,net:n.id,tier:i},'sm',S.cash<1500+P2.setup/2||!portOk(c,i)):'').join('')}</div><div class="meta">${pniEta(n.id)}${pniMin(n.id)?' · '+tr('city_panel.no_10g_net_starts_at_100g',{net:esc(n.name)}):pniG1(n.id)?' · '+tr('city_panel.sells_pnis_down_to_1g'):''}</div>${chk.fee?`<div class="meta">${tr('city_panel.paid_peering_price_mo_on_top',{price:fmt$(chk.fee)})}</div>`:''}`:`<div class="why">${esc(chk.why)}</div>`;}
return h+`</div></div>`;}
function pniListHtml(c){const f=UI.pniF||'all',az=UI.pniSort==='az',open=UI.pniOpen||{};

View file

@ -21,7 +21,7 @@ function connUp(r){if(r.mine)return '';const nx=t=>PORT[t+1]&&portShown(t+1)?t+1
if(n<LAG_MAX)h+=btn(tr('common.lag_member_cost_mo_mo',{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(t.city,t.tier));}
else if(r.k==='p'){const p=S.pni.find(x=>x.id===r.id);if(!p)return '';if(!pniOn(p)||p.up||msfNope(p.net,p.city))return `<span class="meta">${!pniOn(p)||p.up?tr('common.on_order'):''}</span>`;const n=p.n||1,i=p.g1?0:nx(p.tier),c=i>=0?(1500+PORT[i].setup/2)*n:0;
if(i>=0){const a={port:PORT[i].n,cost:fmt$(c),mo:fmt$(PORT[i].pni*n)};h+=btn(n>1?tr('common.upgrade_all_to_port_cost_mo',a):tr('common.upgrade_port_cost_mo_mo',a),'pni',{city:p.city,net:p.net,tier:i},'sm',!portOk(p.city,i)||S.cash<c);}
if(n<LAG_MAX)h+=btn(tr('common.lag_member_cost_mo_mo',{cost:fmt$(1500+PORT[p.tier].setup/2),mo:fmt$(PORT[p.tier].pni)}),'lagP',{id:p.id,d:1},'sm',S.cash<1500+PORT[p.tier].setup/2);}
if(n<pniLagMax(p.city))h+=btn(tr('common.lag_member_cost_mo_mo',{cost:fmt$(1500+PORT[p.tier].setup/2),mo:fmt$(PORT[p.tier].pni)}),'lagP',{id:p.id,d:1},'sm',S.cash<1500+PORT[p.tier].setup/2);}
else if(r.k==='ix'){const c=r.id,city=ixCity(c),n=(S.ixn||{})[c]||1,i=nx(S.ixp[c]);
if(i>=0)h+=btn(tr('common.upgrade_port_price',{port:PORT[i].n,price:portMo(ixPortMo(c,i)*n)}),'buyIx',{city:c,tier:i},'sm',(!!S.pops[city]&&!portOk(city,i))||(!S.pops[city]&&i>1));
if(S.pops[city]&&!S.myIx[c]&&n<LAG_MAX)h+=btn(tr('common.lag_member_price',{price:portMo(ixPortMo(c,S.ixp[c]))}),'lagIx',{city:c,d:1},'sm',S.cash<ixPortMo(c,S.ixp[c]));}

View file

@ -3889,6 +3889,7 @@
"pni_list.f_pni":"Already PNI",
"pni_list.f_transit":"Via transit",
"pni_list.f_worth":"Worth it",
"pni_list.lag_full_add_a_router":"LAG full at {n} members: each router here holds {more}, up to {max}. Add a router to grow it.",
"pni_list.list_more":"{list} +{n}",
"pni_list.little_to_gain_here":"Little to gain here: {g}",
"pni_list.n_here":"{g} here",
@ -3949,6 +3950,7 @@
"pops_transit_ix.router_installed_in_city_upside_down":"<b>Router installed in {city}.</b><br>Upside down, as is customary down here. The packets don’t seem to mind.",
"pops_transit_ix.signed_with_de_kicks_welcome_to":"<b>Signed with DE-KICKS.</b><br>Welcome to the family. Please don't tell anyone what you pay.",
"pops_transit_ix.stay_take_the_discount":"Stay, take the discount",
"pops_transit_ix.this_pni_already_bundles_n_ports":"<b>This PNI already bundles {n} ports</b>, all your routers here can hold. Each router takes {more} members of a PNI, up to {max}: add a router for more.",
"pops_transit_ix.wait_before_you_go":"Wait! Before you go…",
"pops_transit_ix.we_value_our_partnership_too_much":"We value our partnership too much to let a little thing like price get in the way.",
"pops_transit_ix.you_need_a_license_first_foreign":"<b>You need a license first.</b><br>Foreign networks need a joint venture to build in mainland China.",
@ -4321,6 +4323,7 @@
"routescript.every_gigabit_leaving_your_network_picks":"Every gigabit leaving your network picks an exit: a PNI, an IX port or a transit port. Left alone, it takes the nearest peering with room (a PNI before an IX port in the same city), and transit only when no peering can take it. RouteScript changes those choices, the way local-pref, AS-path prepending and maintenance drains do on real routers.",
"routescript.filled_in_from_your_network_as":"Filled in from your network as it is right now. Load one, read it, check it, then deploy.",
"routescript.for_a_ddos_rtbh_the_target":"For a DDoS: blackhole the target upstream and keep business customers first. The target is dark while it lasts, so remove it when the attack is over.",
"routescript.from_this_load_on_spill_onto":"A spill tier: once the shortest path is this full, the overflow takes the best detour if it adds no more than these milliseconds and stays under the same line. Stack them (80% within 10 ms, 90% within 20 ms) to spill earlier and further as links get hotter.",
"routescript.great_question_here_is_a_production":"Great question! Here is a production-ready script, tailored to your live traffic. I checked it thoroughly.",
"routescript.help_and_ready_made_scripts":"Help and ready-made scripts",
"routescript.here_you_go_i_was_trained":"Here you go! I was trained on every router config ever posted to a forum, including the ones titled “why is this broken”.",
@ -4332,6 +4335,7 @@
"routescript.line_n_i_don_t_understand":"line {n}: I don't understand “{text}”. Try: spill at 80%, prefer pni for goggle, avoid transit for netchill, cap transit cogentle at 20 gbps, drain paris, avoid link fra-ams, blackhole ddos",
"routescript.line_n_prepend_1_to_3":"line {n}: prepend 1 to 3 times",
"routescript.line_n_spill_must_be_between":"line {n}: spill must be between 20% and 100%",
"routescript.line_n_within_1_to_100_ms":"line {n}: within must be between 1 and 100 ms",
"routescript.live_state_rules":"Live: {state} · {rules}",
"routescript.maintenance_window_change_the_names":"# Maintenance Window: change the names, deploy, do the work, then remove it.",
"routescript.missing_what":"missing {what}",
@ -4368,6 +4372,7 @@
"routing.routing_and_ddos":"Routing & DDoS",
"routing.trace_note":"Follow one packet hop by hop and see why it leaves where it does.",
"routing.trace_run":"Trace",
"routing_and_routers.a_pni_here_bundles_n_ports":"<b>Shrink a PNI first.</b><br>Your PNI with {net} bundles {n} ports, and one router fewer holds only {m}.",
"routing_and_routers.maintenance_window_in_city":"Maintenance window in {city}",
"routing_and_routers.model_unlocks_at_customer_level_lv":"<b>{model} unlocks at customer level {lv}.</b>",
"routing_and_routers.new_router_in_city_swapped_before":"<b>New router in {city}</b><br>Swapped before anything was plugged in: zero downtime, zero angry customers.",