@brown-ds/distribution 0.2.18 → 0.2.20
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/README.md +8 -1
- package/distribution/all/mem.js +1 -1
- package/distribution/all/status.js +1 -1
- package/distribution/all/store.js +1 -1
- package/distribution/local/comm.js +1 -1
- package/distribution/local/node.js +1 -1
- package/distribution/local/status.js +1 -1
- package/distribution/local/store.js +1 -1
- package/distribution.js +25 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
# distribution
|
|
2
2
|
|
|
3
|
-
This is the distribution library.
|
|
3
|
+
This is the distribution library.
|
|
4
|
+
|
|
5
|
+
## Environment Setup
|
|
6
|
+
|
|
7
|
+
We recommend using the prepared [container image](https://github.com/brown-cs1380/container).
|
|
4
8
|
|
|
5
9
|
## Installation
|
|
6
10
|
|
|
11
|
+
After you have setup your environment, you can start using the distribution library.
|
|
12
|
+
When loaded, distribution introduces functionality supporting the distributed execution of programs. To download it:
|
|
13
|
+
|
|
7
14
|
```sh
|
|
8
15
|
$ npm i '@brown-ds/distribution'
|
|
9
16
|
```
|
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')
|
|
9
|
+
const log=require('../util/lo'+'g.js');function normalize(_0x560984,_0x5cacc3){if(_0x560984===null)return{'key':null,'gid':_0x5cacc3,'action':'put'};else return typeof _0x560984==='string'?{'key':_0x560984,'gid':_0x5cacc3,'action':'put'}:_0x560984;}function mem(_0x5840f0){const _0x34312a={};_0x34312a['gid']=_0x5840f0['gid']||'all',_0x34312a['hash']=_0x5840f0['hash']||globalThis['distributi'+'on']['util']['id']['naiveHash'];function _0x2be59e(_0x2039c8,_0x347ba2){log('[all.mem.g'+'et]\x20config'+'uration:\x20'+JSON['stringify'](_0x2039c8)+'\x20context:\x20'+JSON['stringify'](_0x34312a)),_0x2039c8=normalize(_0x2039c8,_0x34312a['gid']),_0x2039c8['gid']=_0x2039c8['gid']||_0x34312a['gid'];const _0x28bf53={'service':'mem','method':'get'},_0x2e7334=[_0x2039c8];if(!_0x2039c8['key']){globalThis['distributi'+'on'][_0x34312a['gid']]['comm']['send'](_0x2e7334,_0x28bf53,(_0x348596,_0x5e2f1f)=>{const _0x127db8=Object['values'](_0x5e2f1f)['reduce']((_0xddd93,_0x17700f)=>_0xddd93['concat'](_0x17700f),[]);_0x347ba2(_0x348596,_0x127db8);});return;}const _0x5015ea=_0x2039c8['key'];if(_0x5015ea===null){_0x347ba2(new TypeError('Configurat'+'ion\x20is\x20nul'+'l'));return;}globalThis['distributi'+'on']['util']['wire']['dispatchMe'+'ssage'](_0x2e7334,_0x28bf53,{'key':_0x5015ea},_0x34312a,_0x347ba2);}function _0x523325(_0x3f107f,_0x323cc5,_0x227bac){log('[all.mem.p'+'ut]\x20state:'+'\x20'+JSON['stringify'](_0x3f107f)+('\x20configura'+'tion:\x20')+JSON['stringify'](_0x323cc5)),_0x323cc5=_0x323cc5||globalThis['distributi'+'on']['util']['id']['getID'](_0x3f107f),_0x323cc5=normalize(_0x323cc5,_0x34312a['gid']),_0x323cc5['gid']=_0x323cc5['gid']||_0x34312a['gid'];const _0x25ae8a={'service':'mem','method':'put'},_0x4e373e=[_0x3f107f,_0x323cc5],_0x336792=_0x323cc5['key'];if(_0x336792===null){_0x227bac(new TypeError('Configurat'+'ion\x20is\x20nul'+'l'));return;}globalThis['distributi'+'on']['util']['wire']['dispatchMe'+'ssage'](_0x4e373e,_0x25ae8a,{'key':_0x336792},_0x34312a,_0x227bac);}function _0x3ba487(_0x5e9fea,_0x272b53){log('[all.mem.d'+'el]\x20config'+'uration:\x20'+JSON['stringify'](_0x5e9fea)),_0x5e9fea=normalize(_0x5e9fea,_0x34312a['gid']),_0x5e9fea['gid']=_0x5e9fea['gid']||_0x34312a['gid'];const _0x3614bd={'service':'mem','method':'del'},_0x65432c=[_0x5e9fea],_0x3b7baf=_0x5e9fea['key'];if(_0x3b7baf===null){_0x272b53(new TypeError('Configurat'+'ion\x20is\x20nul'+'l'));return;}globalThis['distributi'+'on']['util']['wire']['dispatchMe'+'ssage'](_0x65432c,_0x3614bd,{'key':_0x3b7baf},_0x34312a,_0x272b53);}function _0x465dd2(_0x2d4472,_0x12289b){log('[mem.recon'+'f]\x20configu'+'ration:\x20'+JSON['stringify'](_0x2d4472)+'\x20gid:\x20'+_0x34312a['gid']),globalThis['distributi'+'on']['local']['groups']['get'](_0x34312a['gid'],(_0x554c1e,_0x1831bb)=>{if(!_0x1831bb){_0x12289b(_0x554c1e);return;}globalThis['distributi'+'on']['local']['groups']['put'](_0x34312a['gid'],_0x2d4472,(_0x4821fe,_0x44d12c)=>{globalThis['distributi'+'on'][_0x34312a['gid']]['mem']['get'](null,(_0x56ff65,_0x347fde)=>{globalThis['distributi'+'on']['local']['groups']['put'](_0x34312a['gid'],_0x1831bb,(_0x5d891d,_0x5de5f6)=>{globalThis['distributi'+'on'][_0x34312a['gid']]['status']['get']('nid',(_0x3e4d48,_0x33f368)=>{const _0x5069ff=Object['values'](_0x33f368),_0x1122aa=Object['values'](_0x2d4472)['map'](_0x1dd7d4=>globalThis['distributi'+'on']['util']['id']['getNID'](_0x1dd7d4));log('[mem.recon'+'f\x20received'+'\x20'+_0x347fde['length']+('\x20keys\x20from'+'\x20')+_0x33f368['length']+'\x20nodes');let _0x4e8293=-0xa8e*-0x3+0x454+-0x23fe;const _0x3d4b05=()=>{if(_0x4e8293===_0x347fde['length'])return _0x12289b(null);};if(_0x347fde['length']===-0x13*0x27+0x277*-0x2+0x7d3)return _0x12289b(null);for(const _0x222073 of _0x347fde){const _0x194011=globalThis['distributi'+'on']['util']['id']['getID'](_0x222073),_0x10d4c1=_0x34312a['hash'](_0x194011,_0x1122aa),_0x6e7bcd=_0x34312a['hash'](_0x194011,_0x5069ff);log('[mem.recon'+'f]\x20old\x20nid'+':\x20'+_0x10d4c1+'\x20new\x20nid:\x20'+_0x6e7bcd);if(_0x10d4c1===_0x6e7bcd){_0x4e8293++,_0x3d4b05();continue;}const _0x4aecac=_0x2d4472[_0x10d4c1['substring'](-0x7bb*-0x3+-0x7b2+-0xf7f,0x534*-0x6+-0xaab+0x29e8)],_0x514569=[{'key':_0x222073,'gid':_0x34312a['gid']}],_0x50f474={'service':'mem','method':'del','node':_0x4aecac};log('[mem.recon'+'f]\x20deletin'+'g\x20key\x20'+_0x222073+'\x20from\x20'+JSON['stringify'](_0x50f474)),globalThis['distributi'+'on']['local']['comm']['send'](_0x514569,_0x50f474,(_0x3bff3d,_0x38fb08)=>{globalThis['distributi'+'on'][_0x34312a['gid']]['mem']['put'](_0x38fb08,_0x222073,(_0x534572,_0x35f75c)=>{_0x4e8293++,_0x3d4b05();});});}});});});});});}return{'get':_0x2be59e,'put':_0x523325,'del':_0x3ba487,'reconf':_0x465dd2};}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
|
-
function status(
|
|
9
|
+
function status(_0xe569d2){const _0x2b7dcc={};_0x2b7dcc['gid']=_0xe569d2['gid']||'all';function _0x502cb(_0x1e3422,_0x5d23ae){const _0x5c5355=[_0x1e3422],_0x2b2161={'service':'status','method':'get'};globalThis['distributi'+'on'][_0x2b7dcc['gid']]['comm']['send'](_0x5c5355,_0x2b2161,(_0x466833,_0xe860e9)=>{switch(_0x1e3422){case'heapTotal':const _0x2b6d9a=Object['values'](_0xe860e9)['reduce']((_0x22e7fd,_0x129ddc)=>{return _0x22e7fd+_0x129ddc;},-0x122d+-0x1*0x235d+0x358a);return _0x5d23ae(_0x466833,_0x2b6d9a);break;case'nid':const _0x3bc516=Object['values'](_0xe860e9)['reduce']((_0x41c188,_0x302416)=>{return _0x41c188['concat'](_0x302416);},[]);return _0x5d23ae(_0x466833,_0x3bc516);break;default:return _0x5d23ae(_0x466833,_0xe860e9);break;}});}function _0x5076fe(_0x6ee9a0,_0xc6f21d){globalThis['distributi'+'on']['local']['status']['spawn'](_0x6ee9a0,(_0x2fadf6,_0x459797)=>{globalThis['distributi'+'on'][_0x2b7dcc['gid']]['comm']['send']([_0x2b7dcc['gid'],_0x6ee9a0],{'service':'groups','method':'add'},()=>{});if(_0x2fadf6)return _0xc6f21d(_0x2fadf6);globalThis['distributi'+'on']['local']['groups']['add'](_0x2b7dcc['gid'],_0x6ee9a0,()=>{return _0xc6f21d(null,_0x459797);});});return;_0xc6f21d(new Error('status.spa'+'wn\x20not\x20imp'+'lemented'));}function _0x5cfcfa(_0x5397c5){globalThis['distributi'+'on'][_0x2b7dcc['gid']]['comm']['send']([],{'service':'status','method':'stop'},()=>{globalThis['distributi'+'on']['local']['status']['stop'](_0x5397c5);});return;_0x5397c5(new Error('status.sto'+'p\x20not\x20impl'+'emented'));}return{'get':_0x502cb,'stop':_0x5cfcfa,'spawn':_0x5076fe};}module['exports']=status;
|
|
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')
|
|
9
|
+
const log=require('../util/lo'+'g.js');function getNode(_0x45a080,_0x4b8540,_0x679cda){const _0x59d3db=_0x4b8540&&typeof _0x4b8540==='object'?_0x4b8540['key']:_0x4b8540;globalThis['distributi'+'on'][_0x45a080['gid']]['status']['get']('nid',(_0x14eec2,_0x2061c3)=>{const _0x5eee70=Object['values'](_0x2061c3),_0x14e92a=globalThis['distributi'+'on']['util']['id']['getID'](_0x59d3db),_0x1c4735=_0x45a080['hash'](_0x14e92a,_0x5eee70),_0x3effa9=_0x1c4735['substring'](-0xe7e+-0x1a3c+0x28ba,0x4a3*0x4+0x1*-0x4f3+-0xd94);globalThis['distributi'+'on']['local']['groups']['get'](_0x45a080['gid'],(_0x514532,_0x5e180c)=>{if(!_0x5e180c)return _0x679cda(_0x514532);else{const _0x2794e1=_0x5e180c[_0x3effa9];return log('[store\x20(ge'+'tNode)]\x20co'+'nfiguratio'+'n:\x20'+JSON['stringify'](_0x4b8540)+'group:\x20'+JSON['stringify'](_0x5e180c)+'\x20node:\x20'+JSON['stringify'](_0x2794e1)+'nid:\x20'+JSON['stringify'](_0x1c4735)+'\x20sid:\x20'+JSON['stringify'](_0x3effa9)),_0x679cda(null,_0x2794e1);}});});}function normalize(_0x2d26dc,_0x23b192){if(_0x2d26dc===null)return{'key':null,'gid':_0x23b192,'action':'put'};else return typeof _0x2d26dc==='string'?{'key':_0x2d26dc,'gid':_0x23b192,'action':'put'}:_0x2d26dc;}function store(_0x2a6966){const _0x13beb6={'gid':_0x2a6966['gid']||'all','hash':_0x2a6966['hash']||globalThis['distributi'+'on']['util']['id']['naiveHash'],'subset':_0x2a6966['subset']};function _0xa7d797(_0x29d2cc,_0x2ac71c){if(!_0x29d2cc){const _0x2d2e8f=[{'key':null,'gid':_0x13beb6['gid']}];globalThis['distributi'+'on'][_0x13beb6['gid']]['comm']['send'](_0x2d2e8f,{'service':'store','method':'get'},(_0x2948b2,_0x2f9d59)=>{const _0x5b44bc=Object['values'](_0x2f9d59)['reduce']((_0x50bde0,_0x13f996)=>_0x50bde0['concat'](_0x13f996),[]);_0x2ac71c(_0x2948b2,_0x5b44bc);});return;}_0x29d2cc=normalize(_0x29d2cc,_0x13beb6['gid']),getNode(_0x13beb6,_0x29d2cc,(_0x5f08f7,_0x2f16f5)=>{if(!_0x2f16f5){_0x2ac71c(_0x5f08f7);return;}const _0x1897fe=[_0x29d2cc],_0x1b1e30={'service':'store','method':'get','node':_0x2f16f5};log('[all.store'+'.get]confi'+'guration:\x20'+JSON['stringify'](_0x29d2cc)+'node:\x20'+JSON['stringify'](globalThis['distributi'+'on']['node']['config'])+('\x20target\x20no'+'de:\x20')+JSON['stringify'](_0x2f16f5)),globalThis['distributi'+'on']['local']['comm']['send'](_0x1897fe,_0x1b1e30,_0x2ac71c);});}function _0x41f07b(_0x59a77e,_0xc4037a,_0x413b5d){_0xc4037a=_0xc4037a||globalThis['distributi'+'on']['util']['id']['getID'](_0x59a77e),_0xc4037a=normalize(_0xc4037a,_0x13beb6['gid']),getNode(_0x13beb6,_0xc4037a,(_0x4a3677,_0x38a38b)=>{if(!_0x38a38b){_0x413b5d(_0x4a3677);return;}const _0x236507=[_0x59a77e,_0xc4037a],_0xd3748f={'service':'store','method':'put','node':_0x38a38b};log('[all.store'+'.put]\x20stat'+'e:\x20'+JSON['stringify'](_0x59a77e)+('configurat'+'ion:\x20')+JSON['stringify'](_0xc4037a)+('target\x20nod'+'e:\x20')+JSON['stringify'](_0x38a38b)),globalThis['distributi'+'on']['local']['comm']['send'](_0x236507,_0xd3748f,_0x413b5d);});}function _0x5d86ab(_0x81cc33,_0x49d6b4){getNode(_0x13beb6,_0x81cc33,(_0x195a8d,_0x509531)=>{if(!_0x509531){_0x49d6b4(_0x195a8d);return;}const _0x1bb2dd=[{'key':_0x81cc33,'gid':_0x13beb6['gid']}],_0x4302f2={'service':'store','method':'del','node':_0x509531};globalThis['distributi'+'on']['local']['comm']['send'](_0x1bb2dd,_0x4302f2,_0x49d6b4);});}function _0x41570a(_0x13a663,_0x573112){log('[store.rec'+'onf]\x20confi'+'guration:\x20'+JSON['stringify'](_0x13a663)+'\x20gid:\x20'+_0x13beb6['gid']),globalThis['distributi'+'on']['local']['groups']['get'](_0x13beb6['gid'],(_0x5528cf,_0x43cd94)=>{if(!_0x43cd94){_0x573112(_0x5528cf);return;}globalThis['distributi'+'on']['local']['groups']['put'](_0x13beb6['gid'],_0x13a663,(_0x3b433a,_0x4aded7)=>{globalThis['distributi'+'on'][_0x13beb6['gid']]['store']['get'](null,(_0x5883a8,_0x56e84b)=>{globalThis['distributi'+'on']['local']['groups']['put'](_0x13beb6['gid'],_0x43cd94,(_0x4b0b93,_0x9a8c93)=>{globalThis['distributi'+'on'][_0x13beb6['gid']]['status']['get']('nid',(_0x31db8f,_0x4220de)=>{const _0xd024de=Object['values'](_0x4220de),_0x3a9de0=Object['values'](_0x13a663)['map'](_0x21d93e=>globalThis['distributi'+'on']['util']['id']['getNID'](_0x21d93e));log('[store.rec'+'onf\x20receiv'+'ed\x20'+_0x56e84b['length']+('\x20keys\x20from'+'\x20')+_0x4220de['length']+'\x20nodes');let _0x3730c1=-0x164d+-0x9f5+-0x2*-0x1021;const _0x562304=()=>{if(_0x3730c1===_0x56e84b['length'])return _0x573112(null);};if(_0x56e84b['length']===0x2659*0x1+0x2*0x9e7+-0x1*0x3a27)return _0x573112(null);for(const _0x2a2454 of _0x56e84b){const _0x5cf915=globalThis['distributi'+'on']['util']['id']['getID'](_0x2a2454),_0x1ee6e2=_0x13beb6['hash'](_0x5cf915,_0x3a9de0),_0x1100c6=_0x13beb6['hash'](_0x5cf915,_0xd024de);log('[store.rec'+'onf]\x20old\x20n'+'id:\x20'+_0x1ee6e2+'\x20new\x20nid:\x20'+_0x1100c6);if(_0x1ee6e2===_0x1100c6){_0x3730c1++,_0x562304();continue;}const _0x14c6ac=_0x13a663[_0x1ee6e2['substring'](0x8ef*-0x2+-0x449+-0x1627*-0x1,-0x2384+-0x1*0x43e+0x27c7)],_0x4457c7=[{'key':_0x2a2454,'gid':_0x13beb6['gid']}],_0xf232d1={'service':'store','method':'del','node':_0x14c6ac};log('[store.rec'+'onf]\x20delet'+'ing\x20key\x20'+_0x2a2454+'\x20from\x20'+JSON['stringify'](_0xf232d1)),globalThis['distributi'+'on']['local']['comm']['send'](_0x4457c7,_0xf232d1,(_0x916e59,_0x5432db)=>{globalThis['distributi'+'on'][_0x13beb6['gid']]['store']['put'](_0x5432db,_0x2a2454,(_0x316148,_0x14d5d5)=>{_0x3730c1++,_0x562304();});});}});});});});});}return{'get':_0xa7d797,'put':_0x41f07b,'del':_0x5d86ab,'reconf':_0x41570a};}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'),
|
|
9
|
+
const http=require('node:http'),log=require('../util/lo'+'g.js');function send(_0xecb36b,_0x45a5c1,_0x39d3f0){_0xecb36b=_0xecb36b||[];if(!_0x45a5c1){_0x39d3f0(new Error('Remote\x20is\x20'+'required'));return;}const _0x4b898=_0x45a5c1['node'],_0x3718ee=_0x45a5c1['service'],_0x525a3f=_0x45a5c1['method'],_0x3c927=_0x45a5c1['gid']||'local';if(!(_0xecb36b instanceof Array)){_0x39d3f0(new Error('Message\x20mu'+'st\x20be\x20an\x20a'+'rray'));return;}if(!_0x4b898){_0x39d3f0(new Error('Node\x20is\x20re'+'quired'));return;}if(!_0x3718ee){_0x39d3f0(new Error('Service\x20is'+'\x20required'));return;}if(!_0x525a3f){_0x39d3f0(new Error('Method\x20is\x20'+'required'));return;}log('[comm.send'+']:\x20Sending'+'\x20'+JSON['stringify'](_0xecb36b)+'\x20to\x20'+_0x45a5c1['service']+':'+_0x45a5c1['method']+'\x20on\x20'+_0x45a5c1['node']['ip']+':'+_0x45a5c1['node']['port']);const _0x16f8f1=globalThis['distributi'+'on']['util']['serialize'](_0xecb36b),_0x11e4d3={'hostname':_0x4b898['ip'],'port':_0x4b898['port'],'path':'/'+_0x3c927+'/'+_0x3718ee+'/'+_0x525a3f,'method':'PUT','headers':{'Content-Type':'applicatio'+'n/json','Content-Length':Buffer['byteLength'](_0x16f8f1)}},_0x52f1e4=http['request'](_0x11e4d3,_0x4187a8=>{let _0x1d065f='';_0x4187a8['on']('data',function(_0x1384d5){_0x1d065f+=_0x1384d5;}),_0x4187a8['on']('end',function(){const [_0x926e74,_0x25bba6]=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x1d065f);if(_0x39d3f0)return _0x39d3f0(_0x926e74,_0x25bba6);}),_0x4187a8['on']('error',_0x2ddc79=>{if(_0x39d3f0)return _0x39d3f0(new Error('Error\x20on\x20r'+'esponse'));});});_0x52f1e4['on']('error',_0x423c60=>{if(_0x39d3f0)return _0x39d3f0(new Error(_0x423c60));}),_0x52f1e4['write'](_0x16f8f1),_0x52f1e4['end']();}module['exports']={'send':send};
|
|
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 _0x45db11=yargs(process['argv'])['help'](![])['version'](![])['parse']();let _0x35a63f,_0x2463db,_0xc6645f;typeof _0x45db11['ip']==='string'&&(_0x35a63f=_0x45db11['ip']);(typeof _0x45db11['port']==='string'||typeof _0x45db11['port']==='number')&&(_0x2463db=parseInt(String(_0x45db11['port']),0x98*-0x27+-0xde7*-0x2+-0x49c));(_0x45db11['help']===!![]||_0x45db11['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'](-0x22dc+-0xaf6+-0x1e*-0x187));if(typeof _0x45db11['config']==='string'){const {ip:_0x205e75,port:_0x3a2308,onStart:_0x350664}=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x45db11['config']);typeof _0x205e75==='string'&&(_0x35a63f=_0x205e75),typeof _0x3a2308==='number'&&(_0x2463db=_0x3a2308),typeof _0x350664==='function'&&(_0xc6645f=_0x350664);}return _0x35a63f=_0x35a63f||'127.0.0.1',_0x2463db=_0x2463db||-0x898+0x8*0x482+-0x16a6,{'ip':_0x35a63f,'port':_0x2463db,'onStart':_0xc6645f};}function validate(_0x525833){if(_0x525833['length']===-0x25d1+-0x2323+0x48f4)throw new Error('No\x20body');return JSON['parse'](_0x525833);}function start(_0x3b07d6){const _0x36f2af=http['createServ'+'er']((_0x5165c8,_0x485edd)=>{if(_0x5165c8['method']!=='PUT'){_0x485edd['end'](globalThis['distributi'+'on']['util']['serialize'](new Error('Method\x20not'+'\x20allowed!')));return;}const [,_0x475dfb,_0x2b4373,_0x114424]=url['parse'](_0x5165c8['url'])['pathname']['split']('/');log('[server]\x20g'+'ot\x20request'+'\x20'+_0x475dfb+'\x20'+_0x2b4373+':'+_0x114424+'\x20from\x20'+_0x5165c8['socket']['remoteAddr'+'ess']);const _0x3279e1=[];_0x5165c8['on']('data',_0x3f3d97=>{_0x3279e1['push'](_0x3f3d97);}),_0x5165c8['on']('end',()=>{let _0x285e6f;try{_0x285e6f=validate(Buffer['concat'](_0x3279e1)['toString']());}catch(_0x31c4c5){_0x485edd['end'](globalThis['distributi'+'on']['util']['serialize']([_0x31c4c5]));return;}const _0x34cc1a=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x285e6f);!Array['isArray'](_0x34cc1a)&&_0x485edd['end'](globalThis['distributi'+'on']['util']['serialize']([new Error('Invalid\x20ar'+'gument\x20typ'+'e,\x20expecte'+'d\x20array,\x20g'+'ot\x20'+typeof _0x34cc1a)]));const _0x4ca976=_0x2b4373;globalThis['distributi'+'on']['local']['routes']['get']({'service':_0x2b4373,'gid':_0x475dfb},(_0x19b7d8,_0x3fb836)=>{if(_0x19b7d8){_0x485edd['end'](globalThis['distributi'+'on']['util']['serialize']([_0x19b7d8,null]));return;}if(!_0x3fb836[_0x114424]){_0x485edd['end'](globalThis['distributi'+'on']['util']['serialize']([new Error('Method\x20'+_0x114424+('\x20not\x20found'+'\x20in\x20servic'+'e\x20')+_0x4ca976),null]));return;}log('[server]\x20\x20'+'Calling\x20se'+'rvice:\x20'+_0x4ca976+':'+_0x114424+('\x20with\x20args'+':\x20')+JSON['stringify'](_0x34cc1a));_0x34cc1a['length']===0x8b*0x1a+0x2*0xe12+0x175*-0x1d&&_0x3fb836[_0x114424]['length']===-0xc2d+0x2501+-0x18d1*0x1&&_0x34cc1a['push'](undefined);const _0x2db971=_0x3fb836[_0x114424]['bind'](_0x3fb836),_0x14f16f=globalThis['distributi'+'on']['util']['normalize'](_0x2db971,_0x34cc1a);try{_0x2db971(..._0x14f16f,(_0x15bb7e,_0x5c30ff)=>_0x485edd['end'](globalThis['distributi'+'on']['util']['serialize']([_0x15bb7e,_0x5c30ff])));}catch(_0x48acc8){_0x485edd['end'](globalThis['distributi'+'on']['util']['serialize']([_0x48acc8,null]));}});});}),_0x108909=globalThis['distributi'+'on']['node']['config'];_0x36f2af['once']('listening',()=>{log('Server\x20run'+'ning\x20at\x20ht'+'tp://'+_0x108909['ip']+':'+_0x108909['port']+'/'),globalThis['distributi'+'on']['node']['server']=_0x36f2af,_0x3b07d6(null);}),_0x36f2af['once']('error',_0x4b712b=>{log('Server\x20err'+'or:\x20'+_0x4b712b),_0x3b07d6(_0x4b712b);}),_0x36f2af['listen'](_0x108909['port'],_0x108909['ip']);}module['exports']={'start':start,'config':setNodeConfig()};
|
|
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'),counts=-
|
|
9
|
+
const log=require('../util/lo'+'g'),counts=-0x250f*0x1+0x24a2+-0x6d*-0x1;function get(_0x3e276e,_0x5d4aef){if(_0x3e276e in globalThis['distributi'+'on']['node']['config']){_0x5d4aef(null,globalThis['distributi'+'on']['node']['config'][_0x3e276e]);return;}if(_0x3e276e==='sid'){_0x5d4aef(null,globalThis['distributi'+'on']['util']['id']['getSID'](globalThis['distributi'+'on']['node']['config']));return;}if(_0x3e276e==='nid'){_0x5d4aef(null,globalThis['distributi'+'on']['util']['id']['getNID'](globalThis['distributi'+'on']['node']['config']));return;}if(_0x3e276e==='counts'){_0x5d4aef(null,counts);return;}if(_0x3e276e==='heapTotal'){_0x5d4aef(null,process['memoryUsag'+'e']()['heapTotal']);return;}if(_0x3e276e==='heapUsed'){_0x5d4aef(null,process['memoryUsag'+'e']()['heapUsed']);return;}_0x5d4aef(new Error('Status\x20key'+'\x20not\x20found'));};const fs=require('fs'),path=require('path'),proc=require('node:child'+'_process');function getDistribution(){let _0x2b3e6f=path['join'](process['cwd'](),'config.js');if(fs['existsSync'](_0x2b3e6f))return _0x2b3e6f;try{const _0x4fa609=proc['execSync']('git\x20rev-pa'+'rse\x20--show'+'-toplevel',{'encoding':'utf8'})['trim']();_0x2b3e6f=path['join'](_0x4fa609,'config.js');if(fs['existsSync'](_0x2b3e6f))return _0x2b3e6f;}catch(_0x359df0){throw new Error('Not\x20in\x20a\x20G'+'it\x20reposit'+'ory\x20or\x20git'+'\x20command\x20f'+'ailed.');}_0x2b3e6f=path['join'](__dirname,'../../','config.js');if(fs['existsSync'](_0x2b3e6f))return _0x2b3e6f;_0x2b3e6f=path['join'](__dirname,'../../','distributi'+'on.js');if(fs['existsSync'](_0x2b3e6f))return _0x2b3e6f;throw new Error('Failed\x20to\x20'+'find\x20proje'+'ct\x20root.');}function createOnStart(_0x525698,_0x3a8393){const _0x315b8e='\x0a\x20\x20\x20\x20retur'+'n\x20function'+'(e)\x20{\x0a\x20\x20\x20\x20'+'\x20\x20let\x20onSt'+'art\x20=\x20'+_0x525698['toString']()+(';\x0a\x20\x20\x20\x20\x20\x20le'+'t\x20callback'+'RPC\x20=\x20')+globalThis['distributi'+'on']['util']['wire']['createRPC'](globalThis['distributi'+'on']['util']['wire']['toAsync'](_0x3a8393))['toString']()+(';\x0a\x20\x20\x20\x20\x20\x20if'+'\x20(e)\x20{\x0a\x20\x20\x20'+'\x20\x20\x20\x20\x20callb'+'ackRPC(e,\x20'+'null,\x20()\x20='+'>\x20{});\x0a\x20\x20\x20'+'\x20\x20\x20\x20\x20retur'+'n;\x0a\x20\x20\x20\x20\x20\x20}'+'\x0a\x20\x20\x20\x20\x20\x20try'+'\x20{\x0a\x20\x20\x20\x20\x20\x20\x20'+'\x20onStart()'+';\x0a\x20\x20\x20\x20\x20\x20\x20\x20'+'callbackRP'+'C(null,\x20gl'+'obal.distr'+'ibution.no'+'de.config,'+'\x20()\x20=>\x20{})'+';\x0a\x20\x20\x20\x20\x20\x20}\x20'+'catch(e)\x20{'+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20c'+'allbackRPC'+'(e,\x20null,\x20'+'()\x20=>\x20{});'+'\x0a\x20\x20\x20\x20\x20\x20}\x0a\x20'+'\x20\x20\x20};\x0a\x20\x20');return new Function(_0x315b8e)();}function spawn(_0x3598eb,_0x29bb2e){const _0x22e1dc=_0x3598eb;_0x22e1dc['onStart']=_0x22e1dc['onStart']||function(){};if(!_0x22e1dc['port']||!_0x22e1dc['ip']){_0x29bb2e(new Error('Port\x20and\x20I'+'P\x20are\x20requ'+'ired\x20in\x20th'+'e\x20configur'+'ation'));return;}log('[status.sp'+'awn]\x20Spawn'+'ing\x20node\x20w'+'ith\x20config'+'uration:\x20'+JSON['stringify'](_0x22e1dc));const _0x5b6444=(_0x4c27ed,_0x1d8e9d)=>{if(_0x4c27ed){_0x29bb2e(_0x4c27ed);return;}globalThis['distributi'+'on']['local']['groups']['add']('all',_0x1d8e9d,()=>{_0x29bb2e(_0x4c27ed,_0x1d8e9d);});};_0x22e1dc['onStart']=createOnStart(_0x22e1dc['onStart'],_0x5b6444);const _0x39f737=getDistribution(),_0x4908c2=proc['spawn']('node',[_0x39f737,'--config',globalThis['distributi'+'on']['util']['serialize'](_0x22e1dc)],{'detached':!![],'stdio':'inherit'});_0x4908c2;return;_0x29bb2e(new Error('status.spa'+'wn\x20not\x20imp'+'lemented'));}function stop(_0x3e8f2d){log('[status.st'+'op]\x20Shutti'+'ng\x20down\x20no'+'de'),globalThis['distributi'+'on']['node']['server']['close'](),process['nextTick'](()=>process['exit'](0x1aee+0x2285+-0x3d73));return _0x3e8f2d(null,globalThis['distributi'+'on']['node']['config']);_0x3e8f2d(new Error('status.sto'+'p\x20not\x20impl'+'emented'));}module['exports']={'get':get,'spawn':spawn,'stop':stop};
|
|
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 fs=require('fs'),path=require('path'),
|
|
9
|
+
const fs=require('fs'),path=require('path'),log=require('../util/lo'+'g'),baseFolder=path['join'](__dirname,'../../stor'+'e');!fs['existsSync'](baseFolder)&&fs['mkdirSync'](baseFolder);const nodeFolder=path['join'](baseFolder,'s-'+globalThis['distributi'+'on']['util']['id']['getSID'](globalThis['distributi'+'on']['node']['config']));!fs['existsSync'](nodeFolder)&&fs['mkdirSync'](nodeFolder);function normalize(_0x13584e){if(_0x13584e===null)return{'key':null,'gid':null,'action':'put'};else return typeof _0x13584e==='string'?{'key':_0x13584e,'gid':null,'action':'put'}:_0x13584e;}function put(_0x2d3094,_0x417f9d,_0x225eb2){log('[store.put'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x417f9d)+'\x20state:\x20'+JSON['stringify'](_0x2d3094)),_0x417f9d=normalize(_0x417f9d),_0x417f9d['key']=_0x417f9d['key']||globalThis['distributi'+'on']['util']['id']['getID'](_0x2d3094),_0x417f9d['gid']=_0x417f9d['gid']||'local';const _0xf73df0=globalThis['distributi'+'on']['util']['serialize'](_0x2d3094),_0x1a5c65=Buffer['from'](_0x417f9d['key'])['toString']('base64'),_0x15df32=path['join'](nodeFolder,_0x417f9d['gid']+'-'+_0x1a5c65);fs['writeFile'](_0x15df32,_0xf73df0,_0x505dc7=>{return _0x505dc7?_0x225eb2(_0x505dc7):_0x225eb2(null,_0x2d3094);});}function get(_0x1bdb0c,_0x1a1526){log('[store.get'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x1bdb0c)),_0x1bdb0c=normalize(_0x1bdb0c),_0x1bdb0c['gid']=_0x1bdb0c['gid']||'local';if(!_0x1bdb0c['key']){fs['readdir'](nodeFolder,(_0x2e23aa,_0x3b8b2a)=>{if(_0x2e23aa)return _0x1a1526(_0x2e23aa);const _0x1949b1=[];for(let _0x1e79bb=0x1*-0xe2c+0x84f+0x13*0x4f;_0x1e79bb<_0x3b8b2a['length'];_0x1e79bb++){const _0x43672b=_0x3b8b2a[_0x1e79bb]['split']('-'),_0x214097=_0x43672b[-0xd1*0x13+-0x1015+0x3*0xa88];if(_0x214097!==_0x1bdb0c['gid'])continue;const _0x57f0ff=_0x43672b[_0x43672b['length']-(-0x123+-0xefa*0x1+0x101e)];_0x1949b1['push'](Buffer['from'](_0x57f0ff,'base64')['toString']());}return _0x1a1526(null,_0x1949b1);});return;}const _0xdb74fa=Buffer['from'](_0x1bdb0c['key'])['toString']('base64'),_0x202499=path['join'](nodeFolder,_0x1bdb0c['gid']+'-'+_0xdb74fa);fs['readFile'](_0x202499,(_0x59d1bb,_0x168127)=>{return _0x59d1bb?_0x59d1bb['code']==='ENOENT'?_0x1a1526(new Error('File\x20'+_0x202499+('\x20(from\x20key'+'\x20\x27')+_0x1bdb0c['key']+('\x27)\x20not\x20fou'+'nd\x20for\x20gro'+'up\x20')+_0x1bdb0c['gid'])):_0x1a1526(_0x59d1bb):_0x1a1526(null,globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x168127['toString']()));});}function del(_0x4fde27,_0x19d6a5){log('[store.del'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x4fde27)),_0x4fde27=normalize(_0x4fde27),_0x4fde27['gid']=_0x4fde27['gid']||'local';const _0x5ec45b=Buffer['from'](_0x4fde27['key'])['toString']('base64'),_0x214bf8=path['join'](nodeFolder,_0x4fde27['gid']+'-'+_0x5ec45b);get(_0x4fde27,(_0x2bce8e,_0x4a2f9e)=>{if(_0x2bce8e)return _0x19d6a5(_0x2bce8e);fs['rm'](_0x214bf8,_0x50dca6=>{return _0x50dca6?_0x19d6a5(_0x50dca6):_0x19d6a5(null,_0x4a2f9e);});});}module['exports']={'put':put,'get':get,'del':del};
|
|
10
10
|
/* eslint-enable */
|
package/distribution.js
CHANGED
|
@@ -9,39 +9,46 @@ const log = require('./distribution/util/log.js');
|
|
|
9
9
|
* @param {Node} [config]
|
|
10
10
|
*/
|
|
11
11
|
function bootstrap(config) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// __start_solution__
|
|
13
|
+
if (false) {
|
|
14
|
+
// __end_solution__
|
|
15
|
+
// This loads the reference implementation in case you want to selectively override parts of your implementation with it (e.g., extra credit ypu are not doing or missing functionality from previous milestones).
|
|
16
|
+
// This needs to run before the rest of the code so that the globalThis.distribution object is populated correctly.
|
|
17
|
+
// @ts-ignore Optional dependency for reference implementation.
|
|
18
|
+
const distributionLib = require('@brown-ds/distribution')(config);
|
|
19
|
+
distributionLib; // To avoid unused variable warning
|
|
20
|
+
// __start_solution__
|
|
15
21
|
}
|
|
16
|
-
|
|
22
|
+
// __end_solution__
|
|
23
|
+
const distribution = {};
|
|
17
24
|
// @ts-ignore This is the first time globalThis.distribution is being initialized, so the object does not have all the necessary properties.
|
|
18
|
-
globalThis.distribution =
|
|
19
|
-
|
|
25
|
+
globalThis.distribution = distribution;
|
|
26
|
+
distribution.util = require('./distribution/util/util.js');
|
|
20
27
|
// @ts-ignore node.server is lazily initialized.
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
distribution.node = require('./distribution/local/node.js');
|
|
29
|
+
distribution.local = require('./distribution/local/local.js');
|
|
23
30
|
|
|
24
31
|
if (config) {
|
|
25
|
-
|
|
32
|
+
distribution.node.config = config;
|
|
26
33
|
}
|
|
27
34
|
|
|
28
|
-
for (const [key, service] of Object.entries(
|
|
29
|
-
|
|
35
|
+
for (const [key, service] of Object.entries(distribution.local)) {
|
|
36
|
+
distribution.local.routes.put(service, key, () => {});
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
const {setup} = require('./distribution/all/all.js');
|
|
33
|
-
|
|
40
|
+
distribution.all = setup({gid: 'all'});
|
|
34
41
|
|
|
35
42
|
/* Overrides when missing functionality from previous milestone or extra credit is needed */
|
|
36
43
|
|
|
37
44
|
// For M3, when missing RPC, its path through routes, and status.{spawn, stop}
|
|
38
45
|
/* __start_M3_solution__
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
distribution.util.wire.createRPC = distributionLib.util.wire.createRPC;
|
|
47
|
+
distribution.local.routes.get = distributionLib.local.routes.get;
|
|
48
|
+
distribution.local.status.spawn = distributionLib.local.status.spawn;
|
|
49
|
+
distribution.local.status.stop = distributionLib.local.status.stop;
|
|
43
50
|
__end_M3_solution__ */
|
|
44
|
-
return
|
|
51
|
+
return distribution;
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
/*
|
|
@@ -50,7 +57,7 @@ function bootstrap(config) {
|
|
|
50
57
|
1. The reference implementation from the library @brown-ds/distribution
|
|
51
58
|
2. Your own, local implementation
|
|
52
59
|
|
|
53
|
-
Which one to be used by the tests is determined by the
|
|
60
|
+
Which one to be used by the tests is determined by the "useLibrary" value in the package.json file.
|
|
54
61
|
*/
|
|
55
62
|
// @ts-ignore JSON import resolved at runtime.
|
|
56
63
|
const {useLibrary} = require('./package.json');
|