selfsdk 0.0.169 → 0.0.174

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: e525b40ab24f81c5e2ece5c34a8bdb312fae674074981ba8188d168a4c27644d
4
- data.tar.gz: c97ce7cf0278006e0ef0a3fff16b5ce80f0d5564c84b0419354dc41dab35bd21
3
+ metadata.gz: 2c5f337bf8029e978de8dfc0e81f9689f34ce7c746db0ee49da981a48f621a33
4
+ data.tar.gz: baf4784345f281cfda38d86e9a24a5f2c8f1991f587696ac6d2e655ce379a02c
5
5
  SHA512:
6
- metadata.gz: b069aaabdcc6a10a941c7ecdff18ec69d57d6773275903b9b8f9e1192ec045d1b43d361e57e8203abffd77878b184ac43ae84a2b0cd771112124a58e4860c1d4
7
- data.tar.gz: 66d71475ac439e52ab6982e676348547a90cfd3455f80a091dbf8fb7af777185fe9aff65c341fda2d0ec406cb217557fdbdaa513a6a666326128d9dfdd370965
6
+ metadata.gz: 11161a22d7e15e23e85e4871fd10bb5ee501f5ace89046f5155c897e58b4384a64dcdfcfb1b9869009fa40ff017370b6740c89073805a66fe852226de1e10e1f
7
+ data.tar.gz: 025fb47e5b70062d7c861bba26084d6ffdfd953a5eebf496066da3f3358e670e7b7a5fcbbffa0bb012d6dded72b8530b9276d625f5b41c9bd661b7c5b7654b31
data/lib/acl.rb CHANGED
@@ -11,16 +11,19 @@ module SelfSDK
11
11
  def initialize(messaging)
12
12
  @messaging = messaging
13
13
  @jwt = @messaging.jwt
14
+ @acl_rules = []
14
15
  end
15
16
 
16
17
  # Lists allowed connections.
17
18
  def list
18
19
  SelfSDK.logger.info "Listing allowed connections"
19
- @messaging.list_acl_rules
20
+ @acl_rules = @messaging.list_acl_rules if @acl_rules.empty?
21
+ @acl_rules
20
22
  end
21
23
 
22
24
  # Allows incomming messages from the given identity.
23
25
  def allow(id)
26
+ @acl_rules << id
24
27
  SelfSDK.logger.info "Allowing connections from #{id}"
25
28
  @messaging.add_acl_rule(@jwt.prepare(jti: SecureRandom.uuid,
26
29
  cid: SecureRandom.uuid,
@@ -35,6 +38,7 @@ module SelfSDK
35
38
 
36
39
  # Deny incomming messages from the given identity.
37
40
  def deny(id)
41
+ @acl_rules.delete(id)
38
42
  SelfSDK.logger.info "Denying connections from #{id}"
39
43
  @messaging.remove_acl_rule(@jwt.prepare(jti: SecureRandom.uuid,
40
44
  cid: SecureRandom.uuid,
@@ -43,7 +43,7 @@ module SelfSDK
43
43
  def proto(to_device)
44
44
  Msgproto::Message.new(type: Msgproto::MsgType::MSG,
45
45
  sender: "#{@jwt.id}:#{@messaging.device_id}",
46
- id: @id,
46
+ id: SecureRandom.uuid,
47
47
  recipient: "#{@to}:#{to_device}",
48
48
  ciphertext: encrypt_message(@jwt.prepare(body), @to, to_device))
49
49
  end
data/lib/messages/base.rb CHANGED
@@ -21,8 +21,13 @@ module SelfSDK
21
21
  msgs = []
22
22
  devices.each do |d|
23
23
  msgs << proto(d)
24
- SelfSDK.logger.info "synchronously messaging to #{@to}:#{d}"
25
24
  end
25
+ current_devices.each do |d|
26
+ if d != @messaging.device_id
27
+ msgs << proto(d)
28
+ end
29
+ end
30
+ SelfSDK.logger.info "synchronously messaging to #{@to}"
26
31
  res = @messaging.send_and_wait_for_response(msgs, self)
27
32
  res
28
33
  end
@@ -84,6 +89,10 @@ module SelfSDK
84
89
  @client.devices(@intermediary)
85
90
  end
86
91
 
92
+ def current_devices
93
+ @client.devices(@jwt.id)
94
+ end
95
+
87
96
  def check_credits!
88
97
  app = @client.app(@jwt.id)
89
98
  raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
@@ -105,7 +105,7 @@ module SelfSDK
105
105
 
106
106
  Msgproto::Message.new(
107
107
  type: Msgproto::MsgType::MSG,
108
- id: @id,
108
+ id: SecureRandom.uuid,
109
109
  sender: "#{@jwt.id}:#{@messaging.device_id}",
110
110
  recipient: recipient,
111
111
  ciphertext: ciphertext )
data/lib/messaging.rb CHANGED
@@ -101,15 +101,27 @@ module SelfSDK
101
101
  # @param type [string] message type
102
102
  # @param request [hash] original message requesing information
103
103
  def send_custom(recipient, request_body)
104
- # TODO (adriacidre) this is sending the message to the first device only
105
- @to_device = @client.devices(recipient).first
106
- send_message msg = Msgproto::Message.new(
104
+ @client.devices(recipient).each do |to_device|
105
+ send_message Msgproto::Message.new(
107
106
  type: Msgproto::MsgType::MSG,
108
107
  id: SecureRandom.uuid,
109
108
  sender: "#{@jwt.id}:#{@device_id}",
110
- recipient: "#{recipient}:#{@to_device}",
109
+ recipient: "#{recipient}:#{to_device}",
111
110
  ciphertext: @jwt.prepare(request_body),
112
111
  )
112
+ end
113
+
114
+ @client.devices(@jwt.id).each do |to_device|
115
+ if to-device != @device_id
116
+ send_message Msgproto::Message.new(
117
+ type: Msgproto::MsgType::MSG,
118
+ id: SecureRandom.uuid,
119
+ sender: "#{@jwt.id}:#{@device_id}",
120
+ recipient: "#{recipient}:#{to_device}",
121
+ ciphertext: @jwt.prepare(request_body),
122
+ )
123
+ end
124
+ end
113
125
  end
114
126
 
115
127
  # Allows incomming messages from the given identity
@@ -281,10 +293,6 @@ module SelfSDK
281
293
  loop { sleep 10; clean_timeouts }
282
294
  end
283
295
 
284
- Thread.new do
285
- loop { sleep 30; ping }
286
- end
287
-
288
296
  @mon.synchronize do
289
297
  @acks[auth_id][:waiting_cond].wait_while { @acks[auth_id][:waiting] }
290
298
  @acks.delete(auth_id)
@@ -351,11 +359,6 @@ module SelfSDK
351
359
  end
352
360
  end
353
361
 
354
- # Pings the websocket server to keep the connection alive.
355
- def ping
356
- # SelfSDK.logger.info "ping"
357
- @ws&.ping
358
- end
359
362
 
360
363
  # Process an event when it arrives through the websocket connection.
361
364
  def on_message(event)
@@ -363,7 +366,8 @@ module SelfSDK
363
366
  SelfSDK.logger.info " - received #{input.id} (#{input.type})"
364
367
  case input.type
365
368
  when :ERR
366
- SelfSDK.logger.info "error #{input.sender} on #{input.id}"
369
+ SelfSDK.logger.warn "error #{input.sender} on #{input.id}"
370
+ SelfSDK.logger.warn "#{input.to_json}"
367
371
  mark_as_arrived(input.id)
368
372
  when :ACK
369
373
  SelfSDK.logger.info "#{input.id} acknowledged"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selfsdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.169
4
+ version: 0.0.174
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures