@brown-ds/distribution 0.2.19 → 0.2.21

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(_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};
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 fs=require('fs'),path=require('path'),id=require('../util/id'),serialization=require('../util/se'+'rializatio'+'n'),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(_0x3b0f47){if(_0x3b0f47===null)return{'key':null,'gid':null,'action':'put'};else return typeof _0x3b0f47==='string'?{'key':_0x3b0f47,'gid':null,'action':'put'}:_0x3b0f47;}function put(_0x1ec5ba,_0x345ea9,_0x87322d){log('[store.put'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x345ea9)+'\x20state:\x20'+JSON['stringify'](_0x1ec5ba)),_0x345ea9=normalize(_0x345ea9),_0x345ea9['key']=_0x345ea9['key']||id['getID'](_0x1ec5ba),_0x345ea9['gid']=_0x345ea9['gid']||'local';const _0x3f2527=serialization['serialize'](_0x1ec5ba),_0x4a286f=Buffer['from'](_0x345ea9['key'])['toString']('base64'),_0x2e3100=path['join'](nodeFolder,_0x345ea9['gid']+'-'+_0x4a286f);fs['writeFile'](_0x2e3100,_0x3f2527,_0x4fb0c1=>{return _0x4fb0c1?_0x87322d(_0x4fb0c1):_0x87322d(null,_0x1ec5ba);});}function get(_0x14d784,_0x3fed28){log('[store.get'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x14d784)),_0x14d784=normalize(_0x14d784),_0x14d784['gid']=_0x14d784['gid']||'local';if(!_0x14d784['key']){fs['readdir'](nodeFolder,(_0x561559,_0x399954)=>{if(_0x561559)return _0x3fed28(_0x561559);const _0x47fbf7=[];for(let _0x372683=-0x8*-0x265+0x161f*-0x1+0x2f7;_0x372683<_0x399954['length'];_0x372683++){const _0x27cae0=_0x399954[_0x372683]['split']('-'),_0x13fc9a=_0x27cae0[-0x4*-0x313+0x622+-0x126e];if(_0x13fc9a!==_0x14d784['gid'])continue;const _0x1ab0cc=_0x27cae0[_0x27cae0['length']-(-0x101a+0x75b+0x8c0)];_0x47fbf7['push'](Buffer['from'](_0x1ab0cc,'base64')['toString']());}return _0x3fed28(null,_0x47fbf7);});return;}const _0x42e084=Buffer['from'](_0x14d784['key'])['toString']('base64'),_0x17e0c8=path['join'](nodeFolder,_0x14d784['gid']+'-'+_0x42e084);fs['readFile'](_0x17e0c8,(_0x52c8db,_0x558936)=>{return _0x52c8db?_0x52c8db['code']==='ENOENT'?_0x3fed28(new Error('File\x20'+_0x17e0c8+('\x20(from\x20key'+'\x20\x27')+_0x14d784['key']+('\x27)\x20not\x20fou'+'nd\x20for\x20gro'+'up\x20')+_0x14d784['gid'])):_0x3fed28(_0x52c8db):_0x3fed28(null,serialization['deserializ'+'e'](_0x558936['toString']()));});}function del(_0x58a169,_0x4db702){log('[store.del'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x58a169)),_0x58a169=normalize(_0x58a169),_0x58a169['gid']=_0x58a169['gid']||'local';const _0x26992a=Buffer['from'](_0x58a169['key'])['toString']('base64'),_0x5409ab=path['join'](nodeFolder,_0x58a169['gid']+'-'+_0x26992a);get(_0x58a169,(_0x41afcd,_0x26fc3f)=>{if(_0x41afcd)return _0x4db702(_0x41afcd);fs['rm'](_0x5409ab,_0x41ab40=>{return _0x41ab40?_0x4db702(_0x41ab40):_0x4db702(null,_0x26fc3f);});});}module['exports']={'put':put,'get':get,'del':del};
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 */
@@ -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(_0x4552bb,_0x4eb303){const _0x8ae455=[..._0x4eb303];if(_0x4eb303['length']<_0x4552bb['length']-(-0x1808+-0x6d4+-0x1edd*-0x1)){const _0x57a91d=_0x4552bb['length']-_0x4eb303['length']-(-0x13a2+0x1d7e+-0x9db);for(let _0x1a2262=-0x122b*-0x1+0x2463+-0x368e;_0x1a2262<_0x57a91d;_0x1a2262++){_0x8ae455['push'](undefined);}}return _0x8ae455;}module['exports']={'normalize':normalize,'serialize':serialization['serialize'],'deserialize':serialization['deserializ'+'e'],'id':id,'wire':wire};
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
@@ -9,35 +9,51 @@ const log = require('./distribution/util/log.js');
9
9
  * @param {Node} [config]
10
10
  */
11
11
  function bootstrap(config) {
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__
21
+ }
22
+ // __end_solution__
23
+ const distribution = {};
12
24
  // @ts-ignore This is the first time globalThis.distribution is being initialized, so the object does not have all the necessary properties.
13
- globalThis.distribution = {};
14
- globalThis.distribution.util = require('./distribution/util/util.js');
25
+ globalThis.distribution = distribution;
26
+ distribution.util = require('./distribution/util/util.js');
15
27
  // @ts-ignore node.server is lazily initialized.
16
- globalThis.distribution.node = require('./distribution/local/node.js');
17
- globalThis.distribution.local = require('./distribution/local/local.js');
28
+ distribution.node = require('./distribution/local/node.js');
29
+ distribution.local = require('./distribution/local/local.js');
18
30
 
19
31
  if (config) {
20
- globalThis.distribution.node.config = config;
21
- }
22
-
23
- for (const [key, service] of Object.entries(globalThis.distribution.local)) {
24
- globalThis.distribution.local.routes.put(service, key, () => {});
32
+ distribution.node.config = config;
25
33
  }
26
34
 
27
35
  const {setup} = require('./distribution/all/all.js');
28
- globalThis.distribution.all = setup({gid: 'all'});
36
+ distribution.all = setup({gid: 'all'});
29
37
 
30
38
  /* Overrides when missing functionality from previous milestone or extra credit is needed */
31
39
 
32
40
  // For M3, when missing RPC, its path through routes, and status.{spawn, stop}
33
41
  /* __start_M3_solution__
34
- const distributionLib = require('@brown-ds/distribution')(config);
35
- globalThis.distribution.util.wire.createRPC = distributionLib.util.wire.createRPC;
36
- globalThis.distribution.local.routes.get = distributionLib.local.routes.get;
37
- globalThis.distribution.local.status.spawn = distributionLib.local.status.spawn;
38
- globalThis.distribution.local.status.stop = distributionLib.local.status.stop;
42
+ distribution.util.wire.createRPC = distributionLib.util.wire.createRPC;
43
+ distribution.local.routes = distributionLib.local.routes;
44
+ distribution.local.status.spawn = distributionLib.local.status.spawn;
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.node.util.serialize = distributionLib.node.util.serialize;
49
+ distribution.node.util.deserialize = distributionLib.node.util.deserialize;
39
50
  __end_M3_solution__ */
40
- return globalThis.distribution;
51
+
52
+ for (const [key, service] of Object.entries(distribution.local)) {
53
+ distribution.local.routes.put(service, key, () => {});
54
+ }
55
+
56
+ return distribution;
41
57
  }
42
58
 
43
59
  /*
@@ -46,7 +62,7 @@ function bootstrap(config) {
46
62
  1. The reference implementation from the library @brown-ds/distribution
47
63
  2. Your own, local implementation
48
64
 
49
- Which one to be used by the tests is determined by the value of the property "useLibrary" in the package.json file.
65
+ Which one to be used by the tests is determined by the "useLibrary" value in the package.json file.
50
66
  */
51
67
  // @ts-ignore JSON import resolved at runtime.
52
68
  const {useLibrary} = require('./package.json');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brown-ds/distribution",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "description": "A library for building distributed systems.",
5
5
  "main": "distribution.js",
6
6
  "useLibrary": false,