From 18f3936058164936cde410e13431ecfca0d6f015 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Mon, 26 Oct 2026 17:47:51 +0100 Subject: [PATCH] Sell spare dark-fiber capacity from the fiber itself (#51) Wholesale alien waves and spare-pair leases already existed, but only as random offers, and the fiber only said how many channels were sold. Each dark fiber in service now has a 'Selling spare capacity' section: free channels, who rents what and for how much, a pending offer with Accept, and 'List it with a capacity broker', which creates an offer for that fiber at once at the usual price minus a 10% broker cut (alien waves on free channels first, then a spare pair in your own trench). One listing per fiber at a time. Random offers use the same helpers and draw the same random numbers in the same order, so seeded games are unchanged. --- CHANGELOG.md | 1 + site/i18n/fr.js | 8 ++++++++ site/i18n/it.js | 8 ++++++++ site/i18n/pt.js | 8 ++++++++ site/index.html | 24 +++++++++++++++++++----- tests/issues.test.js | 27 +++++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8bdcef..f2cf501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Spare capacity on your dark fiber is now easy to sell (#51). Each fiber shows its free channels and who rents alien waves or a spare pair on it, and a capacity broker can list it for you: an offer turns up at once, and the broker keeps 10%. - Red Sea Crisis now asks you to keep 80 Gbps flowing between Asia and the rest of your network for 30 days in a row, instead of 300 Gbps served anywhere, which broadband alone could reach on day 0 (#113). The scenario card shows today's traffic to and from Asia and how many days in a row you have held it. - Luxembourg gets its own eyeball network, Poste Restante, at LU-SICK in Bettembourg, so there is a reason to peer there (#84). - You can now run a scrubbing center in every POP, not just one (#117). An attack goes to the nearest working center and spills to the next when it is full. A center in another city means the flood rides your backbone there and back: it fills your links, adds latency, and whatever your links cannot carry is not scrubbed. DDoS protection customers mind when their attacks are hauled across an ocean, some new customers ask for a center on their own continent, and the NOC shows where each attack is being cleaned. diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 116ced8..1b4c2ba 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -2623,4 +2623,12 @@ "A path from Marseille to Singapore, and 80 Gbps between Asia and the rest of your network for 30 days in a row":"Un chemin de Marseille à Singapour, et 80 Gbps entre l’Asie et le reste de ton réseau pendant 30 jours d’affilée", "Your traffic to and from Asia":"Ton trafic vers et depuis l’Asie", "Days in a row at {g} or more":"Jours d’affilée à {g} ou plus", +"Nothing spare to sell on this fiber.
Every channel is lit or sold, and the trench has no free pair.":"Rien à vendre sur cette fibre.
Chaque canal est allumé ou vendu, et la tranchée n’a plus de paire libre.", +"Listed with a capacity broker.
{name} wants {what}. Accept it on the fiber or in Deals.":"Mise en vente chez un courtier en capacité.
{name} veut {what}. Accepte sur la fibre ou dans Offres.", +"Selling spare capacity":"Vendre la capacité libre", +"Other carriers rent what you do not use: alien waves on free channels of your line system, or on your own build a spare fiber pair in the trench.":"D’autres opérateurs louent ce que tu n’utilises pas : des alien waves sur les canaux libres de ton système de ligne ou, si tu l’as construite, une paire de fibre libre dans la tranchée.", +"Free channels":"Canaux libres", +"via a capacity broker":"via un courtier en capacité", +"List it with a capacity broker they keep 10%":"La confier à un courtier en capacité il garde 10 %", +"Nothing spare to sell on this fiber right now.":"Rien à vendre sur cette fibre pour l’instant.", }; diff --git a/site/i18n/it.js b/site/i18n/it.js index 4596a3b..6bf8565 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2623,4 +2623,12 @@ "A path from Marseille to Singapore, and 80 Gbps between Asia and the rest of your network for 30 days in a row":"Un percorso da Marsiglia a Singapore, e 80 Gbps tra l’Asia e il resto della tua rete per 30 giorni di fila", "Your traffic to and from Asia":"Il tuo traffico da e per l’Asia", "Days in a row at {g} or more":"Giorni di fila con almeno {g}", +"Nothing spare to sell on this fiber.
Every channel is lit or sold, and the trench has no free pair.":"Niente da vendere su questa fibra.
Ogni canale è acceso o venduto, e nello scavo non c’è una coppia libera.", +"Listed with a capacity broker.
{name} wants {what}. Accept it on the fiber or in Deals.":"In vendita tramite un broker di capacità.
{name} vuole {what}. Accetta dalla fibra o in Offerte.", +"Selling spare capacity":"Vendere la capacità libera", +"Other carriers rent what you do not use: alien waves on free channels of your line system, or on your own build a spare fiber pair in the trench.":"Altri operatori affittano quello che non usi: alien wave sui canali liberi del tuo sistema di linea o, se l’hai costruita tu, una coppia di fibre libera nello scavo.", +"Free channels":"Canali liberi", +"via a capacity broker":"tramite un broker di capacità", +"List it with a capacity broker they keep 10%":"Mettila in vendita con un broker di capacità trattiene il 10%", +"Nothing spare to sell on this fiber right now.":"Per ora non c’è niente da vendere su questa fibra.", }; diff --git a/site/i18n/pt.js b/site/i18n/pt.js index 02029e5..9c443f5 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -2623,4 +2623,12 @@ "A path from Marseille to Singapore, and 80 Gbps between Asia and the rest of your network for 30 days in a row":"Um caminho de Marselha a Singapura, e 80 Gbps entre a Ásia e o resto da sua rede por 30 dias seguidos", "Your traffic to and from Asia":"Seu tráfego de e para a Ásia", "Days in a row at {g} or more":"Dias seguidos com {g} ou mais", +"Nothing spare to sell on this fiber.
Every channel is lit or sold, and the trench has no free pair.":"Nada sobrando para vender nesta fibra.
Todos os canais estão acesos ou vendidos, e a vala não tem par livre.", +"Listed with a capacity broker.
{name} wants {what}. Accept it on the fiber or in Deals.":"Anunciado com um corretor de capacidade.
{name} quer {what}. Aceite na fibra ou em Negócios.", +"Selling spare capacity":"Vender capacidade ociosa", +"Other carriers rent what you do not use: alien waves on free channels of your line system, or on your own build a spare fiber pair in the trench.":"Outras operadoras alugam o que você não usa: alien waves nos canais livres do seu sistema de linha ou, se a obra é sua, um par de fibra livre na vala.", +"Free channels":"Canais livres", +"via a capacity broker":"por um corretor de capacidade", +"List it with a capacity broker they keep 10%":"Anunciar com um corretor de capacidade ele fica com 10%", +"Nothing spare to sell on this fiber right now.":"Nada sobrando para vender nesta fibra por enquanto.", }; diff --git a/site/index.html b/site/index.html index de8b321..9334e32 100644 --- a/site/index.html +++ b/site/index.html @@ -2214,7 +2214,7 @@ function sanitize(s){ 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);} 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(!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('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)); @@ -2293,6 +2293,13 @@ function diversityPossible(a,b,state=S){ } function fiberOk(b){const l=S.links.find(x=>x.id===b.link);if(!l)return false;if(b.type==='dfpair'||b.type==='pairs')return l.ready<=S.day&&!(l.cut>S.day);return l.ready<=S.day&&!(l.cut>S.day)&&!(l.eqDown>S.day);} function soldSlots(l){return S.biz.filter(b=>b.type==='wwave'&&b.link===l.id).reduce((a,b)=>a+(b.slots||0),0);} +// 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); +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:trn('{n}× 400G alien wave on your {a}–{b} fiber','{n}× 400G alien waves on your {a}–{b} fiber',slots,{a:CITY[l.a].name,b:CITY[l.b].name}),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};} function bizSf(b){const T=BIZ_T[b.type];return T.fiber?(fiberOk(b)?1:0):T.l2?clamp((R.l2[b.id]||0)/b.bw,0,1):bizSfOf(R,b.city);} // Protected business traffic has its own served share; without the rule it shares the city's. function bizSfOf(r,c){const d=r.bizDem&&r.bizDem[c];return teRules()&&teRules().protect&&d>1e-6?clamp(r.bizSrv[c]/d,0,1):sfOf(r,c);} @@ -2334,10 +2341,8 @@ function spawnSpecial(t){const T=BIZ_T[t],mine=Object.keys(S.pops),lv=S.lvl||1; while(sites.lengthl.kind==='df'&&l.ready<=S.day); - if(t==='wwave'){const free=l=>chMax(l)-(l.ch||[]).length-soldSlots(l);const ls=ready.filter(l=>free(l)>=1&&!S.offers.some(o=>o.link===l.id));if(!ls.length)return;const l=pick(ls),slots=1+Math.floor(Math.random()*Math.min(4,free(l))); - S.offers.push({id:uid(),city:l.a,city2:l.b,link:l.id,slots,what:trn('{n}× 400G alien wave on your {a}–{b} fiber','{n}× 400G alien waves on your {a}–{b} fiber',slots,{a:CITY[l.a].name,b:CITY[l.b].name}),name:nm(),type:t,bw:1,rate:Math.round(waveMo(l.km,false,2)*0.55*slots),reqs:[],exp:S.day+30});return;} - if(t==='dfpair'){const ls=ready.filter(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)&&!S.offers.some(o=>o.link===l.id));if(!ls.length)return;const l=pick(ls); - S.offers.push({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),reqs:[],exp:S.day+30});} + if(t==='wwave'){const ls=ready.filter(l=>freeCh(l)>=1&&!S.offers.some(o=>o.link===l.id));if(!ls.length)return;S.offers.push(fiberOffer(t,pick(ls),nm));return;} + if(t==='dfpair'){const ls=ready.filter(l=>pairFree(l)&&!S.offers.some(o=>o.link===l.id));if(!ls.length)return;S.offers.push(fiberOffer(t,pick(ls),nm));} } function cnOk(){return S.cnLic&&S.cnLic.state==='ok';} function regionMult(c){const C=CITY[c];if(!C||C.cn)return 1;if(C.kr)return KR_TRANSIT;if(C.tape)return 1.5;return C.reg==='AS'?2.5:C.reg==='AF'?2:C.reg==='OC'?1.8:C.reg==='SA'?1.6:1;} @@ -2994,6 +2999,11 @@ const ACT={ rmCache:({id})=>{S.caches=S.caches.filter(c=>c.id!==id);after();}, // Move one of a CDN's boxes to the other building (#69), so a dark building only takes out part of the cache. cacheSite:({city,net,s})=>{if(s!=='a'&&s!=='b'||!S.pops[city]||!S.pops[city].site2)return;const x=S.caches.find(c=>c.city===city&&c.net===net&&(c.site==='b'?'b':'a')!==s);if(!x)return;x.site=s;sfx('click');after();}, + advertise:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||l.ready>S.day)return;if(S.offers.some(o=>o.link===l.id))return; + const t=freeCh(l)>=1?'wwave':pairFree(l)?'dfpair':null;if(!t){toast(tr('Nothing spare to sell on this fiber.
Every channel is lit or sold, and the trench has no free pair.'),'bad');sfx('err');return;} + const T=BIZ_T[t],nm=()=>{const list=T.names.filter(n=>!S.usedNames.includes(n)),n=list.length?pick(list):pick(T.names);S.usedNames.push(n);return n;}; + // A capacity broker finds a buyer at once and keeps 10% of the monthly price. + const o=fiberOffer(t,l,nm,0.9);o.broker=true;S.offers.push(o);toast(tr('Listed with a capacity broker.
{name} wants {what}. Accept it on the fiber or in Deals.',{name:esc(o.name),what:esc(o.what)}),'good');sfx('click');after();}, accept:({id})=>{const o=S.offers.find(x=>x.id===id);if(!o)return;if(!bHas(o)){toast(tr('You need a POP in every city on the contract first.'),'bad');return;} if(o.type==='wwave'){const l=S.links.find(x=>x.id===o.link);if(!l||chMax(l)-(l.ch||[]).length-soldSlots(l)Not enough free channels on that fiber any more.'),'bad');return;}} if(BIZ_T[o.type].event&&S.day>=o.start){toast(tr('Too late: the event has already started.'),'bad');return;} @@ -3575,6 +3585,10 @@ function dfPanel(l){ h+=`

${tr('Capacity')}

${tr('{n} of {max} channels lit',{n:(l.ch||[]).length,max:chMax(l)})}${soldSlots(l)?` · ${tr('{n} sold as alien waves',{n:soldSlots(l)})}`:''}${fmtG(load)} / ${fmtG(cap)}
${l.own&&l.sub?`
${tr('Cable design')}${tr((SEA_DESIGNS[l.seaDesign]||SEA_DESIGNS.standard).n)}
`:''}
${tr('Latency')}${tr('{ms} ms one-way',{ms:linkLat(l).toFixed(1)})}
${l.own?tr('Right-of-way upkeep'):tr('IRU lease')}${tr('{price}/mo',{price:fmt$(l.mo)})}
${tr('{n} amp huts',{n:amps})}${tr('{price}/mo',{price:fmt$(amps*AMP_MO)})}
${!bld&&!(l.ch||[]).length?`

${tr('This fiber is dark. Add optics below to carry traffic.')}

`:''}
`; + if(!bld){const sold=S.biz.filter(b=>b.link===l.id&&(b.type==='wwave'||b.type==='dfpair'||b.type==='pairs')),off=S.offers.find(o=>o.link===l.id),fc=freeCh(l); + h+=`

${tr('Selling spare capacity')}

${tr('Other carriers rent what you do not use: alien waves on free channels of your line system, or on your own build a spare fiber pair in the trench.')}

+
${tr('Free channels')}${fc} / ${chMax(l)}
${sold.map(b=>`
${esc(b.name)}
${esc(b.what||BIZ_T[b.type].l)} · ${tr('{price}/mo',{price:fmt$(b.rate)})}
`).join('')} + ${off?`
${esc(off.name)}
${esc(off.what)} · ${tr('{price}/mo',{price:fmt$(off.rate)})} · ${tr('{n}d left',{n:off.exp-S.day})}${off.broker?' · '+tr('via a capacity broker'):''}
${btn(tr('Accept'),'accept',{id:off.id},'pink sm')}
`:fc>=1||pairFree(l)?`
${btn(tr('List it with a capacity broker they keep 10%'),'advertise',{id:l.id},'sm')}
`:`

${tr('Nothing spare to sell on this fiber right now.')}

`}
`;} h+=`

${tr('Optics')}

${tr('Each channel is a pair of optics, one per end. ZR+ optics plug straight into your routers. Transponders sit on a shelf.')}

`; if(l.own&&l.sub)h+=subUpgradePanel(l); for(const k of Object.keys(OPT)){const O=OPT[k],n=(l.ch||[]).filter(x=>x===k).length,why=chWhy(l,k); diff --git a/tests/issues.test.js b/tests/issues.test.js index a67c6ae..1aee2f8 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -1248,3 +1248,30 @@ test('#84 Luxembourg has its own eyeball ISP at LU-SICK; no real company names a assert.ok(ev("!WAVECO.some(n=>/GTT/.test(n))&&!BIZ_T.wwave.names.some(n=>/GTT/.test(n))")); assert.deepEqual(errors, []); }); + +test('#51 a dark fiber shows what is rented out, and spare capacity can be listed with a broker', () => { + const { ev, errors } = load(); + ev("ACT.start({});S.cash=1e9;S.lvl=4;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'ams'});S.offers=[];S.links.push({id:'df1',a:'fra',b:'ams',kind:'df',own:true,sys:'roadm',ch:['tp16','tp16'],km:450,ready:0,day:0,cut:0,mo:100,trench:'own:df1',pairs:1});after();UI.sel={type:'link',id:'df1'};renderPanel()"); + const txt = () => ev("document.getElementById('panelBody').textContent"); + assert.match(txt(), /Selling spare capacity/); assert.match(txt(), /Free channels\s*62 \/ 64/); + // a broker finds a buyer for free channels at once, and keeps 10% + ev("__reseed(9);ACT.advertise({id:'df1'})"); + const o = JSON.parse(ev("JSON.stringify(S.offers.find(x=>x.link==='df1'))")); + assert.equal(o.type, 'wwave'); assert.ok(o.broker); + assert.equal(o.rate, ev(`Math.round(waveMo(450,false,2)*0.55*${o.slots}*0.9)`), 'the usual alien-wave price minus the broker'); + assert.match(txt(), /via a capacity broker/); + ev("ACT.advertise({id:'df1'})"); assert.equal(ev("S.offers.filter(x=>x.link==='df1').length"), 1, 'one listing at a time'); + ev(`document.querySelector('#panelBody [data-act=accept]').click()`); + assert.ok(txt().includes(o.name), 'the customer is listed on the fiber'); + assert.match(txt(), new RegExp(`Free channels\\s*${62 - o.slots} / 64`)); + // when every channel is lit or sold, the spare pair in your own trench is offered instead; then nothing is left + ev("const l=S.links[0];l.ch=Array(chMax(l)-soldSlots(l)).fill('tp16');after();ACT.advertise({id:'df1'})"); + assert.equal(ev("S.offers.find(x=>x.link==='df1').type"), 'dfpair'); + ev("for(const x of S.offers.filter(x=>x.link==='df1'))ACT.accept({id:x.id});S.biz.push({id:'p2',type:'dfpair',link:'df1',city:'fra',city2:'ams',name:'X',bw:1,rate:1,reqs:[]});S.offers=[];renderPanel()"); + assert.match(txt(), /Nothing spare to sell on this fiber right now/); + ev("ACT.advertise({id:'df1'})"); assert.equal(ev("S.offers.length"), 0); + // a broker offer survives a save, and random offers still come the same way + ev("S.offers=[{...fiberOffer('dfpair',S.links[0],()=>'Y',0.9),broker:'yes'}];S=sanitize(S)"); + assert.equal(ev('S.offers[0].broker'), true); + assert.deepEqual(errors, []); +});