From 507fe70e250b9769918acdef1c4886b21ce39257 Mon Sep 17 00:00:00 2001
From: Frederic Jung Remote peering is
const REMOTE_WHY=['Policy: no remote peers. Be in the building or be in the transit bill.','Saw your session come in over a fabric and said "we can smell the VXC from here".','Only peers with members they can reach without a 1,500 km hairpin.','Their PearingDB entry says "Remote peering: No (we mean it)".','Tried a remote peer once. It flapped during a product launch. Never again.'];
function isRemote(c){return S.ixp[c]!==undefined&&!S.pops[c]&&!S.myIx[c];}
function noRemote(id){const n=NET[id];if(!n||n.pol!=='selective')return false;return hstr(id+'|remote')%100<(n.share>=0.03?60:30);}
-function ixPortMo(c,tier){return Math.round(PORT[tier].ix*(S.pops[c]?1:REMOTE_FEE));}
+function ixPortMo(c,tier){return Math.round(PORT[tier].ix*(S.pops[c]?1:REMOTE_FEE)*dkMult(c));}
+/* DE-KICKS Group: runs several big exchanges and really, really hates open pricing.
+ No price list, personalised quotes, haggling, yearly "harmonisation", auto-enrolled add-ons
+ you have to opt out of, and a retention offer when you try to leave. */
+const DK_CITIES=['fra','mad','mrs','dxb','bom','nyc'];
+const isDk=c=>DK_CITIES.includes(c)&&!!CITY[c]&&!!CITY[c].ix&&!S.myIx[c];
+const DK_ADDONS=[['Blackholing Plus™','Like blackholing, but with a Plus.'],['Route Server Gold','The same route server, in a gold-coloured portal.'],['Premium Port LEDs','Your port light now blinks in brand colours.'],['Strategic Peering Insights','A monthly PDF of your own traffic graphs.'],['GlobePeer Ready™','Makes your port "ready" for a product you did not buy.'],['Cloud Exchange Readiness Fee','A fee for being ready for the cloud.'],['Account Manager Lunch Fund','Your account manager is hungry.']];
+const DK_STALL=['Your account manager would love to "align on value" first. Strategic call booked for next week.','Pricing is reviewed by the Global Commercial Council, who meet on the next full moon.','They sent a 14-page NDA before they can even repeat the price. Lawyers estimate a week.','Your account manager is at a conference in Dubai. And then one in Madrid.'];
+function dkMult(c){if(!S||!isDk(c)||!S.dk||!S.dk.m[c])return 1;const ret=S.dk.ret[c];return S.dk.m[c]*(ret&&ret>S.day?0.6:1);}
+function dkAddonMo(c){return S.dk&&S.dk.add[c]?S.dk.add[c].reduce((a,x)=>a+x.mo,0):0;}
+function dkState(){S.dk=S.dk||{m:{},add:{},ret:{},retUsed:{},stall:0,q:null};return S.dk;}
+function dkQuoteMult(){const pops=Object.keys(S.pops).length,big=Math.min(1.2,pops*0.04+(R.served||0)/20000);return +(0.95+Math.random()*0.45+big).toFixed(2);}
+function dkQuoteModal(){const q=S.dk.q,c=q.city,mo=Math.round(PORT[q.tier].ix*(S.pops[c]?1:REMOTE_FEE)*q.m);
+ openModal(` “Thanks for your interest! We don't publish prices, because every customer is unique.” Quotes go up with how big you look. ${q.h>=3?'Your account manager has stopped replying to haggling.':`Haggles left: ${3-q.h}.`} We value our partnership too much to let a little thing like price get in the way. After that, the normal price returns, plus a small loyalty administration fee. Running an exchange in mainland China takes a different license entirely. Peer with Chinese networks over PNIs, or meet them in Hong Kong. There's no IX in ${C.name} yet. Found one: networks join over time, pay you for ports, and peer with you for free.Your personalised ${PORT[q.tier].n} quote for ${esc(ixName(c))}
+
Price is back, plus 10% for "loyalty programme administration".`,'bad');}
+ if(dk.m[c]&&(d+hstr(c)%90)%365===0){const f=1.08+Math.random()*0.07;dk.m[c]=+(dk.m[c]*f).toFixed(3);toast(`DE-KICKS has harmonised its prices.
Harmonised means up: ${esc(ixName(c))} now costs ${Math.round((f-1)*100)}% more. Thank you for your continued partnership.`,'bad');}
+ const add=dk.add[c]=dk.add[c]||[];
+ if(add.length<3&&Math.random()<1/150){const a=DK_ADDONS.filter(x=>!add.some(y=>y.n===x[0]));if(a.length){const [n,blurb]=pick(a),mo=Math.round((300+Math.random()*1200)/50)*50;add.push({n,blurb,mo,day:d});
+ toast(`Good news! You've been enrolled in ${esc(n)}.
${esc(blurb)} ${fmt$(mo)}/mo, added to your ${esc(ixName(c))} invoice. Opt out any time in the IX panel.`,'bad');}}}
+}
+
function snubWhy(sn){const d=Math.max(1,sn.until-S.day);return `${sn.why} They will reconsider in ${d} day${d===1?'':'s'}.`;}
function peerOk(id,via,city){
const n=NET[id],dem=R.demTo[id]||0;
@@ -912,7 +940,7 @@ function compute(){
C.links=S.links.reduce((a,l)=>a+(l.mo||0),0);
C.nni=(S.nni||[]).reduce((a,x)=>a+NNI[x.tier].mo,0);
C.transit=S.transit.reduce((a,t)=>{const q=p95(t,R2.useT[t.id]||0);R2.p95[t.id]=q;const n=t.n||1;return a+Math.max(q,PORT[t.tier].g*n*0.2)*NET[t.net].price*(t.premium&&t.city==='hkg'?NET[t.net].premium:1)*pm*regionMult(t.city)+PORT[t.tier].tmo*n;},0);
- C.ix=Object.keys(S.ixp).reduce((a,c)=>a+(S.myIx[c]?MYIX_MO:ixPortMo(c,S.ixp[c])*((S.ixn||{})[c]||1)),0);
+ C.ix=Object.keys(S.ixp).reduce((a,c)=>a+(S.myIx[c]?MYIX_MO:ixPortMo(c,S.ixp[c])*((S.ixn||{})[c]||1)+dkAddonMo(c)),0);
C.pni=S.pni.reduce((a,p)=>a+PORT[p.tier].pni*(p.n||1)+(NET[p.net].pol==='paid'?NET[p.net].paidFee:0),0);
C.caches=S.caches.length*CACHE_MO;
C.loans=(S.loans||[]).reduce((a,l)=>a+(BANKS[l.bank].equity?0:l.pay),0);
@@ -931,7 +959,7 @@ function linkDown(l){return l.cut>S.day||(S.ev.runet>S.day&&ruCity(l.a)!==ruCity
function remoteCities(){return [...new Set(S.links.filter(l=>l.kind==='vxc').flatMap(l=>[l.a,l.b]))].filter(c=>!S.pops[c]);}
function nniUsed(c,prov){return S.links.filter(l=>l.kind==='vxc'&&l.prov===prov&&(l.a===c||l.b===c)).reduce((a,l)=>a+VXC[l.vt].g,0);}
function nniPort(c,prov){return (S.nni||[]).find(x=>x.city===c&&x.prov===prov);}
-function migrate(s){s.hist=s.hist||[];s.loans=s.loans||[];s.loanOffers=s.loanOffers||[];s.loanStrikes=s.loanStrikes||0;for(const l of s.links||[])if(!l.kind)l.kind='wave';
+function migrate(s){if(s.dk){s.dk.m=s.dk.m||{};s.dk.add=s.dk.add||{};s.dk.ret=s.dk.ret||{};s.dk.retUsed=s.dk.retUsed||{};}s.hist=s.hist||[];s.loans=s.loans||[];s.loanOffers=s.loanOffers||[];s.loanStrikes=s.loanStrikes||0;for(const l of s.links||[])if(!l.kind)l.kind='wave';
for(const c in s.pops){const p=s.pops[c];if(p.rgen===undefined){let g=0;const need=(i,key)=>{const k=RG.findIndex(r=>r[key]>=i);if(k>g)g=k;};
for(const l of s.links||[])if((l.a===c||l.b===c)&&l.kind==='wave')need(l.tier,'maxLT');
for(const t of s.transit||[])if(t.city===c)need(t.tier,'maxP');for(const x of s.pni||[])if(x.city===c)need(x.tier,'maxP');if(s.ixp&&s.ixp[c]!==undefined)need(s.ixp[c],'maxP');p.rgen=g;}}for(const b of s.biz||[])if(!b.reqs)b.reqs=BIZ_T[b.type]&&BIZ_T[b.type].div?['diverse']:[];for(const o of s.offers||[])if(!o.reqs)o.reqs=[];if(!s.lvl)s.lvl=1;s.nni=s.nni||[];s.cnLic=s.cnLic||{state:'none'};if(s.scrubAt===undefined)s.scrubAt=null;s.ev=s.ev||{};for(const l of s.links){if(!l.kind)l.kind='wave';if(l.mo===undefined)l.mo=Math.round(waveMo(l.km,l.sub,l.tier)*(l.mult||1));}for(const c in s.pops){if(!s.pops[c].routers)s.pops[c].routers=1;}return s;}
@@ -1178,6 +1206,7 @@ function dayTick(){
if(!S||S.lost)return;
S.day++;
const d=S.day;
+ dkTick(d);
for(const k in S.peers){const [id,c]=k.split('@'),sn=snub(id,c);if(!sn)continue;delete S.peers[k];
toast(`${esc(NET[id].name)} de-peered you in ${esc(CITY[c].name)}.
${esc(sn.why)} Traffic falls back to your next best path.`,'bad');}
if(S.cnLic&&S.cnLic.state==='pending'&&d>=S.cnLic.ready){S.cnLic.state='ok';toast('License granted!
Your joint venture can now build POPs in mainland China.','goal');sfx('coin');}
@@ -1288,11 +1317,22 @@ const ACT={
buyTransit:({city,net,tier})=>{tier=+tier;if(!S.pops[city]||!NET[net]||!NET[net].price||!NET[net].pops.includes(city)||!PORT[tier])return;if(!portOk(city,tier)){toast(`Your router can't take a ${PORT[tier].n} port.
Upgrade it in the Infra tab.`,'bad');sfx('err');return;}const ex=S.transit.find(t=>t.city===city&&t.net===net);if(ex&&tier<=ex.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});toast(`${esc(NET[net].name)} transit is live in ${CITY[city].name}.
Full table received: ~1,000,000 routes.`,'good');after();},
lagT:({id,d})=>{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))return;if(!spend(PORT[t.tier].setup))return;}t.n=n;toast(+d>0?`LAG member added.
${esc(NET[t.net].name)} in ${CITY[t.city].name} is now ${lagName(t.tier,n)}.`:`LAG member removed.`,'good');after();},
lagP:({id,d})=>{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&&!spend(1500+PORT[p.tier].setup/2))return;p.n=n;sfx('build');after();},
- lagIx:({city,d})=>{if(S.ixp[city]===undefined||S.myIx[city]||!S.pops[city])return;S.ixn=S.ixn||{};const n=(S.ixn[city]||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0&&!spend(PORT[S.ixp[city]].ix))return;S.ixn[city]=n;sfx('build');after();},
+ lagIx:({city,d})=>{if(S.ixp[city]===undefined||S.myIx[city]||!S.pops[city])return;S.ixn=S.ixn||{};const n=(S.ixn[city]||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0&&!spend(ixPortMo(city,S.ixp[city])))return;S.ixn[city]=n;sfx('build');after();},
cancelTransit:({id})=>{if(UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.transit=S.transit.filter(t=>t.id!==id);UI.confirm=null;after();},
- buyIx:({city,tier})=>{tier=+tier;if(!PORT[tier]||!ixName(city)||(!S.pops[city]&&(!remoteCities().includes(city)||tier>1))||(S.ixp[city]!==undefined&&tier<=S.ixp[city]))return;if(S.pops[city]&&!portOk(city,tier)){toast(`Your router can't take a ${PORT[tier].n} port.
Upgrade it in the Infra tab.`,'bad');sfx('err');return;}const had=S.ixp[city]!==undefined;if(!spend(ixPortMo(city,tier)*(had?((S.ixn||{})[city]||1):1)))return;S.ixp[city]=tier;if(!had)toast(S.pops[city]?`Port up at ${esc(ixName(city))}!
Now request peering, or join the route server.`:`Remote port up at ${esc(ixName(city))}.
It came through a reseller, so expect a markup, a crowded port and some networks that won't talk to you. The route server is your friend here.`,'good');after();},
- cancelIx:({city})=>{if(UI.confirm!=='ix'+city){UI.confirm='ix'+city;renderPanel();return;}delete S.ixp[city];delete S.rs[city];if(S.ixn)delete S.ixn[city];for(const k in S.peers)if(k.endsWith('@'+city))delete S.peers[k];UI.confirm=null;after();},
+ buyIx:({city,tier,signed})=>{tier=+tier;if(!PORT[tier]||!ixName(city)||(!S.pops[city]&&(!remoteCities().includes(city)||tier>1))||(S.ixp[city]!==undefined&&tier<=S.ixp[city]))return;if(S.pops[city]&&!portOk(city,tier)){toast(`Your router can't take a ${PORT[tier].n} port.
Upgrade it in the Infra tab.`,'bad');sfx('err');return;}
+ if(isDk(city)&&S.ixp[city]===undefined&&!signed){const dk=dkState();if(dk.stall>S.day){toast(`DE-KICKS sales is still "aligning".
They will get back to you in ${dk.stall-S.day} days.`,'bad');sfx('err');return;}dk.q={city,tier,m:dkQuoteMult(),h:0};dkQuoteModal();return;}const had=S.ixp[city]!==undefined;if(!spend(ixPortMo(city,tier)*(had?((S.ixn||{})[city]||1):1)))return;S.ixp[city]=tier;if(!had)toast(S.pops[city]?`Port up at ${esc(ixName(city))}!
Now request peering, or join the route server.`:`Remote port up at ${esc(ixName(city))}.
It came through a reseller, so expect a markup, a crowded port and some networks that won't talk to you. The route server is your friend here.`,'good');after();},
+ cancelIx:({city,sure})=>{if(UI.confirm!=='ix'+city){UI.confirm='ix'+city;renderPanel();return;}
+ if(isDk(city)&&!sure){const dk=dkState();if(!dk.retUsed[city]){openModal(`Wait! Before you go…
You now peer with every open network on this IX, in one go.','good');sfx('build');after();},
+ dkAccept:()=>{const dk=dkState(),q=dk.q;if(!q)return;dk.m[q.city]=q.m;dk.q=null;closeModal();ACT.buyIx({city:q.city,tier:q.tier,signed:true});if(S.ixp[q.city]===undefined)delete dk.m[q.city];else toast(`Signed with DE-KICKS.
Welcome to the family. Please don't tell anyone what you pay.`,'good');},
+ dkHaggle:()=>{const dk=dkState(),q=dk.q;if(!q||q.h>=3)return;q.h++;const r=Math.random();
+ if(r<0.45){q.m=+(q.m*(0.75+Math.random()*0.15)).toFixed(2);dkQuoteModal();toast('"Just this once."
Your account manager found a special discount. Do not tell the others.','good');}
+ else if(r<0.75){q.m=+(q.m*1.1).toFixed(2);dkQuoteModal();toast('"After consulting with management…"
The price went up. Management was consulted.','bad');}
+ else{dk.stall=S.day+5+Math.floor(Math.random()*6);dk.q=null;closeModal();toast(`Haggling paused.
${esc(pick(DK_STALL))}`,'bad');}},
+ dkWalk:()=>{const dk=dkState();dk.q=null;closeModal();toast('DE-KICKS will "circle back".
Expect an email titled "Quick question 🙂" within the hour.','');},
+ dkOptOut:({city,n})=>{const dk=dkState(),k='dk'+city+n;if(UI.confirm!==k){UI.confirm=k;renderPanel();return;}dk.add[city]=(dk.add[city]||[]).filter(x=>x.n!==n);UI.confirm=null;toast(`Opted out of ${esc(n)}.
It took four clicks, a survey and a "we're sad to see you go" page.`,'good');after();},
+ dkStay:({city})=>{const dk=dkState();dk.ret[city]=S.day+180;dk.retUsed[city]=true;UI.confirm=null;closeModal();toast(`40% off ${esc(ixName(city))} for 6 months.
Your account manager is relieved. Read the small print later.`,'good');after();},
peer:({city,net})=>{const r=peerOk(net,'ix',city);if(!r.ok){toast(`${esc(NET[net].name)} declined.
${esc(r.why)}`,'bad');sfx('err');return;}S.peers[net+'@'+city]=true;
toast(`${esc(NET[net].name)} accepted!
${NET[net].pol==='selective'?'They checked your PearingDB page and liked the traffic numbers.':'BGP session established.'}`,'good');sfx('build');after();},
unpeer:({city,net})=>{delete S.peers[net+'@'+city];after();},
@@ -1572,12 +1612,14 @@ function ixSection(c){const C=CITY[c],ix=ixName(c);let h='';
h+=`Internet Exchange
`;
if(!ix&&C.cn){h+=`
${esc(ix)} is a shared switch. One port lets you peer with every member for free. Members: ${ixMembers(c).map(id=>esc(NET[id].name)).join(', ')||'nobody yet'}.
${S.pops[c]?'':REMOTE_WARN}${esc(ix)} is a shared switch. One port lets you peer with every member for free. Members: ${ixMembers(c).map(id=>esc(NET[id].name)).join(', ')||'nobody yet'}.
${S.pops[c]?'':REMOTE_WARN}${isDk(c)?`Run by DE-KICKS Group. No public price list. Ask sales for a personalised quote and bring your haggling face.
`:''}DE-KICKS personalised pricing: ${Math.round(dkMult(c)*100)}% of what a normal IX would charge${rt&&rt>S.day?` (promo, ${rt-S.day} days left)`:''}.
`; + for(const x of ad)h+=`Remote port via a reseller: 1.5× price, 80% usable, and ${ixMembers(c).filter(noRemote).length} member${ixMembers(c).filter(noRemote).length===1?'':'s'} here refuse remote peers.
`; if(mine)h+=`${esc(S?S.name:'Your network')} and everything it owns will be deleted. This cannot be undone.
${esc(dateStr(r.s.day))} · ${fmt$(r.s.cash)} in the bank · ${Object.keys(r.s.pops).length} POP${Object.keys(r.s.pops).length===1?'':'s'} · saved by v${esc(r.ver)}
${S&&UI.started&&!S.lost?`This replaces ${esc(S.name)}. Export it first if you want to keep it.
`:''}All systems green. Enjoy it while it lasts.
`; for(const i of S.inc){h+=`v${APP_VERSION} · Source on GitHub · Cookieless stats, no tracking
`); +v${APP_VERSION} · Source on GitHub · Cookieless stats, no tracking
`); if(sv){S=migrate(sv);compute();} } // "What's new": shown once to returning players after an update, or on demand. @@ -1820,7 +1860,7 @@ function showHelp(){${esc(S.name)} (AS${S.asn}) is transit-free. You peer with every giant on the planet and pay nobody to reach the internet. Took you ${S.day} days and ${S.stats.incidents} incidents.
${btn('Keep building','keepPlaying',{},'pink big')}`);sfx('coin');} function showLose(){openModal(`The bank repossessed your routers and sold them on eBuy. ${esc(S.name)} lasted ${S.day} days and peaked at ${fmtG(S.stats.peak)}.
${btn('Try again','newgame',{},'pink big')}`);try{localStorage.removeItem('sot-save-v1');}catch(e){}} @@ -2035,6 +2075,7 @@ function drawBackhoe(x,y,now,sub){ } const LBLW={}; function drawCity(C,sx,sy,sc,now,lyOverride){ + const hot=(UI.hotMap||{})[C.id]; const p=S.pops[C.id],down=p&&p.down>S.day,sel=UI.sel&&UI.sel.type==='city'&&UI.sel.id===C.id,hov=UI.hover===C.id||(UI.snap&&UI.snap.id===C.id); const k=sc*(hov?1.15:1); ctx.save();ctx.translate(sx,sy); @@ -2063,8 +2104,9 @@ function drawCity(C,sx,sy,sc,now,lyOverride){ ctx.translate(0,-2); } const ixn=ixName(C.id); - if(ixn){const mine=!!S.myIx[C.id],joined=S.ixp[C.id]!==undefined;ctx.fillStyle=mine?'#FF4F9A':joined?'#FFD23F':'#FFFFFF';ctx.beginPath();for(let i=0;i<6;i++){const a=Math.PI/3*i+Math.PI/6;ctx.lineTo(19+8.5*Math.cos(a),-h+2+8.5*Math.sin(a));}ctx.closePath();ctx.fill();ctx.lineWidth=2;ctx.stroke(); - ctx.fillStyle=mine?'#fff':'#1E2640';ctx.font='900 8px Nunito, sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText('IX',19,-h+2.5);} + if(ixn){const mine=!!S.myIx[C.id],joined=S.ixp[C.id]!==undefined;const ixHot=hot&&hot.ix;ctx.fillStyle=ixHot?(Math.sin(now/180)>0?'#FF4D5E':'#FF8A3D'):mine?'#FF4F9A':joined?'#FFD23F':'#FFFFFF';ctx.beginPath();for(let i=0;i<6;i++){const a=Math.PI/3*i+Math.PI/6;ctx.lineTo(19+8.5*Math.cos(a),-h+2+8.5*Math.sin(a));}ctx.closePath();ctx.fill();ctx.lineWidth=2;ctx.stroke(); + ctx.fillStyle=mine||ixHot?'#fff':'#1E2640';ctx.font='900 8px Nunito, sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText('IX',19,-h+2.5);} + if(hot&&p){let y=-14;const pulse=.75+.25*Math.sin(now/200);for(const k of ['r','t','p','c']){if(!hot[k])continue;ctx.globalAlpha=pulse;ctx.fillStyle='#FF4D5E';ctx.beginPath();ctx.arc(-29,y,6.5,0,7);ctx.fill();ctx.globalAlpha=1;ctx.lineWidth=2;ctx.strokeStyle='#1E2640';ctx.stroke();ctx.fillStyle='#fff';ctx.font='900 8px Nunito, sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(HOTL[k],-29,y+0.5);y+=14;}} const off=S.offers.some(o=>bCities(o).includes(C.id)); if(off){const by=-h-16+Math.sin(now/250)*3;ctx.fillStyle='#fff';ctx.lineWidth=2.2;ctx.beginPath();ctx.ellipse(-2,by,11,9,0,0,7);ctx.fill();ctx.stroke();ctx.beginPath();ctx.moveTo(-5,by+8);ctx.lineTo(-7,by+14);ctx.lineTo(0,by+8);ctx.fillStyle='#fff';ctx.fill();const big=S.offers.some(o=>bCities(o).includes(C.id)&&(BIZ_T[o.type].lv>=3||BIZ_T[o.type].event));ctx.fillStyle=big?'#FF4F9A':'#16A866';ctx.font='900 13px "Baloo 2", sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(big?'$$':'$',-2,by+1);} const inc=S.inc.some(i=>i.ref===C.id&&i.type!=='leak'); @@ -2117,7 +2159,7 @@ addEventListener('keydown',e=>{if(e.target.tagName==='INPUT')return;if(e.code=== let pressing=false; document.addEventListener('pointerdown',e=>{if(e.target.closest('#panel,#left'))pressing=true;}); addEventListener('pointerup',()=>setTimeout(()=>pressing=false,0)); -document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b||b.disabled)return;audioInit();const fn=ACT[b.dataset.act];if(!fn)return;if(!S&&!['start','pickStart','cont','help','helpClose','newgame','mute','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);}); +document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b||b.disabled)return;audioInit();const fn=ACT[b.dataset.act];if(!fn)return;if(!S&&!['start','pickStart','cont','help','helpClose','newgame','mute','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);}); /* ================= LOOP ================= */ let last=performance.now(),acc=0,hudT=0; diff --git a/tests/issues.test.js b/tests/issues.test.js new file mode 100644 index 0000000..19d2017 --- /dev/null +++ b/tests/issues.test.js @@ -0,0 +1,67 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); + +function base(ev) { + ev("ACT.start({});S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'})"); +} + +test('#4 several transits in one city share the load instead of filling one by one', () => { + const { ev, errors } = load(); + base(ev); + ev("ACT.buyTransit({city:'fra',net:'cog',tier:1});ACT.buyTransit({city:'fra',net:'lvl',tier:1});compute()"); + const u = JSON.parse(ev("JSON.stringify(S.transit.map(t=>R.useT[t.id]||0))")); + assert.equal(u.length, 2); + assert.ok(u[0] > 0 && u[1] > 0, `both carry traffic (${u})`); + assert.ok(Math.abs(u[0] - u[1]) / (u[0] + u[1]) < 0.35, `roughly balanced (${u})`); + // local exits still win over far ones: a transit in London is not used while Frankfurt has room + ev("ACT.buildPop({city:'lon'});UI.via=null;openLinkModal('fra','lon');ACT.buildLink({tier:3});closeModal();ACT.buyTransit({city:'lon',net:'tly',tier:1});compute()"); + assert.equal(ev("R.useT[S.transit.find(t=>t.city==='lon').id]||0"), 0, 'remote transit stays idle'); + // backup-only still means backup only + ev("S.transit[1].pref='low';compute()"); + assert.equal(ev("R.useT[S.transit[1].id]||0"), 0); + assert.deepEqual(errors, []); +}); + +test('#5 export writes a file and import restores it, with checks', () => { + const { ev, dom, errors } = load(); + const window = dom.window; + base(ev); + ev("S.name='Export Me';S.cash=1234567;compute()"); + let blobText = null; + window.URL.createObjectURL = b => { blobText = b; return 'blob:x'; }; + window.URL.revokeObjectURL = () => {}; + window.HTMLAnchorElement.prototype.click = function () { window.__dl = this.download; }; + ev("ACT.exportSave()"); + assert.match(window.__dl, /^series-of-tubes-export-me-\d{4}-\d\d-\d\d\.json$/); + const txt = ev("JSON.stringify({app:'series-of-tubes',version:APP_VERSION,S})"); + assert.ok(blobText); + ev("S.cash=1;S.name='Other'"); + assert.match(ev(`parseSave('{"nope":1}').err`), /does not look/); + assert.match(ev(`parseSave('not json').err`), /not valid JSON/); + assert.match(ev(`parseSave(JSON.stringify(Object.assign(JSON.parse(${JSON.stringify(txt)}).S,{lost:true}))).err`), /bankrupt/); + ev(`UI.importing=parseSave(${JSON.stringify(txt)}).s;ACT.importGo()`); + assert.equal(ev("S.name"), 'Export Me'); + assert.equal(ev("S.cash"), 1234567); + assert.equal(ev("JSON.parse(localStorage.getItem('sot-save-v1')).name"), 'Export Me', 'saved on this device'); + ev("showHelp()"); + assert.match(ev("document.getElementById('modalCard').textContent"), /Export save.*Import a save/); + assert.deepEqual(errors, []); +}); + +test('#6 full transit, IX, caches and routers show up in the NOC and on the map', () => { + const { ev, errors } = load(); + base(ev); + ev("S.pops.fra.bb.d=5000;ACT.buyTransit({city:'fra',net:'cog',tier:0});ACT.buyIx({city:'ams',tier:0,signed:true});S.caches.push({id:'cx',city:'fra',net:'akm'});compute()"); + ev("R.nodeLoad.fra=R.nodeCap.fra;UI.hotMap=hotByCity()"); + const ks = JSON.parse(ev("JSON.stringify(hotPorts().map(h=>h.k))")); + for (const k of ['t', 'c', 'r']) assert.ok(ks.includes(k), `${k} is reported hot (${ks})`); + assert.ok(ev("UI.hotMap.fra&&UI.hotMap.fra.t>=0.9")); + ev("ACT.leftTab({t:'noc'})"); // NOC reads R as it is now (router forced hot above) + const noc = ev("document.getElementById('leftBody')?document.getElementById('leftBody').textContent:document.body.textContent"); + assert.match(noc, /running hot/); + assert.match(noc, /Akamaybe Box cache/); + assert.match(noc, /transit/); + ev("draw&&draw(performance.now())"); + assert.deepEqual(errors, []); +}); From 8649495b5042db1d7344d9a823b9b581e74d4fc3 Mon Sep 17 00:00:00 2001 From: Frederic JungThe model sets your fastest interface and how much this POP can forward. More routers add capacity and survive crashes.
This chassis takes forever to boot: crashes last longer, and swapping the only router here takes 3 days. A second router hides it.
`:''}Maxed out. Traffic here is being dropped.
`:''}${esc(S.name)} (AS${S.asn}) is transit-free. You peer with every giant on the planet and pay nobody to reach the internet. Took you ${S.day} days and ${S.stats.incidents} incidents.
${btn('Keep building','keepPlaying',{},'pink big')}`);sfx('coin');} diff --git a/tests/issues.test.js b/tests/issues.test.js index 19d2017..f486627 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -65,3 +65,23 @@ test('#6 full transit, IX, caches and routers show up in the NOC and on the map' ev("draw&&draw(performance.now())"); assert.deepEqual(errors, []); }); + +test('some routers take forever to boot, PacketOinkers most of all', () => { + const { ev, errors } = load(); + base(ev); + const pct = JSON.parse(ev("JSON.stringify(RG.map((G,g)=>{let n=0;for(const c of ALLC){S.pops[c]=S.pops[c]||{rgen:g,routers:1};S.pops[c].rgen=g;if(slowBoot(c))n++;}return n/ALLC.length;}))")); + assert.ok(pct[0] < pct[2] && pct[2] > 0.2 && pct[0] < 0.3, `bigger chassis are slow more often (${pct})`); + assert.match(ev("RG[2].chip"), /PacketOinker/); + // find a slow and a fast POP and crash them + ev("for(const c of ALLC)if(c!=='fra')delete S.pops[c];S.pops.fra.rgen=2;S.pops.fra.routers=1"); + const slowCity = ev("ALLC.find(c=>{S.pops[c]={rgen:2,routers:1,down:0};const s=slowBoot(c);if(!s)delete S.pops[c];return s;})"); + ev(`for(const c of Object.keys(S.pops))if(c!=='${slowCity}')delete S.pops[c];S.transit=[];S.ixp={};for(let i=0;i<800&&!S.inc.some(x=>x.type==='crash');i++){fireFailure();S.inc=S.inc.filter(x=>x.type==='crash');}`); + const inc = JSON.parse(ev("JSON.stringify(S.inc.find(i=>i.type==='crash'))")); + assert.ok(inc.slow, 'crash on a slow booter is flagged'); + assert.ok(inc.until - ev('S.day') >= 4, 'and lasts longer'); + ev(`S.cash=1e6;ACT.fixInc({id:'${inc.id}'})`); + assert.equal(ev(`S.inc.find(i=>i.id==='${inc.id}').until`), ev('S.day+1'), 'rushing it still takes a day'); + ev(`selectCity('${slowCity}');ACT.tab({t:'infra'})`); + assert.match(ev("document.getElementById('panelBody').textContent"), /a slow one/); + assert.deepEqual(errors, []); +}); From de313bda0bc7e0ed877c02a4937668385ac8f3ec Mon Sep 17 00:00:00 2001 From: Frederic JungGp@e)Bq
z9b_$zkQoWZEY1#>#V}N}dbP*O#Q}bI3bgF)i^T#t9aZ&r7HgdyyNV{QF2m`;DGj c-znBCWYRC_8w`hpmK9E-3|*>eI9gWUT>dJF)Q<+YkYb@gcsF^C=L;HzQEql`
zvmQs#LnKlwBIN?5dqcU>gIrva-!`U*5%;@%rEhft=cM!4smE0*fkH_7Q-lt~Y88~%
zCuHFxJ7_|7vP1qiui9{#VilH*ArpE*L9lrp6KRQ57~ttf_Sp`EsdT6hp&?PBnNLfc
zAbrp#*z=;d!eRC#RL-gY#WprDP1~4;g{oNxDp)$}W~29V+qikr4RgVy%UXk3u^ZZ1
zVI>0*f=G&)S@w)4 >=2nh%%`_O_8Kcn6qngD`Xh?;ygLc_jBCybG
zc+&VxV0NT)6;46y*c)n@nz~%fvpCtbGH!K9_qD#7otaM~p)D67pQ}Ss8)xc9d?2Ud
z#~Pqq?&3P3WAk08RWH`VBr(y*98bj#xMa<>DM*om
UY&Vkqzp{o1kKjif*v~aT2gdvgrQ?XqaF%jwJ
zv0JyocIj4!LS1(qd0!*OTD|E9_YX?Zv7g3hPW4(8s*vuNoyvwBxPd!YVA
1
z_L({fpc3)a`$@P?V~@?w?ARQ*)Uem57>5MVh7VAfSoStG?k(%1*j3(7-t;~+cK#h0
zC@4cnf!CQG2*Va>%y&{7%(xn~OVLQWA5j=g+kXfee_BP%<3tW_^!J_eHoR3RKz=@G
znDgGDT$Q6Qz3~