@brown-ds/distribution 0.2.25 → 0.2.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/distribution/all/mem.js
CHANGED
|
@@ -6,5 +6,5 @@ Do NOT edit this file directly. Use it as a black box.
|
|
|
6
6
|
|
|
7
7
|
If you notice any issues with using this file, please contact the TAs.
|
|
8
8
|
*/
|
|
9
|
-
const log=require('../util/lo'+'g.js');function normalize(
|
|
9
|
+
const log=require('../util/lo'+'g.js');function normalize(_0x32024c,_0x453b57){if(_0x32024c===null)return{'key':null,'gid':_0x453b57,'action':'put'};else return typeof _0x32024c==='string'?{'key':_0x32024c,'gid':_0x453b57,'action':'put'}:_0x32024c;}function mem(_0x596c5f){const _0x49e839={};_0x49e839['gid']=_0x596c5f['gid']||'all',_0x49e839['hash']=_0x596c5f['hash']||globalThis['distributi'+'on']['util']['id']['naiveHash'];function _0x371c08(_0x21a52e,_0x2c108d){log('[all.mem.g'+'et]\x20config'+'uration:\x20'+JSON['stringify'](_0x21a52e)+'\x20context:\x20'+JSON['stringify'](_0x49e839)),_0x21a52e=normalize(_0x21a52e,_0x49e839['gid']),_0x21a52e['gid']=_0x21a52e['gid']||_0x49e839['gid'];const _0x1fa5ac={'service':'mem','method':'get'},_0x326650=[_0x21a52e];if(!_0x21a52e['key']){globalThis['distributi'+'on'][_0x49e839['gid']]['comm']['send'](_0x326650,_0x1fa5ac,(_0x2b3bc6,_0x352974)=>{const _0x4dbc3e=Object['values'](_0x352974)['reduce']((_0x3f3d3a,_0x278732)=>_0x3f3d3a['concat'](_0x278732),[]);_0x2c108d(_0x2b3bc6,_0x4dbc3e);});return;}const _0xeffa28=_0x21a52e['key'];if(_0xeffa28===null){_0x2c108d(new TypeError('Configurat'+'ion\x20is\x20nul'+'l'));return;}globalThis['distributi'+'on']['util']['wire']['dispatchMe'+'ssage'](_0x326650,_0x1fa5ac,{'key':_0xeffa28},_0x49e839,_0x2c108d);return;return _0x2c108d(new Error('mem.get\x20no'+'t\x20implemen'+'ted'));}function _0x23a5a1(_0x502045,_0x348891,_0x3f229b){log('[all.mem.p'+'ut]\x20state:'+'\x20'+JSON['stringify'](_0x502045)+('\x20configura'+'tion:\x20')+JSON['stringify'](_0x348891)),_0x348891=_0x348891||globalThis['distributi'+'on']['util']['id']['getID'](_0x502045),_0x348891=normalize(_0x348891,_0x49e839['gid']),_0x348891['gid']=_0x348891['gid']||_0x49e839['gid'];const _0x17052e={'service':'mem','method':'put'},_0x41961f=[_0x502045,_0x348891],_0x3380b1=_0x348891['key'];if(_0x3380b1===null){_0x3f229b(new TypeError('Configurat'+'ion\x20is\x20nul'+'l'));return;}globalThis['distributi'+'on']['util']['wire']['dispatchMe'+'ssage'](_0x41961f,_0x17052e,{'key':_0x3380b1},_0x49e839,_0x3f229b);return;return _0x3f229b(new Error('mem.put\x20no'+'t\x20implemen'+'ted'));}function _0x3a2765(_0x31c931,_0xb9548a){log('[all.mem.d'+'el]\x20config'+'uration:\x20'+JSON['stringify'](_0x31c931)),_0x31c931=normalize(_0x31c931,_0x49e839['gid']),_0x31c931['gid']=_0x31c931['gid']||_0x49e839['gid'];const _0xee4669={'service':'mem','method':'del'},_0x22c96a=[_0x31c931],_0x2c602f=_0x31c931['key'];if(_0x2c602f===null){_0xb9548a(new TypeError('Configurat'+'ion\x20is\x20nul'+'l'));return;}globalThis['distributi'+'on']['util']['wire']['dispatchMe'+'ssage'](_0x22c96a,_0xee4669,{'key':_0x2c602f},_0x49e839,_0xb9548a);return;return _0xb9548a(new Error('mem.del\x20no'+'t\x20implemen'+'ted'));}function _0x1b7e3a(_0x15a049,_0x2f5b91){log('[mem.recon'+'f]\x20configu'+'ration:\x20'+JSON['stringify'](_0x15a049)+'\x20gid:\x20'+_0x49e839['gid']),globalThis['distributi'+'on']['local']['groups']['get'](_0x49e839['gid'],(_0x446233,_0x360998)=>{if(!_0x360998){_0x2f5b91(_0x446233);return;}globalThis['distributi'+'on']['local']['groups']['put'](_0x49e839['gid'],_0x15a049,(_0x54d5da,_0x2a007b)=>{globalThis['distributi'+'on'][_0x49e839['gid']]['mem']['get'](null,(_0x753d8c,_0x4cdb76)=>{globalThis['distributi'+'on']['local']['groups']['put'](_0x49e839['gid'],_0x360998,(_0x484939,_0x5a11c7)=>{globalThis['distributi'+'on'][_0x49e839['gid']]['status']['get']('nid',(_0x1096d9,_0x3d4957)=>{const _0x795cc4=Object['values'](_0x3d4957),_0x55ac29=Object['values'](_0x15a049)['map'](_0x2910d4=>globalThis['distributi'+'on']['util']['id']['getNID'](_0x2910d4));log('[mem.recon'+'f\x20received'+'\x20'+_0x4cdb76['length']+('\x20keys\x20from'+'\x20')+_0x3d4957['length']+'\x20nodes');let _0x36b9c7=-0x6*0x4a+-0x805+-0x1*-0x9c1;const _0xbf6699=()=>{if(_0x36b9c7===_0x4cdb76['length'])return _0x2f5b91(null);};if(_0x4cdb76['length']===-0x3e*-0x78+0x182b+-0x353b)return _0x2f5b91(null);for(const _0x531f23 of _0x4cdb76){const _0x20623b=globalThis['distributi'+'on']['util']['id']['getID'](_0x531f23),_0xdcce56=_0x49e839['hash'](_0x20623b,_0x55ac29),_0x25e240=_0x49e839['hash'](_0x20623b,_0x795cc4);log('[mem.recon'+'f]\x20old\x20nid'+':\x20'+_0xdcce56+'\x20new\x20nid:\x20'+_0x25e240);if(_0xdcce56===_0x25e240){_0x36b9c7++,_0xbf6699();continue;}const _0x4855bc=_0x15a049[_0xdcce56['substring'](0x19f1+-0xaed*0x2+-0x417,-0xc*0x20a+-0x1943+0x18e*0x20)],_0xf96b0c=[{'key':_0x531f23,'gid':_0x49e839['gid']}],_0x491d0b={'service':'mem','method':'del','node':_0x4855bc};log('[mem.recon'+'f]\x20deletin'+'g\x20key\x20'+_0x531f23+'\x20from\x20'+JSON['stringify'](_0x491d0b)),globalThis['distributi'+'on']['local']['comm']['send'](_0xf96b0c,_0x491d0b,(_0x8c4449,_0x52687f)=>{globalThis['distributi'+'on'][_0x49e839['gid']]['mem']['put'](_0x52687f,_0x531f23,(_0x457f0c,_0x2ac296)=>{_0x36b9c7++,_0xbf6699();});});}});});});});});return;return _0x2f5b91(new Error('mem.reconf'+'\x20not\x20imple'+'mented'));}return{'get':_0x371c08,'put':_0x23a5a1,'del':_0x3a2765,'reconf':_0x1b7e3a};}module['exports']=mem;
|
|
10
10
|
/* eslint-enable */
|
|
@@ -6,5 +6,5 @@ Do NOT edit this file directly. Use it as a black box.
|
|
|
6
6
|
|
|
7
7
|
If you notice any issues with using this file, please contact the TAs.
|
|
8
8
|
*/
|
|
9
|
-
const log=require('../util/lo'+'g.js');function getNode(
|
|
9
|
+
const log=require('../util/lo'+'g.js');function getNode(_0x56df33,_0xd97253,_0x3ad8f8){const _0x19cc0d=_0xd97253&&typeof _0xd97253==='object'?_0xd97253['key']:_0xd97253;globalThis['distributi'+'on'][_0x56df33['gid']]['status']['get']('nid',(_0x167305,_0x541898)=>{const _0x268f87=Object['values'](_0x541898),_0x3a1cdd=globalThis['distributi'+'on']['util']['id']['getID'](_0x19cc0d),_0x4a8379=_0x56df33['hash'](_0x3a1cdd,_0x268f87),_0x2f2141=_0x4a8379['substring'](-0x4*0x35b+-0x1434+0x21a*0x10,0x12b3+-0x1e11+-0x37*-0x35);globalThis['distributi'+'on']['local']['groups']['get'](_0x56df33['gid'],(_0x400922,_0x8bcfb2)=>{if(!_0x8bcfb2)return _0x3ad8f8(_0x400922);else{const _0x5870d2=_0x8bcfb2[_0x2f2141];return log('[store\x20(ge'+'tNode)]\x20co'+'nfiguratio'+'n:\x20'+JSON['stringify'](_0xd97253)+'group:\x20'+JSON['stringify'](_0x8bcfb2)+'\x20node:\x20'+JSON['stringify'](_0x5870d2)+'nid:\x20'+JSON['stringify'](_0x4a8379)+'\x20sid:\x20'+JSON['stringify'](_0x2f2141)),_0x3ad8f8(null,_0x5870d2);}});});}function normalize(_0x38566b,_0x5b7ebe){if(_0x38566b===null)return{'key':null,'gid':_0x5b7ebe,'action':'put'};else return typeof _0x38566b==='string'?{'key':_0x38566b,'gid':_0x5b7ebe,'action':'put'}:_0x38566b;}function store(_0x59c946){const _0x5dbe89={'gid':_0x59c946['gid']||'all','hash':_0x59c946['hash']||globalThis['distributi'+'on']['util']['id']['naiveHash'],'subset':_0x59c946['subset']};function _0x1d0a59(_0x28695e,_0x274138){if(!_0x28695e){const _0x485b58=[{'key':null,'gid':_0x5dbe89['gid']}];globalThis['distributi'+'on'][_0x5dbe89['gid']]['comm']['send'](_0x485b58,{'service':'store','method':'get'},(_0x59d1eb,_0x52aeaf)=>{const _0xd617d7=Object['values'](_0x52aeaf)['reduce']((_0x350b51,_0x14825a)=>_0x350b51['concat'](_0x14825a),[]);_0x274138(_0x59d1eb,_0xd617d7);});return;}_0x28695e=normalize(_0x28695e,_0x5dbe89['gid']),getNode(_0x5dbe89,_0x28695e,(_0x18ccae,_0x35bd7c)=>{if(!_0x35bd7c){_0x274138(_0x18ccae);return;}const _0x549a6e=[_0x28695e],_0x4d7ad1={'service':'store','method':'get','node':_0x35bd7c};log('[all.store'+'.get]confi'+'guration:\x20'+JSON['stringify'](_0x28695e)+'node:\x20'+JSON['stringify'](globalThis['distributi'+'on']['node']['config'])+('\x20target\x20no'+'de:\x20')+JSON['stringify'](_0x35bd7c)),globalThis['distributi'+'on']['local']['comm']['send'](_0x549a6e,_0x4d7ad1,_0x274138);});return;return _0x274138(new Error('store.get\x20'+'not\x20implem'+'ented'));}function _0x42e18c(_0x2059e6,_0x32c08a,_0x2c652e){_0x32c08a=_0x32c08a||globalThis['distributi'+'on']['util']['id']['getID'](_0x2059e6),_0x32c08a=normalize(_0x32c08a,_0x5dbe89['gid']),getNode(_0x5dbe89,_0x32c08a,(_0x12260d,_0x461835)=>{if(!_0x461835){_0x2c652e(_0x12260d);return;}const _0x5aa60a=[_0x2059e6,_0x32c08a],_0x256fac={'service':'store','method':'put','node':_0x461835};log('[all.store'+'.put]\x20stat'+'e:\x20'+JSON['stringify'](_0x2059e6)+('configurat'+'ion:\x20')+JSON['stringify'](_0x32c08a)+('target\x20nod'+'e:\x20')+JSON['stringify'](_0x461835)),globalThis['distributi'+'on']['local']['comm']['send'](_0x5aa60a,_0x256fac,_0x2c652e);});return;return _0x2c652e(new Error('store.put\x20'+'not\x20implem'+'ented'));}function _0x28659f(_0x7bc9bf,_0x19a9fa){getNode(_0x5dbe89,_0x7bc9bf,(_0xc1bf99,_0x186200)=>{if(!_0x186200){_0x19a9fa(_0xc1bf99);return;}const _0x4d706e=[{'key':_0x7bc9bf,'gid':_0x5dbe89['gid']}],_0x3b5f70={'service':'store','method':'del','node':_0x186200};globalThis['distributi'+'on']['local']['comm']['send'](_0x4d706e,_0x3b5f70,_0x19a9fa);});return;return _0x19a9fa(new Error('store.del\x20'+'not\x20implem'+'ented'));}function _0x5863c7(_0x22e783,_0x1d7c88){log('[store.rec'+'onf]\x20confi'+'guration:\x20'+JSON['stringify'](_0x22e783)+'\x20gid:\x20'+_0x5dbe89['gid']),globalThis['distributi'+'on']['local']['groups']['get'](_0x5dbe89['gid'],(_0x2af156,_0x2b066f)=>{if(!_0x2b066f){_0x1d7c88(_0x2af156);return;}globalThis['distributi'+'on']['local']['groups']['put'](_0x5dbe89['gid'],_0x22e783,(_0x4507b1,_0x18023b)=>{globalThis['distributi'+'on'][_0x5dbe89['gid']]['store']['get'](null,(_0x38bea3,_0x3c2836)=>{globalThis['distributi'+'on']['local']['groups']['put'](_0x5dbe89['gid'],_0x2b066f,(_0x31010b,_0x3a214f)=>{globalThis['distributi'+'on'][_0x5dbe89['gid']]['status']['get']('nid',(_0x2e730c,_0x2dbb1a)=>{const _0x85a6c7=Object['values'](_0x2dbb1a),_0x438210=Object['values'](_0x22e783)['map'](_0x430426=>globalThis['distributi'+'on']['util']['id']['getNID'](_0x430426));log('[store.rec'+'onf\x20receiv'+'ed\x20'+_0x3c2836['length']+('\x20keys\x20from'+'\x20')+_0x2dbb1a['length']+'\x20nodes');let _0x3be2b9=-0x5a2*0x2+-0x166c+0x31*0xb0;const _0x28032c=()=>{if(_0x3be2b9===_0x3c2836['length'])return _0x1d7c88(null);};if(_0x3c2836['length']===0x243d*0x1+0x502*0x5+-0x3d47)return _0x1d7c88(null);for(const _0x25e296 of _0x3c2836){const _0x50ef19=globalThis['distributi'+'on']['util']['id']['getID'](_0x25e296),_0x4c7d1=_0x5dbe89['hash'](_0x50ef19,_0x438210),_0x5ef2ca=_0x5dbe89['hash'](_0x50ef19,_0x85a6c7);log('[store.rec'+'onf]\x20old\x20n'+'id:\x20'+_0x4c7d1+'\x20new\x20nid:\x20'+_0x5ef2ca);if(_0x4c7d1===_0x5ef2ca){_0x3be2b9++,_0x28032c();continue;}const _0x2296a1=_0x22e783[_0x4c7d1['substring'](-0xb34+-0x1ca5*-0x1+-0x5f*0x2f,0xba7+-0x8a0+-0x302)],_0x4c5116=[{'key':_0x25e296,'gid':_0x5dbe89['gid']}],_0x5e757a={'service':'store','method':'del','node':_0x2296a1};log('[store.rec'+'onf]\x20delet'+'ing\x20key\x20'+_0x25e296+'\x20from\x20'+JSON['stringify'](_0x5e757a)),globalThis['distributi'+'on']['local']['comm']['send'](_0x4c5116,_0x5e757a,(_0x56383b,_0x1bf949)=>{globalThis['distributi'+'on'][_0x5dbe89['gid']]['store']['put'](_0x1bf949,_0x25e296,(_0x456d15,_0x3f892c)=>{_0x3be2b9++,_0x28032c();});});}});});});});});return;return _0x1d7c88(new Error('store.reco'+'nf\x20not\x20imp'+'lemented'));}return{'get':_0x1d0a59,'put':_0x42e18c,'del':_0x28659f,'reconf':_0x5863c7};}module['exports']=store;
|
|
10
10
|
/* eslint-enable */
|
|
@@ -6,5 +6,5 @@ Do NOT edit this file directly. Use it as a black box.
|
|
|
6
6
|
|
|
7
7
|
If you notice any issues with using this file, please contact the TAs.
|
|
8
8
|
*/
|
|
9
|
-
const http=require('node:http'),url=require('node:url'),log=require('../util/lo'+'g.js'),yargs=require('yargs/yarg'+'s');function setNodeConfig(){const
|
|
9
|
+
const http=require('node:http'),url=require('node:url'),log=require('../util/lo'+'g.js'),yargs=require('yargs/yarg'+'s');function setNodeConfig(){const _0x12b3a0=yargs(process['argv'])['help'](![])['version'](![])['parse']();let _0x23ca2e,_0x44bf6f,_0x58f68d;typeof _0x12b3a0['ip']==='string'&&(_0x23ca2e=_0x12b3a0['ip']);(typeof _0x12b3a0['port']==='string'||typeof _0x12b3a0['port']==='number')&&(_0x44bf6f=parseInt(String(_0x12b3a0['port']),-0xd82+-0x11d0+0x24*0xdf));(_0x12b3a0['help']===!![]||_0x12b3a0['h']===!![])&&(console['log']('Node\x20usage'+':'),console['log']('\x20\x20--ip\x20<ip'+'\x20address>\x20'+'\x20\x20\x20\x20\x20The\x20i'+'p\x20address\x20'+'to\x20bind\x20th'+'e\x20node\x20to'),console['log']('\x20\x20--port\x20<'+'port>\x20\x20\x20\x20\x20'+'\x20\x20\x20\x20\x20The\x20p'+'ort\x20to\x20bin'+'d\x20the\x20node'+'\x20to'),console['log']('\x20\x20--config'+'\x20<config>\x20'+'\x20\x20\x20\x20\x20The\x20s'+'erialized\x20'+'config\x20str'+'ing'),process['exit'](0x26c+-0xcb8+0xa4c));if(typeof _0x12b3a0['config']==='string'){let _0x2edf40=undefined;try{_0x2edf40=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x12b3a0['config']);}catch(_0x196b68){try{_0x2edf40=JSON['parse'](_0x12b3a0['config']);}catch{console['error']('Cannot\x20des'+'erialize\x20c'+'onfig\x20stri'+'ng:\x20'+_0x12b3a0['config']),process['exit'](-0x583*-0x5+-0xb76+-0x1018);}}typeof _0x2edf40?.['ip']==='string'&&(_0x23ca2e=_0x2edf40?.['ip']),typeof _0x2edf40?.['port']==='number'&&(_0x44bf6f=_0x2edf40?.['port']),typeof _0x2edf40?.['onStart']==='function'&&(_0x58f68d=_0x2edf40?.['onStart']);}return _0x23ca2e=_0x23ca2e??'127.0.0.1',_0x44bf6f=_0x44bf6f??-0x7*0x4eb+0x46*-0x85+0x4b9d,{'ip':_0x23ca2e,'port':_0x44bf6f,'onStart':_0x58f68d};}function validate(_0x4c88f5){if(_0x4c88f5['length']===0x4*-0x1f8+0x175*0xf+-0x4a9*0x3)throw new Error('No\x20body');return _0x4c88f5;}function start(_0x20e157){const _0x2f4093=http['createServ'+'er']((_0x1eba6f,_0x416fca)=>{if(_0x1eba6f['method']!=='PUT'){_0x416fca['end'](globalThis['distributi'+'on']['util']['serialize'](new Error('Method\x20not'+'\x20allowed!')));return;}const [,_0x6fdf98,_0x950986,_0x4340db]=url['parse'](_0x1eba6f['url'])['pathname']['split']('/');log('[server]\x20g'+'ot\x20request'+'\x20'+_0x6fdf98+'\x20'+_0x950986+':'+_0x4340db+'\x20from\x20'+_0x1eba6f['socket']['remoteAddr'+'ess']);const _0x3c4653=[];_0x1eba6f['on']('data',_0x39cca0=>{_0x3c4653['push'](_0x39cca0);}),_0x1eba6f['on']('end',()=>{let _0x185859;try{_0x185859=validate(Buffer['concat'](_0x3c4653)['toString']());}catch(_0x53b0ef){_0x416fca['end'](globalThis['distributi'+'on']['util']['serialize']([_0x53b0ef]));return;}const _0xf099cb=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x185859);!Array['isArray'](_0xf099cb)&&_0x416fca['end'](globalThis['distributi'+'on']['util']['serialize']([new Error('Invalid\x20ar'+'gument\x20typ'+'e,\x20expecte'+'d\x20array,\x20g'+'ot\x20'+typeof _0xf099cb)]));const _0x9b7800=_0x950986;globalThis['distributi'+'on']['local']['routes']['get']({'service':_0x950986,'gid':_0x6fdf98},(_0x45900d,_0x4af5b2)=>{if(_0x45900d){_0x416fca['end'](globalThis['distributi'+'on']['util']['serialize']([_0x45900d,null]));return;}if(!_0x4af5b2[_0x4340db]){_0x416fca['end'](globalThis['distributi'+'on']['util']['serialize']([new Error('Method\x20'+_0x4340db+('\x20not\x20found'+'\x20in\x20servic'+'e\x20')+_0x9b7800),null]));return;}log('[server]\x20\x20'+'Calling\x20se'+'rvice:\x20'+_0x9b7800+':'+_0x4340db+('\x20with\x20args'+':\x20')+JSON['stringify'](_0xf099cb));_0xf099cb['length']===0x4b*0x6e+-0x2b5+-0x1d84&&_0x4af5b2[_0x4340db]['length']===0x4a*-0x6f+-0x34*0x56+0x1*0x3191&&_0xf099cb['push'](undefined);const _0x5232b8=_0x4af5b2[_0x4340db]['bind'](_0x4af5b2),_0x15f5c3=globalThis['distributi'+'on']['util']['normalize'](_0x5232b8,_0xf099cb);try{_0x5232b8(..._0x15f5c3,(_0x159b25,_0x349259)=>_0x416fca['end'](globalThis['distributi'+'on']['util']['serialize']([_0x159b25,_0x349259])));}catch(_0x10b5c9){_0x416fca['end'](globalThis['distributi'+'on']['util']['serialize']([_0x10b5c9,null]));}});});});globalThis['distributi'+'on']['node']['server']=_0x2f4093;const _0x225567=globalThis['distributi'+'on']['node']['config'];_0x2f4093['once']('listening',()=>{log('Server\x20run'+'ning\x20at\x20ht'+'tp://'+_0x225567['ip']+':'+_0x225567['port']+'/'),_0x20e157(null);}),_0x2f4093['once']('error',_0x49cc14=>{log('Server\x20err'+'or:\x20'+_0x49cc14),_0x20e157(_0x49cc14);}),_0x2f4093['listen'](_0x225567['port'],_0x225567['ip']);}module['exports']={'start':start,'config':setNodeConfig()};
|
|
10
10
|
/* eslint-enable */
|
package/distribution/util/id.js
CHANGED
|
@@ -6,5 +6,5 @@ Do NOT edit this file directly. Use it as a black box.
|
|
|
6
6
|
|
|
7
7
|
If you notice any issues with using this file, please contact the TAs.
|
|
8
8
|
*/
|
|
9
|
-
const assert=require('assert'),crypto=require('crypto');function getID(
|
|
9
|
+
const assert=require('assert'),crypto=require('crypto');function getID(_0xbb9df0){const _0x51967b=crypto['createHash']('sha256');return _0x51967b['update'](JSON['stringify'](_0xbb9df0)),_0x51967b['digest']('hex');}function getNID(_0xe388){return _0xe388={'ip':_0xe388['ip'],'port':_0xe388['port']},getID(_0xe388);}function getSID(_0x2abc00){return getNID(_0x2abc00)['substring'](-0x2247*-0x1+0x8*-0x394+-0x5a7,0x2507+0x250b+-0x4a0d);}function getMID(_0x3ba368){const _0x108b63={};return _0x108b63['date']=new Date()['getTime'](),_0x108b63['mss']=_0x3ba368,getID(_0x108b63);}function idToNum(_0x55bc3c){assert(typeof _0x55bc3c==='string','idToNum:\x20i'+'d\x20is\x20not\x20i'+'n\x20KID\x20form'+'!');const _0x1c5871=_0x55bc3c['startsWith']('0x')?_0x55bc3c['slice'](0x6fd*-0x3+0x2022+-0xb29):_0x55bc3c;if(/^[0-9a-fA-F]+$/['test'](_0x1c5871))return BigInt('0x'+_0x1c5871);return BigInt(_0x55bc3c);}const naiveHash=(_0x2446b8,_0x564e44)=>{const _0x2e26e1=[..._0x564e44]['sort'](),_0x1090fb=Number(idToNum(_0x2446b8)%BigInt(_0x2e26e1['length']));return _0x2e26e1[_0x1090fb];},consistentHash=(_0x2274e3,_0xca9f6d)=>{const _0x5770f1=idToNum(_0x2274e3),_0x5e4464=_0xca9f6d['map'](_0x45e8fd=>({'id':_0x45e8fd,'hash':idToNum(_0x45e8fd)}));_0x5e4464['sort']((_0x4859a5,_0x35260d)=>{if(_0x4859a5['hash']<_0x35260d['hash'])return-(-0x136b+-0xe5b+0x21c7);if(_0x4859a5['hash']>_0x35260d['hash'])return-0x160a+0x146f*-0x1+0x2a7a;return-0xfb*-0x8+0xf71+-0x7c3*0x3;});for(const _0x5853ac of _0x5e4464){if(_0x5770f1<=_0x5853ac['hash'])return _0x5853ac['id'];}return _0x5e4464[-0x20e7*0x1+-0x16f6+-0x129f*-0x3]['id'];},rendezvousHash=(_0x29654e,_0x9f43e3)=>{let _0x108962=null,_0x3eacbc=null;for(const _0x2cc936 of _0x9f43e3){const _0x37ef7c=getID(_0x29654e+_0x2cc936),_0x496bd5=idToNum(_0x37ef7c);(_0x108962===null||_0x496bd5>_0x108962)&&(_0x108962=_0x496bd5,_0x3eacbc=_0x2cc936);}if(_0x3eacbc===null)throw Error('maxNID\x20is\x20'+'null.\x20nids'+'\x20is\x20likely'+'\x20an\x20empty\x20'+'list');else return _0x3eacbc;};module['exports']={'getID':getID,'getNID':getNID,'getSID':getSID,'getMID':getMID,'naiveHash':naiveHash,'consistentHash':consistentHash,'rendezvousHash':rendezvousHash};
|
|
10
10
|
/* eslint-enable */
|
|
@@ -6,5 +6,5 @@ Do NOT edit this file directly. Use it as a black box.
|
|
|
6
6
|
|
|
7
7
|
If you notice any issues with using this file, please contact the TAs.
|
|
8
8
|
*/
|
|
9
|
-
const nativeFunctions={'forward':new Map(),'reverse':new Map()};function createNativeMap(){const
|
|
9
|
+
const nativeFunctions={'forward':new Map(),'reverse':new Map()};function createNativeMap(){const _0x404350=[];function _0x3f00f3(_0x5ac571,_0x269c43){if(_0x269c43===null||_0x269c43===undefined)return;if(_0x404350['indexOf'](_0x269c43)!==-(-0x10e7+0x172e+0x1*-0x646))return;_0x404350['push'](_0x269c43),Object['getOwnProp'+'ertyNames'](_0x269c43)['forEach'](_0x4e2d8a=>{if(typeof _0x269c43[_0x4e2d8a]==='function'){nativeFunctions['forward']['set'](_0x269c43[_0x4e2d8a],_0x5ac571+'.'+_0x4e2d8a),nativeFunctions['reverse']['set'](_0x5ac571+'.'+_0x4e2d8a,_0x269c43[_0x4e2d8a]);return;}typeof _0x269c43[_0x4e2d8a]==='object'&&_0x404350['indexOf'](_0x269c43[_0x4e2d8a])===-(0x3b7*-0x1+-0x115*0x6+0xa36)&&_0x3f00f3(_0x5ac571+'.'+_0x4e2d8a,_0x269c43[_0x4e2d8a]);});}for(const _0xcd95ea of require('repl')['_builtinLi'+'bs']){if(['wasi','sys','punycode','crypto']['includes'](_0xcd95ea))continue;const _0x5739bc=require(_0xcd95ea);_0x3f00f3(_0xcd95ea,_0x5739bc);}}createNativeMap();function decycleObject(_0x34e228){if(_0x34e228===null||_0x34e228===undefined)return _0x34e228;const _0x540b4e=new WeakMap();function _0x38a577(_0x78cf26,_0x1b0f00){let _0xcc04b0;if(!(typeof _0x78cf26==='object'&&!(_0x78cf26 instanceof Error)&&!(_0x78cf26 instanceof Date)&&!(_0x78cf26 instanceof Boolean)&&_0x78cf26!==null))return _0x78cf26;const _0xf3d91e=_0x540b4e['get'](_0x78cf26);if(_0xf3d91e!==undefined)return{'$reference':_0xf3d91e};return _0x540b4e['set'](_0x78cf26,_0x1b0f00),Array['isArray'](_0x78cf26)?(_0xcc04b0=[],_0x78cf26['forEach'](function(_0x32bd04,_0x8a6618){const _0x1c3add=[..._0x1b0f00,_0x8a6618];_0xcc04b0[_0x8a6618]=_0x38a577(_0x32bd04,_0x1c3add);})):(_0xcc04b0={},Object['keys'](_0x78cf26)['forEach'](_0x177fb4=>{const _0x51fc50=[..._0x1b0f00,JSON['stringify'](_0x177fb4)];_0xcc04b0[_0x177fb4]=_0x38a577(_0x78cf26[_0x177fb4],_0x51fc50);})),_0xcc04b0;}return _0x38a577(_0x34e228,[]);}function serializeBaseStructure(_0x10f456){return{'type':typeof _0x10f456,'value':_0x10f456['toString']()};}function serializeBigInt(_0xbdc724){return{'type':'bigint','value':_0xbdc724['toString']()};}function serializeUndefined(_0xb3c155){return{'type':'undefined','value':''};}function serializeObject(_0x1db01e){if(_0x1db01e===null)return{'type':'null','value':''};else{if(_0x1db01e instanceof Date)return{'type':'date','value':_0x1db01e['toJSON']()};else{if(_0x1db01e instanceof Error)return{'type':'error','value':serializeObject({'name':_0x1db01e['name'],'message':_0x1db01e['message'],'cause':_0x1db01e['cause']})};}}if(_0x1db01e['$reference']!==undefined&&Object['keys'](_0x1db01e)['length']===-0x14*-0x17+0xa*-0x1a5+-0xb*-0x155)return{'type':'reference','value':_0x1db01e['$reference']};const _0x20c2d2=Object['fromEntrie'+'s'](Object['entries'](_0x1db01e)['map'](([_0x59c0aa,_0xfb4a8e])=>[_0x59c0aa,serialize(_0xfb4a8e)]));return{'type':_0x1db01e instanceof Array?'array':'object','value':_0x20c2d2};}function serializeFunction(_0x38e653){const _0x38fb7a=nativeFunctions['forward']['get'](_0x38e653);return _0x38fb7a===undefined?{'type':'function','value':_0x38e653['toString']()}:{'type':'native','value':_0x38fb7a};}function serialize(_0x4d944c){_0x4d944c=decycleObject(_0x4d944c);let _0x449851;switch(typeof _0x4d944c){case'object':_0x449851=serializeObject(_0x4d944c);break;case'function':_0x449851=serializeFunction(_0x4d944c);break;case'undefined':_0x449851=serializeUndefined(_0x4d944c);break;case'number':case'string':case'boolean':_0x449851=serializeBaseStructure(_0x4d944c);break;case'bigint':_0x449851=serializeBigInt(_0x4d944c);break;}return JSON['stringify'](_0x449851);}function deserializeObject(_0xb07ca,_0x1d43e4){for(const [_0xa696f6,_0x4f0f65]of Object['entries'](_0xb07ca)){_0x1d43e4[_0xa696f6]=doSerialize(_0x4f0f65,_0x1d43e4);}return _0x1d43e4;}function deserializeArray(_0x46048f,_0x47c969){for(const [_0x15070e,_0x5ba4a3]of Object['entries'](_0x46048f)){_0x47c969[Number(_0x15070e)]=doSerialize(_0x5ba4a3,_0x47c969);}return _0x47c969;}function deserializeString(_0x37b705){return _0x37b705;}function deserializeNumber(_0x471aa0){return Number(_0x471aa0);}function deserializeFunction(_0x612ed7){return new Function('return\x20'+_0x612ed7)();}function deserializeError(_0x2e3adb){const _0x4f1b6c=doSerialize(_0x2e3adb),_0x5f4632=new Error(_0x4f1b6c['message'],_0x4f1b6c['cause']);return _0x5f4632;}function deserializeReference(_0x287fe9,_0x17258d){let _0x38b8a5=_0x17258d;for(const _0x22de58 of _0x287fe9){_0x38b8a5=_0x38b8a5[JSON['parse'](_0x22de58)];}return _0x38b8a5;}function deserializeNative(_0x11d654){const _0x56229e=nativeFunctions['reverse']['get'](_0x11d654);if(_0x56229e===undefined)throw Error('Function\x20n'+'ot\x20found\x20i'+'n\x20native\x20f'+'unction\x20ma'+'p');return _0x56229e;}function deserializeReferences(_0x39daf1,_0x1d28d2){if(typeof _0x39daf1!=='object'||_0x39daf1===null)return _0x39daf1;if(_0x39daf1['type']==='reference')return deserializeReference(_0x39daf1['value'],_0x1d28d2);if(Array['isArray'](_0x39daf1))for(let _0x47cbb4=-0x1ed6+0x3e7+0x563*0x5;_0x47cbb4<_0x39daf1['length'];_0x47cbb4++){_0x39daf1[_0x47cbb4]=deserializeReferences(_0x39daf1[_0x47cbb4],_0x1d28d2);}else for(const [_0xbd32ca,_0x4eef23]of Object['entries'](_0x39daf1)){_0x39daf1[_0xbd32ca]=deserializeReferences(_0x4eef23,_0x1d28d2);}return _0x39daf1;}function doSerialize(_0x3b5585,_0x588a31=null){let _0x5d5928;if(typeof _0x3b5585==='object')_0x5d5928=_0x3b5585;else{if(typeof _0x3b5585==='string')_0x5d5928=JSON['parse'](_0x3b5585);else throw new Error('Invalid\x20ar'+'gument\x20typ'+'e:\x20'+typeof _0x3b5585+'.');}_0x588a31===null&&(_0x588a31={});switch(_0x5d5928['type']){case'object':return deserializeObject(_0x5d5928['value'],{});case'array':return deserializeArray(_0x5d5928['value'],[]);case'function':return deserializeFunction(_0x5d5928['value']);case'native':return deserializeNative(_0x5d5928['value']);case'reference':return _0x5d5928;case'number':return deserializeNumber(_0x5d5928['value']);case'string':return deserializeString(_0x5d5928['value']);case'boolean':return _0x5d5928['value']==='true';case'bigint':return BigInt(_0x5d5928['value']);case'date':return new Date(_0x5d5928['value']);case'error':return deserializeError(_0x5d5928['value']);case'null':return null;case'undefined':return undefined;default:throw new Error('Invalid\x20se'+'rialized\x20o'+'bject\x20type');}}function deserialize(_0x1b2d00){if(typeof _0x1b2d00!=='string')throw new Error('Invalid\x20ar'+'gument\x20typ'+'e:\x20'+typeof _0x1b2d00+'.');const _0x17e244=doSerialize(_0x1b2d00);return deserializeReferences(_0x17e244,_0x17e244),_0x17e244;}module['exports']={'serialize':serialize,'deserialize':deserialize};
|
|
10
10
|
/* eslint-enable */
|
package/distribution.js
CHANGED
|
@@ -24,6 +24,7 @@ function bootstrap(config) {
|
|
|
24
24
|
// @ts-ignore This is the first time globalThis.distribution is being initialized, so the object does not have all the necessary properties.
|
|
25
25
|
globalThis.distribution = distribution;
|
|
26
26
|
distribution.util = require('./distribution/util/util.js');
|
|
27
|
+
|
|
27
28
|
// @ts-ignore node.server is lazily initialized.
|
|
28
29
|
distribution.node = require('./distribution/local/node.js');
|
|
29
30
|
distribution.local = require('./distribution/local/local.js');
|
|
@@ -37,7 +38,6 @@ function bootstrap(config) {
|
|
|
37
38
|
|
|
38
39
|
/* Overrides when missing functionality from previous milestone or extra credit is needed */
|
|
39
40
|
|
|
40
|
-
// For M3, when missing RPC, its path through routes, and status.{spawn, stop}
|
|
41
41
|
/* __start_M3_solution__
|
|
42
42
|
distribution.util.wire.createRPC = distributionLib.util.wire.createRPC;
|
|
43
43
|
distribution.local.routes = distributionLib.local.routes;
|
|
@@ -45,8 +45,6 @@ function bootstrap(config) {
|
|
|
45
45
|
distribution.local.status.stop = distributionLib.local.status.stop;
|
|
46
46
|
distribution.local.comm = distributionLib.local.comm;
|
|
47
47
|
distribution.node.start = distributionLib.node.start;
|
|
48
|
-
distribution.util.serialize = distributionLib.util.serialize;
|
|
49
|
-
distribution.util.deserialize = distributionLib.util.deserialize;
|
|
50
48
|
__end_M3_solution__ */
|
|
51
49
|
|
|
52
50
|
for (const [key, service] of Object.entries(distribution.local)) {
|
|
@@ -61,15 +59,14 @@ function bootstrap(config) {
|
|
|
61
59
|
It can either be:
|
|
62
60
|
1. The reference implementation from the library @brown-ds/distribution
|
|
63
61
|
2. Your own, local implementation
|
|
64
|
-
|
|
65
|
-
Which one to be used by the tests is determined by the "useLibrary" value in the package.json file.
|
|
62
|
+
Set "useLibrary" in package.json to true or false accordingly.
|
|
66
63
|
*/
|
|
67
64
|
// @ts-ignore JSON import resolved at runtime.
|
|
68
65
|
const {useLibrary} = require('./package.json');
|
|
69
66
|
// @ts-ignore Optional dependency for reference implementation.
|
|
70
67
|
const distribution = useLibrary ? require('@brown-ds/distribution') : bootstrap;
|
|
71
68
|
|
|
72
|
-
/* The following code is run when distribution.js is
|
|
69
|
+
/* The following code is run when distribution.js is invoked directly */
|
|
73
70
|
if (require.main === module) {
|
|
74
71
|
globalThis.distribution = distribution();
|
|
75
72
|
// __start_solution__
|
|
@@ -78,7 +75,9 @@ if (require.main === module) {
|
|
|
78
75
|
JSON.stringify(globalThis.distribution.node.config)
|
|
79
76
|
}`,
|
|
80
77
|
);
|
|
78
|
+
// __end_solution__
|
|
81
79
|
globalThis.distribution.node.start(globalThis.distribution.node.config.onStart || (() => {
|
|
80
|
+
// Start REPL for interactive use
|
|
82
81
|
const repl = require('node:repl');
|
|
83
82
|
repl.start({
|
|
84
83
|
prompt: `${globalThis.distribution.util.id.getSID(globalThis.distribution.node.config)}> `,
|
|
@@ -88,7 +87,6 @@ if (require.main === module) {
|
|
|
88
87
|
useGlobal: true,
|
|
89
88
|
});
|
|
90
89
|
}));
|
|
91
|
-
// __end_solution__
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
module.exports = distribution;
|