cryptpad-server 0.0.3 → 0.0.5

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/index.js CHANGED
@@ -47,6 +47,14 @@ args.some(arg => {
47
47
  prev = '';
48
48
  });
49
49
 
50
+ // Clean quit: kill child processes
51
+ const childPids = [];
52
+
53
+ const cleanSubprocesses = () => childPids.forEach((pid) => process.kill(pid));
54
+
55
+ process.on('SIGTERM', cleanSubprocesses);
56
+ process.on('exit', cleanSubprocesses);
57
+
50
58
  const start = (serverConfig, infraConfig) => {
51
59
  const Log = {
52
60
  debug: console.debug,
@@ -57,9 +65,7 @@ const start = (serverConfig, infraConfig) => {
57
65
  };
58
66
 
59
67
  let serverId;
60
- const startNode = (type, index, forking, cb) => {
61
- if (typeof (cb) !== 'function') { cb = () => { }; };
62
-
68
+ const startNode = (type, index, forking) => new Promise((resolve, reject) => {
63
69
  const nodeFile = './build/' + type + '.js';
64
70
  const path = Path.join(__dirname, nodeFile);
65
71
  const initConfig = {
@@ -72,51 +78,49 @@ const start = (serverConfig, infraConfig) => {
72
78
  //Log.info(`Starting: ${initConfig.myId}`);
73
79
  if (forking) {
74
80
  let nodeProcess = fork(path);
81
+ childPids.push(nodeProcess.pid);
75
82
  nodeProcess.send(initConfig);
76
83
  nodeProcess.on('message', (message) => {
77
84
  if (message.msg === 'READY') {
78
- Log.info(`Started: ${type}:${message.index}`);
85
+ // Log.info(`Started: ${type}:${message.index}`);
79
86
  if (message.dev) {
80
87
  Log.info('DEV mode enabled');
81
88
  }
82
- cb();
89
+ resolve();
83
90
  }
84
91
  });
85
- // FIXME
86
92
  nodeProcess.on('error', (err) => {
87
93
  Log.error('Child process stopped due to error.');
88
94
  Log.error(err);
95
+ reject(`${type}:${index}: error ${err}`);
89
96
  process.exit(1);
90
97
  });
91
98
  nodeProcess.on('exit', (err) => {
92
99
  Log.error('Child process stopped due to error.');
93
100
  Log.error(err);
94
- process.exit(1);
101
+ reject(`${type}:${index}: exit(${err})`);
102
+ process.exit(err);
95
103
  });
96
104
  } else {
105
+ // Single process start
106
+ // Can only be called from CLI and not from external module
97
107
  require(path).start(initConfig);
98
108
  }
99
- };
109
+ });
100
110
 
101
111
  const coresReady = () => {
102
112
  const promises = [];
103
113
  infraConfig?.front?.forEach((data, index) => {
104
- promises.push(new Promise(resolve => {
105
- if (serverId && data.serverId !== serverId) { return resolve(); }
106
- startNode('front', index, true, resolve);
107
- }));
114
+ if (serverId && data.serverId !== serverId) { return; }
115
+ promises.push(startNode('front', index, true));
108
116
  });
109
117
  infraConfig?.storage?.forEach((data, index) => {
110
- promises.push(new Promise(resolve => {
111
- if (serverId && data.serverId !== serverId) { return resolve(); }
112
- startNode('storage', index, true, resolve);
113
- }));
118
+ if (serverId && data.serverId !== serverId) { return; }
119
+ promises.push(startNode('storage', index, true));
114
120
  });
115
- promises.push(new Promise(resolve => {
116
- if (serverId && infraConfig?.public?.httpServerId !== serverId) { return resolve(); }
117
- startNode('http', 0, true, resolve);
118
- }));
119
- Promise.all(promises).then(() => {
121
+ if (serverId && infraConfig?.public?.httpServerId !== serverId) { return; }
122
+ promises.push(startNode('http', 0, true));
123
+ return Promise.all(promises.filter(Boolean)).then(() => {
120
124
  Log.info('CryptPad server ready');
121
125
  });
122
126
  };
@@ -128,21 +132,14 @@ const start = (serverConfig, infraConfig) => {
128
132
  }
129
133
  serverConfig.private.nodes_key = Crypto.randomBytes(32).toString('base64');
130
134
  }
131
- const corePromises = infraConfig?.core.map((data, index) => new Promise((resolve, reject) => {
135
+ const corePromises = infraConfig?.core.map((data, index) => {
132
136
  // hosted on another machine?
133
- if (serverId && data.serverId !== serverId) { return resolve(); }
134
- startNode('core', index, true, (err) => {
135
- if (err) {
136
- Log.error('START_CORE_ERROR', err);
137
- return reject(err);
138
- }
139
- return resolve();
140
- });
141
- }));
137
+ if (serverId && data.serverId !== serverId) { return; }
138
+ return startNode('core', index, true);
139
+ });
142
140
 
143
- Promise.all(corePromises)
144
- .then(() => { coresReady(); })
145
- .catch((e) => { return Log.error('START_CORE_ERROR', e); });
141
+ return Promise.all(corePromises.filter(Boolean))
142
+ .then(() => coresReady());
146
143
  };
147
144
 
148
145
 
@@ -153,18 +150,18 @@ const start = (serverConfig, infraConfig) => {
153
150
  if (!serverConfig?.private?.nodes_key) {
154
151
  throw Error('E_MISSINGKEY');
155
152
  }
156
- startNode(type, index, false, (err) => {
153
+ return startNode(type, index, false).catch((err) => {
157
154
  if (err) { return Log.error('START_NODE_ERROR', err); }
158
155
  });
159
156
  } else {
160
157
  serverId = cliArgs.server;
161
- startCores();
158
+ return startCores();
162
159
  }
163
160
  };
164
161
 
165
162
  if (require.main === module) {
166
- const { config, infra } = require('./common/load-config');
167
- start(config, infra);
163
+ const { config, infra } = require('./common/load-config')();
164
+ start(config, infra).catch((e) => { console.error('CryptPad server start failed:', e); });
168
165
  } else {
169
166
  module.exports = { start };
170
167
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cryptpad-server",
3
3
  "description": "CryptPad Server",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "license": "AGPL-3.0+",
6
6
  "repository": {
7
7
  "type": "git",
@@ -16,12 +16,13 @@
16
16
  "build"
17
17
  ],
18
18
  "dependencies": {
19
+ "@mcrowe/minibloom": "^0.2.0",
19
20
  "connect-gzip-static": "^4.2.1",
20
21
  "cookie-parser": "^1.4.7",
21
22
  "express": "~5.2.1",
22
- "mime-types": "^3.0.2",
23
23
  "fs-extra": "^7.0.0",
24
24
  "http-proxy-middleware": "^3.0.3",
25
+ "mime-types": "^3.0.2",
25
26
  "nthen": "0.1.8",
26
27
  "otpauth": "^9.4.1",
27
28
  "pull-stream": "^3.6.1",
@@ -61,6 +62,7 @@
61
62
  "build:core": "TYPE=core rollup -c",
62
63
  "build:storage": "TYPE=storage rollup -c",
63
64
  "build:http": "TYPE=http rollup -c",
65
+ "build:eviction": "TYPE=eviction rollup -c",
64
66
  "tests": "node --test tests/",
65
67
  "test": "node tests/runAll.js",
66
68
  "start": "node index.js",
package/readme.md CHANGED
@@ -90,12 +90,8 @@ node index.js --server [serverId value]
90
90
  The directory [`tests`](tests/) contains some unit and integration tests scripts
91
91
  and files.
92
92
 
93
- - [`interface.test.js`](tests/interface.test.js): test the communication
94
- interface by implementing a simple ping-pong protocol that computes the time it
95
- takes to go back and forth in the network.
96
-
97
93
  The aforementioned tests can be run with the following command (make sure to
98
94
  have installed the dependencies with `npm install` beforehand):
99
95
  ```bash
100
- npm run tests
96
+ npm run test
101
97
  ```