@brown-ds/distribution 0.2.28 → 0.2.30
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 +15 -5
- package/distribution/all/comm.js +1 -1
- package/distribution/all/status.js +1 -1
- package/distribution/util/serialization.js +1 -1
- package/distribution.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,15 +99,25 @@ If you wanted to run this same sequence of commands in a script, you could do so
|
|
|
99
99
|
```js
|
|
100
100
|
let distribution = require("@brown-ds/distribution")();
|
|
101
101
|
// Now we're only doing a few of the things we did above
|
|
102
|
+
const out = (cb) => {
|
|
103
|
+
distribution.local.status.stop(cb); // Shut down the local node
|
|
104
|
+
};
|
|
102
105
|
distribution.node.start(() => {
|
|
103
106
|
// This will run only after the node has started
|
|
104
|
-
node = {
|
|
105
|
-
distribution.local.status.spawn(node, () => {
|
|
107
|
+
const node = {ip: '127.0.0.1', port: 8765};
|
|
108
|
+
distribution.local.status.spawn(node, (e, v) => {
|
|
109
|
+
if (e) {
|
|
110
|
+
return out(console.log);
|
|
111
|
+
}
|
|
106
112
|
// This will run only after the new node has been spawned
|
|
107
113
|
distribution.all.status.get('sid', (e, v) => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
// This will run only after we communicated with all nodes and got their sids
|
|
115
|
+
console.log(v); // { '8cf1b': '8cf1b', '8cf1c': '8cf1c' }
|
|
116
|
+
// Shut down the remote node
|
|
117
|
+
distribution.local.comm.send([], {service: 'status', method: 'stop', node: node}, () => {
|
|
118
|
+
// Finally, stop the local node
|
|
119
|
+
out(console.log); // null, {ip: '127.0.0.1', port: 1380}
|
|
120
|
+
});
|
|
111
121
|
});
|
|
112
122
|
});
|
|
113
123
|
});
|
package/distribution/all/comm.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
|
-
function comm(
|
|
9
|
+
function comm(_0x17e568){const _0x543f7b={};_0x543f7b['gid']=_0x17e568['gid']||'all';function _0x4738df(_0x114e26,_0x27d271,_0x43252b){globalThis['distributi'+'on']['local']['groups']['get'](_0x543f7b['gid'],(_0x5d70cd,_0x40759f)=>{if(!_0x40759f){_0x43252b(_0x5d70cd);return;}const _0x369edf=Object['keys'](_0x40759f)['length'];if(_0x369edf===-0x2*0x3f5+-0x2*0x9f1+0x1bcc){_0x43252b(new Error('No\x20nodes\x20i'+'n\x20group\x20'+_0x543f7b['gid']+'\x20found!'));return;}let _0x1b730e=0x1072+0xfdd+-0x204f;const _0x5ae99f={},_0x2af7b0={};for(const _0x33c7ce of Object['keys'](_0x40759f)){const _0x959419=_0x40759f[_0x33c7ce],_0x574b2d={'node':{'ip':_0x959419['ip'],'port':_0x959419['port']},'service':_0x27d271['service'],'method':_0x27d271['method'],'gid':_0x27d271['gid']||'local'};globalThis['distributi'+'on']['local']['comm']['send'](_0x114e26,_0x574b2d,(_0x4aadb3,_0x3ecdc4)=>{_0x4aadb3?_0x2af7b0[_0x33c7ce]=_0x4aadb3:_0x5ae99f[_0x33c7ce]=_0x3ecdc4;_0x1b730e+=0x6da+0x1*0x17ee+-0x1ec7;if(_0x1b730e===_0x369edf)return _0x43252b(_0x2af7b0,_0x5ae99f);});}});return;_0x43252b(new Error('comm.send\x20'+'not\x20implem'+'ented'));}return{'send':_0x4738df};}module['exports']=comm;
|
|
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(_0x423aac){const _0x41f0a4={};_0x41f0a4['gid']=_0x423aac['gid']||'all';function _0x28bb8a(_0x5996f0,_0x40a397){const _0x45ffcc=[_0x5996f0],_0x321e52={'service':'status','method':'get'};globalThis['distributi'+'on'][_0x41f0a4['gid']]['comm']['send'](_0x45ffcc,_0x321e52,(_0x3ac603,_0x3c8658)=>{switch(_0x5996f0){case'heapTotal':const _0x16d43a=Object['values'](_0x3c8658)['reduce']((_0x36a757,_0x4c9396)=>{return _0x36a757+_0x4c9396;},-0x7f*0x4a+0x19*0x1d+-0x15*-0x19d);return _0x40a397(_0x3ac603,_0x16d43a);break;case'nid':const _0x34ffda=Object['values'](_0x3c8658)['reduce']((_0x27a954,_0x186898)=>{return _0x27a954['concat'](_0x186898);},[]);return _0x40a397(_0x3ac603,_0x34ffda);break;default:return _0x40a397(_0x3ac603,_0x3c8658);break;}});return;_0x40a397(new Error('status.get'+'\x20not\x20imple'+'mented'));}function _0x38df6f(_0x1b0684,_0x2f73ba){globalThis['distributi'+'on']['local']['status']['spawn'](_0x1b0684,(_0x484b26,_0x1ab6fd)=>{globalThis['distributi'+'on'][_0x41f0a4['gid']]['comm']['send']([_0x41f0a4['gid'],_0x1b0684],{'service':'groups','method':'add'},()=>{});if(_0x484b26)return _0x2f73ba(_0x484b26);globalThis['distributi'+'on']['local']['groups']['add'](_0x41f0a4['gid'],_0x1b0684,()=>{return _0x2f73ba(null,_0x1ab6fd);});});return;_0x2f73ba(new Error('status.spa'+'wn\x20not\x20imp'+'lemented'));}function _0x547b3a(_0x4b6742){globalThis['distributi'+'on'][_0x41f0a4['gid']]['comm']['send']([],{'service':'status','method':'stop'},()=>{globalThis['distributi'+'on']['local']['status']['stop'](_0x4b6742);});return;_0x4b6742(new Error('status.sto'+'p\x20not\x20impl'+'emented'));}return{'get':_0x28bb8a,'stop':_0x547b3a,'spawn':_0x38df6f};}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 nativeFunctions={'forward':new Map(),'reverse':new Map()};function createNativeMap(){const
|
|
9
|
+
const nativeFunctions={'forward':new Map(),'reverse':new Map()};function createNativeMap(){const _0x35dfa6=[];function _0x5a4e60(_0x676140,_0x31d35a){if(_0x31d35a===null||_0x31d35a===undefined)return;if(_0x35dfa6['indexOf'](_0x31d35a)!==-(0xdff*-0x2+0x23a6+0x7a7*-0x1))return;_0x35dfa6['push'](_0x31d35a),Object['getOwnProp'+'ertyNames'](_0x31d35a)['forEach'](_0x4beb5a=>{if(typeof _0x31d35a[_0x4beb5a]==='function'){nativeFunctions['forward']['set'](_0x31d35a[_0x4beb5a],_0x676140+'.'+_0x4beb5a),nativeFunctions['reverse']['set'](_0x676140+'.'+_0x4beb5a,_0x31d35a[_0x4beb5a]);return;}typeof _0x31d35a[_0x4beb5a]==='object'&&_0x35dfa6['indexOf'](_0x31d35a[_0x4beb5a])===-(-0x2012*-0x1+0x946+-0x1*0x2957)&&_0x5a4e60(_0x676140+'.'+_0x4beb5a,_0x31d35a[_0x4beb5a]);});}for(const _0x421636 of require('repl')['_builtinLi'+'bs']){if(['wasi','sys','punycode','crypto']['includes'](_0x421636))continue;const _0x48e8d2=require(_0x421636);_0x5a4e60(_0x421636,_0x48e8d2);}}createNativeMap();function decycleObject(_0x185a9b){if(_0x185a9b===null||_0x185a9b===undefined)return _0x185a9b;const _0x30b92a=new WeakMap();function _0x3a1587(_0x32a59b,_0x31516b){let _0x40e0bf;if(!(typeof _0x32a59b==='object'&&!(_0x32a59b instanceof Error)&&!(_0x32a59b instanceof Date)&&!(_0x32a59b instanceof Boolean)&&_0x32a59b!==null))return _0x32a59b;const _0x10ceb8=_0x30b92a['get'](_0x32a59b);if(_0x10ceb8!==undefined)return{'$reference':_0x10ceb8};return _0x30b92a['set'](_0x32a59b,_0x31516b),Array['isArray'](_0x32a59b)?(_0x40e0bf=[],_0x32a59b['forEach'](function(_0x5d28b5,_0x162321){const _0x2ab30c=[..._0x31516b,_0x162321];_0x40e0bf[_0x162321]=_0x3a1587(_0x5d28b5,_0x2ab30c);})):(_0x40e0bf={},Object['keys'](_0x32a59b)['forEach'](_0x1fd335=>{const _0x63fa97=[..._0x31516b,JSON['stringify'](_0x1fd335)];_0x40e0bf[_0x1fd335]=_0x3a1587(_0x32a59b[_0x1fd335],_0x63fa97);})),_0x40e0bf;}return _0x3a1587(_0x185a9b,[]);}function serializeBaseStructure(_0x34ac8a){return{'type':typeof _0x34ac8a,'value':_0x34ac8a['toString']()};}function serializeBigInt(_0x30fb24){return{'type':'bigint','value':_0x30fb24['toString']()};}function serializeUndefined(_0x8d1ff2){return{'type':'undefined','value':''};}function serializeObject(_0x3edd79){if(_0x3edd79===null)return{'type':'null','value':''};else{if(_0x3edd79 instanceof Date)return{'type':'date','value':_0x3edd79['toJSON']()};else{if(_0x3edd79 instanceof Error)return{'type':'error','value':serializeObject({'name':_0x3edd79['name'],'message':_0x3edd79['message'],'cause':_0x3edd79['cause']})};}}if(_0x3edd79['$reference']!==undefined&&Object['keys'](_0x3edd79)['length']===-0x1*0x15cf+0x1c19+-0x1*0x649)return{'type':'reference','value':_0x3edd79['$reference']};const _0x1b6fdc=Object['fromEntrie'+'s'](Object['entries'](_0x3edd79)['map'](([_0x490e53,_0x53d409])=>{const _0x5a87ce=serialize(_0x53d409);return[_0x490e53,JSON['parse'](_0x5a87ce)];}));return{'type':_0x3edd79 instanceof Array?'array':'object','value':_0x1b6fdc};}function serializeFunction(_0x5438a1){const _0x18c8c0=nativeFunctions['forward']['get'](_0x5438a1);return _0x18c8c0===undefined?{'type':'function','value':_0x5438a1['toString']()}:{'type':'native','value':_0x18c8c0};}function serialize(_0x1b9faf){_0x1b9faf=decycleObject(_0x1b9faf);let _0x414e6f;switch(typeof _0x1b9faf){case'object':_0x414e6f=serializeObject(_0x1b9faf);break;case'function':_0x414e6f=serializeFunction(_0x1b9faf);break;case'undefined':_0x414e6f=serializeUndefined(_0x1b9faf);break;case'number':case'string':case'boolean':_0x414e6f=serializeBaseStructure(_0x1b9faf);break;case'bigint':_0x414e6f=serializeBigInt(_0x1b9faf);break;}return JSON['stringify'](_0x414e6f);}function deserializeObject(_0x4a0d3a,_0x2612d6){for(const [_0x2de30b,_0x346dac]of Object['entries'](_0x4a0d3a)){_0x2612d6[_0x2de30b]=doSerialize(_0x346dac,_0x2612d6);}return _0x2612d6;}function deserializeArray(_0x5dfb6f,_0x5b0823){for(const [_0x134191,_0x3dc79b]of Object['entries'](_0x5dfb6f)){_0x5b0823[Number(_0x134191)]=doSerialize(_0x3dc79b,_0x5b0823);}return _0x5b0823;}function deserializeString(_0x355e7f){return _0x355e7f;}function deserializeNumber(_0x19d683){return Number(_0x19d683);}function deserializeFunction(_0x3ef33a){return new Function('return\x20'+_0x3ef33a)();}function deserializeError(_0x48cbb4){const _0x16a8ea=doSerialize(_0x48cbb4),_0x104047=new Error(_0x16a8ea['message'],_0x16a8ea['cause']);return _0x104047;}function deserializeReference(_0x2acfd1,_0x42b8d0){let _0x1ac3e0=_0x42b8d0;for(const _0x2c43f8 of _0x2acfd1){_0x1ac3e0=_0x1ac3e0[JSON['parse'](_0x2c43f8)];}return _0x1ac3e0;}function deserializeNative(_0x472aad){const _0x23dcbc=nativeFunctions['reverse']['get'](_0x472aad);if(_0x23dcbc===undefined)throw Error('Function\x20n'+'ot\x20found\x20i'+'n\x20native\x20f'+'unction\x20ma'+'p');return _0x23dcbc;}function deserializeReferences(_0x2ab907,_0x4fe960){if(typeof _0x2ab907!=='object'||_0x2ab907===null)return _0x2ab907;if(_0x2ab907['type']==='reference')return deserializeReference(_0x2ab907['value'],_0x4fe960);if(Array['isArray'](_0x2ab907))for(let _0x2c962b=-0xf7d+-0x3*-0x26f+0x830;_0x2c962b<_0x2ab907['length'];_0x2c962b++){_0x2ab907[_0x2c962b]=deserializeReferences(_0x2ab907[_0x2c962b],_0x4fe960);}else for(const [_0x36b720,_0x427176]of Object['entries'](_0x2ab907)){_0x2ab907[_0x36b720]=deserializeReferences(_0x427176,_0x4fe960);}return _0x2ab907;}function doSerialize(_0x52f3be,_0x239fb1=null){let _0x2cee1e;if(typeof _0x52f3be==='object')_0x2cee1e=_0x52f3be;else{if(typeof _0x52f3be==='string')_0x2cee1e=JSON['parse'](_0x52f3be);else throw new Error('Invalid\x20ar'+'gument\x20typ'+'e:\x20'+typeof _0x52f3be+'.');}_0x239fb1===null&&(_0x239fb1={});switch(_0x2cee1e['type']){case'object':return deserializeObject(_0x2cee1e['value'],{});case'array':return deserializeArray(_0x2cee1e['value'],[]);case'function':return deserializeFunction(_0x2cee1e['value']);case'native':return deserializeNative(_0x2cee1e['value']);case'reference':return _0x2cee1e;case'number':return deserializeNumber(_0x2cee1e['value']);case'string':return deserializeString(_0x2cee1e['value']);case'boolean':return _0x2cee1e['value']==='true';case'bigint':return BigInt(_0x2cee1e['value']);case'date':return new Date(_0x2cee1e['value']);case'error':return deserializeError(_0x2cee1e['value']);case'null':return null;case'undefined':return undefined;default:throw new Error('Invalid\x20se'+'rialized\x20o'+'bject\x20type');}}function deserialize(_0x28bcf3){if(typeof _0x28bcf3!=='string')throw new Error('Invalid\x20ar'+'gument\x20typ'+'e:\x20'+typeof _0x28bcf3+'.');const _0x43b7d7=doSerialize(_0x28bcf3);return deserializeReferences(_0x43b7d7,_0x43b7d7),_0x43b7d7;}module['exports']={'serialize':serialize,'deserialize':deserialize};
|
|
10
10
|
/* eslint-enable */
|
package/distribution.js
CHANGED
|
@@ -21,17 +21,17 @@ function bootstrap(config) {
|
|
|
21
21
|
}
|
|
22
22
|
// __end_solution__
|
|
23
23
|
const distribution = {};
|
|
24
|
+
|
|
24
25
|
// @ts-ignore This is the first time globalThis.distribution is being initialized, so the object does not have all the necessary properties.
|
|
25
26
|
globalThis.distribution = distribution;
|
|
26
27
|
distribution.util = require('./distribution/util/util.js');
|
|
27
28
|
|
|
28
29
|
// @ts-ignore node.server is lazily initialized.
|
|
29
30
|
distribution.node = require('./distribution/local/node.js');
|
|
30
|
-
distribution.local = require('./distribution/local/local.js');
|
|
31
|
-
|
|
32
31
|
if (config) {
|
|
33
32
|
distribution.node.config = config;
|
|
34
33
|
}
|
|
34
|
+
distribution.local = require('./distribution/local/local.js');
|
|
35
35
|
|
|
36
36
|
const {setup} = require('./distribution/all/all.js');
|
|
37
37
|
distribution.all = setup({gid: 'all'});
|