@cosyte/mllp 0.1.8 → 0.1.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.10
4
+ ### Patch Changes
5
+
6
+ - 84c8ad6: A server can now bound how many connections it holds at once. New option `ServerOptions.maxConnections` (a positive integer; unset means no cap, the behaviour so far): a connection that arrives while the server already holds that many is closed at accept, before any byte is read and before any TLS handshake, and never reaches `onMessage` or the `'connection'` event. Each one is reported on the new `'connectionRejected'` event, a frozen `ConnectionRejectedEvent` carrying the new stable code `MLLP_CONNECTION_LIMIT_REACHED`, the cap and the peer's address and port. The count is of open sockets, so it bounds file descriptors. New exports: `MLLP_CONNECTION_LIMIT_REACHED` and the type `ConnectionRejectedEvent`. Nothing changes for a caller who does not set the option; a `maxConnections` that is not a positive integer throws a `RangeError` when the server is created.
7
+
8
+ ## 0.1.9
9
+ ### Patch Changes
10
+
11
+ - b3f843c: Add the npm keywords `client` and `server` so the package is easier to find in npm search.
12
+
3
13
  ## 0.1.8
4
14
  ### Patch Changes
5
15
 
package/dist/index.cjs CHANGED
@@ -1744,6 +1744,8 @@ function isWildcardHost(host) {
1744
1744
  }
1745
1745
  return false;
1746
1746
  }
1747
+ var MLLP_CONNECTION_LIMIT_REACHED = "MLLP_CONNECTION_LIMIT_REACHED";
1748
+ var CONNECTION_LIMIT_MESSAGE = "connection closed at accept: the server already holds maxConnections connections";
1747
1749
  var SERVER_DEFAULT_FRAMING = {
1748
1750
  allowFsOnly: true,
1749
1751
  allowLfAfterFs: true,
@@ -1790,6 +1792,12 @@ var MllpServer = class extends events.EventEmitter {
1790
1792
  */
1791
1793
  constructor(opts) {
1792
1794
  super();
1795
+ const maxConnections = opts.maxConnections;
1796
+ if (maxConnections !== void 0 && !(Number.isSafeInteger(maxConnections) && maxConnections >= 1)) {
1797
+ throw new RangeError(
1798
+ "ServerOptions.maxConnections must be a positive integer, or left unset for no cap"
1799
+ );
1800
+ }
1793
1801
  this._opts = opts;
1794
1802
  this._isTls = opts.tls !== void 0;
1795
1803
  let cipherPolicy = null;
@@ -1846,6 +1854,29 @@ var MllpServer = class extends events.EventEmitter {
1846
1854
  this.emit("error", err);
1847
1855
  }
1848
1856
  });
1857
+ if (maxConnections !== void 0) {
1858
+ this._netServer.maxConnections = maxConnections;
1859
+ this._netServer.on("drop", (data) => {
1860
+ this._onConnectionOverCap(maxConnections, data);
1861
+ });
1862
+ }
1863
+ }
1864
+ /**
1865
+ * Report a connection the listener closed at accept because the cap was full.
1866
+ *
1867
+ * Contained: this runs inside the listener's own 'drop' callback, so a throwing subscriber would
1868
+ * otherwise unwind into the accept path. The throw is surfaced on 'error' instead.
1869
+ */
1870
+ _onConnectionOverCap(maxConnections, data) {
1871
+ const event = Object.freeze({
1872
+ code: MLLP_CONNECTION_LIMIT_REACHED,
1873
+ message: CONNECTION_LIMIT_MESSAGE,
1874
+ maxConnections,
1875
+ remoteAddress: data?.remoteAddress ?? null,
1876
+ remotePort: data?.remotePort ?? null,
1877
+ timestamp: /* @__PURE__ */ new Date()
1878
+ });
1879
+ this._emitContained("connectionRejected", event);
1849
1880
  }
1850
1881
  /**
1851
1882
  * Start listening on the given port.
@@ -5151,13 +5182,14 @@ async function runDifferential(options = {}) {
5151
5182
  }
5152
5183
 
5153
5184
  // src/index.ts
5154
- var VERSION = "0.1.8";
5185
+ var VERSION = "0.1.10";
5155
5186
 
5156
5187
  exports.ATNA_CIPHER_LIST = ATNA_CIPHER_LIST;
5157
5188
  exports.ATNA_CIPHER_SUITES = ATNA_CIPHER_SUITES;
5158
5189
  exports.Connection = Connection;
5159
5190
  exports.FrameReader = FrameReader;
5160
5191
  exports.MLLP_BIND_ALL_INTERFACES = MLLP_BIND_ALL_INTERFACES;
5192
+ exports.MLLP_CONNECTION_LIMIT_REACHED = MLLP_CONNECTION_LIMIT_REACHED;
5161
5193
  exports.MLLP_DIFF_PEER_UNPARSEABLE = MLLP_DIFF_PEER_UNPARSEABLE;
5162
5194
  exports.MLLP_TLS_CIPHER_LIST_REJECTED = MLLP_TLS_CIPHER_LIST_REJECTED;
5163
5195
  exports.MLLP_TLS_CIPHER_OPTION_CONFLICT = MLLP_TLS_CIPHER_OPTION_CONFLICT;