@brown-ds/distribution 0.2.16 → 0.2.19

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 CHANGED
@@ -1,9 +1,16 @@
1
1
  # distribution
2
2
 
3
- This is the distribution library. When loaded, distribution introduces functionality supporting the distributed execution of programs. To download it:
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
  ```
@@ -30,50 +37,80 @@ By default, all regular tests are run. Use the options below to run different se
30
37
 
31
38
  ## Usage
32
39
 
33
- To import the library, be it in a JavaScript file or on the interactive console, run:
40
+ To try out the distribution library inside an interactive Node.js session, run:
41
+
42
+ ```sh
43
+ $ node
44
+ ```
45
+
46
+ Then, load the distribution library:
34
47
 
35
48
  ```js
36
- let distribution = require("@brown-ds/distribution");
49
+ > let distribution = require("@brown-ds/distribution")();
50
+ > distribution.node.start(console.log);
37
51
  ```
38
52
 
39
53
  Now you have access to the full distribution library. You can start off by serializing some values.
40
54
 
41
55
  ```js
42
- let s = distribution.util.serialize(1); // '{"type":"number","value":"1"}'
43
- let n = distribution.util.deserialize(s); // 1
56
+ > s = distribution.util.serialize(1); // '{"type":"number","value":"1"}'
57
+ > n = distribution.util.deserialize(s); // 1
44
58
  ```
45
59
 
46
60
  You can inspect information about the current node (for example its `sid`) by running:
47
61
 
48
62
  ```js
49
- distribution.local.status.get('sid', console.log); // 8cf1b
63
+ > distribution.local.status.get('sid', console.log); // null 8cf1b (null here is the error value; meaning there is no error)
50
64
  ```
51
65
 
52
66
  You can also store and retrieve values from the local memory:
53
67
 
54
68
  ```js
55
- distribution.local.mem.put({name: 'nikos'}, 'key', console.log); // {name: 'nikos'}
56
- distribution.local.mem.get('key', console.log); // {name: 'nikos'}
69
+ > distribution.local.mem.put({name: 'nikos'}, 'key', console.log); // null {name: 'nikos'} (again, null is the error value)
70
+ > distribution.local.mem.get('key', console.log); // null {name: 'nikos'}
71
+
72
+ > distribution.local.mem.get('wrong-key', console.log); // Error('Key not found') undefined
57
73
  ```
58
74
 
59
75
  You can also spawn a new node:
60
76
 
61
77
  ```js
62
- let node = { ip: '127.0.0.1', port: 8080 };
63
- distribution.local.status.spawn(node, console.log);
78
+ > node = { ip: '127.0.0.1', port: 8080 };
79
+ > distribution.local.status.spawn(node, console.log);
64
80
  ```
65
81
 
66
82
  Using the `distribution.all` set of services will allow you to act
67
83
  on the full set of nodes created as if they were a single one.
68
84
 
69
85
  ```js
70
- distribution.all.status.get('sid', console.log); // { '8cf1b': '8cf1b', '8cf1c': '8cf1c' }
86
+ > distribution.all.status.get('sid', console.log); // {} { '8cf1b': '8cf1b', '8cf1c': '8cf1c' } (now, errors are per-node and form an object)
71
87
  ```
72
88
 
73
89
  You can also send messages to other nodes:
74
90
 
75
91
  ```js
76
- distribution.all.comm.send(['sid'], {node: node, service: 'status', method: 'get'}, console.log); // 8cf1c
92
+ > distribution.local.comm.send(['sid'], {node: node, service: 'status', method: 'get'}, console.log); // null 8cf1c
93
+ ```
94
+
95
+ Most methods in the distribution library are asynchronous and take a callback as their last argument.
96
+ This callback is called when the method completes, with the first argument being an error (if any) and the second argument being the result.
97
+ If you wanted to run this same sequence of commands in a script, you could do something like this (note the nested callbacks):
98
+
99
+ ```js
100
+ let distribution = require("@brown-ds/distribution")();
101
+ // Now we're only doing a few of the things we did above
102
+ distribution.node.start(() => {
103
+ // This will run only after the node has started
104
+ node = { ip: '127.0.0.1', port: 8080 };
105
+ distribution.local.status.spawn(node, () => {
106
+ // This will run only after the new node has been spawned
107
+ distribution.all.status.get('sid', (e, v) => {
108
+ // This will run only after we communicated with all nodes and got their sids
109
+ console.log(v); // { '8cf1b': '8cf1b', '8cf1c': '8cf1c' }
110
+ distribution.local.status.stop(console.log);
111
+ });
112
+ });
113
+ });
77
114
  ```
78
115
 
79
116
  # Results and Reflections
@@ -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'),id=require('../util/id'+'.js');function normalize(_0x591c23,_0x20082e){if(_0x591c23===null)return{'key':null,'gid':_0x20082e,'action':'put'};else return typeof _0x591c23==='string'?{'key':_0x591c23,'gid':_0x20082e,'action':'put'}:_0x591c23;}function mem(_0x356653){const _0x196bbd={};_0x196bbd['gid']=_0x356653['gid']||'all',_0x196bbd['hash']=_0x356653['hash']||id['naiveHash'];function _0x5b04f0(_0x23d0a8,_0x4ad4d1){log('[all.mem.g'+'et]\x20config'+'uration:\x20'+JSON['stringify'](_0x23d0a8)+'\x20context:\x20'+JSON['stringify'](_0x196bbd)),_0x23d0a8=normalize(_0x23d0a8,_0x196bbd['gid']),_0x23d0a8['gid']=_0x23d0a8['gid']||_0x196bbd['gid'];const _0x119b8a={'service':'mem','method':'get'},_0x577f36=[_0x23d0a8];if(!_0x23d0a8['key']){globalThis['distributi'+'on'][_0x196bbd['gid']]['comm']['send'](_0x577f36,_0x119b8a,(_0x22554e,_0x1f7e60)=>{const _0x1b51ed=Object['values'](_0x1f7e60)['reduce']((_0x1bd2fe,_0x39aa0c)=>_0x1bd2fe['concat'](_0x39aa0c),[]);_0x4ad4d1(_0x22554e,_0x1b51ed);});return;}const _0x288021=_0x23d0a8['key'];if(_0x288021===null){_0x4ad4d1(new TypeError('Configurat'+'ion\x20is\x20nul'+'l'));return;}globalThis['distributi'+'on']['util']['wire']['dispatchMe'+'ssage'](_0x577f36,_0x119b8a,{'key':_0x288021},_0x196bbd,_0x4ad4d1);}function _0x2728a8(_0x254a67,_0x154f9e,_0x33d4d4){log('[all.mem.p'+'ut]\x20state:'+'\x20'+JSON['stringify'](_0x254a67)+('\x20configura'+'tion:\x20')+JSON['stringify'](_0x154f9e)),_0x154f9e=_0x154f9e||globalThis['distributi'+'on']['util']['id']['getID'](_0x254a67),_0x154f9e=normalize(_0x154f9e,_0x196bbd['gid']),_0x154f9e['gid']=_0x154f9e['gid']||_0x196bbd['gid'];const _0x3519e7={'service':'mem','method':'put'},_0x415567=[_0x254a67,_0x154f9e],_0x303888=_0x154f9e['key'];if(_0x303888===null){_0x33d4d4(new TypeError('Configurat'+'ion\x20is\x20nul'+'l'));return;}globalThis['distributi'+'on']['util']['wire']['dispatchMe'+'ssage'](_0x415567,_0x3519e7,{'key':_0x303888},_0x196bbd,_0x33d4d4);}function _0x4adf94(_0x2aede1,_0x3c4fb6){log('[all.mem.d'+'el]\x20config'+'uration:\x20'+JSON['stringify'](_0x2aede1)),_0x2aede1=normalize(_0x2aede1,_0x196bbd['gid']),_0x2aede1['gid']=_0x2aede1['gid']||_0x196bbd['gid'];const _0x2bb8f7={'service':'mem','method':'del'},_0x5e54fe=[_0x2aede1],_0x21dee8=_0x2aede1['key'];if(_0x21dee8===null){_0x3c4fb6(new TypeError('Configurat'+'ion\x20is\x20nul'+'l'));return;}globalThis['distributi'+'on']['util']['wire']['dispatchMe'+'ssage'](_0x5e54fe,_0x2bb8f7,{'key':_0x21dee8},_0x196bbd,_0x3c4fb6);}function _0x22bb56(_0x572579,_0x3b7c89){log('[mem.recon'+'f]\x20configu'+'ration:\x20'+JSON['stringify'](_0x572579)+'\x20gid:\x20'+_0x196bbd['gid']),globalThis['distributi'+'on']['local']['groups']['get'](_0x196bbd['gid'],(_0x4120d2,_0x2bc999)=>{if(!_0x2bc999){_0x3b7c89(_0x4120d2);return;}globalThis['distributi'+'on']['local']['groups']['put'](_0x196bbd['gid'],_0x572579,(_0x2194b0,_0x411fcc)=>{globalThis['distributi'+'on'][_0x196bbd['gid']]['mem']['get'](null,(_0x6ee088,_0x24f514)=>{globalThis['distributi'+'on']['local']['groups']['put'](_0x196bbd['gid'],_0x2bc999,(_0x3f0344,_0x2d8cf0)=>{globalThis['distributi'+'on'][_0x196bbd['gid']]['status']['get']('nid',(_0xb514ce,_0x96f40f)=>{const _0x2ee36e=Object['values'](_0x96f40f),_0xc4b120=Object['values'](_0x572579)['map'](_0x107508=>globalThis['distributi'+'on']['util']['id']['getNID'](_0x107508));log('[mem.recon'+'f\x20received'+'\x20'+_0x24f514['length']+('\x20keys\x20from'+'\x20')+_0x96f40f['length']+'\x20nodes');let _0x1e85c2=0x2134+0x1701+-0x3835*0x1;const _0x3b61f0=()=>{if(_0x1e85c2===_0x24f514['length'])return _0x3b7c89(null);};if(_0x24f514['length']===0x1878+0x50*-0x5f+0x2*0x29c)return _0x3b7c89(null);for(const _0x250562 of _0x24f514){const _0x25d18a=globalThis['distributi'+'on']['util']['id']['getID'](_0x250562),_0x3514a1=_0x196bbd['hash'](_0x25d18a,_0xc4b120),_0x392cbf=_0x196bbd['hash'](_0x25d18a,_0x2ee36e);log('[mem.recon'+'f]\x20old\x20nid'+':\x20'+_0x3514a1+'\x20new\x20nid:\x20'+_0x392cbf);if(_0x3514a1===_0x392cbf){_0x1e85c2++,_0x3b61f0();continue;}const _0x54967f=_0x572579[_0x3514a1['substring'](-0x1*-0x7a+0x1*0x1861+-0x18db,0x92f+0x13c5+0x9*-0x337)],_0x401ab4=[{'key':_0x250562,'gid':_0x196bbd['gid']}],_0x4a9164={'service':'mem','method':'del','node':_0x54967f};log('[mem.recon'+'f]\x20deletin'+'g\x20key\x20'+_0x250562+'\x20from\x20'+JSON['stringify'](_0x4a9164)),globalThis['distributi'+'on']['local']['comm']['send'](_0x401ab4,_0x4a9164,(_0x3ca5e3,_0x5338c0)=>{globalThis['distributi'+'on'][_0x196bbd['gid']]['mem']['put'](_0x5338c0,_0x250562,(_0x526b36,_0x356fa2)=>{_0x1e85c2++,_0x3b61f0();});});}});});});});});}return{'get':_0x5b04f0,'put':_0x2728a8,'del':_0x4adf94,'reconf':_0x22bb56};}module['exports']=mem;
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(_0x543e8f){const _0x30aea1={};_0x30aea1['gid']=_0x543e8f['gid']||'all';function _0x4657fd(_0x81d5fe,_0x39c5e3){const _0x202a65=[_0x81d5fe],_0x1b1a26={'service':'status','method':'get'};globalThis['distributi'+'on'][_0x30aea1['gid']]['comm']['send'](_0x202a65,_0x1b1a26,(_0xef2e3e,_0x27ae26)=>{switch(_0x81d5fe){case'heapTotal':const _0x53e3d1=Object['values'](_0x27ae26)['reduce']((_0x46c7b4,_0x56cc4b)=>{return _0x46c7b4+_0x56cc4b;},-0x24*-0x68+-0x165c+0x7bc);return _0x39c5e3(_0xef2e3e,_0x53e3d1);break;case'nid':const _0x1bb02d=Object['values'](_0x27ae26)['reduce']((_0x2eff33,_0x5ce96f)=>{return _0x2eff33['concat'](_0x5ce96f);},[]);return _0x39c5e3(_0xef2e3e,_0x1bb02d);break;default:return _0x39c5e3(_0xef2e3e,_0x27ae26);break;}});}function _0x1575b2(_0x1fdcdc,_0x535956){globalThis['distributi'+'on']['local']['status']['spawn'](_0x1fdcdc,(_0x5a2284,_0x89795f)=>{globalThis['distributi'+'on'][_0x30aea1['gid']]['comm']['send']([_0x30aea1['gid'],_0x1fdcdc],{'service':'groups','method':'add'},()=>{});if(_0x5a2284)return _0x535956(_0x5a2284);globalThis['distributi'+'on']['local']['groups']['add'](_0x30aea1['gid'],_0x1fdcdc,()=>{return _0x535956(null,_0x89795f);});});}function _0x5ee009(_0x1354c7){globalThis['distributi'+'on'][_0x30aea1['gid']]['comm']['send']([],{'service':'status','method':'stop'},()=>{globalThis['distributi'+'on']['local']['status']['stop'](_0x1354c7);});}return{'get':_0x4657fd,'stop':_0x5ee009,'spawn':_0x1575b2};}module['exports']=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'),id=require('../util/id'+'.js');function getNode(_0x54f2ab,_0x104310,_0x417e49){const _0x286a0c=_0x104310&&typeof _0x104310==='object'?_0x104310['key']:_0x104310;globalThis['distributi'+'on'][_0x54f2ab['gid']]['status']['get']('nid',(_0x1bb184,_0x1094d6)=>{const _0x4ce8c6=Object['values'](_0x1094d6),_0x170a06=globalThis['distributi'+'on']['util']['id']['getID'](_0x286a0c),_0x884c49=_0x54f2ab['hash'](_0x170a06,_0x4ce8c6),_0x3b2660=_0x884c49['substring'](0x756+0xf51+0x16a7*-0x1,0x2*-0xe35+0x674+0x15fb);globalThis['distributi'+'on']['local']['groups']['get'](_0x54f2ab['gid'],(_0x417d10,_0x1e541a)=>{if(!_0x1e541a)return _0x417e49(_0x417d10);else{const _0x5a6480=_0x1e541a[_0x3b2660];return log('[store\x20(ge'+'tNode)]\x20co'+'nfiguratio'+'n:\x20'+JSON['stringify'](_0x104310)+'group:\x20'+JSON['stringify'](_0x1e541a)+'\x20node:\x20'+JSON['stringify'](_0x5a6480)+'nid:\x20'+JSON['stringify'](_0x884c49)+'\x20sid:\x20'+JSON['stringify'](_0x3b2660)),_0x417e49(null,_0x5a6480);}});});}function normalize(_0x58ddde,_0x2fc7b5){if(_0x58ddde===null)return{'key':null,'gid':_0x2fc7b5,'action':'put'};else return typeof _0x58ddde==='string'?{'key':_0x58ddde,'gid':_0x2fc7b5,'action':'put'}:_0x58ddde;}function store(_0x4ce0c4){const _0x342ef9={'gid':_0x4ce0c4['gid']||'all','hash':_0x4ce0c4['hash']||id['naiveHash'],'subset':_0x4ce0c4['subset']};function _0x5eee3b(_0x31d5d4,_0x45697f){if(!_0x31d5d4){const _0x4f822c=[{'key':null,'gid':_0x342ef9['gid']}];globalThis['distributi'+'on'][_0x342ef9['gid']]['comm']['send'](_0x4f822c,{'service':'store','method':'get'},(_0x24701d,_0x59d7ae)=>{const _0x27749b=Object['values'](_0x59d7ae)['reduce']((_0x3ffffc,_0x80eed9)=>_0x3ffffc['concat'](_0x80eed9),[]);_0x45697f(_0x24701d,_0x27749b);});return;}_0x31d5d4=normalize(_0x31d5d4,_0x342ef9['gid']),getNode(_0x342ef9,_0x31d5d4,(_0x4b8867,_0x524904)=>{if(!_0x524904){_0x45697f(_0x4b8867);return;}const _0x3578bd=[_0x31d5d4],_0x3061cf={'service':'store','method':'get','node':_0x524904};log('[all.store'+'.get]confi'+'guration:\x20'+JSON['stringify'](_0x31d5d4)+'node:\x20'+JSON['stringify'](globalThis['distributi'+'on']['node']['config'])+('\x20target\x20no'+'de:\x20')+JSON['stringify'](_0x524904)),globalThis['distributi'+'on']['local']['comm']['send'](_0x3578bd,_0x3061cf,_0x45697f);});}function _0x258e41(_0x2d3ff1,_0x469b5e,_0x41fd2b){_0x469b5e=_0x469b5e||globalThis['distributi'+'on']['util']['id']['getID'](_0x2d3ff1),_0x469b5e=normalize(_0x469b5e,_0x342ef9['gid']),getNode(_0x342ef9,_0x469b5e,(_0x15be48,_0x14b088)=>{if(!_0x14b088){_0x41fd2b(_0x15be48);return;}const _0x2e5ef8=[_0x2d3ff1,_0x469b5e],_0x4a465f={'service':'store','method':'put','node':_0x14b088};log('[all.store'+'.put]\x20stat'+'e:\x20'+JSON['stringify'](_0x2d3ff1)+('configurat'+'ion:\x20')+JSON['stringify'](_0x469b5e)+('target\x20nod'+'e:\x20')+JSON['stringify'](_0x14b088)),globalThis['distributi'+'on']['local']['comm']['send'](_0x2e5ef8,_0x4a465f,_0x41fd2b);});}function _0x43d7ee(_0x5e4181,_0x599c54){getNode(_0x342ef9,_0x5e4181,(_0x3e7c40,_0x2e63a2)=>{if(!_0x2e63a2){_0x599c54(_0x3e7c40);return;}const _0x3af5a1=[{'key':_0x5e4181,'gid':_0x342ef9['gid']}],_0x1dc4d1={'service':'store','method':'del','node':_0x2e63a2};globalThis['distributi'+'on']['local']['comm']['send'](_0x3af5a1,_0x1dc4d1,_0x599c54);});}function _0x125e7f(_0x24a30c,_0xa57bbb){log('[store.rec'+'onf]\x20confi'+'guration:\x20'+JSON['stringify'](_0x24a30c)+'\x20gid:\x20'+_0x342ef9['gid']),globalThis['distributi'+'on']['local']['groups']['get'](_0x342ef9['gid'],(_0x3617a4,_0x16ec7c)=>{if(!_0x16ec7c){_0xa57bbb(_0x3617a4);return;}globalThis['distributi'+'on']['local']['groups']['put'](_0x342ef9['gid'],_0x24a30c,(_0x3b0ae4,_0x30e7ab)=>{globalThis['distributi'+'on'][_0x342ef9['gid']]['store']['get'](null,(_0x14b1ba,_0x731a19)=>{globalThis['distributi'+'on']['local']['groups']['put'](_0x342ef9['gid'],_0x16ec7c,(_0x148482,_0xe6899f)=>{globalThis['distributi'+'on'][_0x342ef9['gid']]['status']['get']('nid',(_0xa49683,_0x25087d)=>{const _0x1c4cfb=Object['values'](_0x25087d),_0x47f47e=Object['values'](_0x24a30c)['map'](_0xc416e7=>globalThis['distributi'+'on']['util']['id']['getNID'](_0xc416e7));log('[store.rec'+'onf\x20receiv'+'ed\x20'+_0x731a19['length']+('\x20keys\x20from'+'\x20')+_0x25087d['length']+'\x20nodes');let _0xa392ee=-0x657+-0x26b*0x4+-0x1003*-0x1;const _0x43432d=()=>{if(_0xa392ee===_0x731a19['length'])return _0xa57bbb(null);};if(_0x731a19['length']===-0xb43*-0x1+-0x12da*-0x1+0x1e1d*-0x1)return _0xa57bbb(null);for(const _0x4cda3e of _0x731a19){const _0x18d567=globalThis['distributi'+'on']['util']['id']['getID'](_0x4cda3e),_0x138fb2=_0x342ef9['hash'](_0x18d567,_0x47f47e),_0x9791cf=_0x342ef9['hash'](_0x18d567,_0x1c4cfb);log('[store.rec'+'onf]\x20old\x20n'+'id:\x20'+_0x138fb2+'\x20new\x20nid:\x20'+_0x9791cf);if(_0x138fb2===_0x9791cf){_0xa392ee++,_0x43432d();continue;}const _0x48e3af=_0x24a30c[_0x138fb2['substring'](0x1b5*0x14+-0x17*-0x65+-0x2b37,0x324+-0x1*-0x18c5+0x4*-0x6f9)],_0x2a66f7=[{'key':_0x4cda3e,'gid':_0x342ef9['gid']}],_0x465828={'service':'store','method':'del','node':_0x48e3af};log('[store.rec'+'onf]\x20delet'+'ing\x20key\x20'+_0x4cda3e+'\x20from\x20'+JSON['stringify'](_0x465828)),globalThis['distributi'+'on']['local']['comm']['send'](_0x2a66f7,_0x465828,(_0x4628e6,_0x3ef34a)=>{globalThis['distributi'+'on'][_0x342ef9['gid']]['store']['put'](_0x3ef34a,_0x4cda3e,(_0x2dd16d,_0x53a8b6)=>{_0xa392ee++,_0x43432d();});});}});});});});});}return{'get':_0x5eee3b,'put':_0x258e41,'del':_0x43d7ee,'reconf':_0x125e7f};}module['exports']=store;
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'),serialization=require('../util/se'+'rializatio'+'n.js'),log=require('../util/lo'+'g.js');function send(_0x224dea,_0x7093a8,_0x5d4715){_0x224dea=_0x224dea||[];if(!_0x7093a8){_0x5d4715(new Error('Remote\x20is\x20'+'required'));return;}const _0x4e2e21=_0x7093a8['node'],_0x56ac91=_0x7093a8['service'],_0x48edf5=_0x7093a8['method'],_0x2e4c6b=_0x7093a8['gid']||'local';if(!(_0x224dea instanceof Array)){_0x5d4715(new Error('Message\x20mu'+'st\x20be\x20an\x20a'+'rray'));return;}if(!_0x4e2e21){_0x5d4715(new Error('Node\x20is\x20re'+'quired'));return;}if(!_0x56ac91){_0x5d4715(new Error('Service\x20is'+'\x20required'));return;}if(!_0x48edf5){_0x5d4715(new Error('Method\x20is\x20'+'required'));return;}log('[comm.send'+']:\x20Sending'+'\x20'+JSON['stringify'](_0x224dea)+'\x20to\x20'+_0x7093a8['service']+':'+_0x7093a8['method']+'\x20on\x20'+_0x7093a8['node']['ip']+':'+_0x7093a8['node']['port']);const _0xa6cadd=serialization['serialize'](_0x224dea),_0xe13459={'hostname':_0x4e2e21['ip'],'port':_0x4e2e21['port'],'path':'/'+_0x2e4c6b+'/'+_0x56ac91+'/'+_0x48edf5,'method':'PUT','headers':{'Content-Type':'applicatio'+'n/json','Content-Length':Buffer['byteLength'](_0xa6cadd)}},_0x5e937b=http['request'](_0xe13459,_0x581cf3=>{let _0x442a8e='';_0x581cf3['on']('data',function(_0x242e2d){_0x442a8e+=_0x242e2d;}),_0x581cf3['on']('end',function(){const [_0x1d6204,_0x55b1e9]=serialization['deserializ'+'e'](_0x442a8e);if(_0x5d4715)return _0x5d4715(_0x1d6204,_0x55b1e9);}),_0x581cf3['on']('error',_0x3a1543=>{if(_0x5d4715)return _0x5d4715(new Error('Error\x20on\x20r'+'esponse'));});});_0x5e937b['on']('error',_0x82e349=>{if(_0x5d4715)return _0x5d4715(new Error(_0x82e349));}),_0x5e937b['write'](_0xa6cadd),_0x5e937b['end']();}module['exports']={'send':send};
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'),args=require('yargs')['argv'];function setNodeConfig(){let _0x41c15b,_0x2ce115,_0x1f9a29;typeof args['ip']==='string'&&(_0x41c15b=args['ip']);typeof args['port']==='string'&&(_0x2ce115=parseInt(args['port']));if(typeof args['config']==='string'){const {ip:_0x44fcbd,port:_0x335446,onStart:_0x16a4f5}=globalThis['distributi'+'on']['util']['deserializ'+'e'](args['config']);typeof _0x44fcbd==='string'&&(_0x41c15b=_0x44fcbd),typeof _0x335446==='number'&&(_0x2ce115=_0x335446),typeof _0x16a4f5==='function'&&(_0x1f9a29=_0x16a4f5);}return _0x41c15b=_0x41c15b||'127.0.0.1',_0x2ce115=_0x2ce115||0x16c7+-0xb*-0x293+-0x1*0x2e46,{'ip':_0x41c15b,'port':_0x2ce115,'onStart':_0x1f9a29};}function validate(_0x35101b){if(_0x35101b['length']===-0x1bc8+0x15f0+0x58*0x11)throw new Error('No\x20body');return JSON['parse'](_0x35101b);}function start(_0x2edead){const _0x3eca42=http['createServ'+'er']((_0x1144bd,_0x651cbe)=>{if(_0x1144bd['method']!=='PUT'){_0x651cbe['end'](globalThis['distributi'+'on']['util']['serialize'](new Error('Method\x20not'+'\x20allowed!')));return;}const [,_0x4ddf2c,_0x3e5e05,_0x56a5d5]=url['parse'](_0x1144bd['url'])['pathname']['split']('/');log('[server]\x20g'+'ot\x20request'+'\x20'+_0x4ddf2c+'\x20'+_0x3e5e05+':'+_0x56a5d5+'\x20from\x20'+_0x1144bd['socket']['remoteAddr'+'ess']);const _0x57b4da=[];_0x1144bd['on']('data',_0x533dcf=>{_0x57b4da['push'](_0x533dcf);}),_0x1144bd['on']('end',()=>{let _0x3f49c4;try{_0x3f49c4=validate(Buffer['concat'](_0x57b4da)['toString']());}catch(_0x2e25d3){_0x651cbe['end'](globalThis['distributi'+'on']['util']['serialize']([_0x2e25d3]));return;}const _0x479c5d=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x3f49c4);!Array['isArray'](_0x479c5d)&&_0x651cbe['end'](globalThis['distributi'+'on']['util']['serialize']([new Error('Invalid\x20ar'+'gument\x20typ'+'e,\x20expecte'+'d\x20array,\x20g'+'ot\x20'+typeof _0x479c5d)]));const _0x41ed9f=_0x3e5e05;globalThis['distributi'+'on']['local']['routes']['get']({'service':_0x3e5e05,'gid':_0x4ddf2c},(_0x544747,_0x10a68a)=>{if(_0x544747){_0x651cbe['end'](globalThis['distributi'+'on']['util']['serialize']([_0x544747,null]));return;}if(!_0x10a68a[_0x56a5d5]){_0x651cbe['end'](globalThis['distributi'+'on']['util']['serialize']([new Error('Method\x20'+_0x56a5d5+('\x20not\x20found'+'\x20in\x20servic'+'e\x20')+_0x41ed9f),null]));return;}log('[server]\x20\x20'+'Calling\x20se'+'rvice:\x20'+_0x41ed9f+':'+_0x56a5d5+('\x20with\x20args'+':\x20')+JSON['stringify'](_0x479c5d));_0x479c5d['length']===0x1f2e*-0x1+0x1020+0xf0f&&_0x10a68a[_0x56a5d5]['length']===-0x1342+-0x1*-0x2072+-0xd2d&&_0x479c5d['push'](undefined);const _0x273bc1=_0x10a68a[_0x56a5d5]['bind'](_0x10a68a),_0x3746ab=globalThis['distributi'+'on']['util']['normalize'](_0x273bc1,_0x479c5d);try{_0x273bc1(..._0x3746ab,(_0x310183,_0x1473b2)=>_0x651cbe['end'](globalThis['distributi'+'on']['util']['serialize']([_0x310183,_0x1473b2])));}catch(_0x463d82){_0x651cbe['end'](globalThis['distributi'+'on']['util']['serialize']([_0x463d82,null]));}});});}),_0x3e09d7=globalThis['distributi'+'on']['node']['config'];_0x3eca42['listen'](_0x3e09d7['port'],_0x3e09d7['ip'],()=>{log('Server\x20run'+'ning\x20at\x20ht'+'tp://'+_0x3e09d7['ip']+':'+_0x3e09d7['port']+'/'),globalThis['distributi'+'on']['node']['server']=_0x3eca42,_0x2edead();}),_0x3eca42['on']('error',_0x56cfe6=>{log('Server\x20err'+'or:\x20'+_0x56cfe6);throw _0x56cfe6;});}module['exports']={'start':start,'config':setNodeConfig()};
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=0x2*0x5f7+-0xd2a*-0x1+-0x1918;function get(_0x1d680b,_0x4be35a){if(_0x1d680b in globalThis['distributi'+'on']['node']['config']){_0x4be35a(null,globalThis['distributi'+'on']['node']['config'][_0x1d680b]);return;}if(_0x1d680b==='sid'){_0x4be35a(null,globalThis['distributi'+'on']['util']['id']['getSID'](globalThis['distributi'+'on']['node']['config']));return;}if(_0x1d680b==='nid'){_0x4be35a(null,globalThis['distributi'+'on']['util']['id']['getNID'](globalThis['distributi'+'on']['node']['config']));return;}if(_0x1d680b==='counts'){_0x4be35a(null,counts);return;}if(_0x1d680b==='heapTotal'){_0x4be35a(null,process['memoryUsag'+'e']()['heapTotal']);return;}if(_0x1d680b==='heapUsed'){_0x4be35a(null,process['memoryUsag'+'e']()['heapUsed']);return;}_0x4be35a(new Error('Status\x20key'+'\x20not\x20found'));};const fs=require('fs'),path=require('path'),proc=require('node:child'+'_process');function getDistribution(){let _0x5455b3=path['join'](process['cwd'](),'config.js');if(fs['existsSync'](_0x5455b3))return _0x5455b3;try{const _0x441f08=proc['execSync']('git\x20rev-pa'+'rse\x20--show'+'-toplevel',{'encoding':'utf8'})['trim']();_0x5455b3=path['join'](_0x441f08,'config.js');if(fs['existsSync'](_0x5455b3))return _0x5455b3;}catch(_0x99b481){throw new Error('Not\x20in\x20a\x20G'+'it\x20reposit'+'ory\x20or\x20git'+'\x20command\x20f'+'ailed.');}_0x5455b3=path['join'](__dirname,'../../','config.js');if(fs['existsSync'](_0x5455b3))return _0x5455b3;_0x5455b3=path['join'](__dirname,'../../','distributi'+'on.js');if(fs['existsSync'](_0x5455b3))return _0x5455b3;throw new Error('Failed\x20to\x20'+'find\x20proje'+'ct\x20root.');}function createOnStart(_0x2d7911,_0x4c59b1){const _0x5a5dbe='\x0a\x20\x20\x20\x20let\x20o'+'nStart\x20=\x20'+_0x2d7911['toString']()+(';\x0a\x20\x20\x20\x20let\x20'+'callbackRP'+'C\x20=\x20')+globalThis['distributi'+'on']['util']['wire']['createRPC'](globalThis['distributi'+'on']['util']['wire']['toAsync'](_0x4c59b1))['toString']()+(';\x0a\x20\x20\x20\x20try\x20'+'{\x0a\x20\x20\x20\x20\x20\x20on'+'Start();\x0a\x20'+'\x20\x20\x20\x20\x20callb'+'ackRPC(nul'+'l,\x20global.'+'distributi'+'on.node.co'+'nfig,\x20()\x20='+'>\x20{});\x0a\x20\x20\x20'+'\x20}\x20catch(e'+')\x20{\x0a\x20\x20\x20\x20\x20\x20'+'callbackRP'+'C(e,\x20null,'+'\x20()\x20=>\x20{})'+';\x0a\x20\x20\x20\x20}\x0a\x20\x20');return new Function(_0x5a5dbe);}function spawn(_0x4f0991,_0x1b0bd2){const _0x46f8bb=_0x4f0991;_0x46f8bb['onStart']=_0x46f8bb['onStart']||function(){};if(!_0x46f8bb['port']||!_0x46f8bb['ip']){_0x1b0bd2(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'](_0x46f8bb));const _0x3a74a8=(_0x4222ef,_0x5dcaf9)=>{if(_0x4222ef){_0x1b0bd2(_0x4222ef);return;}globalThis['distributi'+'on']['local']['groups']['add']('all',_0x5dcaf9,()=>{_0x1b0bd2(_0x4222ef,_0x5dcaf9);});};_0x46f8bb['onStart']=createOnStart(_0x46f8bb['onStart'],_0x3a74a8);const _0xc572dd=getDistribution(),_0x2b3e41=proc['spawn']('node',[_0xc572dd,'--config',globalThis['distributi'+'on']['util']['serialize'](_0x46f8bb)],{'detached':!![],'stdio':'inherit'});_0x2b3e41;}function stop(_0x3c79f9){return log('[status.st'+'op]\x20Shutti'+'ng\x20down\x20no'+'de'),globalThis['distributi'+'on']['node']['server']['close'](),process['nextTick'](()=>process['exit'](0x3*-0x43+-0x1b*0x115+0x1e00)),_0x3c79f9(null,globalThis['distributi'+'on']['node']['config']);}module['exports']={'get':get,'spawn':spawn,'stop':stop};
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('node:fs'),path=require('node:path'),logFile=path['join']('/tmp','log.txt');function log(_0x3ac907,_0x284121){!_0x284121&&(_0x284121='info');const _0x37f7ee=new Date(),_0x1eac02=new Intl['DateTimeFo'+'rmat']('en-GB',{'day':'2-digit','month':'2-digit','year':'numeric','hour':'2-digit','minute':'2-digit','second':'2-digit','hour12':![]})['format'](_0x37f7ee)+'.'+String(_0x37f7ee['getMillise'+'conds']()*(0x914+0x1dfa*-0x1+0x5*0x4f6))['padStart'](0x1c2c+-0x10*-0x1e+-0x44a*0x7,'0'),_0x5aa946=globalThis['distributi'+'on']['util']['id']['getSID'](globalThis['distributi'+'on']['node']['config']);fs['appendFile'+'Sync'](logFile,_0x1eac02+'\x20['+globalThis['distributi'+'on']['node']['config']['ip']+':'+globalThis['distributi'+'on']['node']['config']['port']+'\x20('+_0x5aa946+')]\x20['+_0x284121+']\x20'+_0x3ac907+'\x0a');}module['exports']=log;
9
+ const fs=require('node:fs'),path=require('node:path'),logFile=process['env']['DISTRIBUTI'+'ON_LOG_FIL'+'E']||path['join']('/tmp','log.txt');function log(_0x4f06c4,_0x1ac06e){!_0x1ac06e&&(_0x1ac06e='info');const _0x3f9755=new Date(),_0x10586b=new Intl['DateTimeFo'+'rmat']('en-GB',{'day':'2-digit','month':'2-digit','year':'numeric','hour':'2-digit','minute':'2-digit','second':'2-digit','hour12':![]})['format'](_0x3f9755)+'.'+String(_0x3f9755['getMillise'+'conds']()*(-0xdd3*-0x1+0x2555+-0xbd0*0x4))['padStart'](-0x211c+-0x829*-0x4+-0x1*-0x7e,'0'),_0x59d4f4=globalThis['distributi'+'on']['util']['id']['getSID'](globalThis['distributi'+'on']['node']['config']);fs['appendFile'+'Sync'](logFile,_0x10586b+'\x20['+globalThis['distributi'+'on']['node']['config']['ip']+':'+globalThis['distributi'+'on']['node']['config']['port']+'\x20('+_0x59d4f4+')]\x20['+_0x1ac06e+']\x20'+_0x4f06c4+'\x0a');}module['exports']=log;
10
10
  /* eslint-enable */
package/distribution.js CHANGED
@@ -9,11 +9,6 @@ const log = require('./distribution/util/log.js');
9
9
  * @param {Node} [config]
10
10
  */
11
11
  function bootstrap(config) {
12
- if (globalThis.distribution) {
13
- log('global.distribution has already been setup');
14
- return;
15
- }
16
-
17
12
  // @ts-ignore This is the first time globalThis.distribution is being initialized, so the object does not have all the necessary properties.
18
13
  globalThis.distribution = {};
19
14
  globalThis.distribution.util = require('./distribution/util/util.js');
@@ -35,12 +30,14 @@ function bootstrap(config) {
35
30
  /* Overrides when missing functionality from previous milestone or extra credit is needed */
36
31
 
37
32
  // For M3, when missing RPC, its path through routes, and status.{spawn, stop}
38
- /*
39
- globalThis.distribution.util.wire.createRPC = require('@brown-ds/distribution').util.wire.createRPC;
40
- globalThis.distribution.local.routes.get = require('@brown-ds/distribution').local.routes.get;
41
- globalThis.distribution.local.status.spawn = require('@brown-ds/distribution').local.status.spawn;
42
- globalThis.distribution.local.status.stop = require('@brown-ds/distribution').local.status.stop;
43
- */
33
+ /* __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;
39
+ __end_M3_solution__ */
40
+ return globalThis.distribution;
44
41
  }
45
42
 
46
43
  /*
@@ -58,15 +55,24 @@ const distribution = useLibrary ? require('@brown-ds/distribution') : bootstrap;
58
55
 
59
56
  /* The following code is run when distribution.js is run directly */
60
57
  if (require.main === module) {
61
- distribution();
58
+ globalThis.distribution = distribution();
62
59
  // __start_solution__
63
60
  log(
64
61
  `[node] Starting node with configuration: ${
65
62
  JSON.stringify(globalThis.distribution.node.config)
66
63
  }`,
67
64
  );
65
+ globalThis.distribution.node.start(globalThis.distribution.node.config.onStart || (() => {
66
+ const repl = require('node:repl');
67
+ repl.start({
68
+ prompt: `${globalThis.distribution.util.id.getSID(globalThis.distribution.node.config)}> `,
69
+ input: process.stdin,
70
+ output: process.stdout,
71
+ terminal: true,
72
+ useGlobal: true,
73
+ });
74
+ }));
68
75
  // __end_solution__
69
- globalThis.distribution.node.start(globalThis.distribution.node.config.onStart || (() => {}));
70
76
  }
71
77
 
72
78
  module.exports = distribution;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brown-ds/distribution",
3
- "version": "0.2.16",
3
+ "version": "0.2.19",
4
4
  "description": "A library for building distributed systems.",
5
5
  "main": "distribution.js",
6
6
  "useLibrary": false,