Server-run engine: a restored network plays on exactly as before
A network loaded from its checkpoint drifted from the one that never stopped:
after a checkpoint on day 1, 2 or 5 its R differed at once (bizDem at Ashburn
6426 against 26, then cityDem, citySrv, tNet), and from the next day S too
(cash, eyeball growth). Three causes, each shown by a probe:
- R after a day is the R of the day's last routing, made before the day's end
changed S (customers who left or signed, moods, bills, transit history) and
routed from the memory of the R before it. srvLoad routed the saved S again
from R's own memory: another R, which the next day reads (sfOf for eyeball
growth, the peering share). Every compute() in the realm now keeps, for the
R it makes, S as it routed it (one JSON per top-level key, 0.8 ms big) and
the memory it started from. rt carries that routing point (pt: the memory,
the keys that changed since, the keys S did not have then), and srvLoad
routes that S again from it: the same R, byte for byte. The old restore test
checkpointed after day 10, where a failure or event routed again at the end
of the day and nothing changed after it: it passed by luck.
- The sales desk's tried offers (UI.slTried, an offer that did not fit waits a
week) live outside S. A fresh realm forgot them and the desk tried other
offers. rt carries them (sl); a day mark keeps them and the in-place restore
after a throw puts them back (before, a parsed S dropped them).
- A save and a reload give some keys back in another key order (a customer's
defaults go last, the intern's week tally in its own order), and the week's
report lists the tally in that order. At a checkpoint rt carries the live
text of each such key (ord, srvGate's round trip, about 8 ms), taken on load
only where it holds what sanitize() made of the save. A fresh realm after a
timeout takes the mark's own text the same way (live).
The plain game drifts across a save and a reload too (jsdom: from the first
day after it; the page routes a reloaded S with an empty R and keeps no desk
memory): a game property, so the engine carries what is missing.
The envelope keeps its shape {s, uidN, rt, last, day}; rt keeps R's own route
memory, so an older checkpoint loads as before (close, not exact). Big network:
the checkpoint grows from about 42-49 KB gzip to 54-79 KB (rt 7-29 KB; the
whole R would be 375 KB), srvSave from 2-2.5 ms to 7-8 ms, a load by one
routing. A day with its mark costs the same (big 39.8 -> 37.8 ms, busy
90.0 -> 88.8 ms, within noise: the day mark joins per-key JSON now, which pays
for the routing point).
Tests: the restore test checkpoints after days 1, 2, 5 and 10 of the scenic big
network and of the same network busy (intern on every order, the desk signing
on its own, failures, events, an attack), those after days 2 and 10 right after
an action and a what-if (sent to the copies too), each compared byte for byte
at once and 10 days later (SIM_LONG: after every day to 30, 60 checkpoints). It
fails on the old engine, and without any one of the three parts. The retry test
plays busy networks (fails without the desk memory in srvRestore). The market
checkpoint compares bytes too; canon() is gone.
This commit is contained in:
parent
065c922287
commit
c5c7ea9508
5 changed files with 169 additions and 72 deletions
|
|
@ -6,8 +6,10 @@
|
|||
// const engine = createEngine({workers: 2, heapMb: 1536, root, log});
|
||||
// engine.load(code, [{nid, env?, begin?, lang, prefs, rng?}]) → [{t:'loaded', nid, epoch, day, lost, saved?} |
|
||||
// {t:'loaded', nid, err}], one per network, in order. env: the checkpoint envelope {s, uidN, rt, last,
|
||||
// day} (s: the save text); begin: {name, home, preset, asn, mp, tut} builds a new network, checkpointed
|
||||
// at once (saved). A network whose save does not load (or that cannot begin) answers err: broken (4.7).
|
||||
// day} (s: the save text; rt: what the realm needs besides it to play on exactly as before, opaque
|
||||
// here: route memory, R's routing point, key order, the sales desk's memory); begin: {name, home,
|
||||
// preset, asn, mp, tut} builds a new network, checkpointed at once (saved). A network whose save
|
||||
// does not load (or that cannot begin) answers err: broken (4.7).
|
||||
// engine.day(code, {d, speed, last, alone:[nid], nets:[nid], mute}) → {t:'dayDone', code, d, nets:{[nid]: {day, lost,
|
||||
// pause?, err?, retried?, ms}}}. Each network in sorted order; one that failed twice answers err and
|
||||
// its day as it was, and is broken from then on (no more days; actions answer 'stopped').
|
||||
|
|
|
|||
|
|
@ -161,7 +161,8 @@ function srvSlimR(){const c=SIM_RTXT.get(R);if(c)return c;const o={};
|
|||
const t=JSON.stringify(o,srvR6);SIM_RTXT.set(R,t);return t;}
|
||||
const SIM_RTXT=new WeakMap();
|
||||
|
||||
/* ---- route memory (4.1): what compute() reads of yesterday's R; efg cut to the scenic circuits' keys ---- */
|
||||
/* ---- rt (4.1, 4.6): what a fresh realm needs besides the save to go on exactly as this one ---- */
|
||||
// The route memory: what compute() reads of the R before it (R.load, R.l2route, R.efg cut to the scenic circuits' keys).
|
||||
function srvRtOut(r){const efg={},E=r&&r.efg;
|
||||
if(E)for(const id in E){const t=E[id]&&E[id].t;if(!t||!t.g)continue;const g=[],v=[];for(const [k,s] of t.g)if(String(k).startsWith('l2:')){g.push([k,v.length]);v.push(+t.v[s]);}if(g.length)efg[id]={g,v};}
|
||||
return {load:(r&&r.load)||{},l2route:(r&&r.l2route)||{},efg};}
|
||||
|
|
@ -170,10 +171,54 @@ function srvRtIn(rt){const r=emptyR();if(!rt||typeof rt!=='object')return r;
|
|||
if(rt.efg&&typeof rt.efg==='object'){const o={};for(const id of Object.keys(rt.efg)){const t=rt.efg[id];if(t&&Array.isArray(t.g)&&Array.isArray(t.v))o[id]={g:new Map(t.g),v:t.v};}
|
||||
Object.defineProperty(r,'efg',{value:rwEfgIn(o)});}
|
||||
return r;}
|
||||
function srvRt(inp){const m=inp?JSON.parse(inp):{};return JSON.stringify(m.mark?(SIMR.markRt||srvRtOut(SIMR.mark?SIMR.mark.R:R)):srvRtOut(R));}
|
||||
/* R itself, whole, for the fresh realm that replaces this one after a timeout: route memory and compute() give a close R
|
||||
but not the same one (scenic paths settle over days, and S moved on since R's last routing), so the marked R travels
|
||||
the way the route worker sends it (rwPack/rwUnpack), as text: Maps, Sets, typed arrays and non-finite numbers tagged. */
|
||||
/* The routing point. R after a day is the R of the day's last routing, which ran before the day's end changed S (bills,
|
||||
moods, customers who left or signed) and started from the memory of the R before it. compute() of the saved S, even
|
||||
from R's own memory, gives another R, and the next day reads it (eyeball growth, the peering share): a network
|
||||
restored that way drifts from its first day on. So every compute() keeps, for the R it makes, S as it routed it (one
|
||||
JSON per top-level key, 0.8 ms big) and the memory it started from. rt carries that point (pt: the memory, at: the
|
||||
keys that changed since, gone: the keys S did not have then), and a fresh realm routes that S again from that memory:
|
||||
the same R (srvReroute). Trials route and put R back: their points go with their R. */
|
||||
const SIM_RIN=new WeakMap();
|
||||
{const c0=compute;compute=function(){const k=S?srvKeyJson():null,rt=JSON.stringify(srvRtOut(R)),v=c0.apply(this,arguments);if(k)SIM_RIN.set(R,{k,rt});return v;};}
|
||||
// The sales desk's memory (39-sales-auto.js): the offers it tried, which wait a week before it tries them again. It is
|
||||
// not in S; rt carries the entries of offers still on the table (no other can count again).
|
||||
function srvSlOut(){const t=UI.slTried;if(!t||t.s!==S||!t.m)return [];const ids=new Set(S.offers.map(o=>o.id));return [...t.m].filter(e=>ids.has(e[0]));}
|
||||
function srvSlIn(sl){const m=new Map();if(Array.isArray(sl))for(const e of sl.slice(0,1000))if(Array.isArray(e)&&typeof e[0]==='string'&&Number.isInteger(e[1]))m.set(e[0],e[1]);UI.slTried=m.size?{s:S,m}:null;}
|
||||
/* Key order: a reload gives some keys back with their keys in another order (a customer's defaults go last, the intern's
|
||||
week tally comes back in its own order, and the week's report lists it in that order). At a checkpoint rt carries the
|
||||
live text of each such key (ord, srvGate's round trip: ≈ 8 ms big, once per checkpoint), and a fresh realm takes it
|
||||
only where it holds what sanitize() made of the save (srvSame): only the order comes from it. */
|
||||
function srvOrdOut(txt,K){const u0=uidN,r0=S.rng;let B;
|
||||
try{B=migrate(JSON.parse(txt));}catch(e){srvLog('checkpoint: the save does not load: '+String(e&&e.message||e));return '{}';}finally{uidN=u0;S.rng=r0;}
|
||||
const o=[];for(const k in K)if(srvOwn(B,k)&&JSON.stringify(B[k])!==K[k])o.push(JSON.stringify(k)+':'+K[k]);return '{'+o.join(',')+'}';}
|
||||
function srvOrdIn(o){if(!o||typeof o!=='object'||Array.isArray(o))return;for(const k of Object.keys(o))if(srvOwn(S,k)&&srvSame(o[k],S[k]))S[k]=o[k];}
|
||||
// rt as JSON text: R's own route memory, its routing point against S as K holds it (when R was routed here), ord when
|
||||
// given, and the desk's memory sl.
|
||||
function srvRtText(r,K,ord,sl){const p=K&&SIM_RIN.get(r);let t=JSON.stringify(srvRtOut(r)).slice(0,-1);
|
||||
if(p){const at=[],gone=[];for(const k in p.k)if(K[k]!==p.k[k])at.push(JSON.stringify(k)+':'+p.k[k]);for(const k in K)if(!srvOwn(p.k,k))gone.push(k);
|
||||
t+=',"pt":'+p.rt.slice(0,-1)+',"at":{'+at.join(',')+'},"gone":'+JSON.stringify(gone)+'}';}
|
||||
return t+(ord?',"ord":'+ord:'')+',"sl":'+JSON.stringify(sl||[])+'}';}
|
||||
const srvKeysOf=s=>{const o=JSON.parse(s),K={};for(const k of Object.keys(o)){const j=JSON.stringify(o[k]);if(j!==undefined)K[k]=j;}return K;};
|
||||
// The S of a routing point (pt), one JSON per key: the loaded S with the keys of at put back and those of gone left out.
|
||||
function srvAtK(pt){if(!pt||typeof pt!=='object'||!pt.at||typeof pt.at!=='object'||Array.isArray(pt.at)||!Array.isArray(pt.gone))return null;
|
||||
const K=srvKeyJson();for(const k of Object.keys(pt.at))K[k]=JSON.stringify(pt.at[k]);for(const k of pt.gone)if(typeof k==='string')delete K[k];return K;}
|
||||
// R as the routing point gives it: that S routed from that memory, then the loaded S again (R's attacks found in it).
|
||||
function srvReroute(pt){const K=srvAtK(pt);if(!K)return false;const S1=S,u0=uidN;
|
||||
try{S=JSON.parse(srvJoin(K));R=srvRtIn(pt);compute();}
|
||||
catch(e){srvLog('routing the checkpoint again failed: '+String(e&&e.stack||e));return false;}
|
||||
finally{S=S1;uidN=u0;}
|
||||
srvAttacks();return true;}
|
||||
// R with its point, when it came whole (rpack): a checkpoint before its next routing still carries the point.
|
||||
function srvPointIn(r,pt){const K=srvAtK(pt);if(K)SIM_RIN.set(r,{k:K,rt:JSON.stringify({load:pt.load||{},l2route:pt.l2route||{},efg:pt.efg||{}})});}
|
||||
// R's attacks are its only references into S (rwPack): looked up again in a new S.
|
||||
function srvAttacks(){if(!R||!Array.isArray(R.ddos))return;const as=ddosAll(S,false);for(const x of R.ddos)if(x.attack)x.attack=as.find(a=>a.id===x.attack.id)||null;}
|
||||
// mark: rt of the marked R against the marked S (a day's mark has it at once); else of R against S now.
|
||||
function srvRt(inp){const m=inp?JSON.parse(inp):{},k=SIMR.mark;
|
||||
if(!m.mark)return srvRtText(R,srvKeyJson(),'',srvSlOut());
|
||||
return SIMR.markRt||(k?srvRtText(k.R,SIMR.markK||srvKeysOf(k.s),'',k.sl):srvRtText(R,null,'',[]));}
|
||||
/* R itself, whole, for the fresh realm that replaces this one after a timeout (routing it again from its point costs a
|
||||
routing; the old realm still answers), the way the route worker sends it (rwPack/rwUnpack), as text: Maps, Sets, typed
|
||||
arrays and non-finite numbers tagged. A checkpoint carries the point instead: 20 KB gzip, where R is 375 KB. */
|
||||
const SIM_TA=new Set(['Float64Array','Float32Array','Int32Array','Uint32Array','Int16Array','Uint16Array','Int8Array','Uint8Array','Uint8ClampedArray']);
|
||||
const srvEnc=(k,v)=>typeof v==='number'&&!Number.isFinite(v)?{__n:String(v)}:v instanceof Map?{__m:[...v]}:v instanceof Set?{__s:[...v]}:ArrayBuffer.isView(v)&&SIM_TA.has(v.constructor.name)?{__t:v.constructor.name,a:Array.from(v)}:v;
|
||||
const srvDec=(k,v)=>!v||typeof v!=='object'||Array.isArray(v)?v:'__n' in v?Number(v.__n):'__m' in v?new Map(v.__m):'__s' in v?new Set(v.__s):'__t' in v&&SIM_TA.has(v.__t)?new self[v.__t](v.a):v;
|
||||
|
|
@ -183,18 +228,22 @@ function srvSetPrefs(p){if(!p||typeof p!=='object')return;for(const k of SIMT.PR
|
|||
function srvFresh(epoch){SIMR.epoch=String(epoch||'');SIMR.v=0;SIMR.seen=false;SIMR.fx=[];SIMR.acts=[];SIMR.floats=0;SIMR.rSent=new WeakRef(R);SIMR.base=srvKeyJson();SIMR.mark=null;SIMR.markK=null;SIMR.markRt=null;
|
||||
UI.sel=null;UI.confirm=null;UI.pending=null;UI.started=true;UI.pitched=true;UI.clockLocked=true;$('modal').hidden=true;}
|
||||
|
||||
/* srvLoad: a network from its save (a checkpoint, or the mark of a realm that timed out). The route memory goes in
|
||||
before compute(), the way the route worker seeds its R: then the days to come are the ones the old realm had. A
|
||||
realm that replaces one that timed out gets the old realm's R itself when it could still pack it (rpack). */
|
||||
function srvLoad(inp){const m=JSON.parse(inp);SIMR.strict=!!m.strict;
|
||||
/* srvLoad: a network from its save (a checkpoint, or the mark of a realm that timed out) and its rt: S in its live key
|
||||
order, R routed again from its routing point, the desk's memory; then the days to come are the ones the old realm
|
||||
had. A realm that replaces one that timed out gets the old realm's R itself when it could still pack it (rpack); live:
|
||||
the save is the old realm's own S as text (a mark), key order and all. An rt without a point (an older checkpoint)
|
||||
seeds R with its memory before compute(), the way the route worker does: close, not always the same. */
|
||||
function srvLoad(inp){const m=JSON.parse(inp),rt=m.rt&&typeof m.rt==='object'?m.rt:{};SIMR.strict=!!m.strict;
|
||||
S=migrate(JSON.parse(m.save));
|
||||
if(typeof S.rng!=='number')S.rng=(m.rng|0)||1;
|
||||
if(Number.isInteger(m.uidN)&&m.uidN>0)uidN=m.uidN;
|
||||
srvSetPrefs(m.prefs);
|
||||
// A test's pinned clock goes on where the realm this one replaces had it.
|
||||
if(self.__srvClock&&typeof m.clock==='number')__srvClock(m.clock);
|
||||
if(typeof m.rpack==='string'&&m.rpack){const x=JSON.parse(m.rpack,srvDec);R=rwUnpack(x.o,x.p);UI.hotMap=hotByCity();}
|
||||
else{R=srvRtIn(m.rt);compute();}
|
||||
srvOrdIn(m.live?JSON.parse(m.save):rt.ord);
|
||||
if(typeof m.rpack==='string'&&m.rpack){const x=JSON.parse(m.rpack,srvDec);R=rwUnpack(x.o,x.p);UI.hotMap=hotByCity();srvPointIn(R,rt.pt);}
|
||||
else if(!srvReroute(rt.pt)){R=srvRtIn(rt);compute();}
|
||||
srvSlIn(rt.sl);
|
||||
srvFresh(m.epoch);
|
||||
// Whatever a loaded network says before its first snapshot (days nobody watched) is older than that snapshot: the
|
||||
// first pull handles it like any (5.11). Only a new network's welcome waits for its first page (srvBegin).
|
||||
|
|
@ -215,24 +264,26 @@ function srvBegin(inp){const m=JSON.parse(inp),b=m.begin||{};SIMR.strict=!!m.str
|
|||
function srvPrefs(inp){const m=JSON.parse(inp);srvSetPrefs(m.prefs);return '{}';}
|
||||
|
||||
/* srvMark: the restore point of the next day (day) or action (keys: one JSON per top-level key, whose join is the same
|
||||
string, kept for the action's own comparison). The worker keeps the string, uidN and the route memory too, to build a
|
||||
fresh realm if this one times out. */
|
||||
function srvMark(inp){const m=inp?JSON.parse(inp):{};let s;
|
||||
if(m.keys){SIMR.markK=srvKeyJson();s=srvJoin(SIMR.markK);}else{SIMR.markK=null;s=JSON.stringify(S);}
|
||||
SIMR.mark={s,uidN,rng:S.rng,R,...srvClockNow(),fx:SIMR.fx.slice(),floats:SIMR.floats,ui:{sel:UI.sel,tab:UI.tab,left:UI.left,confirm:UI.confirm,pending:UI.pending}};
|
||||
// A copy: R.load and R.l2route are R's own objects, and a day that fails half-way may already have written to them.
|
||||
const rtJ=m.day?JSON.stringify(srvRtOut(R)):'';SIMR.markRt=rtJ?JSON.parse(rtJ):null;const h=JSON.stringify({uidN,day:S.day,...srvClockNow()});
|
||||
string, kept for the action's own comparison). The worker keeps the string, uidN and a day's rt too, to build a fresh
|
||||
realm if this one times out. */
|
||||
function srvMark(inp){const m=inp?JSON.parse(inp):{};let s,K=null;
|
||||
if(m.keys||m.day){K=srvKeyJson();s=srvJoin(K);}else s=JSON.stringify(S);
|
||||
SIMR.markK=m.keys?K:null;const sl=srvSlOut();
|
||||
SIMR.mark={s,uidN,rng:S.rng,R,sl,...srvClockNow(),fx:SIMR.fx.slice(),floats:SIMR.floats,ui:{sel:UI.sel,tab:UI.tab,left:UI.left,confirm:UI.confirm,pending:UI.pending}};
|
||||
// As text: nothing the day does reaches it.
|
||||
const rtJ=m.day?srvRtText(R,K,'',sl):'';SIMR.markRt=rtJ||null;const h=JSON.stringify({uidN,day:S.day,...srvClockNow()});
|
||||
return (rtJ?h.slice(0,-1)+',"rt":'+rtJ+'}':h)+'\\n'+s;}
|
||||
/* srvRestore: back to the mark, in place (after a throw: the finally blocks ran). S is parsed back only when it
|
||||
changed, so the S object stays on every normal path; R is the marked object, its attacks looked up again in a parsed
|
||||
S. (The design rebuilt R from route memory after a failed day; that R is close, not the same: tests/mp-sim-determinism.) */
|
||||
S; the sales desk's memory is the marked one (a failed day may have added to it). (The design rebuilt R from route
|
||||
memory after a failed day; that R is close, not the same: tests/mp-sim-determinism.) */
|
||||
function srvRestore(inp){const k=SIMR.mark;if(!k)return '{"none":1}';
|
||||
let parsed=false;if(JSON.stringify(S)!==k.s){S=JSON.parse(k.s);parsed=true;}
|
||||
uidN=k.uidN;S.rng=k.rng;if(self.__srvClock&&typeof k.clock==='number')__srvClock(k.clock);
|
||||
// R: the marked object. A day or an action routes into a new R (compute() never writes to the one it starts from),
|
||||
// so the marked one is still the R the network had: route memory and compute() would only give one close to it.
|
||||
R=k.R;if(parsed&&R&&Array.isArray(R.ddos)){const as=ddosAll(S,false);for(const x of R.ddos)if(x.attack)x.attack=as.find(a=>a.id===x.attack.id)||null;}
|
||||
UI.hotMap=hotByCity();
|
||||
R=k.R;if(parsed)srvAttacks();
|
||||
UI.hotMap=hotByCity();UI.slTried=k.sl.length?{s:S,m:new Map(k.sl)}:null;
|
||||
Object.assign(UI,k.ui);SIMR.fx=k.fx.slice();SIMR.floats=k.floats;SIMR.modal=null;SIMR.closed=false;$('modal').hidden=true;
|
||||
return JSON.stringify({parsed});}
|
||||
|
||||
|
|
@ -361,7 +412,9 @@ function srvSub(inp){const m=inp?JSON.parse(inp):{};return JSON.stringify({v:SIM
|
|||
// The one-shots a page says when a network opens (the courtesy route, Australia's prices): they change S, so the
|
||||
// server says them, as fx of the next update.
|
||||
function srvGreet(inp){bootNotes();return srvPull(inp);}
|
||||
function srvSave(){const txt=JSON.stringify(packSave(S));return srvOut({uidN,rt:srvRtOut(R),day:S.day,lost:!!S.lost,...srvClockNow()},txt);}
|
||||
// A checkpoint: the save and its rt, ord included.
|
||||
function srvSave(){const txt=JSON.stringify(packSave(S)),K=srvKeyJson(),h=JSON.stringify({uidN,day:S.day,lost:!!S.lost,...srvClockNow()});
|
||||
return h.slice(0,-1)+',"rt":'+srvRtText(R,K,srvOrdOut(txt,K),srvSlOut())+'}\\n'+txt;}
|
||||
function srvCard(){return JSON.stringify({card:mpCard()});}
|
||||
`;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@
|
|||
// unloads of a session wait for its day; actions for a network that is still loading wait for it.
|
||||
//
|
||||
// Failures. Every realm call has a time limit (a day 2 s, an action 1 s, a what-if 3 s, a pull or a save 1 s). Before
|
||||
// a day or an action the realm is marked (its S as text, uidN, the dice, and for a day yesterday's route memory), and the
|
||||
// worker keeps the mark. A call that throws has run its finally blocks: the realm goes back to the mark in place. A call
|
||||
// that times out has not (vm skips them), so that realm is never used again: a fresh one is built from the mark, with a
|
||||
// new epoch. A failed day runs once more; failing again, the network is broken at its state before the day.
|
||||
// a day or an action the realm is marked (its S as text, uidN, the dice, and for a day its rt: route memory and routing
|
||||
// point), and the worker keeps the mark. A call that throws has run its finally blocks: the realm goes back to the mark
|
||||
// in place. A call that times out has not (vm skips them), so that realm is never used again: a fresh one is built from
|
||||
// the mark, with a new epoch. A failed day runs once more; failing again, the network is broken at its state before
|
||||
// the day.
|
||||
//
|
||||
// The worker → host replies are the shapes of tests/lib/mp-sim-shape.js checkWorker(), sent as {id, ok, reply} (or
|
||||
// {id, ok:false, error}) for the engine to match its promises; logs go up as {log:[level, text]}.
|
||||
|
|
@ -44,27 +45,28 @@ function createCore(opts = {}) {
|
|||
}
|
||||
// A realm call: [header, ...parts]; a throw inside the realm comes back as {srvErr}, a timeout throws.
|
||||
const call = (e, name, input, ms) => e.realm.call(name, input, ms);
|
||||
/* A fresh realm in place of one that timed out, from {s, uidN, rt}: same network, new epoch, versions from 0. R comes
|
||||
from the old realm, which still answers after a timeout: the marked R (mark) or its current one, packed whole. Only
|
||||
when it cannot is R routed again from the route memory, which gives a close R, not always the same. */
|
||||
/* A fresh realm in place of one that timed out, from {s, uidN, rt, live}: same network, new epoch, versions from 0. R
|
||||
comes from the old realm, which still answers after a timeout: the marked R (mark) or its current one, packed whole.
|
||||
When it cannot, R is routed again from rt's routing point. live: s is a mark, the realm's own S as text. */
|
||||
function rebuild(e, from, mark = true) {
|
||||
let rpack = null;
|
||||
try { const s = e.realm && e.realm.raw('srvRPack', { mark }, T.load); if (typeof s === 'string' && s.startsWith('{"o"')) rpack = s; } catch (x) { /* gone */ }
|
||||
const r = build(e.nid, e.lang), epoch = epochOf();
|
||||
const [h] = r.call('srvLoad', { save: from.s, uidN: from.uidN, rt: from.rt, rpack, prefs: e.prefs, epoch, strict: !!opts.strict, clock: from.clock }, T.load);
|
||||
const [h] = r.call('srvLoad', { save: from.s, uidN: from.uidN, rt: from.rt, rpack, live: !!from.live, prefs: e.prefs, epoch, strict: !!opts.strict, clock: from.clock }, T.load);
|
||||
if (h.srvErr) throw new Error('rebuilding the realm failed: ' + h.srvErr);
|
||||
e.realm = r; e.epoch = epoch; e.v = 0; e.day = h.day; e.lost = h.lost;
|
||||
log('warn', `[${e.nid}] realm rebuilt after a timeout (epoch ${epoch}${rpack ? '' : ', R routed again'})`);
|
||||
}
|
||||
// The route memory of the old realm's mark, if it still answers; else the last day's.
|
||||
// The rt of the old realm's mark, if it still answers; else the last day's, whose routing point belongs to that day's
|
||||
// S: with another mark only its route memory counts (a close R).
|
||||
function markRt(e) {
|
||||
try { const [h] = call(e, 'srvRt', { mark: true }, 200); if (h && !h.srvErr && h.load) return h; } catch (x) { /* gone */ }
|
||||
return e.dayMark ? e.dayMark.rt : null;
|
||||
return e.dayMark ? (e.dayMark === e.mark ? e.dayMark.rt : { ...e.dayMark.rt, pt: undefined }) : null;
|
||||
}
|
||||
function mark(e, input) {
|
||||
const [h, s] = call(e, 'srvMark', input, T.mark);
|
||||
if (h.srvErr) throw new Error('mark failed: ' + h.srvErr);
|
||||
const m = { s, uidN: h.uidN, rt: h.rt || null, day: h.day, clock: h.clock };
|
||||
const m = { s, uidN: h.uidN, rt: h.rt || null, day: h.day, clock: h.clock, live: true };
|
||||
if (input.day) e.dayMark = m;
|
||||
e.mark = m;
|
||||
return m;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue