rsmp 0.1.8 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0df1c6fd543202b5e5364133461d565269e5301976301c029e2d4311e6e74611
4
- data.tar.gz: 2944466c2816349afe4f350052bb7756909a271d8466aa954294d905c1e69ae4
3
+ metadata.gz: d6e7b6922c4aad939b08a2235e05a79ef5662534ec401d204255671c2511ede1
4
+ data.tar.gz: e81f0a7c38fb98317e18ebfb3879f43bd878a947de41b5d49e14953d5ed7f86e
5
5
  SHA512:
6
- metadata.gz: 5341c781360c44b1a68fd6c483618fc61d580986ba846fc85192ab02dae3318a526d66dcf911ca84518ad02e2b5263c7149c76df135afc589c6a2c75047bdbd7
7
- data.tar.gz: 4023179107aac97ef4fa93daee1932e0b6cfbf4a1f11ae42c1831ea3970813737ae9127667578c1515dbad51d93277274999ab2aece8f3acc08d2450e0c15cac
6
+ metadata.gz: a8dc63658a0082778509d2da33b44e0e80573f1b0aef8fe76c05d816d34e9dd10084de81f38c37df20d6351a9b47b2a33836bbb4405a7143da028f82ef4e2558
7
+ data.tar.gz: 005bd7b55911a289cd33f521a3850c00ade3622cdce377a1f79e57958925cbc86216b266ffaa6a58a58fdcf66822c5eb34ea48240ff8d29d581f8f2469aa0551
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.1.7)
4
+ rsmp (0.1.10)
5
5
  async (~> 1.23.0)
6
6
  async-io (~> 1.27.1)
7
7
  colorize (~> 0.8.1)
@@ -1,4 +1,3 @@
1
- site_id: RN+SU0001
2
1
  port: 12111
3
2
  rsmp_versions:
4
3
  - 3.1.1
@@ -6,8 +5,8 @@ rsmp_versions:
6
5
  - 3.1.3
7
6
  - 3.1.4
8
7
 
9
- watchdog_interval: 5
10
- watchdog_timeout: 10
8
+ watchdog_interval: 1
9
+ watchdog_timeout: 2
11
10
  acknowledgement_timeout: 2
12
11
  store_messages: false
13
12
  command_response_timeout: 1
@@ -15,9 +14,7 @@ status_response_timeout: 1
15
14
  status_update_timeout: 1
16
15
 
17
16
  sites:
18
- KK+AG9998: # dynniq test tlc
19
- AA+BBCCC=DDD: # rsmp simulator
20
- RN+SI0001: # ruby rsmp site
17
+ any:
21
18
 
22
19
  log:
23
20
  active: true
data/lib/rsmp/cli.rb CHANGED
@@ -30,7 +30,7 @@ module RSMP
30
30
 
31
31
  if options[:supervisors]
32
32
  options[:supervisors].split(',').each do |supervisor|
33
- setting[:supervisors] ||= []
33
+ settings[:supervisors] ||= []
34
34
  ip, port = supervisor.split ':'
35
35
  ip = '127.0.0.1' if ip.empty?
36
36
  port = '12111' if port.empty?
data/lib/rsmp/proxy.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RSMP
4
4
  class Proxy < Base
5
- attr_reader :site_ids, :state, :archive, :connection_info, :sxl
5
+ attr_reader :state, :archive, :connection_info, :sxl
6
6
 
7
7
  def initialize options
8
8
  super options
@@ -15,10 +15,6 @@ module RSMP
15
15
  clear
16
16
  end
17
17
 
18
- def site_id
19
- @site_ids.first #rsmp connection can represent multiple site ids. pick the first
20
- end
21
-
22
18
  def run
23
19
  start
24
20
  @reader.wait if @reader
@@ -44,7 +40,6 @@ module RSMP
44
40
  end
45
41
 
46
42
  def clear
47
- @site_ids = []
48
43
  @awaiting_acknowledgement = {}
49
44
  @latest_watchdog_received = nil
50
45
  @watchdog_started = false
@@ -183,7 +178,7 @@ module RSMP
183
178
  timeout = @settings["watchdog_timeout"]
184
179
  latest = @latest_watchdog_received + timeout
185
180
  left = latest - now
186
- log "check watchdog, time:#{timeout}, last:#{@latest_watchdog_received}, now: #{now}, latest:#{latest}, left #{left}, fail:#{left<0}", level: :debug
181
+ log "Check watchdog, time:#{timeout}, last:#{@latest_watchdog_received}, now: #{now}, latest:#{latest}, left #{left}, fail:#{left<0}", level: :debug
187
182
  if left < 0
188
183
  log "No Watchdog within #{timeout} seconds, received at #{@latest_watchdog_received}, now is #{now}, diff #{now-latest}", level: :error
189
184
  stop
@@ -198,7 +193,7 @@ module RSMP
198
193
  end
199
194
 
200
195
  def log str, options={}
201
- super str, options.merge(ip: @ip, port: @port, site_id: site_id)
196
+ super str, options.merge(ip: @ip, port: @port, site_id: @site_id)
202
197
  end
203
198
 
204
199
  def send_message message, reason=nil
@@ -237,7 +232,7 @@ module RSMP
237
232
  def process_packet json
238
233
  attributes = Message.parse_attributes json
239
234
  message = Message.build attributes, json
240
- message.validate
235
+ message.validate sxl
241
236
  expect_version_message(message) unless @version_determined
242
237
  process_message message
243
238
  message
@@ -299,28 +294,13 @@ module RSMP
299
294
  # find versions that both we and the client support
300
295
  candidates = message.versions & @settings["rsmp_versions"]
301
296
  if candidates.any?
302
- # pick latest version
303
- version = candidates.sort.last
304
- return version
297
+ @rsmp_version = candidates.sort.last # pick latest version
305
298
  else
306
299
  raise FatalError.new "RSMP versions [#{message.versions.join(',')}] requested, but only [#{@settings["rsmp_versions"].join(',')}] supported."
307
300
  end
308
301
  end
309
302
 
310
303
  def process_version message
311
- return extraneous_version message if @version_determined
312
- check_site_ids message
313
- site_ids_changed
314
- rsmp_version = check_rsmp_version message
315
- set_state :version_determined
316
- check_sxl_version message
317
- version_accepted message, rsmp_version
318
- end
319
-
320
- def site_ids_changed
321
- end
322
-
323
- def check_sxl_version message
324
304
  end
325
305
 
326
306
  def acknowledge original
@@ -357,10 +337,12 @@ module RSMP
357
337
  @state
358
338
  end
359
339
 
360
- def send_version site_id_array, rsmp_versions
361
- versions_hash = [rsmp_versions].flatten.map {|v| {"vers" => v} }
340
+ def send_version site_id, rsmp_versions
341
+ versions_array = [rsmp_versions].flatten.map {|v| {"vers" => v} }
342
+ site_id_array = [site_id].flatten.map {|id| {"sId" => id} }
343
+
362
344
  version_response = Version.new({
363
- "RSMP"=>versions_hash,
345
+ "RSMP"=>versions_array,
364
346
  "siteId"=>site_id_array,
365
347
  "SXL"=>sxl_version
366
348
  })
@@ -455,24 +437,6 @@ module RSMP
455
437
  def connection_complete
456
438
  set_state :ready
457
439
  end
458
-
459
- def check_site_ids message
460
- message.attribute("siteId").map { |item| item["sId"] }.each do |site_id|
461
- check_site_id site_id
462
- @site_ids << site_id
463
- end
464
- end
465
-
466
- def check_site_id site_id
467
- end
468
-
469
- def site_id_accetable? site_id
470
- true
471
- end
472
-
473
- def add_site_id site_id
474
- @site_ids << site_id
475
- end
476
440
 
477
441
  def version_acknowledged
478
442
  end
@@ -507,6 +471,5 @@ module RSMP
507
471
  def author
508
472
  node.site_id
509
473
  end
510
-
511
474
  end
512
475
  end
@@ -4,13 +4,14 @@ module RSMP
4
4
  class SiteProxy < Proxy
5
5
  include SiteBase
6
6
 
7
- attr_reader :supervisor
7
+ attr_reader :supervisor, :site_id
8
8
 
9
9
  def initialize options
10
10
  super options
11
11
  initialize_site
12
12
  @supervisor = options[:supervisor]
13
13
  @settings = @supervisor.supervisor_settings.clone
14
+ @site_id = nil
14
15
  end
15
16
 
16
17
  def node
@@ -24,7 +25,7 @@ module RSMP
24
25
 
25
26
  def connection_complete
26
27
  super
27
- log "Connection to site #{@site_ids.first} established", level: :info
28
+ log "Connection to site #{@site_id} established", level: :info
28
29
  end
29
30
 
30
31
  def process_message message
@@ -49,17 +50,16 @@ module RSMP
49
50
  end
50
51
  end
51
52
 
52
- def version_accepted message, rsmp_version
53
- log "Received Version message for sites [#{@site_ids.join(',')}] using RSMP #{rsmp_version}", message: message, level: :log
53
+ def version_accepted message
54
+ log "Received Version message for site #{@site_id} using RSMP #{@rsmp_version}", message: message, level: :log
54
55
  start_timer
55
56
  acknowledge message
56
- send_version message.attributes['siteId'], rsmp_version
57
-
57
+ send_version @site_id, @rsmp_version
58
58
  @version_determined = true
59
59
 
60
- site_id = @site_ids.first
61
60
  if @settings['sites']
62
- @site_settings = @settings['sites'][site_id]
61
+ @site_settings = @settings['sites'][@site_id]
62
+ @site_settings =@settings['sites'][:any] unless @site_settings
63
63
  if @site_settings
64
64
  setup_components @site_settings['components']
65
65
  end
@@ -83,7 +83,7 @@ module RSMP
83
83
  if @site_settings == nil || @site_settings['components'] == nil
84
84
  component = build_component c_id
85
85
  @components[c_id] = component
86
- log "Adding component #{c_id} to site #{site_id}", level: :info
86
+ log "Adding component #{c_id} to site #{@site_id}", level: :info
87
87
  else
88
88
  reason = "component #{c_id} not found"
89
89
  dont_acknowledge message, "Ignoring #{message.type}:", reason
@@ -123,10 +123,6 @@ module RSMP
123
123
  @supervisor.site_ids_changed
124
124
  end
125
125
 
126
- def check_site_id site_id
127
- @site_settings = @supervisor.check_site_id site_id
128
- end
129
-
130
126
  def request_status component, status_list, timeout=nil
131
127
  raise NotReady unless @state == :ready
132
128
  message = RSMP::StatusRequest.new({
@@ -238,7 +234,8 @@ module RSMP
238
234
  end
239
235
 
240
236
  def check_sxl_version message
241
- super message
237
+ # store sxl version requested by site
238
+ # TODO should check agaist site settings
242
239
  @site_sxl_version = message.attribute 'SXL'
243
240
  end
244
241
 
@@ -248,5 +245,22 @@ module RSMP
248
245
  @site_sxl_version
249
246
  end
250
247
 
248
+ def process_version message
249
+ return extraneous_version message if @version_determined
250
+ check_site_ids message
251
+ check_rsmp_version message
252
+ check_sxl_version message
253
+ version_accepted message
254
+ end
255
+
256
+ def check_site_ids message
257
+ # RSMP support multiple site ids. we don't support this yet. instead we use the first id only
258
+ site_id = message.attribute("siteId").map { |item| item["sId"] }.first
259
+ @supervisor.check_site_id site_id
260
+ @site_id = site_id
261
+ site_ids_changed
262
+ end
263
+
264
+
251
265
  end
252
266
  end
@@ -19,7 +19,6 @@ module RSMP
19
19
 
20
20
  def handle_supervisor_settings options
21
21
  @supervisor_settings = {
22
- 'site_id' => 'RN+SU0001',
23
22
  'port' => 12111,
24
23
  'rsmp_versions' => ['3.1.1','3.1.2','3.1.3','3.1.4'],
25
24
  'timer_interval' => 0.1,
@@ -31,7 +30,10 @@ module RSMP
31
30
  'status_update_timeout' => 1,
32
31
  'site_connect_timeout' => 2,
33
32
  'site_ready_timeout' => 1,
34
- 'stop_after_first_session' => false
33
+ 'stop_after_first_session' => false,
34
+ 'sites' => {
35
+ :any => {}
36
+ }
35
37
  }
36
38
 
37
39
  if options[:supervisor_settings]
@@ -40,7 +42,7 @@ module RSMP
40
42
  @supervisor_settings.merge! converted
41
43
  end
42
44
 
43
- required = [:port, :rsmp_versions, :site_id, :watchdog_interval, :watchdog_timeout,
45
+ required = [:port, :rsmp_versions, :watchdog_interval, :watchdog_timeout,
44
46
  :acknowledgement_timeout, :command_response_timeout]
45
47
  check_required_settings @supervisor_settings, required
46
48
 
@@ -87,7 +89,7 @@ module RSMP
87
89
  end
88
90
 
89
91
  def starting
90
- log "Starting supervisor #{@supervisor_settings["site_id"]} on port #{@supervisor_settings["port"]}",
92
+ log "Starting supervisor on port #{@supervisor_settings["port"]}",
91
93
  level: :info,
92
94
  timestamp: RSMP.now_object
93
95
  end
@@ -157,12 +159,14 @@ module RSMP
157
159
 
158
160
  def find_site site_id
159
161
  @proxies.each do |site|
160
- return site if site_id == :any || site.site_ids.include?(site_id)
162
+ return site if site.site_id == site_id
161
163
  end
162
164
  nil
163
165
  end
164
166
 
165
167
  def wait_for_site site_id, timeout
168
+ site = find_site site_id
169
+ return site if site
166
170
  RSMP::Wait.wait_for(@task,@site_id_condition,timeout) { find_site site_id }
167
171
  rescue Async::TimeoutError
168
172
  nil
@@ -195,5 +199,10 @@ module RSMP
195
199
 
196
200
  def aggregated_status_changed site_proxy, component
197
201
  end
202
+
203
+ def self.build_id_from_ip_port ip, port
204
+ Digest::MD5.hexdigest("#{ip}:#{port}")[0..8]
205
+ end
206
+
198
207
  end
199
208
  end
@@ -1,5 +1,7 @@
1
1
  # Handles a site connection to a remote supervisor
2
2
 
3
+ require 'digest'
4
+
3
5
  module RSMP
4
6
  class SupervisorProxy < Proxy
5
7
 
@@ -14,6 +16,7 @@ module RSMP
14
16
  @status_subscriptions = {}
15
17
  @status_subscriptions_mutex = Mutex.new
16
18
  @sxl = @site_settings['sxl']
19
+ @synthetic_id = Supervisor.build_id_from_ip_port @ip, @port
17
20
  end
18
21
 
19
22
  def node
@@ -26,7 +29,7 @@ module RSMP
26
29
  connect
27
30
  @logger.unmute @ip, @port
28
31
  start_reader
29
- send_version @site_settings["rsmp_versions"]
32
+ send_version @site_settings['site_id'], @site_settings["rsmp_versions"]
30
33
  rescue Errno::ECONNREFUSED
31
34
  log "No connection to supervisor at #{@ip}:#{@port}", level: :error
32
35
  unless @site.site_settings["reconnect_interval"] == :no
@@ -97,8 +100,8 @@ module RSMP
97
100
  @task.sleep interval
98
101
  end
99
102
 
100
- def version_accepted message, rsmp_version
101
- log "Received Version message, using RSMP #{rsmp_version}", message: message, level: :log
103
+ def version_accepted message
104
+ log "Received Version message, using RSMP #{@rsmp_version}", message: message, level: :log
102
105
  start_timer
103
106
  acknowledge message
104
107
  connection_complete
@@ -191,16 +194,19 @@ module RSMP
191
194
 
192
195
  component = message.attributes["cId"]
193
196
 
194
- @status_subscriptions[component] ||= {}
197
+ @status_subscriptions[component] ||= {}
195
198
  update_list[component] ||= {}
196
199
 
200
+ subs = @status_subscriptions[component]
201
+
197
202
  message.attributes["sS"].each do |arg|
203
+ sCI = arg["sCI"]
198
204
  subcription = {interval: arg["uRt"].to_i, last_sent_at: nil}
199
- @status_subscriptions[component][arg["sCI"]] ||= {}
200
- @status_subscriptions[component][arg["sCI"]][arg["n"]] = subcription
205
+ subs[sCI] ||= {}
206
+ subs[sCI][arg["n"]] = subcription
201
207
 
202
- update_list[component][arg["sCI"]] ||= []
203
- update_list[component][arg["sCI"]] << arg["n"]
208
+ update_list[component][sCI] ||= []
209
+ update_list[component][sCI] << arg["n"]
204
210
  end
205
211
  acknowledge message
206
212
  send_status_updates update_list # send status after subscribing is accepted
@@ -210,18 +216,16 @@ module RSMP
210
216
  log "Received #{message.type}", message: message, level: :log
211
217
  component = message.attributes["cId"]
212
218
 
213
- if @status_subscriptions[component]
214
- message.attributes["sS"].each do |arg|
215
- if @status_subscriptions[component][arg["sCI"]]
216
- @status_subscriptions[component][arg["sCI"]].delete arg["n"]
217
- end
218
- if @status_subscriptions[component][arg["sCI"]].empty?
219
- @status_subscriptions[component].delete(arg["sCI"])
219
+ subs = @status_subscriptions[component]
220
+ if subs
221
+ message.attributes["sS"].each do |arg|
222
+ sCI = arg["sCI"]
223
+ if subs[sCI]
224
+ subs[sCI].delete arg["n"]
225
+ subs.delete(sCI) if subs[sCI].empty?
220
226
  end
221
227
  end
222
- if @status_subscriptions[component].empty?
223
- @status_subscriptions.delete(component)
224
- end
228
+ @status_subscriptions.delete(component) if subs.empty?
225
229
  end
226
230
  acknowledge message
227
231
  end
@@ -270,10 +274,10 @@ module RSMP
270
274
  sS = []
271
275
  by_code.each_pair do |code,names|
272
276
  names.each do |name|
273
- sS << { "sCI": code,
274
- "n": name,
275
- "s": rand(100),
276
- "q": "recent" }
277
+ sS << { "sCI" => code,
278
+ "n" => name,
279
+ "s" => rand(100).to_s,
280
+ "q" => "recent" }
277
281
  end
278
282
  end
279
283
  update = StatusUpdate.new({
@@ -298,5 +302,17 @@ module RSMP
298
302
  def sxl_version
299
303
  @site_settings['sxl_version']
300
304
  end
305
+
306
+ def process_version message
307
+ return extraneous_version message if @version_determined
308
+ check_rsmp_version message
309
+ check_sxl_version message
310
+ @site_id = Supervisor.build_id_from_ip_port @ip, @port
311
+ version_accepted message
312
+ end
313
+
314
+ def check_sxl_version message
315
+ end
316
+
301
317
  end
302
318
  end
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-13 00:00:00.000000000 Z
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -357,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
357
357
  - !ruby/object:Gem::Version
358
358
  version: '0'
359
359
  requirements: []
360
- rubygems_version: 3.0.3
360
+ rubygems_version: 3.0.6
361
361
  signing_key:
362
362
  specification_version: 4
363
363
  summary: RoadSide Message Protocol (RSMP) library.