wampproto 0.1.1 → 0.1.2

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: 26c4ffaaaa9d483434bebf923785ea5ce2658da33a3e6768836e46c78f1dd212
4
- data.tar.gz: a42dba9c1410edcd9e2ab766d69013752848772ad76cb5ba84bb1128c6e8ee1a
3
+ metadata.gz: f63bc10a2b52f090c1d8bf9b76b688c1c2501169b4cb7aca4e71d07314e26247
4
+ data.tar.gz: 617f88f1242ac8369ea2f8bc2b3a6ad7bbf63f47c64de91108e932af2954de62
5
5
  SHA512:
6
- metadata.gz: 1baf0ae46dd2d53f1b48c7b49f46f1a5b4402be69ac4c920e81ed327b565384746c5722f060aa028d90a7dfd1460565c6f5fc2fb58f0430959fe52606f7b9268
7
- data.tar.gz: 7520812b2fd0666fd677670ac1f8a885919e63d979953b32ba7f3e45ad12f5d2d5ba657a733e32fb67ec0da060dab56cf50e37b60d231a98184875ab5e06156a
6
+ metadata.gz: b1520e1c65e7a61af12622b9826a0d26e27e0d794d16a35225b9a7e7936c534c364c1e4c4bad0605571d80672c573c071b5ef3369de161866e76ea2d60736461
7
+ data.tar.gz: 29a3cf9dd9cbfe57d1b1a283df2781311d6888dad3cf66aee1ceca8f0a4e8ecbd03d7f5d6eb0c14e6774ff4e02df7382d7297b1d3a50ebdad4a6acf562c46742
@@ -2,15 +2,16 @@
2
2
 
3
3
  module Wampproto
4
4
  # Wamprpoto Dealer handler
5
- class Dealer
6
- attr_reader :registrations_by_procedure, :registrations_by_session, :pending_calls, :pending_invocations, :id_gen,
5
+ class Dealer # rubocop:disable Metrics/ClassLength
6
+ PendingInvocation = Struct.new(:caller_id, :callee_id, :call_id, :invocation_id, :receive_progress, :progress)
7
+
8
+ attr_reader :registrations_by_procedure, :registrations_by_session, :pending_calls, :id_gen,
7
9
  :sessions
8
10
 
9
11
  def initialize(id_gen = IdGenerator.new)
10
12
  @registrations_by_session = {}
11
13
  @registrations_by_procedure = Hash.new { |h, k| h[k] = {} }
12
14
  @pending_calls = {}
13
- @pending_invocations = {}
14
15
  @id_gen = id_gen
15
16
  @sessions = {}
16
17
  end
@@ -63,23 +64,18 @@ module Wampproto
63
64
 
64
65
  registration_id, callee_id = registrations.first
65
66
 
66
- pending_calls[callee_id] = {} unless pending_calls.include?(callee_id)
67
- pending_invocations[callee_id] = {} unless pending_invocations.include?(callee_id)
68
-
69
- # we received call from the "caller" lets call that request_id "1"
70
- # we need to send invocation message to "callee" let call that request_id "10"
71
- # we need "caller" id after we have received yield so that request_id will be "10"
72
- # we need to send request to "caller" to the original request_id 1
73
67
  request_id = id_gen.next
74
68
 
75
- pending_invocations[callee_id][request_id] = session_id
69
+ details = invocation_details_for(session_id, message)
76
70
 
77
- pending_calls[callee_id][session_id] = message.request_id
71
+ pending_calls[[callee_id, request_id]] = PendingInvocation.new(
72
+ session_id, callee_id, message.request_id, request_id, details[:receive_progress]
73
+ )
78
74
 
79
75
  invocation = Message::Invocation.new(
80
76
  request_id,
81
77
  registration_id,
82
- invocation_details_for(session_id, message),
78
+ details,
83
79
  *message.args,
84
80
  **message.kwargs
85
81
  )
@@ -88,26 +84,42 @@ module Wampproto
88
84
  end
89
85
 
90
86
  def invocation_details_for(session_id, message)
91
- return {} unless message.options.include?(:disclose_me)
87
+ options = {}
88
+ return options if message.options.empty?
89
+
90
+ receive_progress = message.options[:receive_progress]
91
+ options.merge!(receive_progress: true) if receive_progress
92
+
93
+ return options unless message.options.include?(:disclose_me)
92
94
 
93
95
  session = sessions[session_id]
94
- { caller: session_id, caller_authid: session.authid, caller_authrole: session.authrole }
96
+ options.merge({ caller: session_id, caller_authid: session.authid, caller_authrole: session.authrole })
95
97
  end
96
98
 
97
- def handle_yield(session_id, message)
98
- calls = pending_calls.fetch(session_id, {})
99
+ def handle_yield(session_id, message) # rubocop:disable Metrics/AbcSize
100
+ pending_invocation = pending_calls[[session_id, message.request_id]]
99
101
  error_message = "no pending calls for session #{session_id}"
100
- raise ValueError, error_message if calls.empty?
102
+ raise ValueError, error_message if pending_invocation.nil?
101
103
 
102
- invocations = pending_invocations[session_id]
103
- caller_id = invocations.delete(message.request_id).to_i # make steep happy
104
+ caller_id = pending_invocation.caller_id
105
+ request_id = pending_invocation.call_id
106
+ pending_calls.delete([session_id, message.request_id]) unless message.options[:progress]
104
107
 
105
- request_id = calls.delete(caller_id)
106
-
107
- result = Message::Result.new(request_id, {}, *message.args, **message.kwargs)
108
+ result = Message::Result.new(request_id, result_details_for(session_id, message), *message.args, **message.kwargs)
108
109
  MessageWithRecipient.new(result, caller_id)
109
110
  end
110
111
 
112
+ def result_details_for(session_id, message)
113
+ options = {}
114
+ return options if message.options.empty?
115
+
116
+ pending_invocation = pending_calls[[session_id, message.request_id]]
117
+
118
+ progress = message.options[:progress] && pending_invocation.receive_progress
119
+ options.merge!(progress:) if progress
120
+ options
121
+ end
122
+
111
123
  def handle_register(session_id, message)
112
124
  error_message = "cannot register, session #{session_id} doesn't exist"
113
125
  raise ValueError, error_message unless registrations_by_session.include?(session_id)
@@ -36,7 +36,7 @@ module Wampproto
36
36
  raise ValueError, "cannot yield for unknown invocation request"
37
37
  end
38
38
 
39
- invocation_requests.delete(msg.request_id)
39
+ invocation_requests.delete(msg.request_id) unless msg.options[:progress]
40
40
  when Message::Publish
41
41
  publish_requests[msg.request_id] = msg.request_id if msg.options.fetch(:acknowledge, false)
42
42
  when Message::Subscribe
@@ -62,7 +62,8 @@ module Wampproto
62
62
  case msg
63
63
  when Message::Result
64
64
  error_message = "received RESULT for invalid request_id"
65
- raise ValueError, error_message unless call_requests.delete(msg.request_id)
65
+ request_id = msg.details[:progress] ? call_requests.fetch(msg.request_id) : call_requests.delete(msg.request_id)
66
+ raise ValueError, error_message unless request_id
66
67
  when Message::Registered
67
68
  error_message = "received REGISTERED for invalid request_id"
68
69
  raise ValueError, error_message unless register_requests.delete(msg.request_id)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wampproto
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -7,9 +7,9 @@ module Wampproto
7
7
 
8
8
  @sessions: Hash[Integer, SessionDetails]
9
9
 
10
- @pending_calls: Hash[Integer, Hash[Integer, Integer]]
10
+ PendingInvocation: untyped
11
11
 
12
- @pending_invocations: Hash[Integer, Hash[Integer, Integer]]
12
+ @pending_calls: Hash[[Integer, Integer], untyped]
13
13
 
14
14
  @id_gen: IdGenerator
15
15
 
@@ -19,9 +19,7 @@ module Wampproto
19
19
 
20
20
  attr_reader sessions: Hash[Integer, SessionDetails]
21
21
 
22
- attr_reader pending_calls: Hash[Integer, Hash[Integer, Integer]]
23
-
24
- attr_reader pending_invocations: Hash[Integer, Hash[Integer, Integer]]
22
+ attr_reader pending_calls: Hash[[Integer, Integer], untyped]
25
23
 
26
24
  attr_reader id_gen: IdGenerator
27
25
 
@@ -44,6 +42,8 @@ module Wampproto
44
42
  def handle_unregister: (Integer session_id, Message::Unregister message) -> (nil | MessageWithRecipient)
45
43
 
46
44
  def invocation_details_for: (Integer session_id, untyped message) -> Hash[Symbol, untyped]
45
+
46
+ def result_details_for: (Integer _session_id, untyped message) -> Hash[Symbol, untyped]
47
47
  end
48
48
  end
49
49
 
data/wampproto.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
34
  spec.require_paths = ["lib"]
35
35
 
36
+ spec.add_dependency "base64", "~> 0.2.0"
36
37
  spec.add_dependency "cbor", "~> 0.5.9.8"
37
38
  spec.add_dependency "ed25519", "~> 1.3"
38
39
  spec.add_dependency "msgpack", "~> 1.7.2"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wampproto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismail Akram
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-20 00:00:00.000000000 Z
11
+ date: 2024-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: base64
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: cbor
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -189,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
203
  - !ruby/object:Gem::Version
190
204
  version: '0'
191
205
  requirements: []
192
- rubygems_version: 3.3.27
206
+ rubygems_version: 3.5.9
193
207
  signing_key:
194
208
  specification_version: 4
195
209
  summary: Sans-IO WAMP protocol implementation in Ruby