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 +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/lib/rsmp/node/node.rb +6 -0
- data/lib/rsmp/node/protocol.rb +24 -4
- data/lib/rsmp/node/site/connections.rb +1 -1
- data/lib/rsmp/node/supervisor/modules/connection.rb +1 -1
- data/lib/rsmp/proxy/modules/tasks.rb +1 -1
- data/lib/rsmp/proxy/site/connection.rb +1 -1
- data/lib/rsmp/proxy/supervisor/supervisor_proxy.rb +1 -1
- data/lib/rsmp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb373367603ac82d7f31c3ed12bd7d11d59b6aea3bd7d47dd43ddc3fb984e619
|
|
4
|
+
data.tar.gz: c1d650ab1c69d4a2f3a9848b2c61892153bb6be24c6b5ea36a7bcdff4969107b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '052907a7d2d7a227e7bb5e94f37ceaaa8e3b1d5e0eee8e8dfdc4ebaedbd173b90b9efbec27f98384f864fc34ce332827ca7d005d1f510c785f34fa16c4e51697'
|
|
7
|
+
data.tar.gz: db27f8c21d8335559399ef70da3d70bc45875449c2c86c70d1547ac280b8548486034399114a89d7a3164b8025a01e2f9fdec9c63ea6f4338d7b81e13137c7fd
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/rsmp/node/node.rb
CHANGED
|
@@ -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
|
data/lib/rsmp/node/protocol.rb
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
module RSMP
|
|
2
2
|
# Simple protocol wrapper for reading/writing RSMP framed messages.
|
|
3
3
|
class Protocol
|
|
4
|
-
|
|
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
|
-
|
|
26
|
-
@stream.
|
|
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:
|
|
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 =
|
|
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 ||=
|
|
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 =
|
|
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 =
|
|
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