openc3 7.5.0 → 7.6.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/Gemfile +0 -0
- data/bin/openc3cli +82 -5
- data/data/config/_params.yaml +3 -0
- data/data/config/command_modifiers.yaml +5 -3
- data/data/config/default_plugins.yaml +1 -0
- data/data/config/interface_modifiers.yaml +17 -1
- data/data/config/item_modifiers.yaml +24 -1
- data/data/config/microservice.yaml +15 -1
- data/data/config/parameter_modifiers.yaml +4 -4
- data/data/config/plugins.yaml +511 -3
- data/data/config/settings.yaml +17 -0
- data/data/config/target.yaml +53 -0
- data/data/config/telemetry.yaml +58 -2
- data/data/config/widgets.yaml +30 -0
- data/lib/openc3/accessors/accessor.rb +14 -2
- data/lib/openc3/accessors/binary_accessor.rb +25 -5
- data/lib/openc3/api/CLAUDE.md +1 -0
- data/lib/openc3/api/api.rb +1 -0
- data/lib/openc3/api/cmd_api.rb +9 -1
- data/lib/openc3/api/interface_api.rb +7 -2
- data/lib/openc3/api/limits_api.rb +236 -195
- data/lib/openc3/api/router_api.rb +7 -2
- data/lib/openc3/api/settings_api.rb +4 -1
- data/lib/openc3/api/shared_resource_api.rb +107 -0
- data/lib/openc3/api/tlm_api.rb +229 -61
- data/lib/openc3/interfaces/http_client_interface.rb +84 -27
- data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +6 -2
- data/lib/openc3/interfaces/tcpip_server_interface.rb +205 -125
- data/lib/openc3/io/json_api.rb +2 -10
- data/lib/openc3/io/json_api_object.rb +2 -10
- data/lib/openc3/logs/log_writer.rb +9 -8
- data/lib/openc3/logs/packet_log_writer.rb +8 -3
- data/lib/openc3/microservices/decom_common.rb +4 -1
- data/lib/openc3/microservices/decom_microservice.rb +73 -5
- data/lib/openc3/microservices/interface_decom_common.rb +16 -1
- data/lib/openc3/microservices/interface_microservice.rb +50 -11
- data/lib/openc3/microservices/limits_group_microservice.rb +513 -0
- data/lib/openc3/microservices/log_microservice.rb +22 -8
- data/lib/openc3/microservices/microservice.rb +8 -2
- data/lib/openc3/microservices/multi_microservice.rb +76 -22
- data/lib/openc3/microservices/queue_microservice.rb +29 -24
- data/lib/openc3/migrations/20260704000000_default_bridge.rb +1 -2
- data/lib/openc3/migrations/20261103000001_limits_group_backfill.rb +193 -0
- data/lib/openc3/models/bridge_model.rb +3 -3
- data/lib/openc3/models/cvt_model.rb +10 -3
- data/lib/openc3/models/host_interface_microservice_model.rb +4 -4
- data/lib/openc3/models/interface_model.rb +27 -7
- data/lib/openc3/models/microservice_group.rb +167 -0
- data/lib/openc3/models/microservice_model.rb +88 -2
- data/lib/openc3/models/panel_model.rb +109 -0
- data/lib/openc3/models/plugin_model.rb +1006 -26
- data/lib/openc3/models/plugin_store_model.rb +6 -1
- data/lib/openc3/models/protected_storage_model.rb +64 -0
- data/lib/openc3/models/queue_model.rb +19 -10
- data/lib/openc3/models/scope_model.rb +80 -3
- data/lib/openc3/models/setting_model.rb +2 -2
- data/lib/openc3/models/shared_resource_model.rb +381 -0
- data/lib/openc3/models/target_model.rb +333 -74
- data/lib/openc3/operators/microservice_operator.rb +76 -9
- data/lib/openc3/operators/operator.rb +29 -0
- data/lib/openc3/packets/commands.rb +16 -16
- data/lib/openc3/packets/limits.rb +2 -0
- data/lib/openc3/packets/packet.rb +75 -4
- data/lib/openc3/packets/packet_config.rb +152 -13
- data/lib/openc3/packets/packet_item.rb +48 -22
- data/lib/openc3/packets/packet_item_limits.rb +67 -6
- data/lib/openc3/packets/parsers/limits_parser.rb +69 -2
- data/lib/openc3/packets/parsers/packet_item_parser.rb +6 -0
- data/lib/openc3/packets/parsers/packet_parser.rb +45 -0
- data/lib/openc3/packets/parsers/state_parser.rb +1 -1
- data/lib/openc3/script/CLAUDE.md +1 -0
- data/lib/openc3/script/api_shared.rb +27 -17
- data/lib/openc3/script/calendar.rb +18 -6
- data/lib/openc3/script/commands.rb +11 -9
- data/lib/openc3/script/critical_cmd.rb +22 -2
- data/lib/openc3/script/extract.rb +52 -5
- data/lib/openc3/script/metadata.rb +30 -4
- data/lib/openc3/script/plugins.rb +8 -0
- data/lib/openc3/script/script.rb +9 -25
- data/lib/openc3/script/web_socket_api.rb +23 -17
- data/lib/openc3/system/system.rb +9 -3
- data/lib/openc3/top_level.rb +17 -0
- data/lib/openc3/topics/command_topic.rb +7 -1
- data/lib/openc3/topics/decom_interface_topic.rb +9 -3
- data/lib/openc3/topics/discovery_topic.rb +84 -0
- data/lib/openc3/topics/limits_event_topic.rb +317 -11
- data/lib/openc3/topics/router_topic.rb +6 -2
- data/lib/openc3/topics/system_events_topic.rb +9 -6
- data/lib/openc3/topics/telemetry_decom_topic.rb +12 -3
- data/lib/openc3/topics/topic.rb +9 -1
- data/lib/openc3/utilities/authentication.rb +67 -16
- data/lib/openc3/utilities/bucket.rb +5 -0
- data/lib/openc3/utilities/cli_generator.rb +117 -25
- data/lib/openc3/utilities/client_ip_header_filter.rb +38 -0
- data/lib/openc3/utilities/config_overlay.rb +24 -1
- data/lib/openc3/utilities/cosmos_rails_formatter.rb +18 -10
- data/lib/openc3/utilities/hardware_discovery.rb +279 -0
- data/lib/openc3/utilities/limits_rollup.rb +81 -0
- data/lib/openc3/utilities/local_mode.rb +48 -5
- data/lib/openc3/utilities/questdb_client.rb +256 -54
- data/lib/openc3/utilities/reingest_job.rb +12 -3
- data/lib/openc3/utilities/running_script.rb +206 -49
- data/lib/openc3/utilities/script.rb +24 -12
- data/lib/openc3/utilities/script_env.rb +164 -0
- data/lib/openc3/utilities/script_message_signing.rb +133 -0
- data/lib/openc3/utilities/secrets.rb +5 -0
- data/lib/openc3/utilities/store_autoload.rb +35 -2
- data/lib/openc3/utilities/store_queued.rb +5 -1
- data/lib/openc3/version.rb +5 -5
- data/templates/command_validator/command_validator.py +9 -9
- data/templates/{tool_react/pnpm-workspace.yaml → panel/.prettierrc.cjs} +7 -5
- data/templates/panel/Rakefile +24 -0
- data/templates/panel/package.json +17 -0
- data/templates/{tool_angular → panel}/pnpm-workspace.yaml +5 -0
- data/templates/panel/src/Panel.js +52 -0
- data/templates/panel/src/Panel.vue +60 -0
- data/templates/panel/src/panelSdk.js +24 -0
- data/templates/panel/vite-Panel.config.js +43 -0
- data/templates/tool_vue/package.json +3 -3
- data/templates/widget/package.json +2 -2
- metadata +24 -56
- data/templates/tool_angular/.editorconfig +0 -16
- data/templates/tool_angular/.gitignore +0 -44
- data/templates/tool_angular/.vscode/extensions.json +0 -4
- data/templates/tool_angular/.vscode/launch.json +0 -20
- data/templates/tool_angular/.vscode/tasks.json +0 -42
- data/templates/tool_angular/angular.json +0 -111
- data/templates/tool_angular/extra-webpack.config.js +0 -8
- data/templates/tool_angular/package.json +0 -48
- data/templates/tool_angular/src/app/app-routing.module.ts +0 -15
- data/templates/tool_angular/src/app/app.component.html +0 -22
- data/templates/tool_angular/src/app/app.component.scss +0 -18
- data/templates/tool_angular/src/app/app.component.spec.ts +0 -29
- data/templates/tool_angular/src/app/app.component.ts +0 -52
- data/templates/tool_angular/src/app/app.module.ts +0 -30
- data/templates/tool_angular/src/app/custom-overlay-container.ts +0 -17
- data/templates/tool_angular/src/app/empty-route/empty-route.component.ts +0 -7
- data/templates/tool_angular/src/app/openc3-api.d.ts +0 -1
- data/templates/tool_angular/src/assets/.gitkeep +0 -0
- data/templates/tool_angular/src/environments/environment.prod.ts +0 -3
- data/templates/tool_angular/src/environments/environment.ts +0 -16
- data/templates/tool_angular/src/favicon.ico +0 -0
- data/templates/tool_angular/src/index.html +0 -13
- data/templates/tool_angular/src/main.single-spa.ts +0 -40
- data/templates/tool_angular/src/single-spa/asset-url.ts +0 -12
- data/templates/tool_angular/src/single-spa/single-spa-props.ts +0 -8
- data/templates/tool_angular/src/styles.scss +0 -1
- data/templates/tool_angular/tsconfig.app.json +0 -13
- data/templates/tool_angular/tsconfig.json +0 -33
- data/templates/tool_angular/tsconfig.spec.json +0 -14
- data/templates/tool_react/.eslintrc +0 -7
- data/templates/tool_react/.gitignore +0 -71
- data/templates/tool_react/.prettierignore +0 -8
- data/templates/tool_react/babel.config.json +0 -29
- data/templates/tool_react/jest.config.js +0 -12
- data/templates/tool_react/package.json +0 -51
- data/templates/tool_react/src/openc3-tool_name.js +0 -24
- data/templates/tool_react/src/root.component.js +0 -88
- data/templates/tool_react/src/root.component.test.js +0 -9
- data/templates/tool_react/webpack.config.js +0 -27
- data/templates/tool_svelte/.gitignore +0 -71
- data/templates/tool_svelte/.prettierignore +0 -8
- data/templates/tool_svelte/.prettierrc.js +0 -5
- data/templates/tool_svelte/babel.config.js +0 -12
- data/templates/tool_svelte/build/smui.css +0 -1
- data/templates/tool_svelte/jest.config.js +0 -9
- data/templates/tool_svelte/package.json +0 -49
- data/templates/tool_svelte/pnpm-workspace.yaml +0 -20
- data/templates/tool_svelte/rollup.config.js +0 -74
- data/templates/tool_svelte/src/App.svelte +0 -42
- data/templates/tool_svelte/src/App.test.js +0 -9
- data/templates/tool_svelte/src/theme/_smui-theme.scss +0 -25
- data/templates/tool_svelte/src/tool_name.js +0 -17
- data/templates/widget/LICENSE.md +0 -20
|
@@ -65,7 +65,9 @@ module OpenC3
|
|
|
65
65
|
@write_extra = nil
|
|
66
66
|
if packet.extra
|
|
67
67
|
@write_flags |= COSMOS4_EXTRA_FLAG_MASK
|
|
68
|
-
|
|
68
|
+
# Force binary so appending it can't promote data_to_send to UTF-8, which
|
|
69
|
+
# then raises Encoding::CompatibilityError on the binary fields that follow
|
|
70
|
+
@write_extra = packet.extra.as_json().to_json(allow_nan: true).b
|
|
69
71
|
end
|
|
70
72
|
return packet
|
|
71
73
|
end
|
|
@@ -76,7 +78,9 @@ module OpenC3
|
|
|
76
78
|
data_to_send << @sync_pattern if @sync_pattern
|
|
77
79
|
data_to_send << @write_flags
|
|
78
80
|
if @write_extra
|
|
79
|
-
|
|
81
|
+
# Length field must count bytes, not characters, or a non-ASCII value in
|
|
82
|
+
# extra desyncs the receiver
|
|
83
|
+
data_to_send << [@write_extra.bytesize].pack('N')
|
|
80
84
|
data_to_send << @write_extra
|
|
81
85
|
end
|
|
82
86
|
data_to_send << @write_time_seconds
|
|
@@ -27,18 +27,56 @@ module OpenC3
|
|
|
27
27
|
# connections. For each connection to the read port, a thread is spawned that
|
|
28
28
|
# calls the read method from the interface. This data is then
|
|
29
29
|
# available by calling the TcpipServer read method. For each connection to the
|
|
30
|
-
# write port, a thread is spawned
|
|
31
|
-
# interface when data is
|
|
30
|
+
# write port, a thread is spawned with its own queue which calls the write
|
|
31
|
+
# method from the interface when data is sent to the TcpipServer via the
|
|
32
|
+
# write method. Each client is written independently so a client which stops
|
|
33
|
+
# reading can't delay the other clients or accepting new connections.
|
|
32
34
|
class TcpipServerInterface < StreamInterface
|
|
35
|
+
# Write timeout used when none is given, matching TcpipSocketStream
|
|
36
|
+
DEFAULT_WRITE_TIMEOUT = 10.0
|
|
37
|
+
|
|
38
|
+
# Interface for each client connection. Tracks the time spent writing to
|
|
39
|
+
# the socket so a client which can't keep up can be told apart from one
|
|
40
|
+
# whose protocols take a while (e.g. waiting for a command response).
|
|
41
|
+
class ClientInterface < StreamInterface
|
|
42
|
+
# Total seconds spent in stream writes
|
|
43
|
+
attr_reader :socket_write_time
|
|
44
|
+
|
|
45
|
+
def initialize
|
|
46
|
+
super()
|
|
47
|
+
@socket_write_time = 0.0
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def write_interface(data, extra = nil)
|
|
51
|
+
write_interface_base(data, extra)
|
|
52
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
53
|
+
begin
|
|
54
|
+
@stream.write(data)
|
|
55
|
+
ensure
|
|
56
|
+
@socket_write_time += Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
|
|
57
|
+
end
|
|
58
|
+
return data, extra
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
33
62
|
# Data class which stores the interface and associated information
|
|
34
63
|
class InterfaceInfo
|
|
35
|
-
attr_reader :interface, :
|
|
64
|
+
attr_reader :interface, :host_ip, :port
|
|
65
|
+
# Queue of [method, packet_or_data, socket_write_time] waiting to be written to the client
|
|
66
|
+
attr_accessor :write_queue
|
|
67
|
+
# Thread which services the write_queue
|
|
68
|
+
attr_accessor :write_thread
|
|
36
69
|
|
|
37
|
-
def initialize(interface,
|
|
70
|
+
def initialize(interface, host_ip, port)
|
|
38
71
|
@interface = interface
|
|
39
|
-
@hostname = hostname
|
|
40
72
|
@host_ip = host_ip
|
|
41
73
|
@port = port
|
|
74
|
+
@write_queue = nil
|
|
75
|
+
@write_thread = nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def to_s
|
|
79
|
+
"#{@host_ip}:#{@port}"
|
|
42
80
|
end
|
|
43
81
|
end
|
|
44
82
|
|
|
@@ -104,6 +142,8 @@ module OpenC3
|
|
|
104
142
|
@stream_log_pair = nil
|
|
105
143
|
@raw_logging_enabled = false
|
|
106
144
|
@connection_mutex = Mutex.new
|
|
145
|
+
# Client write threads update the write statistics concurrently
|
|
146
|
+
@write_stats_mutex = Mutex.new
|
|
107
147
|
@listen_address = "0.0.0.0"
|
|
108
148
|
|
|
109
149
|
@read_allowed = false unless ConfigParser.handle_nil(read_port)
|
|
@@ -142,7 +182,7 @@ module OpenC3
|
|
|
142
182
|
break if @cancel_threads
|
|
143
183
|
end
|
|
144
184
|
rescue Exception => e
|
|
145
|
-
|
|
185
|
+
shutdown_write_clients()
|
|
146
186
|
Logger.error("#{@name}: Tcpip server write thread unexpectedly died")
|
|
147
187
|
Logger.error(e.formatted)
|
|
148
188
|
end
|
|
@@ -152,7 +192,7 @@ module OpenC3
|
|
|
152
192
|
break if @cancel_threads
|
|
153
193
|
end
|
|
154
194
|
rescue Exception => e
|
|
155
|
-
|
|
195
|
+
shutdown_write_clients()
|
|
156
196
|
Logger.error("#{@name}: Tcpip server write raw thread unexpectedly died")
|
|
157
197
|
Logger.error(e.formatted)
|
|
158
198
|
end
|
|
@@ -207,7 +247,7 @@ module OpenC3
|
|
|
207
247
|
@write_raw_thread = nil
|
|
208
248
|
end
|
|
209
249
|
|
|
210
|
-
|
|
250
|
+
shutdown_write_clients()
|
|
211
251
|
@connected = false
|
|
212
252
|
super()
|
|
213
253
|
end
|
|
@@ -306,13 +346,36 @@ module OpenC3
|
|
|
306
346
|
def shutdown_interfaces(interface_infos)
|
|
307
347
|
@connection_mutex.synchronize do
|
|
308
348
|
interface_infos.each do |interface_info|
|
|
309
|
-
interface_info
|
|
310
|
-
interface_info.interface.stream_log_pair.stop if interface_info.interface.stream_log_pair
|
|
349
|
+
disconnect_client(interface_info)
|
|
311
350
|
end
|
|
312
351
|
interface_infos.clear
|
|
313
352
|
end
|
|
314
353
|
end
|
|
315
354
|
|
|
355
|
+
# Stop every client write thread and disconnect the clients
|
|
356
|
+
def shutdown_write_clients
|
|
357
|
+
interface_infos = @connection_mutex.synchronize do
|
|
358
|
+
infos = @write_interface_infos.dup
|
|
359
|
+
@write_interface_infos.clear
|
|
360
|
+
infos
|
|
361
|
+
end
|
|
362
|
+
# Stop and join outside the mutex because the client write threads
|
|
363
|
+
# take it to remove themselves as they exit
|
|
364
|
+
interface_infos.each do |interface_info|
|
|
365
|
+
stop_client_write_queue(interface_info)
|
|
366
|
+
disconnect_client(interface_info)
|
|
367
|
+
end
|
|
368
|
+
interface_infos.each do |interface_info|
|
|
369
|
+
thread = interface_info.write_thread
|
|
370
|
+
OpenC3.kill_thread(self, thread) if thread and thread != Thread.current
|
|
371
|
+
end
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
def disconnect_client(interface_info)
|
|
375
|
+
interface_info.interface.disconnect
|
|
376
|
+
interface_info.interface.stream_log_pair.stop if interface_info.interface.stream_log_pair
|
|
377
|
+
end
|
|
378
|
+
|
|
316
379
|
def change_raw_logging(method)
|
|
317
380
|
if @stream_log_pair
|
|
318
381
|
@write_interface_infos.each do |interface_info|
|
|
@@ -380,18 +443,8 @@ module OpenC3
|
|
|
380
443
|
end
|
|
381
444
|
end
|
|
382
445
|
|
|
446
|
+
# No reverse DNS lookup because it blocks accepting further connections
|
|
383
447
|
port, host_ip = Socket.unpack_sockaddr_in(address)
|
|
384
|
-
hostname = ''
|
|
385
|
-
hostname = Socket.lookup_hostname_from_ip(host_ip)
|
|
386
|
-
# if System.instance.acl
|
|
387
|
-
# addr = ["AF_INET", 10, "lc630", host_ip.to_s]
|
|
388
|
-
# if not System.instance.acl.allow_addr?(addr)
|
|
389
|
-
# # Reject connection
|
|
390
|
-
# OpenC3.close_socket(socket)
|
|
391
|
-
# Logger.info "#{@name}: Tcpip server rejected connection from #{hostname}(#{host_ip}):#{port}"
|
|
392
|
-
# return
|
|
393
|
-
# end
|
|
394
|
-
# end
|
|
395
448
|
|
|
396
449
|
# Configure TCP_NODELAY option
|
|
397
450
|
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
|
@@ -408,7 +461,7 @@ module OpenC3
|
|
|
408
461
|
stream.set_option(option_name, option_values)
|
|
409
462
|
end
|
|
410
463
|
|
|
411
|
-
interface =
|
|
464
|
+
interface = ClientInterface.new
|
|
412
465
|
# Only the read side of the connection needs a read thread
|
|
413
466
|
interface.read_allowed = listen_read
|
|
414
467
|
# Each connection buffers its own reads so give it the configured limit
|
|
@@ -426,25 +479,127 @@ module OpenC3
|
|
|
426
479
|
interface.stream = stream
|
|
427
480
|
interface.connect
|
|
428
481
|
|
|
482
|
+
interface_info = InterfaceInfo.new(interface, host_ip, port)
|
|
429
483
|
if listen_write
|
|
430
484
|
@write_connection_callback.call(interface) if @write_connection_callback
|
|
431
|
-
|
|
432
|
-
@write_interface_infos << InterfaceInfo.new(interface, hostname, host_ip, port)
|
|
433
|
-
end
|
|
485
|
+
add_write_client(interface_info)
|
|
434
486
|
end
|
|
435
487
|
if listen_read
|
|
436
488
|
@read_connection_callback.call(interface) if @read_connection_callback
|
|
437
489
|
@connection_mutex.synchronize do
|
|
438
|
-
@read_interface_infos <<
|
|
490
|
+
@read_interface_infos << interface_info
|
|
491
|
+
end
|
|
492
|
+
start_read_thread(interface_info)
|
|
493
|
+
end
|
|
494
|
+
Logger.info "#{@name}: Tcpip server accepted connection from #{interface_info}"
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
# Register a client connected to the write port and start the thread
|
|
498
|
+
# which writes its queued packets
|
|
499
|
+
def add_write_client(interface_info)
|
|
500
|
+
interface_info.write_queue = Queue.new
|
|
501
|
+
# Register before starting the thread so the thread can always remove it
|
|
502
|
+
@connection_mutex.synchronize do
|
|
503
|
+
@write_interface_infos << interface_info
|
|
504
|
+
end
|
|
505
|
+
interface_info.write_thread = Thread.new do
|
|
506
|
+
client_write_thread_body(interface_info)
|
|
507
|
+
rescue Exception => e
|
|
508
|
+
Logger.error "#{@name}: Tcpip server client write thread unexpectedly died"
|
|
509
|
+
Logger.error e.formatted
|
|
510
|
+
ensure
|
|
511
|
+
remove_write_client(interface_info)
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
# Writes everything queued for one client until the client disconnects,
|
|
516
|
+
# stops keeping up, or the queue is stopped
|
|
517
|
+
def client_write_thread_body(interface_info)
|
|
518
|
+
interface = interface_info.interface
|
|
519
|
+
write_queue = interface_info.write_queue
|
|
520
|
+
max_lag = @write_timeout || DEFAULT_WRITE_TIMEOUT
|
|
521
|
+
loop do
|
|
522
|
+
item = write_queue.pop(timeout: 0.1)
|
|
523
|
+
unless item
|
|
524
|
+
# Closed means the client is being removed
|
|
525
|
+
return if write_queue.closed?
|
|
526
|
+
# Detect disconnected clients even when packets aren't flowing
|
|
527
|
+
return unless client_write_connected?(interface_info)
|
|
528
|
+
|
|
529
|
+
next
|
|
439
530
|
end
|
|
440
|
-
|
|
531
|
+
|
|
532
|
+
method, packet_or_data, socket_write_time = item
|
|
533
|
+
# A client which is reading too slowly to keep up would otherwise
|
|
534
|
+
# queue data forever so drop it once it has spent more than
|
|
535
|
+
# write_timeout blocked on the socket since this item was queued.
|
|
536
|
+
# Only socket time counts, not time spent in protocols, so a
|
|
537
|
+
# protocol waiting for a response doesn't get the client dropped.
|
|
538
|
+
lag = interface.socket_write_time - socket_write_time
|
|
539
|
+
if lag > max_lag
|
|
540
|
+
Logger.error "#{@name}: Tcpip server dropping client #{interface_info} which spent #{lag.round(1)}s blocked writing since this data was queued (write timeout #{max_lag}s)"
|
|
541
|
+
return
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
interface_bytes_written = interface.bytes_written
|
|
545
|
+
interface.public_send(method, packet_or_data)
|
|
546
|
+
diff = interface.bytes_written - interface_bytes_written
|
|
547
|
+
@write_stats_mutex.synchronize do
|
|
548
|
+
@written_raw_data_time = interface.written_raw_data_time
|
|
549
|
+
@written_raw_data = interface.written_raw_data
|
|
550
|
+
@bytes_written += diff
|
|
551
|
+
end
|
|
552
|
+
end
|
|
553
|
+
rescue Errno::EPIPE, Errno::ECONNABORTED, IOError, Errno::ECONNRESET
|
|
554
|
+
# Client has normally disconnected
|
|
555
|
+
rescue Timeout::Error
|
|
556
|
+
Logger.error "#{@name}: Tcpip server dropping client #{interface_info} which did not accept data within the write timeout"
|
|
557
|
+
rescue Exception => e
|
|
558
|
+
if e.message != "Stream not connected for write_raw"
|
|
559
|
+
Logger.error "#{@name}: Error sending to client #{interface_info}: #{e.class} #{e.message}"
|
|
441
560
|
end
|
|
442
|
-
|
|
561
|
+
end
|
|
562
|
+
|
|
563
|
+
# @return [Boolean] Whether the client on the write port still appears connected
|
|
564
|
+
def client_write_connected?(interface_info)
|
|
565
|
+
write_socket = interface_info.interface.stream.write_socket
|
|
566
|
+
if @write_port != @read_port
|
|
567
|
+
# Socket should return EWOULDBLOCK if it is still cleanly connected
|
|
568
|
+
write_socket.recvfrom_nonblock(10)
|
|
569
|
+
# Client has disconnected (or is invalidly sending data on the socket)
|
|
570
|
+
return false
|
|
571
|
+
else
|
|
572
|
+
# The read thread detects the disconnect and closes the socket
|
|
573
|
+
return !write_socket.closed?
|
|
574
|
+
end
|
|
575
|
+
rescue Errno::EWOULDBLOCK
|
|
576
|
+
# Client is still cleanly connected as far as we can tell without writing to the socket
|
|
577
|
+
return true
|
|
578
|
+
rescue Errno::ECONNRESET, Errno::ECONNABORTED, IOError
|
|
579
|
+
return false
|
|
580
|
+
end
|
|
581
|
+
|
|
582
|
+
# Called by the client write thread as it exits
|
|
583
|
+
def remove_write_client(interface_info)
|
|
584
|
+
stop_client_write_queue(interface_info)
|
|
585
|
+
removed = @connection_mutex.synchronize { @write_interface_infos.delete(interface_info) }
|
|
586
|
+
# Not found means shutdown_write_clients already removed it
|
|
587
|
+
return unless removed
|
|
588
|
+
|
|
589
|
+
Logger.info "#{@name}: Tcpip server lost write connection to #{interface_info}"
|
|
590
|
+
disconnect_client(interface_info)
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
def stop_client_write_queue(interface_info)
|
|
594
|
+
write_queue = interface_info.write_queue
|
|
595
|
+
return unless write_queue
|
|
596
|
+
|
|
597
|
+
write_queue.clear
|
|
598
|
+
write_queue.close
|
|
443
599
|
end
|
|
444
600
|
|
|
445
601
|
def start_read_thread(interface_info)
|
|
446
602
|
@read_threads << Thread.new do
|
|
447
|
-
index_to_delete = nil
|
|
448
603
|
begin
|
|
449
604
|
begin
|
|
450
605
|
read_thread_body(interface_info.interface)
|
|
@@ -452,24 +607,12 @@ module OpenC3
|
|
|
452
607
|
Logger.error "#{@name}: Tcpip server read thread unexpectedly died"
|
|
453
608
|
Logger.error e.formatted
|
|
454
609
|
end
|
|
455
|
-
Logger.info "#{@name}: Tcpip server lost read connection to #{interface_info
|
|
610
|
+
Logger.info "#{@name}: Tcpip server lost read connection to #{interface_info}"
|
|
456
611
|
@read_threads.delete(Thread.current)
|
|
457
612
|
|
|
458
|
-
index_to_delete = nil
|
|
459
613
|
@connection_mutex.synchronize do
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
if interface_info.interface == read_interface_info.interface
|
|
463
|
-
index_to_delete = index
|
|
464
|
-
read_interface_info.interface.disconnect
|
|
465
|
-
read_interface_info.interface.stream_log_pair.stop if read_interface_info.interface.stream_log_pair
|
|
466
|
-
break
|
|
467
|
-
end
|
|
468
|
-
index += 1
|
|
469
|
-
end
|
|
470
|
-
ensure
|
|
471
|
-
if index_to_delete
|
|
472
|
-
@read_interface_infos.delete_at(index_to_delete)
|
|
614
|
+
if @read_interface_infos.delete(interface_info)
|
|
615
|
+
disconnect_client(interface_info)
|
|
473
616
|
end
|
|
474
617
|
end
|
|
475
618
|
rescue Exception => e
|
|
@@ -481,7 +624,6 @@ module OpenC3
|
|
|
481
624
|
|
|
482
625
|
def write_thread_body
|
|
483
626
|
# Retrieve the next packet to be sent out to clients
|
|
484
|
-
# Handles disconnected clients even when packets aren't flowing
|
|
485
627
|
packet = nil
|
|
486
628
|
|
|
487
629
|
loop do
|
|
@@ -491,7 +633,10 @@ module OpenC3
|
|
|
491
633
|
packet = @write_queue.pop(true) # non_block to raise ThreadError
|
|
492
634
|
break
|
|
493
635
|
rescue ThreadError
|
|
494
|
-
|
|
636
|
+
# Sleep until we receive a packet or for 100ms
|
|
637
|
+
@write_mutex.synchronize do
|
|
638
|
+
@write_condition_variable.wait(@write_mutex, 0.1)
|
|
639
|
+
end
|
|
495
640
|
end
|
|
496
641
|
end
|
|
497
642
|
|
|
@@ -553,86 +698,21 @@ module OpenC3
|
|
|
553
698
|
packet
|
|
554
699
|
end
|
|
555
700
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
@connection_mutex.synchronize do
|
|
561
|
-
@write_interface_infos.each do |interface_info|
|
|
562
|
-
if @write_port != @read_port
|
|
563
|
-
# Socket should return EWOULDBLOCK if it is still cleanly connected
|
|
564
|
-
interface_info.interface.stream.write_socket.recvfrom_nonblock(10)
|
|
565
|
-
elsif !interface_info.interface.stream.write_socket.closed?
|
|
566
|
-
# Let read thread detect disconnect
|
|
567
|
-
next
|
|
568
|
-
end
|
|
569
|
-
# Client has disconnected (or is invalidly sending data on the socket)
|
|
570
|
-
Logger.info "#{@name}: Tcpip server lost write connection to #{interface_info.hostname}(#{interface_info.host_ip}):#{interface_info.port}"
|
|
571
|
-
interface_info.interface.disconnect
|
|
572
|
-
interface_info.interface.stream_log_pair.stop if interface_info.interface.stream_log_pair
|
|
573
|
-
indexes_to_delete.unshift(index) # Put later indexes at front of array
|
|
574
|
-
rescue Errno::ECONNRESET, Errno::ECONNABORTED, IOError
|
|
575
|
-
# Client has disconnected
|
|
576
|
-
Logger.info "#{@name}: Tcpip server lost write connection to #{interface_info.hostname}(#{interface_info.host_ip}):#{interface_info.port}"
|
|
577
|
-
interface_info.interface.disconnect
|
|
578
|
-
interface_info.interface.stream_log_pair.stop if interface_info.interface.stream_log_pair
|
|
579
|
-
indexes_to_delete.unshift(index) # Put later indexes at front of array
|
|
580
|
-
rescue Errno::EWOULDBLOCK
|
|
581
|
-
# Client is still cleanly connected as far as we can tell without writing to the socket
|
|
582
|
-
ensure
|
|
583
|
-
index += 1
|
|
584
|
-
end
|
|
585
|
-
|
|
586
|
-
# Delete any dead sockets
|
|
587
|
-
indexes_to_delete.each do |index_to_delete|
|
|
588
|
-
@write_interface_infos.delete_at(index_to_delete)
|
|
589
|
-
end
|
|
590
|
-
end # connection_mutex.synchronize
|
|
591
|
-
|
|
592
|
-
# Sleep until we receive a packet or for 100ms
|
|
593
|
-
@write_mutex.synchronize do
|
|
594
|
-
@write_condition_variable.wait(@write_mutex, 0.1)
|
|
595
|
-
end
|
|
596
|
-
end
|
|
597
|
-
|
|
701
|
+
# Queue the packet or data for every connected client. Never blocks on a
|
|
702
|
+
# socket. The mutex is only held to copy the client list so a client which
|
|
703
|
+
# stops reading can't delay the other clients or accepting new connections.
|
|
598
704
|
def write_to_clients(method, packet_or_data)
|
|
599
|
-
@connection_mutex.synchronize
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
@written_raw_data = interface_info.interface.written_raw_data
|
|
611
|
-
@bytes_written += diff
|
|
612
|
-
rescue Errno::EPIPE, Errno::ECONNABORTED, IOError, Errno::ECONNRESET
|
|
613
|
-
# Client has normally disconnected
|
|
614
|
-
need_disconnect = true
|
|
615
|
-
rescue Exception => e
|
|
616
|
-
if e.message != "Stream not connected for write_raw"
|
|
617
|
-
Logger.error "#{@name}: Error sending to client: #{e.class} #{e.message}"
|
|
618
|
-
end
|
|
619
|
-
need_disconnect = true
|
|
620
|
-
end
|
|
621
|
-
|
|
622
|
-
if need_disconnect
|
|
623
|
-
Logger.info "#{@name}: Tcpip server lost write connection to #{interface_info.hostname}(#{interface_info.host_ip}):#{interface_info.port}"
|
|
624
|
-
interface_info.interface.disconnect
|
|
625
|
-
interface_info.interface.stream_log_pair.stop if interface_info.interface.stream_log_pair
|
|
626
|
-
indexes_to_delete.unshift(index) # Put later indexes at front of array
|
|
627
|
-
end
|
|
628
|
-
index += 1
|
|
629
|
-
end
|
|
630
|
-
|
|
631
|
-
# Delete any dead sockets
|
|
632
|
-
indexes_to_delete.each do |index_to_delete|
|
|
633
|
-
@write_interface_infos.delete_at(index_to_delete)
|
|
634
|
-
end
|
|
635
|
-
end # connection_mutex.synchronize
|
|
705
|
+
interface_infos = @connection_mutex.synchronize { @write_interface_infos.dup }
|
|
706
|
+
last_index = interface_infos.length - 1
|
|
707
|
+
interface_infos.each_with_index do |interface_info, index|
|
|
708
|
+
item = packet_or_data
|
|
709
|
+
# Each client's protocols run concurrently and may modify the packet
|
|
710
|
+
# so every client but the last gets its own copy
|
|
711
|
+
item = packet_or_data.clone if method == :write and index != last_index
|
|
712
|
+
interface_info.write_queue << [method, item, interface_info.interface.socket_write_time]
|
|
713
|
+
rescue ClosedQueueError
|
|
714
|
+
# Client is being removed
|
|
715
|
+
end
|
|
636
716
|
end
|
|
637
717
|
|
|
638
718
|
def details
|
data/lib/openc3/io/json_api.rb
CHANGED
|
@@ -51,17 +51,9 @@ module OpenC3
|
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
#
|
|
54
|
+
# Generate the authentication object from the standard environment variables.
|
|
55
55
|
def _generate_auth
|
|
56
|
-
|
|
57
|
-
if ENV['OPENC3_API_PASSWORD']
|
|
58
|
-
return OpenC3Authentication.new()
|
|
59
|
-
else
|
|
60
|
-
return nil
|
|
61
|
-
end
|
|
62
|
-
else
|
|
63
|
-
return OpenC3KeycloakAuthentication.new(ENV['OPENC3_KEYCLOAK_URL'])
|
|
64
|
-
end
|
|
56
|
+
OpenC3.authentication_from_environment
|
|
65
57
|
end
|
|
66
58
|
|
|
67
59
|
def _request(*method_params, **kw_params)
|
|
@@ -79,17 +79,9 @@ module OpenC3
|
|
|
79
79
|
# JsonDRb.debug = true # Enable for debugging
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
-
#
|
|
82
|
+
# Generate the authentication object from the standard environment variables.
|
|
83
83
|
def generate_auth
|
|
84
|
-
|
|
85
|
-
if ENV['OPENC3_API_PASSWORD']
|
|
86
|
-
return OpenC3Authentication.new()
|
|
87
|
-
else
|
|
88
|
-
return nil
|
|
89
|
-
end
|
|
90
|
-
else
|
|
91
|
-
return OpenC3KeycloakAuthentication.new(ENV['OPENC3_KEYCLOAK_URL'])
|
|
92
|
-
end
|
|
84
|
+
OpenC3.authentication_from_environment
|
|
93
85
|
end
|
|
94
86
|
|
|
95
87
|
# Forwards all method calls to the remote service.
|
|
@@ -80,14 +80,6 @@ module OpenC3
|
|
|
80
80
|
# Sleeper used to delay cycle thread
|
|
81
81
|
@@cycle_sleeper = nil
|
|
82
82
|
|
|
83
|
-
# Returns the Redis db_shard holding a target stream such as
|
|
84
|
-
# SCOPE__TELEMETRY__{TARGET}__PACKET, or 0 if no target can be determined
|
|
85
|
-
def self.db_shard_for_topic(redis_topic)
|
|
86
|
-
target_match = redis_topic.match(/\{([^{}]+)\}/)
|
|
87
|
-
return 0 unless target_match
|
|
88
|
-
Store.db_shard_for_target(target_match[1], scope: redis_topic.split('__')[0])
|
|
89
|
-
end
|
|
90
|
-
|
|
91
83
|
# @param remote_log_directory [String] The path to store the log files
|
|
92
84
|
# @param logging_enabled [Boolean] Whether to start with logging enabled
|
|
93
85
|
# @param cycle_time [Integer] The amount of time in seconds before creating
|
|
@@ -222,6 +214,15 @@ module OpenC3
|
|
|
222
214
|
end
|
|
223
215
|
end
|
|
224
216
|
|
|
217
|
+
# The db_shard of a target topic like DEFAULT__DECOM__{INST}__HEALTH_STATUS
|
|
218
|
+
# or db_shard 0 for a topic without a target
|
|
219
|
+
def self.db_shard_for_topic(redis_topic)
|
|
220
|
+
scope, _, rest = redis_topic.delete_prefix('{').partition('__')
|
|
221
|
+
# The target is a {TARGET} part between two others, e.g. DECOM__{INST}__HEALTH_STATUS
|
|
222
|
+
target = rest.split('__', -1)[1...-1]&.find { |part| part.length > 2 and part.start_with?('{') and part.end_with?('}') }
|
|
223
|
+
(!scope.empty? and target) ? Store.db_shard_for_target(target[1...-1], scope: scope) : 0
|
|
224
|
+
end
|
|
225
|
+
|
|
225
226
|
def cycle_thread_body
|
|
226
227
|
@@cycle_sleeper = Sleeper.new
|
|
227
228
|
while true
|
|
@@ -318,15 +318,20 @@ module OpenC3
|
|
|
318
318
|
flags |= OPENC3_CBOR_FLAG_MASK
|
|
319
319
|
extra_encoded = extra.as_json.to_cbor
|
|
320
320
|
else
|
|
321
|
-
|
|
321
|
+
# Force binary: JSON.generate returns UTF-8 and appending that to the
|
|
322
|
+
# binary entry raises Encoding::CompatibilityError once the entry holds
|
|
323
|
+
# a byte >= 0x80, which silently drops the packet from the log
|
|
324
|
+
extra_encoded = JSON.generate(extra.as_json, allow_nan: true).b
|
|
322
325
|
end
|
|
323
|
-
|
|
326
|
+
# Count bytes, not characters, so a non-ASCII value in extra can't produce
|
|
327
|
+
# a short entry length
|
|
328
|
+
length += extra_encoded.bytesize
|
|
324
329
|
end
|
|
325
330
|
length += OPENC3_PACKET_SECONDARY_FIXED_SIZE + data.length
|
|
326
331
|
@entry.clear
|
|
327
332
|
@entry << [length, flags, packet_index, time_nsec_since_epoch].pack(OPENC3_PACKET_PACK_DIRECTIVE)
|
|
328
333
|
@entry << [received_time_nsec_since_epoch].pack(OPENC3_RECEIVED_TIME_PACK_DIRECTIVE) if received_time_nsec_since_epoch
|
|
329
|
-
@entry << [extra_encoded.
|
|
334
|
+
@entry << [extra_encoded.bytesize].pack(OPENC3_EXTRA_LENGTH_PACK_DIRECTIVE) << extra_encoded if extra_encoded
|
|
330
335
|
@entry << data.force_encoding('ASCII-8BIT')
|
|
331
336
|
@first_time = time_nsec_since_epoch if !@first_time or time_nsec_since_epoch < @first_time
|
|
332
337
|
@last_time = time_nsec_since_epoch if !@last_time or time_nsec_since_epoch > @last_time
|
|
@@ -40,6 +40,8 @@ module OpenC3
|
|
|
40
40
|
# 'LOG' still evaluates limits (callback handles suppressing reactions).
|
|
41
41
|
# 'DISABLE' skips limits evaluation entirely for stored packets and omits
|
|
42
42
|
# limits states from the decommutated output.
|
|
43
|
+
# @param queued [Boolean] Queue the decom stream and CVT writes (StoreQueued) rather
|
|
44
|
+
# than writing them directly to Redis.
|
|
43
45
|
# @param metric [Metric, nil] Optional; when set, records decom_duration_seconds.
|
|
44
46
|
# @param error_callback [Proc, nil] Called as error_callback.call(exception) when
|
|
45
47
|
# Packet#process or Packet#check_limits raises. The microservice uses this to
|
|
@@ -47,7 +49,7 @@ module OpenC3
|
|
|
47
49
|
# @return [Integer] Number of (sub)packets published.
|
|
48
50
|
def decom_and_publish(packet, scope:, target_names:, logger:, name:,
|
|
49
51
|
check_limits: true, stored_limits_mode: 'PROCESS',
|
|
50
|
-
metric: nil, error_callback: nil)
|
|
52
|
+
queued: false, metric: nil, error_callback: nil)
|
|
51
53
|
start = Process.clock_gettime(Process::CLOCK_MONOTONIC) if metric
|
|
52
54
|
published = 0
|
|
53
55
|
|
|
@@ -75,6 +77,7 @@ module OpenC3
|
|
|
75
77
|
|
|
76
78
|
TelemetryDecomTopic.write_packet(packet_or_subpacket,
|
|
77
79
|
include_limits_states: !disable_stored_limits,
|
|
80
|
+
queued: queued,
|
|
78
81
|
scope: scope)
|
|
79
82
|
published += 1
|
|
80
83
|
end
|