@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(
|
|
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'),
|
|
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(
|
|
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
|
-
|
|
25
|
+
globalThis.distribution = distribution;
|
|
26
|
+
distribution.util = require('./distribution/util/util.js');
|
|
15
27
|
// @ts-ignore node.server is lazily initialized.
|
|
16
|
-
|
|
17
|
-
|
|
28
|
+
distribution.node = require('./distribution/local/node.js');
|
|
29
|
+
distribution.local = require('./distribution/local/local.js');
|
|
18
30
|
|
|
19
31
|
if (config) {
|
|
20
|
-
|
|
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
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
|
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');
|