@brown-ds/distribution 0.2.20 → 0.2.22
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.
|
@@ -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'),log=require('../util/lo'+'g.js');function send(
|
|
9
|
+
const http=require('node:http'),log=require('../util/lo'+'g.js');function createGuardedCallback(_0x28a30d){let _0x6436f4=0x692+-0x210c+0x1a7a;function _0x5b1792(_0x27b8d8,_0x4b8275){_0x6436f4+=-0x223*0xd+0x1d74+-0x1ac;if(_0x6436f4>0x16d2+-0x165c+-0x75){log('Warning:\x20C'+'allback\x20fu'+'nction\x20cal'+'led\x20'+_0x6436f4+'\x20times');return;}if(_0x28a30d!==undefined){_0x28a30d(_0x27b8d8,_0x4b8275);return;}}return _0x5b1792;}function send(_0x408349,_0x1edc84,_0x543a04){_0x543a04=createGuardedCallback(_0x543a04);if(_0x1edc84===undefined){_0x543a04(new Error('Remote\x20is\x20'+'required'));return;}if(_0x1edc84?.['node']?.['ip']===undefined||_0x1edc84?.['node']?.['port']===undefined){_0x543a04(new Error('Remote\x20nod'+'e\x20IP\x20and\x20p'+'ort\x20requir'+'ed'));return;}if(_0x1edc84?.['service']===undefined){_0x543a04(new Error('Remote\x20ser'+'vice\x20is\x20re'+'quired'));return;}if(_0x1edc84?.['method']===undefined){_0x543a04(new Error('Remote\x20met'+'hod\x20is\x20req'+'uired'));return;}if(!(_0x408349 instanceof Array)){_0x543a04(new Error('Message\x20mu'+'st\x20be\x20an\x20a'+'rray\x20of\x20ar'+'guments'));return;}const _0x26dd72=_0x1edc84['node'],_0x23eff8=_0x1edc84['service'],_0x5d4911=_0x1edc84['method'],_0x433a42=_0x1edc84['gid']||'local';log('[comm.send'+']:\x20Sending'+'\x20'+JSON['stringify'](_0x408349)+'\x20to\x20'+_0x1edc84['service']+':'+_0x1edc84['method']+'\x20on\x20'+_0x1edc84['node']['ip']+':'+_0x1edc84['node']['port']);const _0x28523a=globalThis['distributi'+'on']['util']['serialize'](_0x408349),_0x34c38d={'hostname':_0x26dd72['ip'],'port':_0x26dd72['port'],'path':'/'+_0x433a42+'/'+_0x23eff8+'/'+_0x5d4911,'method':'PUT','headers':{'Content-Type':'applicatio'+'n/json','Content-Length':Buffer['byteLength'](_0x28523a)}},_0x273854=http['request'](_0x34c38d,_0x1c1358=>{let _0x20394f='';_0x1c1358['on']('data',function(_0x1b730d){_0x20394f+=_0x1b730d;}),_0x1c1358['on']('end',function(){let _0x2c38c5=undefined,_0x1a3a93=undefined;try{const _0x5b7551=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x20394f);_0x2c38c5=_0x5b7551[-0x2c1+-0x2496+0x2757],_0x1a3a93=_0x5b7551[-0x1*-0x2465+0x4f0*-0x4+0x10a4*-0x1];}catch(_0x1fed1c){let _0xa55726=_0x20394f['slice'](-0x1bb*-0x16+0x1010+-0x3622,0x1a*0x35+-0x1e9d+-0x1d23*-0x1);_0x20394f['length']>-0x1975+-0xabe+-0x281b*-0x1&&(_0xa55726+='...');_0x543a04(new Error('Failed\x20to\x20'+'deserializ'+'e\x20HTTP\x20res'+'ponse:\x20'+_0xa55726));return;}_0x543a04(_0x2c38c5,_0x1a3a93);return;}),_0x1c1358['on']('error',_0x31ad54=>{_0x543a04(new Error('HTTP\x20respo'+'nse\x20error:'+'\x20'+_0x31ad54?.['message']));return;});});_0x273854['on']('error',_0x183288=>{_0x543a04(new Error('HTTP\x20reque'+'st\x20error:\x20'+_0x183288?.['message']));return;}),_0x273854['write'](_0x28523a),_0x273854['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 _0x5ac1e9=yargs(process['argv'])['help'](![])['version'](![])['parse']();let _0x58b69f,_0x318377,_0x5ac937;typeof _0x5ac1e9['ip']==='string'&&(_0x58b69f=_0x5ac1e9['ip']);(typeof _0x5ac1e9['port']==='string'||typeof _0x5ac1e9['port']==='number')&&(_0x318377=parseInt(String(_0x5ac1e9['port']),-0x409*-0x1+0x22cd+-0x26cc));(_0x5ac1e9['help']===!![]||_0x5ac1e9['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'](-0xc23+0x9bf*0x1+-0x99*-0x4));if(typeof _0x5ac1e9['config']==='string'){let _0x4fe36b=undefined;try{_0x4fe36b=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x5ac1e9['config']);}catch(_0x9d2859){try{_0x4fe36b=JSON['parse'](_0x5ac1e9['config']);}catch{console['error']('Cannot\x20des'+'erialize\x20c'+'onfig\x20stri'+'ng:\x20'+_0x5ac1e9['config']),process['exit'](0x2534*-0x1+-0xb*0x2+0x254b);}}typeof _0x4fe36b?.['ip']==='string'&&(_0x58b69f=_0x4fe36b?.['ip']),typeof _0x4fe36b?.['port']==='number'&&(_0x318377=_0x4fe36b?.['port']),typeof _0x4fe36b?.['onStart']==='function'&&(_0x5ac937=_0x4fe36b?.['onStart']);}return _0x58b69f=_0x58b69f??'127.0.0.1',_0x318377=_0x318377??-0xe73+0x7ce+-0x24b*-0x5,{'ip':_0x58b69f,'port':_0x318377,'onStart':_0x5ac937};}function validate(_0x23c72e){if(_0x23c72e['length']===0x5b5+0x1590+-0x1b45)throw new Error('No\x20body');return JSON['parse'](_0x23c72e);}function start(_0x4ea169){const _0x5df02a=http['createServ'+'er']((_0x5f8ee6,_0x189323)=>{if(_0x5f8ee6['method']!=='PUT'){_0x189323['end'](globalThis['distributi'+'on']['util']['serialize'](new Error('Method\x20not'+'\x20allowed!')));return;}const [,_0x44d9a4,_0x211999,_0x4207f6]=url['parse'](_0x5f8ee6['url'])['pathname']['split']('/');log('[server]\x20g'+'ot\x20request'+'\x20'+_0x44d9a4+'\x20'+_0x211999+':'+_0x4207f6+'\x20from\x20'+_0x5f8ee6['socket']['remoteAddr'+'ess']);const _0x24d1c6=[];_0x5f8ee6['on']('data',_0x3900dc=>{_0x24d1c6['push'](_0x3900dc);}),_0x5f8ee6['on']('end',()=>{let _0x1453e1;try{_0x1453e1=validate(Buffer['concat'](_0x24d1c6)['toString']());}catch(_0x176127){_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([_0x176127]));return;}const _0x544639=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x1453e1);!Array['isArray'](_0x544639)&&_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([new Error('Invalid\x20ar'+'gument\x20typ'+'e,\x20expecte'+'d\x20array,\x20g'+'ot\x20'+typeof _0x544639)]));const _0x39b28a=_0x211999;globalThis['distributi'+'on']['local']['routes']['get']({'service':_0x211999,'gid':_0x44d9a4},(_0x39ce9f,_0x4f9c34)=>{if(_0x39ce9f){_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([_0x39ce9f,null]));return;}if(!_0x4f9c34[_0x4207f6]){_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([new Error('Method\x20'+_0x4207f6+('\x20not\x20found'+'\x20in\x20servic'+'e\x20')+_0x39b28a),null]));return;}log('[server]\x20\x20'+'Calling\x20se'+'rvice:\x20'+_0x39b28a+':'+_0x4207f6+('\x20with\x20args'+':\x20')+JSON['stringify'](_0x544639));_0x544639['length']===0x12d2+0x2f*-0x61+-0x102&&_0x4f9c34[_0x4207f6]['length']===-0x1c17+0x3b2+0x1868&&_0x544639['push'](undefined);const _0x40a06c=_0x4f9c34[_0x4207f6]['bind'](_0x4f9c34),_0x156f79=globalThis['distributi'+'on']['util']['normalize'](_0x40a06c,_0x544639);try{_0x40a06c(..._0x156f79,(_0x538e4a,_0x35be1c)=>_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([_0x538e4a,_0x35be1c])));}catch(_0x51a50e){_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([_0x51a50e,null]));}});});});globalThis['distributi'+'on']['node']['server']=_0x5df02a;const _0x18c49f=globalThis['distributi'+'on']['node']['config'];_0x5df02a['once']('listening',()=>{log('Server\x20run'+'ning\x20at\x20ht'+'tp://'+_0x18c49f['ip']+':'+_0x18c49f['port']+'/'),_0x4ea169(null);}),_0x5df02a['once']('error',_0x339745=>{log('Server\x20err'+'or:\x20'+_0x339745),_0x4ea169(_0x339745);}),_0x5df02a['listen'](_0x18c49f['port'],_0x18c49f['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'),routesStore=new Map();function get(
|
|
9
|
+
const log=require('../util/lo'+'g'),routesStore=new Map();function get(_0x3b8f9b,_0xd999cf){log('[routes.ge'+'t]\x20Getting'+'\x20service:\x20'+JSON['stringify'](_0x3b8f9b));if(!_0x3b8f9b)return _0xd999cf(new Error('No\x20configu'+'ration\x20pro'+'vided!'));typeof _0x3b8f9b==='string'&&(_0x3b8f9b={'service':_0x3b8f9b});const _0x261a09=_0x3b8f9b['service'],_0x5a7a79=_0x3b8f9b['gid'];if(_0x5a7a79&&_0x5a7a79!=='local')return log('[routes.ge'+'t]\x20Found\x20d'+'istributed'+'\x20service:\x20'+_0x261a09),_0xd999cf(null,globalThis['distributi'+'on'][_0x5a7a79][_0x261a09]);else{const _0x2a941b=routesStore['get'](_0x261a09);if(_0x2a941b)return log('[routes.ge'+'t]\x20Found\x20l'+'ocal\x20servi'+'ce:\x20'+_0x261a09),_0xd999cf(null,_0x2a941b);else{const _0x7718e2=globalThis['toLocal']['get'](_0x261a09);return _0x7718e2?(log('[routes.ge'+'t]\x20Found\x20R'+'PC:\x20'+_0x261a09),_0xd999cf(null,{'call':_0x7718e2})):_0xd999cf(new Error('Service\x20'+_0x261a09+('\x20not\x20found'+'\x20in\x20routes')));}}}function put(_0x2a5b78,_0x187cc1,_0x49386c){log('[routes.pu'+'t]\x20Putting'+'\x20service:\x20'+_0x187cc1),routesStore['set'](_0x187cc1,_0x2a5b78);if(_0x49386c)return _0x49386c(null,_0x187cc1);}function rem(_0x3c28d1,_0x2f32b8){const _0x4533ce=routesStore['get'](_0x3c28d1);return routesStore['delete'](_0x3c28d1),_0x2f32b8(null,_0x4533ce);}module['exports']={'get':get,'put':put,'rem':rem};
|
|
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=-0x26b*0xd+0xf*0x192+-0x1*-0x7e1;function get(_0x545045,_0xc9c56a){if(_0x545045 in globalThis['distributi'+'on']['node']['config']){_0xc9c56a(null,globalThis['distributi'+'on']['node']['config'][_0x545045]);return;}if(_0x545045==='sid'){_0xc9c56a(null,globalThis['distributi'+'on']['util']['id']['getSID'](globalThis['distributi'+'on']['node']['config']));return;}if(_0x545045==='nid'){_0xc9c56a(null,globalThis['distributi'+'on']['util']['id']['getNID'](globalThis['distributi'+'on']['node']['config']));return;}if(_0x545045==='counts'){_0xc9c56a(null,counts);return;}if(_0x545045==='heapTotal'){_0xc9c56a(null,process['memoryUsag'+'e']()['heapTotal']);return;}if(_0x545045==='heapUsed'){_0xc9c56a(null,process['memoryUsag'+'e']()['heapUsed']);return;}_0xc9c56a(new Error('Status\x20key'+'\x20not\x20found'));};const fs=require('fs'),path=require('path'),proc=require('node:child'+'_process');function getDistribution(){let _0x210eaa=path['join'](__dirname,'../../','distributi'+'on.js');if(fs['existsSync'](_0x210eaa))return _0x210eaa;try{const _0x3e529b=proc['execSync']('git\x20rev-pa'+'rse\x20--show'+'-toplevel',{'encoding':'utf8'})['trim']();_0x210eaa=path['join'](_0x3e529b,'distributi'+'on.js');if(fs['existsSync'](_0x210eaa))return _0x210eaa;}catch(_0x224009){throw new Error('Not\x20in\x20a\x20G'+'it\x20reposit'+'ory\x20or\x20git'+'\x20command\x20f'+'ailed.');}_0x210eaa=path['join'](process['cwd'](),'distributi'+'on.js');if(fs['existsSync'](_0x210eaa))return _0x210eaa;throw new Error('Failed\x20to\x20'+'find\x20proje'+'ct\x20root.');}function createOnStart(_0x213228,_0x1aa40c){const _0x11de11='\x0a\x20\x20\x20\x20retur'+'n\x20function'+'(e)\x20{\x0a\x20\x20\x20\x20'+'\x20\x20let\x20onSt'+'art\x20=\x20'+_0x213228['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'](_0x1aa40c))['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(_0x11de11)();}function spawn(_0xa65a3a,_0x19d836){const _0x531f4b=_0xa65a3a;_0x531f4b['onStart']=_0x531f4b['onStart']||function(){};if(!_0x531f4b['port']||!_0x531f4b['ip']){_0x19d836(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'](_0x531f4b));const _0xa102db=(_0x5f294e,_0x570958)=>{if(_0x5f294e){_0x19d836(_0x5f294e);return;}globalThis['distributi'+'on']['local']['groups']['add']('all',_0x570958,()=>{_0x19d836(_0x5f294e,_0x570958);});};_0x531f4b['onStart']=createOnStart(_0x531f4b['onStart'],_0xa102db);const _0x130e31=getDistribution(),_0x1b0b8d=proc['spawn']('node',[_0x130e31,'--config',globalThis['distributi'+'on']['util']['serialize'](_0x531f4b)],{'detached':!![],'stdio':'inherit'});_0x1b0b8d;return;_0x19d836(new Error('status.spa'+'wn\x20not\x20imp'+'lemented'));}function stop(_0x3d6727){log('[status.st'+'op]\x20Shutti'+'ng\x20down\x20no'+'de'),globalThis['distributi'+'on']['node']['server']['close'](),process['nextTick'](()=>process['exit'](0x1*-0xd5b+0x15a2+-0x847));return _0x3d6727(null,globalThis['distributi'+'on']['node']['config']);_0x3d6727(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 serialization=require('./serializ'+'ation.js'),id=require('./id.js'),wire=require('./wire.js');function normalize(
|
|
9
|
+
const serialization=require('./serializ'+'ation.js'),id=require('./id.js'),wire=require('./wire.js'),log=require('./log.js');function normalize(_0x3c454c,_0x266969){const _0x1d24dc=[..._0x266969];if(_0x266969['length']<_0x3c454c['length']-(-0x33*-0xad+0x23d3+-0x3b3*0x13)){const _0x566abe=_0x3c454c['length']-_0x266969['length']-(-0x1*-0x1064+-0x293*-0x9+-0x3d*0xa6);for(let _0x208926=0x1cf0+-0x1258+0x388*-0x3;_0x208926<_0x566abe;_0x208926++){_0x1d24dc['push'](undefined);}}return _0x1d24dc;}module['exports']={'normalize':normalize,'serialize':serialization['serialize'],'deserialize':serialization['deserializ'+'e'],'id':id,'wire':wire,'log':log};
|
|
10
10
|
/* eslint-enable */
|
package/distribution.js
CHANGED
|
@@ -32,10 +32,6 @@ function bootstrap(config) {
|
|
|
32
32
|
distribution.node.config = config;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
for (const [key, service] of Object.entries(distribution.local)) {
|
|
36
|
-
distribution.local.routes.put(service, key, () => {});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
35
|
const {setup} = require('./distribution/all/all.js');
|
|
40
36
|
distribution.all = setup({gid: 'all'});
|
|
41
37
|
|
|
@@ -44,10 +40,19 @@ function bootstrap(config) {
|
|
|
44
40
|
// For M3, when missing RPC, its path through routes, and status.{spawn, stop}
|
|
45
41
|
/* __start_M3_solution__
|
|
46
42
|
distribution.util.wire.createRPC = distributionLib.util.wire.createRPC;
|
|
47
|
-
distribution.local.routes
|
|
43
|
+
distribution.local.routes = distributionLib.local.routes;
|
|
48
44
|
distribution.local.status.spawn = distributionLib.local.status.spawn;
|
|
49
45
|
distribution.local.status.stop = distributionLib.local.status.stop;
|
|
46
|
+
distribution.local.comm = distributionLib.local.comm;
|
|
47
|
+
distribution.node.start = distributionLib.node.start;
|
|
48
|
+
distribution.util.serialize = distributionLib.util.serialize;
|
|
49
|
+
distribution.util.deserialize = distributionLib.util.deserialize;
|
|
50
50
|
__end_M3_solution__ */
|
|
51
|
+
|
|
52
|
+
for (const [key, service] of Object.entries(distribution.local)) {
|
|
53
|
+
distribution.local.routes.put(service, key, () => {});
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
return distribution;
|
|
52
57
|
}
|
|
53
58
|
|