selfsdk 0.0.166 → 0.0.167
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/messaging.rb +14 -7
- 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: 425117eb38ae08f2a8d3e65e1ba7ba772b06a4cbc378d17cbe5870a5598d2cb2
|
4
|
+
data.tar.gz: a638bc535a0e81732c7f48e11a779fe7ac08a8ea7f5239b0600af087030df65f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69c5dd8b994ddcc2ba6432baac35fb20e03d810d927b991956ae878efa3546a988e617aa12bb831897656fa4a8adb8c6e1180f09934d110703b938cbe3d3e5cf
|
7
|
+
data.tar.gz: 300df2dbe461f01666943f29a5d137e9bc254fc6dbdbdb80763bfaad302b3eca1dc63e35682afcba06a4364f74f7a5f674dccccae7ab6fa69d035af54bcffb59
|
data/lib/messaging.rb
CHANGED
@@ -43,6 +43,7 @@ module SelfSDK
|
|
43
43
|
@client = client
|
44
44
|
@ack_timeout = 60 # seconds
|
45
45
|
@timeout = 120 # seconds
|
46
|
+
@auth_id = SecureRandom.uuid
|
46
47
|
@device_id = options.fetch(:device_id, DEFAULT_DEVICE)
|
47
48
|
@auto_reconnect = options.fetch(:auto_reconnect, DEFAULT_AUTO_RECONNECT)
|
48
49
|
@raw_storage_dir = options.fetch(:storage_dir, DEFAULT_STORAGE_DIR)
|
@@ -264,8 +265,10 @@ module SelfSDK
|
|
264
265
|
# Start sthe websocket listener
|
265
266
|
def start
|
266
267
|
SelfSDK.logger.info "starting"
|
268
|
+
auth_id = @auth_id.dup
|
269
|
+
|
267
270
|
@mon.synchronize do
|
268
|
-
@acks[
|
271
|
+
@acks[auth_id] = { waiting_cond: @mon.new_cond,
|
269
272
|
waiting: true,
|
270
273
|
timeout: SelfSDK::Time.now + @ack_timeout }
|
271
274
|
end
|
@@ -283,16 +286,16 @@ module SelfSDK
|
|
283
286
|
end
|
284
287
|
|
285
288
|
@mon.synchronize do
|
286
|
-
@acks[
|
287
|
-
@acks.delete(
|
289
|
+
@acks[auth_id][:waiting_cond].wait_while { @acks[auth_id][:waiting] }
|
290
|
+
@acks.delete(auth_id)
|
288
291
|
end
|
289
292
|
# In case this does not succeed start the process again.
|
290
|
-
if @acks.include?
|
291
|
-
if @acks[
|
293
|
+
if @acks.include? auth_id
|
294
|
+
if @acks[auth_id][:waiting]
|
292
295
|
close
|
293
296
|
start_connection
|
294
297
|
end
|
295
|
-
@acks.delete(
|
298
|
+
@acks.delete(auth_id)
|
296
299
|
end
|
297
300
|
end
|
298
301
|
|
@@ -412,14 +415,18 @@ module SelfSDK
|
|
412
415
|
|
413
416
|
# Authenticates current client on the websocket server.
|
414
417
|
def authenticate
|
418
|
+
@auth_id = SecureRandom.uuid if @auth_id.nil?
|
419
|
+
|
415
420
|
SelfSDK.logger.info "authenticating"
|
416
421
|
send_raw Msgproto::Auth.new(
|
417
422
|
type: Msgproto::MsgType::AUTH,
|
418
|
-
id:
|
423
|
+
id: @auth_id,
|
419
424
|
token: @jwt.auth_token,
|
420
425
|
device: @device_id,
|
421
426
|
offset: @offset,
|
422
427
|
)
|
428
|
+
|
429
|
+
@auth_id = nil
|
423
430
|
end
|
424
431
|
|
425
432
|
def send_raw(msg)
|