rsmp 0.54.4 → 0.55.0

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: 02d0895a680af99dc43aa494c8c901d63f00eaf5d554543007bf70b85ba6c41a
4
- data.tar.gz: 89b2d16f2cea6516567d4062d92d8456204dd29ccdc89e8ffb7ab832038c21b6
3
+ metadata.gz: fb373367603ac82d7f31c3ed12bd7d11d59b6aea3bd7d47dd43ddc3fb984e619
4
+ data.tar.gz: c1d650ab1c69d4a2f3a9848b2c61892153bb6be24c6b5ea36a7bcdff4969107b
5
5
  SHA512:
6
- metadata.gz: a2b2e1f71684e4e03610bac3d37ab0bf652b1f43999f4c0e784a5af3b8c539fe4c936e5fc88900d9f0cf4992210f7b44c5faa106e5657a1769581e1077bac88b
7
- data.tar.gz: 1f5b279ef872d275588f19d26ccf61d545f5ee14efce736216c1dea89ee6c1d10c450bfdcd5e5df63f1761af89f31879b6c5015f8f85eaff82318046c325bbcd
6
+ metadata.gz: '052907a7d2d7a227e7bb5e94f37ceaaa8e3b1d5e0eee8e8dfdc4ebaedbd173b90b9efbec27f98384f864fc34ce332827ca7d005d1f510c785f34fa16c4e51697'
7
+ data.tar.gz: db27f8c21d8335559399ef70da3d70bc45875449c2c86c70d1547ac280b8548486034399114a89d7a3164b8025a01e2f9fdec9c63ea6f4338d7b81e13137c7fd
data/CHANGELOG.md CHANGED
@@ -767,3 +767,6 @@ Initial release.
767
767
 
768
768
  ## 0.54.4
769
769
  - fix acknowledgement registration race
770
+
771
+ ## 0.55.0
772
+ - Add an optional per-node observer for plain RSMP message types and frame sizes.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.54.4)
4
+ rsmp (0.55.0)
5
5
  async (~> 2.45)
6
6
  colorize (~> 1.1)
7
7
  io-endpoint (~> 0.17)
@@ -14,6 +14,12 @@ module RSMP
14
14
  @deferred = []
15
15
  @clock = Clock.new
16
16
  @collect = options[:collect]
17
+ @traffic_observer = options[:traffic_observer]
18
+ end
19
+
20
+ # All connections of this node share its optional frame observer.
21
+ def build_protocol(stream)
22
+ Protocol.new(stream, traffic_observer: @traffic_observer)
17
23
  end
18
24
 
19
25
  def inspect
@@ -1,7 +1,10 @@
1
1
  module RSMP
2
2
  # Simple protocol wrapper for reading/writing RSMP framed messages.
3
3
  class Protocol
4
- def initialize(stream)
4
+ # The observer's #observe method receives direction, message type (nil if unidentifiable),
5
+ # JSON payload bytes and framed bytes once per read or successful write.
6
+ def initialize(stream, traffic_observer: nil)
7
+ @traffic_observer = traffic_observer
5
8
  @stream = stream
6
9
  @peeked = nil
7
10
  end
@@ -22,8 +25,11 @@ module RSMP
22
25
  end
23
26
 
24
27
  def write_lines(data)
25
- @stream.write(data + RSMP::Proxy::WRAPPING_DELIMITER)
26
- @stream.flush
28
+ frame = data + RSMP::Proxy::WRAPPING_DELIMITER
29
+ @stream.write(frame)
30
+ result = @stream.flush
31
+ observe(:sent, data, frame)
32
+ result
27
33
  end
28
34
 
29
35
  protected
@@ -32,7 +38,21 @@ module RSMP
32
38
  line = @stream.gets(RSMP::Proxy::WRAPPING_DELIMITER)
33
39
  return nil unless line
34
40
 
35
- line.chomp(RSMP::Proxy::WRAPPING_DELIMITER)
41
+ payload = line.chomp(RSMP::Proxy::WRAPPING_DELIMITER)
42
+ observe(:received, payload, line)
43
+ payload
44
+ end
45
+
46
+ def observe(direction, payload, frame)
47
+ @traffic_observer&.observe(direction, message_type(payload), payload.bytesize, frame.bytesize)
48
+ end
49
+
50
+ def message_type(payload)
51
+ attributes = JSON.parse(payload)
52
+ type = attributes['type'] if attributes.is_a?(Hash)
53
+ type if type.is_a?(String) && type.valid_encoding? && !type.empty?
54
+ rescue JSON::ParserError
55
+ nil
36
56
  end
37
57
  end
38
58
  end
@@ -67,7 +67,7 @@ module RSMP
67
67
  supervisor_proxy_options('ip' => remote_ip, 'port' => remote_port).merge(
68
68
  socket: socket,
69
69
  stream: stream,
70
- protocol: RSMP::Protocol.new(stream),
70
+ protocol: build_protocol(stream),
71
71
  info: { ip: remote_ip, port: remote_port, hostname: remote_ip, now: Clock.now }
72
72
  )
73
73
  end
@@ -73,7 +73,7 @@ module RSMP
73
73
 
74
74
  def build_proxy_settings(socket, info)
75
75
  stream = IO::Stream::Buffered.new(socket)
76
- protocol = RSMP::Protocol.new stream
76
+ protocol = build_protocol(stream)
77
77
  site_id = retrieve_site_id(protocol)
78
78
  site_settings = site_id_to_site_setting site_id
79
79
 
@@ -21,7 +21,7 @@ module RSMP
21
21
 
22
22
  def run_reader(id)
23
23
  @stream ||= IO::Stream::Buffered.new(@socket)
24
- @protocol ||= RSMP::Protocol.new(@stream)
24
+ @protocol ||= @node.build_protocol(@stream)
25
25
  while session_active?(id)
26
26
  line = read_protocol_line
27
27
  return line if line.failure?
@@ -59,7 +59,7 @@ module RSMP
59
59
  timeout = @site_settings.dig('timeouts', 'connect') || 1.1
60
60
  task.with_timeout(timeout) { @socket = endpoint.connect }
61
61
  @stream = IO::Stream::Buffered.new(@socket)
62
- @protocol = RSMP::Protocol.new(@stream)
62
+ @protocol = @node.build_protocol(@stream)
63
63
  Result.success(self)
64
64
  rescue SystemCallError, SocketError, IOError, Async::TimeoutError => e
65
65
  Result.failure(
@@ -100,7 +100,7 @@ module RSMP
100
100
  task.sleep delay if delay
101
101
 
102
102
  @stream = IO::Stream::Buffered.new(@socket)
103
- @protocol = RSMP::Protocol.new(@stream) # rsmp messages are json terminated with a form-feed
103
+ @protocol = @node.build_protocol(@stream)
104
104
  Result.success(self)
105
105
  rescue Errno::ECONNREFUSED => e # rescue to avoid log output
106
106
  log 'Connection refused', level: :warning
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = '0.54.4'.freeze
2
+ VERSION = '0.55.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.54.4
4
+ version: 0.55.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin