selfsdk 0.0.175 → 0.0.176

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: 0556e53083b274c5456ab502c20a66bff0ab0c7897b29f794d0f920c7769fd51
4
- data.tar.gz: 58ba0a4bbf08bd9ed86c51a84febb542951a67d63aad27b2145cd31fdd160083
3
+ metadata.gz: 3d465f38002636ad2b874c7eb6e64a70767ab1daf86f3e9748a87de8c02bfce7
4
+ data.tar.gz: 159b58181cf4651732f5a12332d1ec2bb1662770261d648c70df3f663325dec4
5
5
  SHA512:
6
- metadata.gz: 8c10a1f4418eefaee9ebe9a1e933c5a3ad00956f2dc9648c6812c4e0da7c1c1783f1cedaae62b0b0366f78954aa6762d57c030f39c0e064a6a7404ed73033147
7
- data.tar.gz: ed99a0ace0c55eda3e422c56d1653ad33e4955c6432f3c2f70f631b13b9972d2da43211648fe9500540401090a6368ce109606b4346ea6788e4329d455ec0816
6
+ metadata.gz: 66d05b5ca689d1a4183acb6dba9882872ea1603b2eabc9ae0be5cb31a3fda5df5fc72ac15e26094d4f0c332255726f750760740af7c180f58403896122639705
7
+ data.tar.gz: 3cc0d584c0fd8c6f740725fc824ae96c8b068cef5de64012f529781f6ba9d397f0b6ec980d354f78d18d80fc7c31c040e0239523d198547db2eddf3ada6e09af
@@ -2,6 +2,7 @@
2
2
 
3
3
  # frozen_string_literal: true
4
4
 
5
+ require 'self_msgproto'
5
6
  require_relative 'base'
6
7
  require_relative '../ntptime'
7
8
  require_relative 'authentication_message'
@@ -41,11 +42,12 @@ module SelfSDK
41
42
  protected
42
43
 
43
44
  def proto(to_device)
44
- Msgproto::Message.new(type: Msgproto::MsgType::MSG,
45
- sender: "#{@jwt.id}:#{@messaging.device_id}",
46
- id: SecureRandom.uuid,
47
- recipient: "#{@to}:#{to_device}",
48
- ciphertext: encrypt_message(@jwt.prepare(body), @to, to_device))
45
+ m = SelfMsg::Message.new
46
+ m.id = SecureRandom.uuid
47
+ m.sender = "#{@jwt.id}:#{@messaging.device_id}"
48
+ m.recipient = "#{@to}:#{to_device}"
49
+ m.ciphertext = encrypt_message(@jwt.prepare(body), @to, to_device)
50
+ m
49
51
  end
50
52
 
51
53
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  # frozen_string_literal: true
4
4
 
5
+ require 'self_msgproto'
5
6
  require_relative 'base'
6
7
  require_relative '../ntptime'
7
8
 
@@ -103,12 +104,12 @@ module SelfSDK
103
104
  ciphertext = encrypt_message(@jwt.prepare(body), @intermediary, @to_device)
104
105
  end
105
106
 
106
- Msgproto::Message.new(
107
- type: Msgproto::MsgType::MSG,
108
- id: SecureRandom.uuid,
109
- sender: "#{@jwt.id}:#{@messaging.device_id}",
110
- recipient: recipient,
111
- ciphertext: ciphertext )
107
+ m = SelfMsg::Message.new
108
+ m.id = SecureRandom.uuid
109
+ m.sender = "#{@jwt.id}:#{@messaging.device_id}"
110
+ m.recipient = recipient
111
+ m.ciphertext = ciphertext
112
+ m
112
113
  end
113
114
  end
114
115
  end
data/lib/messaging.rb CHANGED
@@ -6,13 +6,9 @@ require 'json'
6
6
  require 'monitor'
7
7
  require 'faye/websocket'
8
8
  require 'fileutils'
9
+ require 'self_msgproto'
9
10
  require_relative 'crypto'
10
11
  require_relative 'messages/message'
11
- require_relative 'proto/auth_pb'
12
- require_relative 'proto/message_pb'
13
- require_relative 'proto/msgtype_pb'
14
- require_relative 'proto/acl_pb'
15
- require_relative 'proto/aclcommand_pb'
16
12
 
17
13
  module SelfSDK
18
14
  class MessagingClient
@@ -86,13 +82,13 @@ module SelfSDK
86
82
  # @param recipient_device [string] device id for the selfID to be requested
87
83
  # @param request [string] original message requesing information
88
84
  def share_information(recipient, recipient_device, request)
89
- send_message Msgproto::Message.new(
90
- type: Msgproto::MsgType::MSG,
91
- id: SecureRandom.uuid,
92
- sender: "#{@jwt.id}:#{@device_id}",
93
- recipient: "#{recipient}:#{recipient_device}",
94
- ciphertext: @jwt.prepare(request),
95
- )
85
+ m = SelfMsg::Message.new
86
+ m.id = SecureRandom.uuid
87
+ m.sender = "#{@jwt.id}:#{@device_id}"
88
+ m.recipient = "#{recipient}:#{recipient_device}"
89
+ m.ciphertext = @jwt.prepare(request)
90
+
91
+ send_message m
96
92
  end
97
93
 
98
94
  # Send custom mmessage
@@ -102,24 +98,24 @@ module SelfSDK
102
98
  # @param request [hash] original message requesing information
103
99
  def send_custom(recipient, request_body)
104
100
  @client.devices(recipient).each do |to_device|
105
- send_message Msgproto::Message.new(
106
- type: Msgproto::MsgType::MSG,
107
- id: SecureRandom.uuid,
108
- sender: "#{@jwt.id}:#{@device_id}",
109
- recipient: "#{recipient}:#{to_device}",
110
- ciphertext: @jwt.prepare(request_body),
111
- )
101
+ m = SelfMsg::Message.new
102
+ m.id = SecureRandom.uuid
103
+ m.sender = "#{@jwt.id}:#{@device_id}"
104
+ m.recipient = "#{recipient}:#{to_device}"
105
+ m.ciphertext = @jwt.prepare(request_body)
106
+
107
+ send_message m
112
108
  end
113
109
 
114
110
  @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
- )
111
+ if to_device != @device_id
112
+ m = SelfMsg::Message.new
113
+ m.id = SecureRandom.uuid
114
+ m.sender = "#{@jwt.id}:#{@device_id}"
115
+ m.recipient = "#{recipient}:#{to_device}"
116
+ m.ciphertext = @jwt.prepare(request_body)
117
+
118
+ send_message m
123
119
  end
124
120
  end
125
121
  end
@@ -128,40 +124,40 @@ module SelfSDK
128
124
  #
129
125
  # @params payload [string] base64 encoded payload to be sent
130
126
  def add_acl_rule(payload)
131
- send_message Msgproto::AccessControlList.new(
132
- type: Msgproto::MsgType::ACL,
133
- id: SecureRandom.uuid,
134
- command: Msgproto::ACLCommand::PERMIT,
135
- payload: payload,
136
- )
127
+ a = SelfMsg::Acl.new
128
+ a.id = SecureRandom.uuid
129
+ a.command = SelfMsg::AclCommandPERMIT
130
+ a.payload = payload
131
+
132
+ send_message a
137
133
  end
138
134
 
139
135
  # Blocks incoming messages from specified identities
140
136
  #
141
137
  # @params payload [string] base64 encoded payload to be sent
142
138
  def remove_acl_rule(payload)
143
- send_message Msgproto::AccessControlList.new(
144
- type: Msgproto::MsgType::ACL,
145
- id: SecureRandom.uuid,
146
- command: Msgproto::ACLCommand::REVOKE,
147
- payload: payload,
148
- )
139
+ a = SelfMsg::Acl.new
140
+ a.id = SecureRandom.uuid
141
+ a.command = SelfMsg::AclCommandREVOKE
142
+ a.payload = payload
143
+
144
+ send_message a
149
145
  end
150
146
 
151
147
  # Lists acl rules
152
148
  def list_acl_rules
153
149
  wait_for 'acl_list' do
154
- send_raw Msgproto::AccessControlList.new(
155
- type: Msgproto::MsgType::ACL,
156
- id: SecureRandom.uuid,
157
- command: Msgproto::ACLCommand::LIST,
158
- )
150
+ a = SelfMsg::Acl.new
151
+ a.id = SecureRandom.uuid
152
+ a.command = SelfMsg::AclCommandLIST
153
+
154
+ send_raw a
159
155
  end
160
156
  end
161
157
 
162
158
  # Sends a message and waits for the response
163
159
  #
164
- # @params msg [Msgproto::Message] message object to be sent
160
+ # @params msg [SelfMsg::Message] message object to be sent
165
161
  def send_and_wait_for_response(msgs, original)
166
162
  wait_for msgs.first.id, original do
167
163
  msgs.each do |msg|
@@ -202,7 +198,7 @@ module SelfSDK
202
198
 
203
199
  # Send a message through self network
204
200
  #
205
- # @params msg [Msgproto::Message] message object to be sent
201
+ # @params msg [SelfMsg::Message] message object to be sent
206
202
  def send_message(msg)
207
203
  uuid = msg.id
208
204
  @mon.synchronize do
@@ -362,34 +358,39 @@ module SelfSDK
362
358
 
363
359
  # Process an event when it arrives through the websocket connection.
364
360
  def on_message(event)
365
- input = Msgproto::Message.decode(event.data.pack('c*'))
366
- SelfSDK.logger.info " - received #{input.id} (#{input.type})"
367
- case input.type
368
- when :ERR
369
- SelfSDK.logger.warn "error #{input.sender} on #{input.id}"
370
- SelfSDK.logger.warn "#{input.to_json}"
371
- mark_as_arrived(input.id)
372
- when :ACK
373
- SelfSDK.logger.info "#{input.id} acknowledged"
374
- mark_as_acknowledged input.id
375
- when :ACL
361
+ data = event.data.pack('c*')
362
+ hdr = SelfMsg::Header.new(data: data)
363
+
364
+ SelfSDK.logger.info " - received #{hdr.id} (#{hdr.type})"
365
+ case hdr.type
366
+ when SelfMsg::MsgTypeMSG
367
+ SelfSDK.logger.info "Message #{hdr.id} received"
368
+ m = SelfMsg::Message.new(data: data)
369
+ process_incomming_message m
370
+ when SelfMsg::MsgTypeACK
371
+ SelfSDK.logger.info "#{hdr.id} acknowledged"
372
+ mark_as_acknowledged hdr.id
373
+ when SelfMsg::MsgTypeERR
374
+ SelfSDK.logger.warn "error on #{hdr.id}"
375
+ e = SelfMsg::Notification.new(data: data)
376
+ SelfSDK.logger.warn "#{e.error}"
377
+ mark_as_arrived(hdr.id)
378
+ when SelfMsg::MsgTypeACL
376
379
  SelfSDK.logger.info "ACL received"
377
- process_incomming_acl input
378
- when :MSG
379
- SelfSDK.logger.info "Message #{input.id} received"
380
- process_incomming_message input
380
+ a = SelfMsg::Acl.new(data: data)
381
+ process_incomming_acl a
381
382
  end
382
383
  rescue TypeError
383
384
  SelfSDK.logger.info "invalid array message"
384
385
  end
385
386
 
386
387
  def process_incomming_acl(input)
387
- list = JSON.parse(input.recipient)
388
+ list = JSON.parse(input.payload)
388
389
 
389
390
  @messages['acl_list'][:response] = list
390
391
  mark_as_arrived 'acl_list'
391
392
  rescue StandardError => e
392
- p "Error processing incoming ACL #{input.to_json}"
393
+ p "Error processing incoming ACL #{input.id} #{input.payload}"
393
394
  SelfSDK.logger.info e
394
395
  SelfSDK.logger.info e.backtrace
395
396
  nil
@@ -422,19 +423,20 @@ module SelfSDK
422
423
  @auth_id = SecureRandom.uuid if @auth_id.nil?
423
424
 
424
425
  SelfSDK.logger.info "authenticating"
425
- send_raw Msgproto::Auth.new(
426
- type: Msgproto::MsgType::AUTH,
427
- id: @auth_id,
428
- token: @jwt.auth_token,
429
- device: @device_id,
430
- offset: @offset,
431
- )
432
-
426
+
427
+ a = SelfMsg::Auth.new
428
+ a.id = @auth_id
429
+ a.token = @jwt.auth_token
430
+ a.device = @device_id
431
+ a.offset = @offset
432
+
433
+ send_raw a
434
+
433
435
  @auth_id = nil
434
436
  end
435
437
 
436
438
  def send_raw(msg)
437
- @ws.send(msg.to_proto.bytes)
439
+ @ws.send(msg.to_fb.bytes)
438
440
  end
439
441
 
440
442
  # Marks a message as arrived.
data/lib/selfsdk.rb CHANGED
@@ -30,7 +30,7 @@ module SelfSDK
30
30
  # @attr_reader [Types] app_key the api key for the current app.
31
31
  class App
32
32
  BASE_URL = "https://api.joinself.com".freeze
33
- MESSAGING_URL = "wss://messaging.joinself.com/v1/messaging".freeze
33
+ MESSAGING_URL = "wss://messaging.joinself.com/v2/messaging".freeze
34
34
 
35
35
  attr_reader :client
36
36
  attr_accessor :messaging_client
@@ -105,7 +105,7 @@ module SelfSDK
105
105
 
106
106
  def messaging_url(opts)
107
107
  return opts[:messaging_url] if opts.key? :messaging_url
108
- return "wss://messaging.#{opts[:env].to_s}.joinself.com/v1/messaging" if opts.key? :env
108
+ return "wss://messaging.#{opts[:env].to_s}.joinself.com/v2/messaging" if opts.key? :env
109
109
  MESSAGING_URL
110
110
  end
111
111
 
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.175
4
+ version: 0.0.176
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: self_msgproto
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: async
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -327,14 +341,6 @@ files:
327
341
  - lib/messages/message.rb
328
342
  - lib/messaging.rb
329
343
  - lib/ntptime.rb
330
- - lib/proto/acl_pb.rb
331
- - lib/proto/aclcommand_pb.rb
332
- - lib/proto/auth_pb.rb
333
- - lib/proto/errtype_pb.rb
334
- - lib/proto/header_pb.rb
335
- - lib/proto/message_pb.rb
336
- - lib/proto/msgtype_pb.rb
337
- - lib/proto/notification_pb.rb
338
344
  - lib/selfsdk.rb
339
345
  - lib/services/auth.rb
340
346
  - lib/services/facts.rb
@@ -350,7 +356,6 @@ post_install_message:
350
356
  rdoc_options: []
351
357
  require_paths:
352
358
  - lib
353
- - lib/proto
354
359
  - lib/messages
355
360
  - lib/services
356
361
  required_ruby_version: !ruby/object:Gem::Requirement
data/lib/proto/acl_pb.rb DELETED
@@ -1,21 +0,0 @@
1
- # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
-
3
- # Generated by the protocol buffer compiler. DO NOT EDIT!
4
- # source: acl.proto
5
-
6
- require 'google/protobuf'
7
-
8
- require_relative 'msgtype_pb'
9
- require_relative 'aclcommand_pb'
10
- Google::Protobuf::DescriptorPool.generated_pool.build do
11
- add_message "msgproto.AccessControlList" do
12
- optional :type, :enum, 1, "msgproto.MsgType"
13
- optional :id, :string, 2
14
- optional :command, :enum, 3, "msgproto.ACLCommand"
15
- optional :payload, :bytes, 4
16
- end
17
- end
18
-
19
- module Msgproto
20
- AccessControlList = Google::Protobuf::DescriptorPool.generated_pool.lookup("msgproto.AccessControlList").msgclass
21
- end
@@ -1,18 +0,0 @@
1
- # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
-
3
- # Generated by the protocol buffer compiler. DO NOT EDIT!
4
- # source: aclcommand.proto
5
-
6
- require 'google/protobuf'
7
-
8
- Google::Protobuf::DescriptorPool.generated_pool.build do
9
- add_enum "msgproto.ACLCommand" do
10
- value :LIST, 0
11
- value :PERMIT, 1
12
- value :REVOKE, 2
13
- end
14
- end
15
-
16
- module Msgproto
17
- ACLCommand = Google::Protobuf::DescriptorPool.generated_pool.lookup("msgproto.ACLCommand").enummodule
18
- end
data/lib/proto/auth_pb.rb DELETED
@@ -1,21 +0,0 @@
1
- # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
-
3
- # Generated by the protocol buffer compiler. DO NOT EDIT!
4
- # source: auth.proto
5
-
6
- require 'google/protobuf'
7
-
8
- require_relative 'msgtype_pb'
9
- Google::Protobuf::DescriptorPool.generated_pool.build do
10
- add_message "msgproto.Auth" do
11
- optional :type, :enum, 1, "msgproto.MsgType"
12
- optional :id, :string, 2
13
- optional :token, :string, 3
14
- optional :device, :string, 4
15
- optional :offset, :int64, 5
16
- end
17
- end
18
-
19
- module Msgproto
20
- Auth = Google::Protobuf::DescriptorPool.generated_pool.lookup("msgproto.Auth").msgclass
21
- end
@@ -1,21 +0,0 @@
1
- # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
-
3
- # Generated by the protocol buffer compiler. DO NOT EDIT!
4
- # source: errtype.proto
5
-
6
- require 'google/protobuf'
7
-
8
- Google::Protobuf::DescriptorPool.generated_pool.build do
9
- add_enum "msgproto.ErrType" do
10
- value :ErrConnection, 0
11
- value :ErrBadRequest, 1
12
- value :ErrInternal, 2
13
- value :ErrMessage, 3
14
- value :ErrAuth, 4
15
- value :ErrACL, 5
16
- end
17
- end
18
-
19
- module Msgproto
20
- ErrType = Google::Protobuf::DescriptorPool.generated_pool.lookup("msgproto.ErrType").enummodule
21
- end
@@ -1,18 +0,0 @@
1
- # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
-
3
- # Generated by the protocol buffer compiler. DO NOT EDIT!
4
- # source: header.proto
5
-
6
- require 'google/protobuf'
7
-
8
- require_relative 'msgtype_pb'
9
- Google::Protobuf::DescriptorPool.generated_pool.build do
10
- add_message "msgproto.Header" do
11
- optional :type, :enum, 1, "msgproto.MsgType"
12
- optional :id, :string, 2
13
- end
14
- end
15
-
16
- module Msgproto
17
- Header = Google::Protobuf::DescriptorPool.generated_pool.lookup("msgproto.Header").msgclass
18
- end
@@ -1,24 +0,0 @@
1
- # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
-
3
- # Generated by the protocol buffer compiler. DO NOT EDIT!
4
- # source: message.proto
5
-
6
- require 'google/protobuf'
7
-
8
- require_relative 'msgtype_pb'
9
- require 'google/protobuf/timestamp_pb'
10
- Google::Protobuf::DescriptorPool.generated_pool.build do
11
- add_message "msgproto.Message" do
12
- optional :type, :enum, 1, "msgproto.MsgType"
13
- optional :id, :string, 2
14
- optional :sender, :string, 3
15
- optional :recipient, :string, 4
16
- optional :ciphertext, :bytes, 5
17
- optional :timestamp, :message, 6, "google.protobuf.Timestamp"
18
- optional :offset, :int64, 7
19
- end
20
- end
21
-
22
- module Msgproto
23
- Message = Google::Protobuf::DescriptorPool.generated_pool.lookup("msgproto.Message").msgclass
24
- end
@@ -1,20 +0,0 @@
1
- # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
-
3
- # Generated by the protocol buffer compiler. DO NOT EDIT!
4
- # source: msgtype.proto
5
-
6
- require 'google/protobuf'
7
-
8
- Google::Protobuf::DescriptorPool.generated_pool.build do
9
- add_enum "msgproto.MsgType" do
10
- value :MSG, 0
11
- value :ACK, 1
12
- value :ERR, 2
13
- value :AUTH, 3
14
- value :ACL, 4
15
- end
16
- end
17
-
18
- module Msgproto
19
- MsgType = Google::Protobuf::DescriptorPool.generated_pool.lookup("msgproto.MsgType").enummodule
20
- end
@@ -1,21 +0,0 @@
1
- # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
-
3
- # Generated by the protocol buffer compiler. DO NOT EDIT!
4
- # source: notification.proto
5
-
6
- require 'google/protobuf'
7
-
8
- require_relative 'msgtype_pb'
9
- require_relative 'errtype_pb'
10
- Google::Protobuf::DescriptorPool.generated_pool.build do
11
- add_message "msgproto.Notification" do
12
- optional :type, :enum, 1, "msgproto.MsgType"
13
- optional :id, :string, 2
14
- optional :error, :string, 3
15
- optional :errtype, :enum, 4, "msgproto.ErrType"
16
- end
17
- end
18
-
19
- module Msgproto
20
- Notification = Google::Protobuf::DescriptorPool.generated_pool.lookup("msgproto.Notification").msgclass
21
- end