antietcd 1.2.3 → 1.2.4

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
@@ -105,17 +105,19 @@ Options:
105
105
  <dd>Use TLS with this key file (PEM format)</dd>
106
106
 
107
107
  <dt>--ca &lt;ca&gt;</dt>
108
- <dd>Use trusted root certificates from this file.
109
- Specify &lt;ca&gt; = &lt;cert&gt; if your certificate is self-signed.</dd>
108
+ <dd>Use trusted root certificates from this file</dd>
109
+
110
+ <dt>--peer_ca &lt;cert&gt;</dt>
111
+ <dd>Use this CA to verify peer antietcd certificates (defaults to the same --cert)</dd>
110
112
 
111
113
  <dt>--client_cert_auth 1</dt>
112
- <dd>Require TLS client certificates signed by <ca> or by default CA to connect.</dd>
114
+ <dd>Require TLS client certificates signed by <ca> or by default CA to connect</dd>
113
115
 
114
116
  <dt>--ws_keepalive_interval 30000</dt>
115
117
  <dd>Client websocket ping (keepalive) interval in milliseconds</dd>
116
118
 
117
119
  <dt>--use_base64 1</dt>
118
- <dd>Use base64 encoding of keys and values, like in etcd (enabled by default).</dd>
120
+ <dd>Use base64 encoding of keys and values, like in etcd (enabled by default)</dd>
119
121
 
120
122
  </dl>
121
123
 
package/anticluster.js CHANGED
@@ -29,6 +29,16 @@ class AntiCluster
29
29
  this.cfg.cluster = (''+this.cfg.cluster).trim().split(/[\s,]*,[\s,]*/)
30
30
  .reduce((a, c) => { c = c.split(/\s*=\s*/); a[c[0]] = c[1]; return a; }, {});
31
31
  }
32
+ this.tls = {};
33
+ if (antietcd.tls)
34
+ {
35
+ this.tls = {
36
+ cert: antietcd.tls.cert,
37
+ key: antietcd.tls.key,
38
+ ca: antietcd.peer_ca || antietcd.tls.cert,
39
+ requestCert: true,
40
+ };
41
+ }
32
42
  this.raft = new TinyRaft({
33
43
  nodes: Object.keys(this.cfg.cluster),
34
44
  nodeId: this.cfg.node_id,
@@ -53,7 +63,7 @@ class AntiCluster
53
63
  if (node_id != this.cfg.node_id && this.cfg.cluster[node_id] &&
54
64
  (!this.cluster_connections[node_id] || !this.antietcd.clients[this.cluster_connections[node_id]]))
55
65
  {
56
- const socket = new ws.WebSocket(this.cfg.cluster[node_id].replace(/^http/, 'ws'), this.antietcd.tls);
66
+ const socket = new ws.WebSocket(this.cfg.cluster[node_id].replace(/^http/, 'ws'), this.tls);
57
67
  const client_id = this.antietcd._startWebsocket(socket, () => setTimeout(() => this.connectToNode(node_id), this.cfg.reconnect_interval||1000));
58
68
  this.cluster_connections[node_id] = client_id;
59
69
  socket.on('open', () =>
package/antietcd-app.js CHANGED
@@ -13,7 +13,7 @@ License: Mozilla Public License 2.0 or Vitastor Network Public License 1.1
13
13
  Usage:
14
14
 
15
15
  ${process.argv[0]} ${process.argv[1]} \n\
16
- [--cert ssl.crt] [--key ssl.key] [--port 12379] \n\
16
+ [--cert ssl.crt] [--key ssl.key] [--ca ca.crt] [--peer_ca ssl.crt] [--port 12379] \n\
17
17
  [--data data.gz] [--persist-filter ./filter.js] [--persist_interval 500] \n\
18
18
  [--node_id node1 --cluster_key abcdef --cluster node1=http://localhost:12379,node2=http://localhost:12380,node3=http://localhost:12381] \n\
19
19
  [other options]
@@ -38,7 +38,8 @@ HTTP:
38
38
  Use TLS with this key file (PEM format)
39
39
  --ca <ca>
40
40
  Use trusted root certificates from this file.
41
- Specify <ca> = <cert> if your certificate is self-signed.
41
+ --peer_ca <cert>
42
+ Use this CA to verify peer antietcd certificates (defaults to the same --cert).
42
43
  --client_cert_auth 1
43
44
  Require TLS client certificates signed by <ca> or by default CA to connect.
44
45
  --ws_keepalive_interval 30000
package/antietcd.js CHANGED
@@ -20,7 +20,7 @@ const AntiCluster = require('./anticluster.js');
20
20
  const AntiLocker = require('./antilocker.js');
21
21
  const { runCallbacks, de64, b64, RequestError } = require('./common.js');
22
22
 
23
- const VERSION = '1.2.3';
23
+ const VERSION = '1.2.4';
24
24
 
25
25
  class AntiEtcd extends EventEmitter
26
26
  {
@@ -53,6 +53,7 @@ class AntiEtcd extends EventEmitter
53
53
  this.locker = null;
54
54
  this.stored_term = 0;
55
55
  this.cfg = cfg;
56
+ this.peer_ca = null;
56
57
  this.loading = false;
57
58
  this.stopped = false;
58
59
  this.inflight = 0;
@@ -62,6 +63,25 @@ class AntiEtcd extends EventEmitter
62
63
 
63
64
  async start()
64
65
  {
66
+ if (this.cfg.cert)
67
+ {
68
+ this.tls = {
69
+ key: await fsp.readFile(this.cfg.key),
70
+ cert: await fsp.readFile(this.cfg.cert),
71
+ };
72
+ if (this.cfg.ca)
73
+ {
74
+ this.tls.ca = await fsp.readFile(this.cfg.ca);
75
+ }
76
+ if (this.cfg.client_cert_auth)
77
+ {
78
+ this.tls.requestCert = true;
79
+ }
80
+ if (this.cfg.peer_ca)
81
+ {
82
+ this.peer_ca = await fsp.readFile(this.cfg.peer_ca);
83
+ }
84
+ }
65
85
  if (this.cfg.data || this.cfg.cluster)
66
86
  {
67
87
  this.etctree.set_replicate_watcher(msg => this._persistAndReplicate(msg));
@@ -83,18 +103,6 @@ class AntiEtcd extends EventEmitter
83
103
  }
84
104
  if (this.cfg.cert)
85
105
  {
86
- this.tls = {
87
- key: await fsp.readFile(this.cfg.key),
88
- cert: await fsp.readFile(this.cfg.cert),
89
- };
90
- if (this.cfg.ca)
91
- {
92
- this.tls.ca = await fsp.readFile(this.cfg.ca);
93
- }
94
- if (this.cfg.client_cert_auth)
95
- {
96
- this.tls.requestCert = true;
97
- }
98
106
  this.server = https.createServer(this.tls, (req, res) => this._handleRequest(req, res));
99
107
  }
100
108
  else
package/antilocker.js CHANGED
@@ -2,8 +2,6 @@
2
2
  // (c) Vitaliy Filippov, 2024+
3
3
  // License: Mozilla Public License 2.0 or Vitastor Network Public License 1.1
4
4
 
5
- const { RequestError } = require('./common.js');
6
-
7
5
  // How does it work:
8
6
  // - Leader sets key-level locks, persists and replicates the change, then removes locks
9
7
  // - Followers set locks, persist and reply to the leader, wait for the feedback, then remove locks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antietcd",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Simplistic etcd replacement based on TinyRaft",
5
5
  "main": "antietcd.js",
6
6
  "scripts": {