cable_room 0.4.2 → 0.4.4

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: 5969f6c18b991780a679a01426571046c9118c033ea238cbdcc69d362595a86a
4
- data.tar.gz: 5f534f87fc9565fc9eeae80a01a9671b90b83762e9fe7ef9621dfd3e0020e247
3
+ metadata.gz: 928184ed2b2f5a529bb24cccde6e0048f9c9f5a7ce2b60b62779bc8f06a998ca
4
+ data.tar.gz: 440782d877fbdc28948fe8499de860bb0d99c4bcde01b1abb933a23f20a14074
5
5
  SHA512:
6
- metadata.gz: f670e13c1944482c446701d6434b3f6d3bde6c77268c70f4c1fbf047281c74825d2500787e3abe4285b12afff4b175320291be610dc06ec8d3bf7cbfe35ddba4
7
- data.tar.gz: 57c4cc7b7d11176accc28f71caa04f0b6ff67e7e386cdbb74c2b1f1623fa79d858f260002b402087cf0301481f510c43cb56775e0a249fc9cc52fa316382af57
6
+ metadata.gz: 95047199ea82748e023d3ca246ba942cc4e5845613bd7f76f18c2700e027027f60277f904bc9f3cc5514f808ae7ca4d9305d051fdf40b00d6c280a5fc4e8aba0
7
+ data.tar.gz: 5e4e966735dffddf5c074776ea44702dd52b6cd5559a5b814f7d87a03c3fb58e7acfb3b0b7401452b67e9444d7e67d29352ae726c8ab4ba35353e5390495685b
@@ -25,6 +25,9 @@ module CableRoom
25
25
  vchannel.subscribe_to_channel
26
26
 
27
27
  true
28
+ rescue => e
29
+ CableRoom.lock_manager.unlock(lock_info) if lock_info
30
+ raise e
28
31
  end
29
32
 
30
33
  def room_port_key(room_key, port = nil)
@@ -28,11 +28,20 @@ module CableRoom
28
28
  end
29
29
  end
30
30
  end
31
+
32
+ # Prevent certain message types being forwarded from clients
33
+ def system_message_types(*types)
34
+ ([self] + ActiveSupport::DescendantsTracker.descendants(self)).reverse_each do |target|
35
+ target._system_message_types = target._system_message_types | Set.new(types.map(&:to_sym))
36
+ end
37
+ end
31
38
  end
32
39
 
33
40
  included do
34
41
  define_callbacks :receive_message
35
42
 
43
+ class_attribute :_system_message_types, instance_writer: false, default: Set.new
44
+
36
45
  set_callback(:receive_message, :before) do
37
46
  logger.debug "Received message: #{message.inspect}"
38
47
  end
@@ -3,9 +3,6 @@ module CableRoom
3
3
  module PortManagement
4
4
  extend ActiveSupport::Concern
5
5
 
6
- require_relative 'port_policies'
7
- include PortPolicies
8
-
9
6
  PORT_TIMEOUT = 30.seconds
10
7
 
11
8
  class_methods do
@@ -38,6 +35,17 @@ module CableRoom
38
35
  @current_message_origin = previous_mtok
39
36
  end
40
37
  end
38
+
39
+ system_message_types(:port_connected, :port_disconnected, :port_ping)
40
+
41
+ require_relative 'port_policies'
42
+ include PortPolicies
43
+
44
+ PortPolicies::TagPolicy.define_tag_alias :connect, [:port_connected, :port_ping, :port_disconnected]
45
+
46
+ inbound_tag_policy(priority: -10) do
47
+ allow :*, :connect
48
+ end
41
49
  end
42
50
 
43
51
  def initialize(...)
@@ -36,10 +36,6 @@ module CableRoom
36
36
  next true if %i[port_connected port_disconnected].include?(msg_type)
37
37
  policy_allows?(msg_type)
38
38
  end
39
-
40
- inbound_tag_policy(priority: -10) do
41
- allow :*, :connect
42
- end
43
39
  end
44
40
 
45
41
  protected
@@ -58,8 +54,6 @@ module CableRoom
58
54
  end
59
55
  end
60
56
 
61
- define_tag_alias :connect, [:port_connected, :port_ping, :port_disconnected]
62
-
63
57
  def initialize()
64
58
  @policy_rules = []
65
59
  @fallback_rule = { action: :allow, priority: -100, tag: :*, methods: :* }
@@ -25,11 +25,13 @@ module CableRoom
25
25
  end
26
26
  end
27
27
 
28
+ system_message_types(:user_joined, :user_left)
29
+
30
+ PortPolicies::TagPolicy.define_tag_alias :join, [:connect, :user_joined, :user_left]
31
+
28
32
  inbound_tag_policy(priority: -10) do
29
33
  allow :*, :join
30
34
  end
31
-
32
- PortPolicies::TagPolicy.define_tag_alias :join, [:connect, :user_joined, :user_left]
33
35
  end
34
36
 
35
37
  def initialize(...)
@@ -120,7 +120,7 @@ module CableRoom
120
120
  def ping!
121
121
  return if left?
122
122
 
123
- self << { type: 'port_ping' }
123
+ port_transmit(room_class::ROOM_IN_CHANNEL, { type: 'port_ping' }, secure_context: true)
124
124
  maybe_provision_room
125
125
  end
126
126
 
@@ -129,7 +129,7 @@ module CableRoom
129
129
 
130
130
  close_streamed_ports!
131
131
  @cable_channel._room_memberships.delete(self)
132
- self << { type: 'port_disconnected' }
132
+ port_transmit(room_class::ROOM_IN_CHANNEL, { type: 'port_disconnected' }, secure_context: true)
133
133
  @has_left = true
134
134
  @on_closed&.call(self)
135
135
  end
@@ -138,9 +138,18 @@ module CableRoom
138
138
 
139
139
  protected
140
140
 
141
- def port_transmit(port, data)
141
+ def port_transmit(port, data, secure_context: false)
142
142
  data[:mtok] = @token
143
- super
143
+
144
+ unless secure_context
145
+ t = (data[:type] || data['type']).to_sym
146
+ if room_class._system_message_types.include?(t)
147
+ logger.warn "Dropping attempt to send system message type: #{t.inspect}"
148
+ return
149
+ end
150
+ end
151
+
152
+ super(port, data)
144
153
  end
145
154
 
146
155
  def room_port_key(port)
@@ -172,7 +181,7 @@ module CableRoom
172
181
  tags: @tags,
173
182
  }
174
183
  msg[:extra] = ::ActiveJob::Arguments.serialize([@extra]) if @extra
175
- self << msg
184
+ port_transmit(room_class::ROOM_IN_CHANNEL, msg, secure_context: true)
176
185
  end
177
186
 
178
187
  def maybe_provision_room
@@ -1,3 +1,3 @@
1
1
  module CableRoom
2
- VERSION = "0.4.2".freeze
2
+ VERSION = "0.4.4".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cable_room
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Knapp