omq-lz4 0.3.4 → 0.4.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc57173f0a05f8ebb0f91e434a5014a648746d988b6a545f8d3b962680201c42
4
- data.tar.gz: ff10911308b70dde76bc87ae3b60c9c2e6e8b500a43bab3b103d01fc061e4e63
3
+ metadata.gz: 97679b611d3920dcfea320791f9340cc0a941c405be6b8dcf0f5fbfcb7422584
4
+ data.tar.gz: 47a65a2a6c2ea66fcc227e4270e31122d90009e35f38136d665cfebf6925b8a1
5
5
  SHA512:
6
- metadata.gz: e1a959b2f55143f3d2b8ba424ad4904299e09cf54023ab2f8645dc1ac0405c0225b254d2258aca5470e0ce2e7aaef7dc33523ad511ce3e5a3f8c6bd04740924c
7
- data.tar.gz: 777534139e2c27163e5767a8f58e48eff55c187476eae4b52d1d707c95fb732eee98a7e39a19ea557805840320cebf8fbe2e779c1ad3c82ccfadb933c0875f95
6
+ metadata.gz: c95b4d40bf5912269c6af3a648b3e2e5f66788fd4b10639416ab9fa94cdde19a1e17d24c1a740cd55993806a17453da59f47997fb73a4acaee53885469439a09
7
+ data.tar.gz: e7d4976fb95a1a85b562b51ed9a3cbef08eca789205149b696d86ad95fa38931707233dff5fb67b532dd603fb55641142e9b5b7c936ecec2d20b3caebb5121f6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,30 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.4.1] - 2026-11-26
6
+
7
+ ### Changed
8
+
9
+ - Require `lz4rip ~> 0.2.2`. An `auto_dict` capacity of 4 to 31 bytes no
10
+ longer raises during training.
11
+
12
+ ## [0.4.0] - 2026-10-15
13
+
14
+ ### Added
15
+
16
+ - Decode revision 2 `LZ4A` arenas with complete validation before delivery,
17
+ bounded decompression, and per-message size and queue accounting.
18
+ - Batch already queued small messages into arenas targeting 16 KiB, with raw
19
+ mode below the compression threshold or when compression does not save bytes.
20
+
21
+ ### Fixed
22
+
23
+ - Reject multipart dictionary shipments and disconnect malformed peers without
24
+ killing the socket.
25
+ - Preserve compression on PUB/RADIO fan-out and allow bounded transport
26
+ envelopes independently of the logical message size limit.
27
+ - Reject encrypted mechanisms on compressed transports.
28
+
5
29
  ## 0.3.4 - 2026-08-08
6
30
 
7
31
  ### Changed
data/README.md CHANGED
@@ -12,6 +12,19 @@ preferred compressed TCP transport. `omq-zstd` is experimental.
12
12
  See [RFC.md](RFC.md) for the wire-format specification and
13
13
  [CHANGELOG.md](CHANGELOG.md) for release history.
14
14
 
15
+ Revision 2 `LZ4A` arenas are supported, including raw and compressed modes
16
+ and dictionaries. Each arena is validated completely before delivery and
17
+ is limited to 64 KiB, 256 messages, and 4096 parts. `max_message_size`
18
+ applies separately to each decoded message, charging payload bytes plus
19
+ 64 bytes per part for storage. Message order and receive HWM apply to the
20
+ individual messages inside an arena.
21
+
22
+ The sender batches already queued small messages, targeting 16 KiB per arena.
23
+ It never waits to fill a batch. Subscription filtering and queue admission
24
+ happen before batching. Isolated or larger messages use per-part encoding.
25
+ Both peers must support revision 2; no revision negotiation is performed.
26
+ Encrypted mechanisms such as CURVE cannot be combined with this transport.
27
+
15
28
  ## Why `lz4+tcp://`
16
29
 
17
30
  LZ4 has no entropy stage (no Huffman, no FSE), ~16 KiB of encoder state
data/lib/omq/lz4/codec.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "lz4rip"
4
+ require "protocol/zmtp"
4
5
 
5
6
  require_relative "errors"
6
7
 
@@ -27,6 +28,7 @@ module OMQ
27
28
  LZ4B_SENTINEL = "LZ4B".b.freeze
28
29
  LZ4M_SENTINEL = "LZ4M".b.freeze
29
30
  LZ4D_SENTINEL = "LZ4D".b.freeze
31
+ LZ4A_SENTINEL = "LZ4A".b.freeze
30
32
 
31
33
  LZ4M_BLOCK_SIZE = 1_073_741_824
32
34
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "protocol/zmtp"
4
+
3
5
  module OMQ
4
6
  module LZ4
5
7
  # Raised when the peer sends bytes that violate the lz4+tcp wire
@@ -8,6 +10,6 @@ module OMQ
8
10
  # per-message size-budget overrun, or a decoder failure on a
9
11
  # compressed part. The transport closes the connection on any
10
12
  # protocol error — never silently drops the offending part.
11
- class ProtocolError < StandardError; end
13
+ class ProtocolError < Protocol::ZMTP::Error; end
12
14
  end
13
15
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OMQ
4
4
  module LZ4
5
- VERSION = "0.3.4"
5
+ VERSION = "0.4.1"
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "delegate"
3
+ require "omq/transport/compressed_connection"
4
4
 
5
5
  require_relative "../../lz4/codec"
6
6
 
@@ -11,17 +11,18 @@ module OMQ
11
11
  # the ZMTP connection so send_message / write_message /
12
12
  # receive_message route through compression, but everything else
13
13
  # (write_command, close, etc.) passes through untouched.
14
- class Lz4Connection < SimpleDelegator
14
+ class Lz4Connection < CompressedConnection
15
15
  DEFAULT_DICT_CAPACITY = 2048
16
16
  DEFAULT_TRAIN_TRIGGER = 100
17
+ ARENA_TARGET_BYTES = 16 * 1024
17
18
 
18
19
  # @return [Integer, nil] wire bytesize of the last received
19
20
  # message (sum across parts, compressed sentinel included).
20
21
  attr_reader :last_wire_size_in
21
22
 
22
23
  def initialize(conn, send_dict_bytes:, max_message_size:, auto_dict: nil)
23
- super(conn)
24
- @max_message_size = max_message_size
24
+ super(conn, max_message_size: max_message_size,
25
+ arena_sentinel: LZ4::Codec::LZ4A_SENTINEL, protocol_error: LZ4::ProtocolError)
25
26
 
26
27
  @recv_codec = build_block_codec(nil)
27
28
  @recv_dict_bytes = nil
@@ -66,28 +67,29 @@ module OMQ
66
67
 
67
68
  def write_messages(messages)
68
69
  messages.each { |parts| maybe_train!(parts) }
69
- wires = messages.map { |parts| encode_parts(parts) }
70
+ wires = CompressionArena.each_batch(messages, target: ARENA_TARGET_BYTES).map do |batch|
71
+ if batch.size == 1
72
+ encode_parts(batch.first)
73
+ else
74
+ threshold = @send_dict_bytes ? LZ4::Codec::MIN_COMPRESS_WITH_DICT : LZ4::Codec::MIN_COMPRESS_NO_DICT
75
+ [CompressionArena.encode(batch, sentinel: LZ4::Codec::LZ4A_SENTINEL, threshold: threshold) do |data|
76
+ @send_codec.compress(data)
77
+ end]
78
+ end
79
+ end
70
80
  ship_send_dict!
71
81
  __getobj__.write_messages(wires)
72
82
  end
73
83
 
74
84
 
75
- def receive_message
76
- # Loop: a dict shipment is consumed silently and we read the
77
- # next ZMTP message. Only data messages are returned to the
78
- # caller. Budget tracking happens inside decode_wire_parts.
79
- loop do
80
- parts = __getobj__.receive_message
81
- decoded = decode_wire_parts(parts)
82
- if decoded
83
- @last_wire_size_in = parts.sum(&:bytesize)
84
- return decoded
85
- end
86
- end
87
- end
85
+ private
88
86
 
89
87
 
90
- private
88
+ def decompress_arena(data, size)
89
+ @recv_codec.decompress(data, decompressed_size: size)
90
+ rescue Lz4rip::DecompressError => error
91
+ raise LZ4::ProtocolError, "LZ4 arena decode failed: #{error.message}"
92
+ end
91
93
 
92
94
 
93
95
  def build_block_codec(dict_bytes)
@@ -148,7 +150,7 @@ module OMQ
148
150
  # Budget tracking is per-message (sum of decompressed sizes
149
151
  # across parts). Dict shipment parts do not count against the
150
152
  # budget — they aren't messages.
151
- def decode_wire_parts(parts)
153
+ def decode_parts(parts)
152
154
  decoded = []
153
155
  all_dicts = true
154
156
  budget = @max_message_size
@@ -158,6 +160,8 @@ module OMQ
158
160
 
159
161
  sentinel = wire.byteslice(0, 4)
160
162
  if sentinel == LZ4::Codec::LZ4D_SENTINEL
163
+ raise LZ4::ProtocolError, "dictionary must be a single-part message" unless parts.size == 1
164
+
161
165
  install_recv_dict!(wire)
162
166
  next
163
167
  end
@@ -36,6 +36,7 @@ module OMQ
36
36
  # with `dict:`.
37
37
  # @return [Listener]
38
38
  def listener(endpoint, engine, dict: nil, auto_dict: nil, **)
39
+ validate_security!(engine)
39
40
  validate_dict!(dict)
40
41
  validate_auto_dict!(auto_dict, dict)
41
42
 
@@ -65,6 +66,7 @@ module OMQ
65
66
  # training. See `listener` for details.
66
67
  # @return [Dialer]
67
68
  def dialer(endpoint, engine, dict: nil, auto_dict: nil, **)
69
+ validate_security!(engine)
68
70
  validate_dict!(dict)
69
71
  validate_auto_dict!(auto_dict, dict)
70
72
  Dialer.new(endpoint, engine, dict&.b, normalize_auto_dict(auto_dict))
@@ -111,6 +113,13 @@ module OMQ
111
113
  private
112
114
 
113
115
 
116
+ def validate_security!(engine)
117
+ if engine.options.mechanism&.encrypted?
118
+ raise ArgumentError, "compressed transports do not support encrypted mechanisms"
119
+ end
120
+ end
121
+
122
+
114
123
  def validate_dict!(dict)
115
124
  return if dict.nil?
116
125
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omq-lz4
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger
@@ -15,28 +15,28 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.28'
18
+ version: '0.29'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '0.28'
25
+ version: '0.29'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: lz4rip
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.2.0
32
+ version: 0.2.2
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.2.0
39
+ version: 0.2.2
40
40
  description: Adds lz4+tcp:// endpoint support to OMQ with per-part LZ4 block-format
41
41
  compression, bounded decompression, in-band dictionary shipping, and automatic dictionary
42
42
  training.
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
- rubygems_version: 4.0.16
77
+ rubygems_version: 4.0.20
78
78
  specification_version: 4
79
79
  summary: LZ4+TCP transport for OMQ
80
80
  test_files: []