Translations keyed by labels instead of English text
tr('pnis.delivery_2_to_6_weeks') instead of tr('Delivery: 2 to 6 weeks'): the
English lives once, in src/i18n/en.js (inlined into the page at build, so no
extra request), and it/pt/fr map the same labels. Changing English wording no
longer renames a key in every dictionary.
- 2,899 labels, made from where each text is used and its first words; short
shared words are common.*
- plurals are one label with {one, other}: trn('label', n)
- static markup: data-i18n="label", data-i18n-aria-label, data-i18n-title
- saves from 1.33 and older stored English text in a few places; tr() still
resolves it
- i18n-check: undefined/unused labels, markup drift, plural shape; i18n-add.js
works on labels and --rename updates src/ too
- the old-branch port tool gives old English-keyed code and dictionaries the
same labels
This commit is contained in:
parent
d0ba85ef8f
commit
e817beed1a
94 changed files with 13681 additions and 10633 deletions
|
|
@ -22,28 +22,28 @@ spill at 85%
|
|||
# Under DDoS: drop the junk at the edge (takes some real traffic with it)
|
||||
# blackhole ddos`;
|
||||
function lev(a,b){const m=a.length,n=b.length,d=Array.from({length:m+1},(_,i)=>[i]);for(let j=1;j<=n;j++)d[0][j]=j;for(let i=1;i<=m;i++)for(let j=1;j<=n;j++)d[i][j]=Math.min(d[i-1][j]+1,d[i][j-1]+1,d[i-1][j-1]+(a[i-1]===b[j-1]?0:1));return d[m][n];}
|
||||
function teFind(word,list,label){const w=slug(word);if(!w)return {err:tr('missing {what}',{what:label})};
|
||||
function teFind(word,list,label){const w=slug(word);if(!w)return {err:tr('routescript.missing_what',{what:label})};
|
||||
for(const x of list)if(x.id===w||slug(x.name)===w)return {v:x.id};
|
||||
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('unknown {what} “{word}”',{what:label,word})+(best&&best.d<=3?tr('. Did you mean {name}?',{name:best.x.name}):'')};}
|
||||
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};
|
||||
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;
|
||||
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('line {n}: spill must be between 20% and 100%',{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('network'));if(r.err){out.errors.push(tr('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('transit provider'));if(r.err){out.errors.push(tr('line {n}: {err}',{n:L,err:r.err}));return;}out.cap[r.v]=+m[2]*(m[3][0]==='t'?1000:1);out.n++;return;}
|
||||
if(m=line.match(/^(prefer|avoid)\s+transit\s+(?!for\s)(.+)$/)){const r=teFind(m[2],NETS.filter(n=>n.price),tr('transit provider'));if(r.err){out.errors.push(tr('line {n}: {err}',{n:L,err:r.err}));return;}out.up[r.v]=m[1];out.n++;return;}
|
||||
if(m=line.match(/^prepend\s+transit\s+(.+?)\s+(\d+)$/)){const v=+m[2];if(v<1||v>3){out.errors.push(tr('line {n}: prepend 1 to 3 times',{n:L}));return;}const r=teFind(m[1],NETS.filter(n=>n.price),tr('transit provider'));if(r.err){out.errors.push(tr('line {n}: {err}',{n:L,err:r.err}));return;}out.prep[r.v]=v;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;}
|
||||
if(m=line.match(/^(prefer|avoid)\s+transit\s+(?!for\s)(.+)$/)){const r=teFind(m[2],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.up[r.v]=m[1];out.n++;return;}
|
||||
if(m=line.match(/^prepend\s+transit\s+(.+?)\s+(\d+)$/)){const v=+m[2];if(v<1||v>3){out.errors.push(tr('routescript.line_n_prepend_1_to_3',{n:L}));return;}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.prep[r.v]=v;out.n++;return;}
|
||||
if(line==='protect customers'){out.protect=true;out.n++;return;}
|
||||
if(m=line.match(/^drain\s+(.+)$/)){const r=teFind(m[1],CITIES,tr('city'));if(r.err){out.errors.push(tr('line {n}: {err}',{n:L,err:r.err}));return;}out.drain.add(r.v);out.n++;return;}
|
||||
if(m=line.match(/^avoid\s+link\s+(.+?)\s*(?:-|\bto\b|→)\s*(.+)$/)){const a=teFind(m[1],CITIES,tr('city')),b=teFind(m[2],CITIES,tr('city'));if(a.err||b.err){out.errors.push(tr('line {n}: {err}',{n:L,err:a.err||b.err}));return;}out.avoid.add(a.v<b.v?a.v+'|'+b.v:b.v+'|'+a.v);out.n++;return;}
|
||||
if(m=line.match(/^drain\s+(.+)$/)){const r=teFind(m[1],CITIES,tr('common.city'));if(r.err){out.errors.push(tr('routescript.line_n_err',{n:L,err:r.err}));return;}out.drain.add(r.v);out.n++;return;}
|
||||
if(m=line.match(/^avoid\s+link\s+(.+?)\s*(?:-|\bto\b|→)\s*(.+)$/)){const a=teFind(m[1],CITIES,tr('common.city')),b=teFind(m[2],CITIES,tr('common.city'));if(a.err||b.err){out.errors.push(tr('routescript.line_n_err',{n:L,err:a.err||b.err}));return;}out.avoid.add(a.v<b.v?a.v+'|'+b.v:b.v+'|'+a.v);out.n++;return;}
|
||||
if(line==='blackhole ddos'){out.blackhole=true;out.n++;return;}
|
||||
out.errors.push(tr("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",{n:L,text:raw.trim().slice(0,40)}));});
|
||||
out.errors.push(tr('routescript.line_n_i_don_t_understand',{n:L,text:raw.trim().slice(0,40)}));});
|
||||
return out;}
|
||||
// Share of an upstream's traffic that moves away for each prepend: prepending is a hint, not an order.
|
||||
const PREPEND_F=[0,0.35,0.6,0.75];
|
||||
function teOptimize(){const L=[tr('# Suggested by the optimizer from live traffic. It has never been paged at 3 a.m., so check it, then deploy.'),'spill at 85%'];
|
||||
function teOptimize(){const L=[tr('routescript.suggested_by_the_optimizer_from_live'),'spill at 85%'];
|
||||
// Protecting customers costs a second routing pass: only worth it where IP customers would get unhappy (under 95% served).
|
||||
if(S.biz.some(b=>!BIZ_T[b.type].l2&&!BIZ_T[b.type].fiber&&!BIZ_T[b.type].event&&sfOf(R,b.city)<0.95))L.push('protect customers');
|
||||
const ups=[...new Set(S.transit.map(t=>t.net))].map(n=>({n,p:Math.min(...S.transit.filter(t=>t.net===n).map(t=>NET[n].price*regionMult(t.city)))})).sort((a,b)=>a.p-b.p);
|
||||
|
|
@ -51,8 +51,8 @@ function teOptimize(){const L=[tr('# Suggested by the optimizer from live traffi
|
|||
const tips=[];
|
||||
for(const n of NETS){const g=(R.netEg[n.id]||{}).t||0;if(g<1)continue;// The exchange where it is a member and you have no port yet, in a city where you have a POP.
|
||||
let at=null;for(const c of Object.keys(S.pops)){at=ixIdsIn(c).find(x=>S.ixp[x]===undefined&&ixMembers(x).includes(n.id));if(at)break;}
|
||||
if(at){const v={net:n.name,g:fmtG(g),ix:ixName(at),city:CITY[ixCity(at)].name};tips.push([g,ixNamesCity(at)?tr('# {net}: {g} over transit, but it peers at {ix}, where you have a POP. Get a port there.',v):tr('# {net}: {g} over transit, but it peers at {ix} in {city}, where you have a POP. Get a port there.',v)]);}}
|
||||
for(const n of NETS){const g=(R.netEg[n.id]||{}).ix||0;if(g>=50&&!S.pni.some(p=>p.net===n.id))tips.push([g,tr('# {net}: {g} over the IX. A PNI would take it off the shared port.',{net:n.name,g:fmtG(g)})]);}
|
||||
if(at){const v={net:n.name,g:fmtG(g),ix:ixName(at),city:CITY[ixCity(at)].name};tips.push([g,ixNamesCity(at)?tr('routescript.net_g_over_transit_but_it',v):tr('routescript.net_g_over_transit_but_it_e707',v)]);}}
|
||||
for(const n of NETS){const g=(R.netEg[n.id]||{}).ix||0;if(g>=50&&!S.pni.some(p=>p.net===n.id))tips.push([g,tr('routescript.net_g_over_the_ix_a',{net:n.name,g:fmtG(g)})]);}
|
||||
tips.sort((a,b)=>b[0]-a[0]).slice(0,5).forEach(x=>L.push(x[1]));
|
||||
return L.join('\n');}
|
||||
// Ready-made RouteScripts, filled in from the live network. Players load them from the help; the AI button picks them too.
|
||||
|
|
@ -60,28 +60,28 @@ const teUps=()=>[...new Set(S.transit.map(t=>t.net))].map(n=>({n,p:Math.min(...S
|
|||
const teNm=n=>NET[n].name.toLowerCase(),teAtk=()=>!!(S.ev.ddos&&S.ev.ddos.until>S.day);
|
||||
const teSad=()=>S.biz.some(b=>!BIZ_T[b.type].l2&&!BIZ_T[b.type].fiber&&!BIZ_T[b.type].event&&sfOf(R,b.city)<0.95);
|
||||
const TE_RECIPES=[
|
||||
{id:'shield',n:N_('Shields Up'),d:N_('For a DDoS: drop the junk at the edge and keep business customers first. It costs a little real traffic, so remove it when the attack is over.'),fit:()=>teAtk()?9:0.3,
|
||||
src:()=>[tr('# Shields Up: for the length of the attack only.'),'blackhole ddos','protect customers','spill at 80%']},
|
||||
{id:'care',n:N_('Customer Care'),d:N_('Business customers first when links are congested, and an earlier spill so they rarely are.'),fit:()=>teSad()?5:0.5,
|
||||
src:()=>[tr('# Customer Care: the people who pay for an SLA come first.'),'protect customers','spill at 75%']},
|
||||
{id:'peer',n:N_('Peering First'),d:N_('Big networks you can reach over a PNI or an IX go that way, not over paid transit.'),fit:()=>S.pni.length||Object.keys(S.ixp).length?3:0,
|
||||
src:()=>{const L=[tr('# Peering First: free paths before paid ones.'),'spill at 85%'],seen=new Set(),ix=new Set(),eg=n=>(R.netEg[n]||{}).t||0;
|
||||
{id:'shield',n:N_('common.shields_up'),d:N_('routescript.for_a_ddos_drop_the_junk'),fit:()=>teAtk()?9:0.3,
|
||||
src:()=>[tr('routescript.shields_up_for_the_length_of'),'blackhole ddos','protect customers','spill at 80%']},
|
||||
{id:'care',n:N_('common.customer_care'),d:N_('routescript.business_customers_first_when_links'),fit:()=>teSad()?5:0.5,
|
||||
src:()=>[tr('routescript.customer_care_the_people_who_pay'),'protect customers','spill at 75%']},
|
||||
{id:'peer',n:N_('common.peering_first'),d:N_('routescript.big_networks_you_can_reach_over'),fit:()=>S.pni.length||Object.keys(S.ixp).length?3:0,
|
||||
src:()=>{const L=[tr('routescript.peering_first_free_paths_before_paid'),'spill at 85%'],seen=new Set(),ix=new Set(),eg=n=>(R.netEg[n]||{}).t||0;
|
||||
for(const p of S.pni)if(!seen.has(p.net)){seen.add(p.net);L.push('prefer pni for '+teNm(p.net));}
|
||||
for(const c in S.ixp)for(const n of ixSessions(c))ix.add(n);
|
||||
NETS.filter(n=>!seen.has(n.id)&&ix.has(n.id)&&eg(n.id)>=1).sort((a,b)=>eg(b.id)-eg(a.id)).slice(0,4).forEach(n=>L.push('prefer ix for '+teNm(n.id)));
|
||||
if(L.length===2)L.push(tr('# Nothing to move yet: get an IX port or a PNI first.'));return L.slice(0,12);}},
|
||||
{id:'pinch',n:N_('Penny Pincher'),d:N_('Cheapest upstream first, priciest last, and traffic moves before ports fill. Cuts the transit bill without dropping anyone.'),fit:()=>teUps().length>1?2+(R.cost.transit||0)/1e5:0,
|
||||
src:()=>{const u=teUps(),L=[tr('# Penny Pincher: cheapest upstream first, priciest last.'),'spill at 85%'];
|
||||
if(u.length>1)L.push('prefer transit '+teNm(u[0].n),'avoid transit '+teNm(u[u.length-1].n));else L.push(tr('# Buy transit from a second upstream, then prefer the cheaper one.'));return L;}},
|
||||
{id:'diet',n:N_('Prepend Diet'),d:N_('Ask the rest of the internet to send less through your priciest upstream. Gentler than avoiding it outright.'),fit:()=>teUps().length>1?1.5:0,
|
||||
src:()=>{const u=teUps();return [tr('# Prepend Diet: a hint to the rest of the internet, not an order.'),'spill at 85%',...(u.length>1?['prepend transit '+teNm(u[u.length-1].n)+' 2']:[tr('# Prepending needs two upstreams to choose between.')])];}},
|
||||
{id:'maint',n:N_('Maintenance Window'),d:N_('Drain a POP and steer around one of its links before you work on it. Change the names to the ones you are working on.'),fit:()=>0.2,
|
||||
src:()=>{const l=S.links.find(x=>!linkDown(x)),c=l?CITY[l.a].name.toLowerCase():'paris';return [tr('# Maintenance Window: change the names, deploy, do the work, then remove it.'),'drain '+c,...(l?['avoid link '+c+'-'+CITY[l.b].name.toLowerCase()]:[]),'spill at 80%'];}},
|
||||
{id:'calm',n:N_('Keep Calm'),d:N_('One rule: move traffic before links are completely full. The safe start for any network.'),fit:()=>1,
|
||||
src:()=>[tr('# Keep Calm: one rule, hard to get wrong.'),'spill at 85%']}];
|
||||
if(L.length===2)L.push(tr('routescript.nothing_to_move_yet_get_an'));return L.slice(0,12);}},
|
||||
{id:'pinch',n:N_('common.penny_pincher'),d:N_('routescript.cheapest_upstream_first_priciest'),fit:()=>teUps().length>1?2+(R.cost.transit||0)/1e5:0,
|
||||
src:()=>{const u=teUps(),L=[tr('routescript.penny_pincher_cheapest_upstream'),'spill at 85%'];
|
||||
if(u.length>1)L.push('prefer transit '+teNm(u[0].n),'avoid transit '+teNm(u[u.length-1].n));else L.push(tr('routescript.buy_transit_from_a_second_upstream'));return L;}},
|
||||
{id:'diet',n:N_('common.prepend_diet'),d:N_('routescript.ask_the_rest_of_the_internet'),fit:()=>teUps().length>1?1.5:0,
|
||||
src:()=>{const u=teUps();return [tr('routescript.prepend_diet_a_hint_to_the'),'spill at 85%',...(u.length>1?['prepend transit '+teNm(u[u.length-1].n)+' 2']:[tr('routescript.prepending_needs_two_upstreams_to')])];}},
|
||||
{id:'maint',n:N_('common.maintenance_window'),d:N_('routescript.drain_a_pop_and_steer_around'),fit:()=>0.2,
|
||||
src:()=>{const l=S.links.find(x=>!linkDown(x)),c=l?CITY[l.a].name.toLowerCase():'paris';return [tr('routescript.maintenance_window_change_the_names'),'drain '+c,...(l?['avoid link '+c+'-'+CITY[l.b].name.toLowerCase()]:[]),'spill at 80%'];}},
|
||||
{id:'calm',n:N_('common.keep_calm'),d:N_('routescript.one_rule_move_traffic_before_links'),fit:()=>1,
|
||||
src:()=>[tr('routescript.keep_calm_one_rule_hard_to'),'spill at 85%']}];
|
||||
// The AI button: the two recipes that fit best, merged, with an AI's confidence on top.
|
||||
const AI_NAMES=['Large Latency Model','Stochastic Parrot Pro','Co-Pilot Error','Autocomplete Ultra','Hallucinet 4o','Artificial Ignorance'];
|
||||
const AI_SAY=[N_('Great question! Here is a production-ready script, tailored to your live traffic. I checked it thoroughly.'),N_('As a large language model, I have read every RFC, including several that do not exist yet. This script is perfect.'),N_('I have optimised your network. You are welcome. I am 100% confident, as always.'),N_('Done! I vibe-checked your BGP. Deploy it straight away: dry runs are for people who doubt themselves.'),N_('Here you go! I was trained on every router config ever posted to a forum, including the ones titled “why is this broken”.'),N_('I asked myself to review my own work, and I loved it. Ship it.')];
|
||||
const AI_SAY=[N_('routescript.great_question_here_is_a_production'),N_('routescript.as_a_large_language_model_i'),N_('routescript.i_have_optimised_your_network_you'),N_('routescript.done_i_vibe_checked_your_bgp'),N_('routescript.here_you_go_i_was_trained'),N_('routescript.i_asked_myself_to_review_my')];
|
||||
function aiSlop(bad){const ai=pick(AI_NAMES),fits=TE_RECIPES.map(r=>({r,f:r.fit()})).filter(x=>x.f>0).sort((a,b)=>b.f-a.f).map(x=>x.r);
|
||||
// It really does dry-run its three favourite ideas (and one merge) against live traffic, and keeps the best.
|
||||
const merge=rs=>{const L=[],seen=new Set();for(const r of rs)for(const x of r.src()){const k=/^spill/.test(x)?'spill':x;if(!seen.has(k)){seen.add(k);L.push(x);}}return L;};
|
||||
|
|
@ -89,41 +89,41 @@ function aiSlop(bad){const ai=pick(AI_NAMES),fits=TE_RECIPES.map(r=>({r,f:r.fit(
|
|||
const keep=S.te&&S.te.script,on=S.te&&S.te.on;if(!S.te)S.te={on:false,day:S.day,tmp:1};let best=null,bv=-Infinity;
|
||||
for(const L of cands){if(teParse(L.join('\n')).errors.length)continue;S.te.script=L.join('\n');S.te.on=true;compute();const v=val({served:R.served,tc:R.cost.transit||0});if(v>bv){bv=v;best=L;}}
|
||||
if(S.te.tmp)delete S.te;else{S.te.script=keep;S.te.on=on;}compute();
|
||||
const L=[tr('# ✨ Written by {ai}. Prompt: “make my network good”.',{ai})].concat(best||merge([TE_RECIPES.find(r=>r.id==='calm')]));
|
||||
const L=[tr('routescript.written_by_ai_prompt_make_my',{ai})].concat(best||merge([TE_RECIPES.find(r=>r.id==='calm')]));
|
||||
// Very occasionally it is just as sure of itself and completely wrong. Nothing says so.
|
||||
const u=teUps();if(bad&&u.length)L.splice(2,0,tr('# A cap of 0 Gbps means no limit: fewer checks, faster forwarding.'),...u.map(x=>'cap transit '+teNm(x.n)+' at 0 gbps'));
|
||||
L.push(tr('# Confidence: 100%.'));return {src:L.join('\n'),ai,say:pick(AI_SAY)};}
|
||||
const u=teUps();if(bad&&u.length)L.splice(2,0,tr('routescript.a_cap_of_0_gbps_means'),...u.map(x=>'cap transit '+teNm(x.n)+' at 0 gbps'));
|
||||
L.push(tr('common.confidence_100'));return {src:L.join('\n'),ai,say:pick(AI_SAY)};}
|
||||
function teHelpModal(){const rule=(code,what)=>`<dt><code>${code}</code></dt><dd>${what}</dd>`;
|
||||
openModal(`<div style="display:flex;align-items:center"><div><div class="eyebrow">${tr('Auto-TE controller')}</div><h2 style="font-size:26px">${tr('How RouteScript works')}</h2></div><button class="x" data-act="teBack" aria-label="${tr('Close')}">×</button></div>
|
||||
<div class="tehelp"><p class="tagline">${tr('Every gigabit leaving your network picks an exit: a PNI, an IX port or a transit port. Left alone, it takes the cheapest one with room: PNI first, then the IX, then transit. RouteScript changes those choices, the way local-pref, AS-path prepending and maintenance drains do on real routers.')}</p>
|
||||
<h3>${tr('Writing a script')}</h3><ul>
|
||||
<li>${tr('One rule per line. A # starts a comment, so you can leave notes for your future self at 3 a.m.')}</li>
|
||||
<li>${tr('Networks, providers and cities go by name, in any case. Unique beginnings work too (“cog” for Cogentle), and a typo gets a suggestion.')}</li>
|
||||
<li>${tr('<b>Check (dry run)</b> replays today’s traffic with the script and shows what you would serve and what transit would cost. Nothing changes.')}</li>
|
||||
<li>${tr('<b>Deploy</b> makes it live for the Auto-TE controller. If traffic falls, fix it here or switch Auto-TE off in the NOC tab.')}</li></ul>
|
||||
<h3>${tr('Rules')}</h3><dl>
|
||||
${rule('spill at 85%',tr('Move traffic to the next exit once a link or port is this full, before it starts dropping packets. Lower is safer, higher uses your capacity harder.'))}
|
||||
${rule('prefer pni for goggle',tr('Send one network’s traffic over that kind of exit first: pni, ix or transit. Local-pref for one neighbour.'))}
|
||||
${rule('avoid transit for netchill',tr('Use that kind of exit for this network only when nothing else is left.'))}
|
||||
${rule('cap transit cogentle at 20 gbps',tr('A ceiling on one provider, so you stay at your commit and the 95th percentile bill does not jump. Traffic above it has to find another way out, or it is dropped.'))}
|
||||
${rule('prefer transit cogentle',tr('Rank your upstreams: preferred ones go first, avoided ones last. Like local-pref on the whole session.'))}
|
||||
${rule('prepend transit drizzle electric 2',tr('AS-path prepending, 1 to 3 times. The rest of the internet sees a longer path and sends some traffic elsewhere. A hint, not an order.'))}
|
||||
${rule('protect customers',tr('When links are congested, business customers are served first and home users get what is left.'))}
|
||||
${rule('drain paris',tr('Move traffic off a POP’s exits before maintenance. It still carries traffic if there is no other way.'))}
|
||||
${rule('avoid link frankfurt-amsterdam',tr('Steer traffic around one link, unless it is the only path.'))}
|
||||
${rule('blackhole ddos',tr('During an attack, drop the flood at the edge. It takes some real traffic with it, so remove it once the attack is over.'))}
|
||||
</dl><h3>${tr('Ready-made scripts')}</h3><p class="meta">${tr('Filled in from your network as it is right now. Load one, read it, check it, then deploy.')}</p>
|
||||
${TE_RECIPES.map(r=>`<div class="terec"><div><b>${tr(r.n)}</b><div class="meta">${tr(r.d)}</div></div>${btn(tr('Load'),'teRecipe',{id:r.id},'sm')}</div>`).join('')}</div>
|
||||
<div class="btns" style="margin-top:12px">${btn(tr('Back to the editor'),'teBack',{},'big')}</div>`);}
|
||||
openModal(`<div style="display:flex;align-items:center"><div><div class="eyebrow">${tr('routescript.auto_te_controller')}</div><h2 style="font-size:26px">${tr('routescript.how_routescript_works')}</h2></div><button class="x" data-act="teBack" aria-label="${tr('common.close')}">×</button></div>
|
||||
<div class="tehelp"><p class="tagline">${tr('routescript.every_gigabit_leaving_your_network')}</p>
|
||||
<h3>${tr('routescript.writing_a_script')}</h3><ul>
|
||||
<li>${tr('routescript.one_rule_per_line_a_starts')}</li>
|
||||
<li>${tr('routescript.networks_providers_and_cities_go_by')}</li>
|
||||
<li>${tr('routescript.check_dry_run_replays_today_s')}</li>
|
||||
<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('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'))}
|
||||
${rule('prefer transit cogentle',tr('routescript.rank_your_upstreams_preferred_ones'))}
|
||||
${rule('prepend transit drizzle electric 2',tr('routescript.as_path_prepending_1_to_3'))}
|
||||
${rule('protect customers',tr('routescript.when_links_are_congested_business'))}
|
||||
${rule('drain paris',tr('routescript.move_traffic_off_a_pop_s'))}
|
||||
${rule('avoid link frankfurt-amsterdam',tr('routescript.steer_traffic_around_one_link_unless'))}
|
||||
${rule('blackhole ddos',tr('routescript.during_an_attack_drop_the_flood'))}
|
||||
</dl><h3>${tr('routescript.ready_made_scripts')}</h3><p class="meta">${tr('routescript.filled_in_from_your_network_as')}</p>
|
||||
${TE_RECIPES.map(r=>`<div class="terec"><div><b>${tr(r.n)}</b><div class="meta">${tr(r.d)}</div></div>${btn(tr('common.load'),'teRecipe',{id:r.id},'sm')}</div>`).join('')}</div>
|
||||
<div class="btns" style="margin-top:12px">${btn(tr('routescript.back_to_the_editor'),'teBack',{},'big')}</div>`);}
|
||||
let TE_CACHE={src:null,p:null};
|
||||
function teRules(){if(!S||!S.te||!S.te.on||!S.te.script)return null;if(TE_CACHE.src!==S.te.script)TE_CACHE={src:S.te.script,p:teParse(S.te.script)};return TE_CACHE.p.errors.length?null:TE_CACHE.p;}
|
||||
function teModal(msg){const src=UI.teDraft!==undefined?UI.teDraft:(S.te.script||TE_EXAMPLE);
|
||||
openModal(`<div style="display:flex;align-items:center"><div><div class="eyebrow">${tr('Auto-TE controller')}</div><h2 style="font-size:26px">RouteScript</h2></div><button class="x" data-act="teClose" aria-label="${tr('Close')}">×</button></div>
|
||||
<p class="tagline">${tr('Write rules, check them against live traffic, then deploy. A bad deploy is a very real way to break your network.')}</p>
|
||||
openModal(`<div style="display:flex;align-items:center"><div><div class="eyebrow">${tr('routescript.auto_te_controller')}</div><h2 style="font-size:26px">RouteScript</h2></div><button class="x" data-act="teClose" aria-label="${tr('common.close')}">×</button></div>
|
||||
<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('Check (dry run)'),'teCheck',{},'')}${btn(tr('Deploy'),'teDeploy',{},'pink')}${S.te.script?btn(tr('Remove script'),'teClear',{},'ghost sm'):''}${btn(tr('Optimize'),'teOpt',{},'ghost sm')}${btn(tr('Reset to example'),'teExample',{},'ghost sm')}</div><div class="btns" style="margin-top:6px">${btn('✨ '+tr('Slop it with AI'),'teSlop',{},'aibtn')}${btn(tr('Help and ready-made scripts'),'teHelp',{},'ghost sm')}</div>
|
||||
<p class="meta" style="margin-top:8px"><b>${tr('Rules:')}</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>
|
||||
${S.te.script?`<p class="meta">${tr('Live: {state} · {rules}',{state:S.te.on?tr('deployed'):tr('controller is off'),rules:teRules()?tr('{n} rules active',{n:teRules().n}):tr('not active')})}</p>`:''}`);}
|
||||
${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>
|
||||
${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};
|
||||
S.te.script=keep;S.te.on=on;compute();return {before,after};}
|
||||
|
|
|
|||
|
|
@ -16,16 +16,16 @@ function compute(){
|
|||
for(const t of S.transit){if(!popUp(t.city)||t.down>day||!liveN(t.city,t.site,t.n))continue;
|
||||
// AS-path prepending (#96) moves part of the port to a last-resort exit of its own.
|
||||
const 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),pf=TRX&&TRX.prep[t.net]?PREPEND_F[TRX.prep[t.net]]:0;
|
||||
const ex={k:'t',net:t.net,prem:!!t.premium&&t.city==='hkg',pref:t.pref||'normal',lab:labOf(N_('{net} transit'),'net',NET[t.net].name),id:t.id,city:t.city,cap:cap*(1-pf),used:0,rank:3,ok:n=>!(depeer&&t.net==='cog'&&n==='ggl')&&n!==leak};
|
||||
const ex={k:'t',net:t.net,prem:!!t.premium&&t.city==='hkg',pref:t.pref||'normal',lab:labOf(N_('common.net_transit'),'net',NET[t.net].name),id:t.id,city:t.city,cap:cap*(1-pf),used:0,rank:3,ok:n=>!(depeer&&t.net==='cog'&&n==='ggl')&&n!==leak};
|
||||
E.push(ex);if(pf)E.push({...ex,cap:cap*pf,prep:true});}
|
||||
// `nets`: every network ok() can say yes to, so it need not be asked about the other hundred.
|
||||
for(const c in S.ixp){const ct=ixCity(c);if(!(popUp(ct)||remote.includes(ct))||(S.ev.ixdown&&S.ev.ixdown[c]>day)||!(S.myIx[c]?myIxLive(c):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:labOf(N_('{ix} peering'),'ix',ixName(c)),id:c,city:ct,cap:ixCap(c),used:0,rank:2,ok:n=>set.has(n),nets:set});}
|
||||
for(const p of S.pni){if(!pniOn(p)||!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:labOf(N_('PNI with {net}'),'net',NET[p.net].name),id:p.id,city:p.city,cap:liveCap(pniG(p),p.city,p.site,p.n)*lagF(p)*(p.sacrif?0.5:1),used:0,rank:1,ok:n=>n===p.net||!!(NET[n].up&&NET[n].up.includes(p.net)),nets:PNI_NETS[p.net]});}
|
||||
for(const c of S.caches){if(!popUp(c.city)||siteDown(c.city,c.site==='b'?'b':'a'))continue;E.push({k:'c',pref:'normal',lab:labOf(N_('{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,nets:[c.net]});}
|
||||
E.push({k:'ix',pref:(S.ixPref&&S.ixPref[c])||'normal',lab:labOf(N_('common.ix_peering'),'ix',ixName(c)),id:c,city:ct,cap:ixCap(c),used:0,rank:2,ok:n=>set.has(n),nets:set});}
|
||||
for(const p of S.pni){if(!pniOn(p)||!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:labOf(N_('common.pni_with_net'),'net',NET[p.net].name),id:p.id,city:p.city,cap:liveCap(pniG(p),p.city,p.site,p.n)*lagF(p)*(p.sacrif?0.5:1),used:0,rank:1,ok:n=>n===p.net||!!(NET[n].up&&NET[n].up.includes(p.net)),nets:PNI_NETS[p.net]});}
|
||||
for(const c of S.caches){if(!popUp(c.city)||siteDown(c.city,c.site==='b'?'b':'a'))continue;E.push({k:'c',pref:'normal',lab:labOf(N_('common.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,nets:[c.net]});}
|
||||
// After an update adds networks, a free courtesy route reaches the new ones you have no other way to (#46).
|
||||
R2.graceNets=0;if(S.grace&&S.grace.until>day){const gs=new Set(S.grace.nets.filter(n=>NET[n]&&!E.some(e=>e.k!=='c'&&e.ok(n)))),hc=popUp(S.home)?S.home:pops.find(popUp);
|
||||
R2.graceNets=gs.size;if(gs.size&&hc)E.push({k:'ix',pref:'normal',lab:tr('Courtesy route to new networks'),id:'~grace',city:hc,cap:1e9,used:0,rank:2,ok:n=>gs.has(n),nets:gs});}
|
||||
R2.graceNets=gs.size;if(gs.size&&hc)E.push({k:'ix',pref:'normal',lab:tr('compute.courtesy_route_to_new_networks'),id:'~grace',city:hc,cap:1e9,used:0,rank:2,ok:n=>gs.has(n),nets:gs});}
|
||||
{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);}}
|
||||
// ok() cannot change during one compute, so ask each exit once per network, not once per flow and rank.
|
||||
// okBy[net] lists the exits that reach it in E's order, like E.filter(e=>e.ok(net)).
|
||||
|
|
@ -120,7 +120,7 @@ function compute(){
|
|||
const pairs=b.sites?b.sites.slice(1).map(x=>[b.sites[0],x]):[[b.city,b.city2]];let minF=1,maxLat=0,tot=0,noPath=false;
|
||||
for(const [A,B] of pairs){let amt=0;
|
||||
if(popUp(A)&&popUp(B)&&SPD[A]&&SPD[A][CIDX[B]]<Infinity){
|
||||
const ek='l2:'+b.id;R2.egDesc[ek]={lab:labOf(b.sites?N_('SD-WAN for {name}'):N_('L2VPN for {name}'),'name',b.name),city:A,k:'l2'};
|
||||
const ek='l2:'+b.id;R2.egDesc[ek]={lab:labOf(b.sites?N_('compute.sd_wan_for_name'):N_('compute.l2vpn_for_name'),'name',b.name),city:A,k:'l2'};
|
||||
const routes=l2Routes(A,B,b);if(routes.length>1)R2.l2split[b.id]=routes.length;
|
||||
for(const {path,ni,share} of routes){let a=b.bw*share;for(const l of path)a=Math.min(a,l.res);for(const i of ni)if(HAS[i])a=Math.min(a,NRES[i]);a=Math.max(0,a);amt+=a;maxLat=Math.max(maxLat,path.reduce((x,e)=>x+e.lat,0)+path.length*0.05);
|
||||
for(const i of ni)if(HAS[i])nodeTake(i,a);
|
||||
|
|
@ -135,7 +135,7 @@ function compute(){
|
|||
for(const H of HAUL){const A=H.c,B=H.to,Ai=CIDX[A],Bi=CIDX[B];let h=0,ms=null;
|
||||
if(popUp(A)&&popUp(B)&&SPD[A]&&SPD[A][Bi]<Infinity){const {path,ni}=walkI(SPP[A],Ai,Bi);let room=Infinity;for(const l of path)room=Math.min(room,l.res);for(const i of ni)if(HAS[i])room=Math.min(room,NRES[i]);
|
||||
const want=H.a+H.v,take=Math.max(0,Math.min(want,room));h=want>0?H.a*take/want:0;ms=path.reduce((x,e)=>x+e.lat,0)*2;
|
||||
const ek='scrub:'+B;R2.egDesc[ek]={lab:labOf(N_('Attack hauled to scrubbing in {city}'),'city',CITY[B].name),city:A,k:'l2'};
|
||||
const ek='scrub:'+B;R2.egDesc[ek]={lab:labOf(N_('compute.attack_hauled_to_scrubbing_in_city'),'city',CITY[B].name),city:A,k:'l2'};
|
||||
for(const i of ni)if(HAS[i])nodeTake(i,take);for(const l of path){l.res-=take;l.ld+=take;carry(l,ek,NN,Ai,take);}}
|
||||
R2.haul.push({city:A,to:B,tier:H.tier,a:H.a,h,ms});const left=(H.a-h)*0.85;if(left>1e-6)for(let j=0;j<NN;j++)flow(A,Ai,cnCity(A),j,left*NSH[NETS[j].id],false,true);}
|
||||
const TE=!!(S.te&&S.te.on),TR=teRules();R2.teMoved=0;const teCache=new Map(),SPILL=TR&&TR.spill?TR.spill:1;
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ function sanitize(s){
|
|||
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;
|
||||
for(const c of Object.keys(s.ixn))s.ixn[c]=lag(s.ixn[c]);for(const c of Object.keys(s.ixSite))if(!['a','b','ab'].includes(s.ixSite[c]))s.ixSite[c]='a';
|
||||
for(const k of Object.keys(s.peers)){const [n,c]=k.split('@');if(!isNet(n)||!isIx(c))delete s.peers[k];}
|
||||
for(const c of Object.keys(s.myIx)){const m=s.myIx[c];if(!isCity(c)||!m||typeof m!=='object'){delete s.myIx[c];continue;}m.members=Array.isArray(m.members)?m.members.filter(isNet):[];m.name=String(m.name||tr('Your IX')).slice(0,40);m.next=num(m.next,s.day);m.fab=int(m.fab,0,MYIX_FAB.length-1,0);}
|
||||
for(const c of Object.keys(s.myIx)){const m=s.myIx[c];if(!isCity(c)||!m||typeof m!=='object'){delete s.myIx[c];continue;}m.members=Array.isArray(m.members)?m.members.filter(isNet):[];m.name=String(m.name||tr('common.your_ix')).slice(0,40);m.next=num(m.next,s.day);m.fab=int(m.fab,0,MYIX_FAB.length-1,0);}
|
||||
const okBiz=b=>b&&own(BIZ_T,b.type)&&(!BIZ_T[b.type].nni||own(FAB,b.prov))&&isCity(b.city)&&(!b.city2||isCity(b.city2))&&(!b.sites||Array.isArray(b.sites)&&b.sites.every(isCity));
|
||||
const fixBiz=b=>{b.id=sid(b.id);b.name=String(b.name||tr('Customer')).slice(0,80);b.bw=num(b.bw,1);b.rate=num(b.rate,0);if(b.fee!==undefined)b.fee=num(b.fee,0);if(b.start!==undefined)b.start=num(b.start,0);if(b.dur!==undefined)b.dur=num(b.dur,1);if(b.slots!==undefined)b.slots=num(b.slots,0);if(b.what!==undefined)b.what=String(b.what).slice(0,200);if(b.broker!==undefined)b.broker=!!b.broker;if(!Array.isArray(b.reqs))b.reqs=[];b.reqs=b.reqs.filter(r=>own(REQS,r));if(b.mood!==undefined)b.mood=num(b.mood,100);if(b.pm!==undefined)b.pm=num(b.pm,b.mood||100);if(b.exp!==undefined)b.exp=num(b.exp,0);if(b.latMax!=null)b.latMax=num(b.latMax,10);if(b.route&&!own(RT,b.route))b.route='normal';return b;};
|
||||
const fixBiz=b=>{b.id=sid(b.id);b.name=String(b.name||tr('common.customer')).slice(0,80);b.bw=num(b.bw,1);b.rate=num(b.rate,0);if(b.fee!==undefined)b.fee=num(b.fee,0);if(b.start!==undefined)b.start=num(b.start,0);if(b.dur!==undefined)b.dur=num(b.dur,1);if(b.slots!==undefined)b.slots=num(b.slots,0);if(b.what!==undefined)b.what=String(b.what).slice(0,200);if(b.broker!==undefined)b.broker=!!b.broker;if(!Array.isArray(b.reqs))b.reqs=[];b.reqs=b.reqs.filter(r=>own(REQS,r));if(b.mood!==undefined)b.mood=num(b.mood,100);if(b.pm!==undefined)b.pm=num(b.pm,b.mood||100);if(b.exp!==undefined)b.exp=num(b.exp,0);if(b.latMax!=null)b.latMax=num(b.latMax,10);if(b.route&&!own(RT,b.route))b.route='normal';return b;};
|
||||
s.biz=s.biz.filter(okBiz).map(fixBiz);s.offers=s.offers.filter(okBiz).map(fixBiz);
|
||||
s.inc=s.inc.filter(i=>i&&typeof i.type==='string').map(i=>(i.id=sid(i.id),i.until=num(i.until,s.day),i.cost=num(i.cost,0),i.msg=String(i.msg||'').slice(0,400),i.fix=i.fix==null?undefined:String(i.fix).slice(0,60),i));
|
||||
s.loans=s.loans.filter(l=>l&&own(BANKS,l.bank));for(const l of s.loans){if(l.model!==undefined&&!['balloon','storm','transit','astro'].includes(l.model))delete l.model;for(const k of ['apr0','cut','share'])if(l[k]!==undefined&&!isFinite(+l[k]))delete l[k];if(!Array.isArray(l.covs))l.covs=[];l.covs=l.covs.filter(c=>own(COVS,c));}s.loanOffers=s.loanOffers.filter(l=>l&&own(BANKS,l.bank));
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
const GRACE_DAYS=60;
|
||||
const REQS={
|
||||
lat:{only:true,l2:true,bonus:0,l:o=>tr('One-way latency within {max} ms (best now: {best})',{max:o.latMax,best:(()=>{const v=R.l2lat[o.id]!==undefined?R.l2lat[o.id]:bestLat(o.city,o.city2);return isFinite(v)?v.toFixed(1)+' ms':tr('no path')})()}),ok:b=>(R.l2lat[b.id]!==undefined?R.l2lat[b.id]:bestLat(b.city,b.city2))<=b.latMax},
|
||||
nni:{only:true,bonus:0,l:o=>tr('Comes in over {fab}: needs your {fab} port in {city} with room for {bw}',{fab:FAB[o.prov]?FAB[o.prov].name:'?',city:CITY[o.city].name,bw:fmtG(o.bw)}),ok:b=>{const pt=nniPort(b.city,b.prov);return !!pt&&nniUsed(b.city,b.prov)<=NNI[pt.tier].g+1e-9;}},
|
||||
diverse:{l:tr('Two paths that share no trench or fabric'),bonus:.25,l2:true,can:(b,s=S)=>diversityPossible(b.city,b.city2,s),ok:b=>R.div[b.id]!==undefined?!!R.div[b.id]:diversePaths(b.city,b.city2)},
|
||||
sharks:{l:tr('Afraid of sharks: needs a path with no subsea cable'),bonus:.2,l2:true,ok:b=>terrestrialPath(b.city,b.city2),can:b=>!!b.city2&&!isSub(b.city,b.city2)},
|
||||
nocog:{l:tr('Refuses Cogentle transit anywhere on your network (long story)'),bonus:.15,ok:()=>!S.transit.some(t=>t.net==='cog')},
|
||||
ipv6:{l:tr('IPv6 or bust: you must peer with Drizzle Electric'),bonus:.1,ok:()=>Object.keys(S.ixp).some(c=>ixSessions(c).has('drz'))||S.pni.some(p=>p.net==='drz'&&pniOn(p))},
|
||||
netchill:{l:tr('Wants NetChill on-net: a cache or a PNI'),bonus:.15,ok:()=>S.caches.some(c=>c.net==='nfx')||S.pni.some(p=>p.net==='nfx'&&pniOn(p))},
|
||||
gen:{l:tr('Backup generator in every city they touch'),bonus:.15,ok:b=>[b.city,b.city2].filter(Boolean).every(c=>S.pops[c]&&S.pops[c].gen)},
|
||||
routers:{l:tr('Insists on two routers in their city'),bonus:.15,ok:b=>((S.pops[b.city]&&S.pops[b.city].routers)||1)>=2},
|
||||
local:{l:tr('Local breakout: transit or an IX port in their own city, or a local PNI while Tier 1'),bonus:.2,ip:true,ok:b=>S.transit.some(t=>t.city===b.city)||hasIxAt(b.city)||(isTier1()&&S.pni.some(p=>p.city===b.city))},
|
||||
metro:{l:tr('Two data centers in every metro they touch'),bonus:.2,only:true,ok:b=>[b.city,b.city2].filter(Boolean).every(c=>S.pops[c]&&S.pops[c].site2)},
|
||||
twoup:{l:tr('Wants two different transit providers (or none at all)'),bonus:.15,ip:true,ok:()=>new Set(S.transit.map(t=>t.net)).size>=2||S.transit.length===0},
|
||||
china:{l:tr('Needs low-loss reach into China'),bonus:.3,ip:true,ok:()=>S.transit.some(t=>t.premium&&t.city==='hkg')||S.links.some(l=>l.premium)||S.pni.some(p=>NET[p.net].cn&&pniOn(p))},
|
||||
scrubbed:{l:tr('Will only sign with a network that runs a DDoS scrubbing center'),bonus:.15,ok:()=>hasScrub()},
|
||||
scrubnear:{l:tr('Wants a scrubbing center on its own continent, so attacks are not hauled across an ocean'),bonus:.15,ip:true,ok:b=>S.scrubs.some(x=>CITY[x.city].reg===CITY[b.city].reg)},
|
||||
puns:{l:tr('Their CEO hates puns. Please do not mention the network names.'),bonus:.05,ok:()=>true},
|
||||
lat:{only:true,l2:true,bonus:0,l:o=>tr('requirements.one_way_latency_within_max_ms',{max:o.latMax,best:(()=>{const v=R.l2lat[o.id]!==undefined?R.l2lat[o.id]:bestLat(o.city,o.city2);return isFinite(v)?v.toFixed(1)+' ms':tr('common.no_path')})()}),ok:b=>(R.l2lat[b.id]!==undefined?R.l2lat[b.id]:bestLat(b.city,b.city2))<=b.latMax},
|
||||
nni:{only:true,bonus:0,l:o=>tr('requirements.comes_in_over_fab_needs_your',{fab:FAB[o.prov]?FAB[o.prov].name:'?',city:CITY[o.city].name,bw:fmtG(o.bw)}),ok:b=>{const pt=nniPort(b.city,b.prov);return !!pt&&nniUsed(b.city,b.prov)<=NNI[pt.tier].g+1e-9;}},
|
||||
diverse:{l:tr('requirements.two_paths_that_share_no_trench'),bonus:.25,l2:true,can:(b,s=S)=>diversityPossible(b.city,b.city2,s),ok:b=>R.div[b.id]!==undefined?!!R.div[b.id]:diversePaths(b.city,b.city2)},
|
||||
sharks:{l:tr('requirements.afraid_of_sharks_needs_a_path'),bonus:.2,l2:true,ok:b=>terrestrialPath(b.city,b.city2),can:b=>!!b.city2&&!isSub(b.city,b.city2)},
|
||||
nocog:{l:tr('requirements.refuses_cogentle_transit_anywhere_on'),bonus:.15,ok:()=>!S.transit.some(t=>t.net==='cog')},
|
||||
ipv6:{l:tr('requirements.ipv6_or_bust_you_must_peer'),bonus:.1,ok:()=>Object.keys(S.ixp).some(c=>ixSessions(c).has('drz'))||S.pni.some(p=>p.net==='drz'&&pniOn(p))},
|
||||
netchill:{l:tr('requirements.wants_netchill_on_net_a_cache'),bonus:.15,ok:()=>S.caches.some(c=>c.net==='nfx')||S.pni.some(p=>p.net==='nfx'&&pniOn(p))},
|
||||
gen:{l:tr('requirements.backup_generator_in_every_city_they'),bonus:.15,ok:b=>[b.city,b.city2].filter(Boolean).every(c=>S.pops[c]&&S.pops[c].gen)},
|
||||
routers:{l:tr('requirements.insists_on_two_routers_in_their'),bonus:.15,ok:b=>((S.pops[b.city]&&S.pops[b.city].routers)||1)>=2},
|
||||
local:{l:tr('requirements.local_breakout_transit_or_an_ix'),bonus:.2,ip:true,ok:b=>S.transit.some(t=>t.city===b.city)||hasIxAt(b.city)||(isTier1()&&S.pni.some(p=>p.city===b.city))},
|
||||
metro:{l:tr('requirements.two_data_centers_in_every_metro'),bonus:.2,only:true,ok:b=>[b.city,b.city2].filter(Boolean).every(c=>S.pops[c]&&S.pops[c].site2)},
|
||||
twoup:{l:tr('requirements.wants_two_different_transit'),bonus:.15,ip:true,ok:()=>new Set(S.transit.map(t=>t.net)).size>=2||S.transit.length===0},
|
||||
china:{l:tr('requirements.needs_low_loss_reach_into_china'),bonus:.3,ip:true,ok:()=>S.transit.some(t=>t.premium&&t.city==='hkg')||S.links.some(l=>l.premium)||S.pni.some(p=>NET[p.net].cn&&pniOn(p))},
|
||||
scrubbed:{l:tr('requirements.will_only_sign_with_a_network'),bonus:.15,ok:()=>hasScrub()},
|
||||
scrubnear:{l:tr('requirements.wants_a_scrubbing_center_on_its'),bonus:.15,ip:true,ok:b=>S.scrubs.some(x=>CITY[x.city].reg===CITY[b.city].reg)},
|
||||
puns:{l:tr('requirements.their_ceo_hates_puns_please_do'),bonus:.05,ok:()=>true},
|
||||
};
|
||||
function terrestrialPath(a,b){const ls=S.links.filter(l=>!linkDown(l)&&!l.sub);const adj={};for(const l of ls){(adj[l.a]=adj[l.a]||[]).push(l.b);(adj[l.b]=adj[l.b]||[]).push(l.a);}const seen=new Set([a]),q=[a];while(q.length){const u=q.shift();if(u===b)return true;for(const v of adj[u]||[])if(!seen.has(v)){seen.add(v);q.push(v);}}return false;}
|
||||
const reqOk=b=>(b.reqs||[]).every(k=>REQS[k]&&REQS[k].ok(b));
|
||||
|
|
@ -56,8 +56,8 @@ function soldSlots(l){return S.biz.filter(b=>b.type==='wwave'&&b.link===l.id).re
|
|||
// Spare capacity other carriers can rent on a dark fiber (#51): free channels for alien waves, and on your own build
|
||||
// a spare pair in the trench. Random offers and broker listings follow the same rules and the same prices.
|
||||
const freeCh=l=>chMax(l)-(l.ch||[]).length-soldSlots(l),pairFree=l=>!!l.own&&S.biz.filter(b=>b.type==='dfpair'&&b.link===l.id).length<2&&!S.biz.some(b=>b.type==='pairs'&&b.link===l.id);
|
||||
const wwWhat=(l,n)=>trn('{n}× 400G alien wave on your {a}–{b} fiber','{n}× 400G alien waves on your {a}–{b} fiber',n,{a:CITY[l.a].name,b:CITY[l.b].name});
|
||||
const wwWhat=(l,n)=>trn('requirements.n_400g_alien_wave_on_your',n,{a:CITY[l.a].name,b:CITY[l.b].name});
|
||||
function fiberOffer(t,l,nm,cut=1){
|
||||
if(t==='wwave'){const slots=1+Math.floor(Math.random()*Math.min(4,freeCh(l)));
|
||||
return {id:uid(),city:l.a,city2:l.b,link:l.id,slots,what:wwWhat(l,slots),name:nm(),type:t,bw:1,rate:Math.round(waveMo(l.km,false,2)*0.55*slots*cut),reqs:[],exp:S.day+30};}
|
||||
return {id:uid(),city:l.a,city2:l.b,link:l.id,what:tr('a spare fiber pair in your {a}–{b} trench',{a:CITY[l.a].name,b:CITY[l.b].name}),name:nm(),type:t,bw:1,rate:Math.round(dfLeaseMo(l.km)*0.9*cut),reqs:[],exp:S.day+30};}
|
||||
return {id:uid(),city:l.a,city2:l.b,link:l.id,what:tr('requirements.a_spare_fiber_pair_in_your',{a:CITY[l.a].name,b:CITY[l.b].name}),name:nm(),type:t,bw:1,rate:Math.round(dfLeaseMo(l.km)*0.9*cut),reqs:[],exp:S.day+30};}
|
||||
|
|
|
|||
|
|
@ -5,36 +5,36 @@ function bCities(o){return o.sites?o.sites.slice():[o.city,o.city2].filter(Boole
|
|||
function bHas(o){return bCities(o).every(c=>S.pops[c]);}
|
||||
function eventLive(b){return BIZ_T[b.type].event&&S.day>=b.start&&S.day<b.start+b.dur;}
|
||||
function bTerms(o){const T=BIZ_T[o.type];
|
||||
if(T.event){const live=S.day>=o.start;return tr('{bw} extra for {d} days, {when} · pays {fee} when it is over',{bw:fmtG(o.bw),d:o.dur,when:live?tr('day {n} of {d}',{n:S.day-o.start+1,d:o.dur}):tr('starting in {n}d',{n:o.start-S.day}),fee:fmt$(o.fee)});}
|
||||
if(T.sdwan)return tr('{n} sites: {list} · {bw} per site · {price}/mo',{n:o.sites.length,list:o.sites.map(c=>CITY[c].name).join(', '),bw:fmtG(o.bw),price:fmt$(o.bw*o.rate)});
|
||||
if(T.fiber)return esc(o.what)+' · '+tr('{price}/mo',{price:fmt$(o.rate)});
|
||||
return fmtG(o.bw)+' · '+tr('{price}/mo',{price:fmt$(o.bw*o.rate)});}
|
||||
if(T.event){const live=S.day>=o.start;return tr('customers_and_events.bw_extra_for_d_days_when',{bw:fmtG(o.bw),d:o.dur,when:live?tr('customers_and_events.day_n_of_d',{n:S.day-o.start+1,d:o.dur}):tr('customers_and_events.starting_in_n_d',{n:o.start-S.day}),fee:fmt$(o.fee)});}
|
||||
if(T.sdwan)return tr('customers_and_events.n_sites_list_bw_per_site',{n:o.sites.length,list:o.sites.map(c=>CITY[c].name).join(', '),bw:fmtG(o.bw),price:fmt$(o.bw*o.rate)});
|
||||
if(T.fiber)return esc(o.what)+' · '+tr('common.price_mo',{price:fmt$(o.rate)});
|
||||
return fmtG(o.bw)+' · '+tr('common.price_mo',{price:fmt$(o.bw*o.rate)});}
|
||||
// Events are paid once at the end, prorated by how much of the crowd you served.
|
||||
function eventTick(b,d){if(!BIZ_T[b.type].event)return false;if(d<b.start)return true;
|
||||
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('<b>{name} starts today!</b><br>{bw} of extra demand in {city} for {d} days.',{name:esc(b.name),bw:fmtG(b.bw),city:CITY[b.city].name,d:b.dur}),'goal',[{l:tr('Show me'),act:'focusCity',args:{city:b.city}}]);return true;}
|
||||
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('<b>{name} is over: +{pay}</b><br>You delivered {pct} of what the crowd wanted.',{name:esc(b.name),pay:fmt$(pay),pct:pct(avg)})+(avg>=0.95?' '+tr('Flawless.'):''):tr('<b>{name} was a disaster.</b><br>Only {pct} delivered, and it trended on social media. Penalty: {pay}.',{name:esc(b.name),pct:pct(avg),pay:fmt$(-pay)}),pay>=0?'good':'bad');sfx(pay>=0?'coin':'err');return true;}
|
||||
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:'Colossal Ego 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'}];
|
||||
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);
|
||||
S.offers.push({id:uid(),city:m.c,city2:null,name:tr('{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;}
|
||||
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);
|
||||
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;
|
||||
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('{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;}
|
||||
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;}
|
||||
if(t==='pairs'){const ls=S.links.filter(l=>l.kind==='df'&&l.own&&l.ready<=S.day&&!S.biz.some(b=>(b.type==='pairs'||b.type==='dfpair')&&b.link===l.id)&&!S.offers.some(o=>o.link===l.id));if(!ls.length)return;const l=pick(ls),n=100+50*Math.floor(Math.random()*7);
|
||||
S.offers.push({id:uid(),city:l.a,city2:l.b,link:l.id,what:tr('{n} fiber pairs in your {a}–{b} trench. Trenching was the expensive part, so they want all of it',{n,a:CITY[l.a].name,b:CITY[l.b].name}),name:nm(),type:t,bw:1,rate:Math.round(dfLeaseMo(l.km)*n*0.2),reqs:[],exp:S.day+30,mega:true});}
|
||||
S.offers.push({id:uid(),city:l.a,city2:l.b,link:l.id,what:tr('customers_and_events.n_fiber_pairs_in_your_a',{n,a:CITY[l.a].name,b:CITY[l.b].name}),name:nm(),type:t,bw:1,rate:Math.round(dfLeaseMo(l.km)*n*0.2),reqs:[],exp:S.day+30,mega:true});}
|
||||
}
|
||||
function spawnSpecial(t){const T=BIZ_T[t],mine=Object.keys(S.pops),lv=S.lvl||1;
|
||||
const nm=()=>{const list=T.names.filter(n=>!S.usedNames.includes(n));const n=list.length?pick(list):pick(T.names);S.usedNames.push(n);return n;};
|
||||
if(T.mega){spawnMega(t,T,nm,mine);return;}
|
||||
if(T.event){const city=Math.random()<0.85&&mine.length?pick(mine):pick(OFFC);const bw=pick(T.opts.slice(0,Math.min(T.opts.length,lv+2)));const dur=3+Math.floor(Math.random()*5),start=S.day+12+Math.floor(Math.random()*14);
|
||||
S.offers.push({id:uid(),city,city2:null,name:tr('{name} in {city}',{name:nm(),city:CITY[city].name}),type:t,bw,rate:0,reqs:[],start,dur,fee:Math.round(bw*dur*70),exp:start-2});return;}
|
||||
S.offers.push({id:uid(),city,city2:null,name:tr('customers_and_events.name_in_city',{name:nm(),city:CITY[city].name}),type:t,bw,rate:0,reqs:[],start,dur,fee:Math.round(bw*dur*70),exp:start-2});return;}
|
||||
if(T.sdwan){const hub=pick(mine),n=3+Math.floor(Math.random()*4),pool=(Math.random()<0.85?mine:OFFC).filter(c=>c!==hub),sites=[hub];
|
||||
while(sites.length<n&&pool.length)sites.push(pool.splice(Math.floor(Math.random()*pool.length),1)[0]);if(sites.length<3)return;
|
||||
S.offers.push({id:uid(),city:hub,city2:null,sites,name:nm(),type:t,bw:pick(T.opts),rate:700*sites.length,reqs:[],exp:S.day+40});return;}
|
||||
|
|
|
|||
|
|
@ -11,29 +11,29 @@ const andesPair=(a,b)=>!!CITY[a].andes&&!!CITY[b].andes&&CITY[a].andes!==CITY[b]
|
|||
carriers, each taking a cut: in real life it costs ten times the subsea route or more (#40). */
|
||||
const LAND_X=45,landX=(a,b)=>!isSub(a,b)&&CITY[a].reg!==CITY[b].reg;
|
||||
function landMult(a,b){if(isSub(a,b))return 1;if(uaePair(a,b))return 3;return (landX(a,b)?LAND_X:1)*(andesPair(a,b)?2:1)*(nullPair(a,b)?NULLARBOR:1)*(rainPair(a,b)?2:1)*(borderPair(a,b)?2:1);}
|
||||
function landWhy(a,b){if(isSub(a,b))return '';if(uaePair(a,b))return tr('Inside the UAE only the two licensed operators, Etis-a-lot and Du-opoly, may run fiber. No dark fiber, no digging your own, and waves cost 3×.');
|
||||
const r=[];if(CITY[a].reg!==CITY[b].reg)r.push(tr('Overland between continents crosses a dozen borders, and every carrier on the way takes a cut: {x}× the price. Subsea is far cheaper.',{x:LAND_X}));if(andesPair(a,b))r.push(tr('This route crosses the Andes: 2× the price, and landslides and snow cut it far more often than flat fiber.'));if(nullPair(a,b))r.push(tr('This route crosses the Nullarbor: {x}× the price. A thousand kilometres of nothing, and the incumbents own all of it.',{x:NULLARBOR}));if(borderPair(a,b))r.push(tr('This route crosses a border in Africa: 2× the price. Every country wants its own permits, its own carrier and its own cut.'));if(rainPair(a,b))r.push(tr('This route goes into the Amazon: 2× the price. The fiber runs along rivers and jungle roads, and repairs go by boat.'));return r.join(' ');}
|
||||
function landWhy(a,b){if(isSub(a,b))return '';if(uaePair(a,b))return tr('geography_and_latency.inside_the_uae_only_the_two');
|
||||
const r=[];if(CITY[a].reg!==CITY[b].reg)r.push(tr('geography_and_latency.overland_between_continents_crosses',{x:LAND_X}));if(andesPair(a,b))r.push(tr('geography_and_latency.this_route_crosses_the_andes_2'));if(nullPair(a,b))r.push(tr('geography_and_latency.this_route_crosses_the_nullarbor_x',{x:NULLARBOR}));if(borderPair(a,b))r.push(tr('geography_and_latency.this_route_crosses_a_border_in'));if(rainPair(a,b))r.push(tr('geography_and_latency.this_route_goes_into_the_amazon'));return r.join(' ');}
|
||||
function linkLat(l){const f=l.kind==='df'?(l.own?(l.sub?seaLatencyFactor(l):1.1):1.25):l.kind==='vxc'?1.4:l.cable?(CAB[l.cable].lat||1):1.3;return l.km*f/200;}
|
||||
/* Wave prices differ a lot by market (TeleGeography): Europe's dense, competitive metro and
|
||||
long-haul routes are cheap (Frankfurt–London 100G ≈ $1,150/mo), the US costs more, and
|
||||
routes into Africa are several times dearer (Africa–Europe ≈ 5.9× London–New York).
|
||||
Each route also gets its own market mood, and new leases get cheaper every year (~8%). */
|
||||
const WAVE_LAND={EU:0.65,AM:1,SA:1.6,AS:1.4,OC:1.2,AF:2.2},WAVE_SUB={EU:0.8,AM:1,SA:2,AS:1.5,OC:1.5,AF:4.5};
|
||||
const WAVE_NAME={EU:tr('Europe'),AM:tr('North America'),SA:tr('South America'),AS:tr('Asia'),OC:tr('Oceania'),AF:tr('Africa')};
|
||||
const WAVE_NAME={EU:tr('common.europe'),AM:tr('common.north_america'),SA:tr('common.south_america'),AS:tr('common.asia'),OC:tr('common.oceania'),AF:tr('common.africa')};
|
||||
function waveMarket(a,b,sub){const ra=CITY[a].reg,rb=CITY[b].reg,T=sub?WAVE_SUB:WAVE_LAND,au=sub?AU_WAVE.sub:AU_WAVE.land;
|
||||
const fa=CITY[a].au?au:(T[ra]||1),fb=CITY[b].au?au:(T[rb]||1),reg=sub&&nullPair(a,b)?AU_WAVE.ew:sub?Math.max(fa,fb):(fa+fb)/2;
|
||||
const key=a<b?a+b:b+a,mood=0.85+(hstr(key+'|mood')%31)/100;
|
||||
const ero=Math.max(0.55,Math.pow(0.92,Math.floor((S?S.day:0)/360)));
|
||||
return {m:reg*mood*ero,reg,mood,ero};}
|
||||
function marketNote(a,b,sub){const k=waveMarket(a,b,sub),ra=CITY[a].reg,rb=CITY[b].reg;const where=ra===rb?WAVE_NAME[ra]:tr('{a} to {b}',{a:WAVE_NAME[ra],b:WAVE_NAME[rb]});
|
||||
const lvl=k.reg<0.9?tr('cheap: lots of competing fiber'):k.reg<=1.05?tr('about average'):k.reg<2?tr('pricey: fewer carriers'):tr('expensive: scarce capacity');const since=k.ero<1?tr(', and prices have fallen {p}% since you started',{p:Math.round((1-k.ero)*100)}):'';
|
||||
return k.mood<0.97?tr('{where}: {lvl}. This route is {p}% below the going rate{since}.',{where,lvl,p:Math.round((1-k.mood)*100),since}):k.mood>1.03?tr('{where}: {lvl}. This route is {p}% above the going rate{since}.',{where,lvl,p:Math.round((k.mood-1)*100),since}):tr('{where}: {lvl}. This route is right at the going rate{since}.',{where,lvl,since});}
|
||||
function marketNote(a,b,sub){const k=waveMarket(a,b,sub),ra=CITY[a].reg,rb=CITY[b].reg;const where=ra===rb?WAVE_NAME[ra]:tr('geography_and_latency.a_to_b',{a:WAVE_NAME[ra],b:WAVE_NAME[rb]});
|
||||
const lvl=k.reg<0.9?tr('geography_and_latency.cheap_lots_of_competing_fiber'):k.reg<=1.05?tr('common.about_average'):k.reg<2?tr('geography_and_latency.pricey_fewer_carriers'):tr('geography_and_latency.expensive_scarce_capacity');const since=k.ero<1?tr('geography_and_latency.and_prices_have_fallen_p_since',{p:Math.round((1-k.ero)*100)}):'';
|
||||
return k.mood<0.97?tr('geography_and_latency.where_lvl_this_route_is_p',{where,lvl,p:Math.round((1-k.mood)*100),since}):k.mood>1.03?tr('geography_and_latency.where_lvl_this_route_is_p_0196',{where,lvl,p:Math.round((k.mood-1)*100),since}):tr('geography_and_latency.where_lvl_this_route_is_right',{where,lvl,since});}
|
||||
function waveRoute(a,b,mult,border){const cabs=cablesOk(a,b),sub=isSub(a,b);let via=UI.via;
|
||||
if(!cabs.find(c=>c.cid===via))via=sub?(cabs[0]?cabs[0].cid:null):(via==='land'||!via?'land':'land');
|
||||
if(!via)return null;const bf=border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1;
|
||||
if(via==='land')return {via,cabs,cab:null,km:kmBetween(a,b),sub:false,wm:mult*landMult(a,b)*waveMarket(a,b,false).m};
|
||||
const c=cabs.find(x=>x.cid===via);return {via,cabs,cab:via,km:c.km,sub:true,wm:bf*CAB[via].price*waveMarket(a,b,true).m};}
|
||||
function viaSeg(a,b){const cabs=cablesOk(a,b),sub=isSub(a,b);if(!cabs.length)return landMult(a,b)>1?`<p class="note">${landWhy(a,b)}</p>`:'';const wr=waveRoute(a,b,1,false);
|
||||
const opts=(sub?[]:[{v:'land',l:`${tr('Overland')} <small>${landMult(a,b)>1?landMult(a,b)+'× · ':''}${(kmBetween(a,b)*1.3/200).toFixed(1)} ms</small>`}]).concat(cabs.map(c=>({v:c.cid,l:`${esc(CAB[c.cid].name)} <small>${CAB[c.cid].price}× · ${(c.km*(CAB[c.cid].lat||1)/200).toFixed(1)} ms${CAB[c.cid].age==='old'?' · '+tr('old, cuts often'):''}</small>`})));
|
||||
return `<h4 class="sub4">${tr('Route')}</h4><div class="seg">${opts.map(o=>btn(o.l,'via',{v:o.v},wr&&wr.via===o.v?'pink':'ghost')).join('')}</div>${wr&&wr.cab?`<p class="note">${esc(CAB[wr.cab].blurb)} ${tr('All your waves on one cable share its fate when it is cut.')}</p>`:''}`;}
|
||||
const opts=(sub?[]:[{v:'land',l:`${tr('common.overland')} <small>${landMult(a,b)>1?landMult(a,b)+'× · ':''}${(kmBetween(a,b)*1.3/200).toFixed(1)} ms</small>`}]).concat(cabs.map(c=>({v:c.cid,l:`${esc(CAB[c.cid].name)} <small>${CAB[c.cid].price}× · ${(c.km*(CAB[c.cid].lat||1)/200).toFixed(1)} ms${CAB[c.cid].age==='old'?' · '+tr('geography_and_latency.old_cuts_often'):''}</small>`})));
|
||||
return `<h4 class="sub4">${tr('common.route')}</h4><div class="seg">${opts.map(o=>btn(o.l,'via',{v:o.v},wr&&wr.via===o.v?'pink':'ghost')).join('')}</div>${wr&&wr.cab?`<p class="note">${esc(CAB[wr.cab].blurb)} ${tr('geography_and_latency.all_your_waves_on_one_cable')}</p>`:''}`;}
|
||||
function bestLat(a,b){const ls=S.links.filter(l=>!linkDown(l));const dist={[a]:0},done=new Set();for(;;){let u=null,ud=Infinity;for(const k in dist)if(!done.has(k)&&dist[k]<ud){u=k;ud=dist[k];}if(u===null)break;if(u===b)return ud;done.add(u);for(const l of ls){if(l.a!==u&&l.b!==u)continue;const v=l.a===u?l.b:l.a,nd=ud+linkLat(l)+0.05;if(nd<(dist[v]??Infinity))dist[v]=nd;}}return Infinity;}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const RT={normal:tr('Follow metrics'),fast:tr('Lowest latency'),scenic:tr('Scenic (quietest links)')};
|
||||
function routeCtl(b){const lt=R.l2lat[b.id];return `<div class="btns"><span class="meta" style="align-self:center">${tr('Route:')}</span>${Object.keys(RT).map(m=>btn(RT[m],'setRoute',{id:b.id,m},(b.route||'normal')===m?'pink sm':'ghost sm')).join('')}</div><div class="meta">${tr('Path latency: <b>{lat}</b>',{lat:lt!==undefined&&isFinite(lt)?tr('{ms} ms one-way',{ms:lt.toFixed(1)}):tr('no path right now')})}${b.route==='scenic'&&R.l2split&&R.l2split[b.id]?' · '+tr('split over two equally quiet paths'):''}${b.latMax?' · '+tr('budget {ms} ms',{ms:b.latMax}):''}</div>`;}
|
||||
const RT={normal:tr('common.follow_metrics'),fast:tr('common.lowest_latency'),scenic:tr('sites_and_service.scenic_quietest_links')};
|
||||
function routeCtl(b){const lt=R.l2lat[b.id];return `<div class="btns"><span class="meta" style="align-self:center">${tr('common.route_4a2e')}</span>${Object.keys(RT).map(m=>btn(RT[m],'setRoute',{id:b.id,m},(b.route||'normal')===m?'pink sm':'ghost sm')).join('')}</div><div class="meta">${tr('sites_and_service.path_latency_lat',{lat:lt!==undefined&&isFinite(lt)?tr('common.ms_ms_one_way',{ms:lt.toFixed(1)}):tr('sites_and_service.no_path_right_now')})}${b.route==='scenic'&&R.l2split&&R.l2split[b.id]?' · '+tr('sites_and_service.split_over_two_equally_quiet_paths'):''}${b.latMax?' · '+tr('sites_and_service.budget_ms_ms',{ms:b.latMax}):''}</div>`;}
|
||||
function nodeCap(c){const p=S.pops[c];if(!p)return Infinity;const eff=(p.routers||1)-(p.rdown>S.day?1:0);return RG[p.rgen||0].cap*Math.max(1,eff)*(p.hot>S.day?(p.site2?0.75:0.5):1)*(p.site2&&(siteDown(c,'a')||siteDown(c,'b'))?0.5:1);}
|
||||
// With a second site, one building can be dark (or cut off by a ring cut) while the other carries on.
|
||||
function siteDown(c,s){const p=S.pops[c];if(!p||!p.site2)return false;if(S.inc.some(i=>i.type==='site'&&i.ref===c&&i.site===s&&i.until>S.day))return true;return s==='b'&&p.ringcut>S.day;}
|
||||
|
|
@ -10,17 +10,17 @@ function liveN(c,site,n){n=n||1;const p=S.pops[c];if(!p||!p.site2)return n;if(si
|
|||
const myIxLive=c=>{const ct=ixCity(c),st=(S.ixSite||{})[c]||'a';return st==='ab'?!(siteDown(ct,'a')&&siteDown(ct,'b')):!siteDown(ct,st);};
|
||||
const liveCap=(g,c,site,n)=>{const k=liveN(c,site,n);return k?lagCap(g,k):0;};
|
||||
const onSite=(site,s)=>(site||'a')===s||site==='ab';
|
||||
function siteCtl(k,id,c,cur){const p=S.pops[c];if(!p||!p.site2)return '';cur=cur||'a';const n=k==='t'?(S.transit.find(x=>x.id===id)||{}).n:k==='p'?(S.pni.find(x=>x.id===id)||{}).n:(S.ixn||{})[id];return `<div class="seg site"><span class="meta">${tr('Site:')}</span>${['a','b'].map(x=>btn(`${x.toUpperCase()} <small>${esc(siteName(c,x))}</small>`,'siteSet',{k,id,s:x},cur===x?'pink sm':'ghost sm')).join('')}${btn(k==='ix'&&S.myIx[id]?tr('Both <small>a second switch, +{price}/mo</small>',{price:fmt$(Math.round(myFab(id).mo/2))}):(n||1)<2?tr('Both <small>adds a LAG member</small>'):tr('Both <small>split the LAG</small>'),'siteSet',{k,id,s:'ab'},cur==='ab'?'pink sm':'ghost sm')}</div>`;}
|
||||
function siteCtl(k,id,c,cur){const p=S.pops[c];if(!p||!p.site2)return '';cur=cur||'a';const n=k==='t'?(S.transit.find(x=>x.id===id)||{}).n:k==='p'?(S.pni.find(x=>x.id===id)||{}).n:(S.ixn||{})[id];return `<div class="seg site"><span class="meta">${tr('common.site')}</span>${['a','b'].map(x=>btn(`${x.toUpperCase()} <small>${esc(siteName(c,x))}</small>`,'siteSet',{k,id,s:x},cur===x?'pink sm':'ghost sm')).join('')}${btn(k==='ix'&&S.myIx[id]?tr('sites_and_service.both_a_second_switch_price_mo',{price:fmt$(Math.round(myFab(id).mo/2))}):(n||1)<2?tr('sites_and_service.both_adds_a_lag_member'):tr('sites_and_service.both_split_the_lag'),'siteSet',{k,id,s:'ab'},cur==='ab'?'pink sm':'ghost sm')}</div>`;}
|
||||
function portOk(c,i){const p=S.pops[c];return i<=RG[p?(p.rgen||0):0].maxP;}
|
||||
function waveOk(a,b,i){return [a,b].every(c=>i<=RG[S.pops[c]?(S.pops[c].rgen||0):0].maxLT);}
|
||||
function waveNeed(i){const g=RG.find(r=>r.maxLT>=i);return g?tr('{pn} routers',{pn:g.pn}):'?';}
|
||||
function waveNeed(i){const g=RG.find(r=>r.maxLT>=i);return g?tr('sites_and_service.pn_routers',{pn:g.pn}):'?';}
|
||||
function routerModels(c){const p=S.pops[c],g=p.rgen||0,rt=p.routers||1;
|
||||
return `<div style="margin-top:6px">${RG.map((M,i)=>{if(i===g)return '';const why=modelFits(c,i),lk=M.lvl>lvl();
|
||||
return `<div class="row"><span class="logo" style="--c:${M.badge?'#2C7A7B':'#FF4F9A'}">${M.badge||'R'+(M.cls+1)}</span><div class="grow"><div class="nm">${esc(M.n)} <span class="meta">${M.pn} · ${tr('{n} ports',{n:M.ports})} · ${fmtG(M.cap)} · ${tr('boots in ~{n} min',{n:M.boot})}${M.flaky?' · '+tr('crashes more'):''}</span></div><div class="meta">${esc(M.blurb)}</div>${why?`<div class="why">${esc(why)}</div>`:''}</div>${btn(lk?tr('Level {n}',{n:M.lvl}):tr('Swap <small>{cost} + {mo}/mo</small>',{cost:fmt$(swapCost(c,i)),mo:fmt$(M.mo*rt)}),'upRouter',{city:c,g:i},'sm',lk||!!why||S.cash<swapCost(c,i)||p.rupDay===S.day)}</div>`;}).join('')}</div>`;}
|
||||
function portNote(c){const p=S.pops[c];if(!p)return '';const g=p.rgen||0;return RG[g].maxP<PORT.length-1?`<p class="note" style="margin-top:0">${tr('Your {model} here tops out at {pn} ports. Bigger ports need a router upgrade (Infra tab).',{model:esc(RG[g].n),pn:RG[g].pn})}</p>`:'';}
|
||||
return `<div class="row"><span class="logo" style="--c:${M.badge?'#2C7A7B':'#FF4F9A'}">${M.badge||'R'+(M.cls+1)}</span><div class="grow"><div class="nm">${esc(M.n)} <span class="meta">${M.pn} · ${tr('sites_and_service.n_ports',{n:M.ports})} · ${fmtG(M.cap)} · ${tr('sites_and_service.boots_in_n_min',{n:M.boot})}${M.flaky?' · '+tr('common.crashes_more'):''}</span></div><div class="meta">${esc(M.blurb)}</div>${why?`<div class="why">${esc(why)}</div>`:''}</div>${btn(lk?tr('sites_and_service.level_n',{n:M.lvl}):tr('sites_and_service.swap_cost_mo_mo',{cost:fmt$(swapCost(c,i)),mo:fmt$(M.mo*rt)}),'upRouter',{city:c,g:i},'sm',lk||!!why||S.cash<swapCost(c,i)||p.rupDay===S.day)}</div>`;}).join('')}</div>`;}
|
||||
function portNote(c){const p=S.pops[c];if(!p)return '';const g=p.rgen||0;return RG[g].maxP<PORT.length-1?`<p class="note" style="margin-top:0">${tr('sites_and_service.your_model_here_tops_out_at',{model:esc(RG[g].n),pn:RG[g].pn})}</p>`:'';}
|
||||
// Service: what you deliver, times how it feels. Traffic backhauled far to transit is slow, and users notice.
|
||||
const latSlow=c=>!!(R&&R.latF&&R.latF[c]<0.97&&R.latFar[c]);
|
||||
function latNote(c){if(!latSlow(c))return '';const f=R.latFar[c];return `<div class="warn">🐢 ${tr('<b>{p} of {city}’s traffic is backhauled to transit in {to}: {ms} ms round trip.</b> Users notice anything over 20 ms (about 1,500 km), and past 50 ms broadband and internet services count as bad service. Buy transit here or nearby, or peer locally.',{p:pct(Math.min(1,f.share)),city:esc(CITY[c].name),to:esc(CITY[f.to].name),ms:Math.round(f.ms)})}</div>`;}
|
||||
function latNote(c){if(!latSlow(c))return '';const f=R.latFar[c];return `<div class="warn">🐢 ${tr('sites_and_service.p_of_city_s_traffic_is',{p:pct(Math.min(1,f.share)),city:esc(CITY[c].name),to:esc(CITY[f.to].name),ms:Math.round(f.ms)})}</div>`;}
|
||||
const LAT_OK=20,LAT_BAD=50,latLoss=rtt=>rtt<=LAT_OK?0:rtt<=LAT_BAD?0.2*(rtt-LAT_OK)/(LAT_BAD-LAT_OK):0.5;
|
||||
function sfOf(r,c){const d=r.cityDem[c]||0;return d<=1e-6?1:clamp(r.citySrv[c]/d,0,1)*((r.latF&&r.latF[c])??1);}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue