wampproto 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +39 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE +22 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/Steepfile +33 -0
- data/lib/wampproto/acceptor/authenticator.rb +14 -0
- data/lib/wampproto/acceptor/request.rb +58 -0
- data/lib/wampproto/acceptor/response.rb +19 -0
- data/lib/wampproto/acceptor.rb +183 -0
- data/lib/wampproto/auth/anonymous.rb +14 -0
- data/lib/wampproto/auth/base.rb +20 -0
- data/lib/wampproto/auth/cra.rb +84 -0
- data/lib/wampproto/auth/cryptosign.rb +86 -0
- data/lib/wampproto/auth/helpers.rb +25 -0
- data/lib/wampproto/auth/ticket.rb +27 -0
- data/lib/wampproto/auth.rb +14 -0
- data/lib/wampproto/broker.rb +155 -0
- data/lib/wampproto/dealer.rb +143 -0
- data/lib/wampproto/id_generator.rb +23 -0
- data/lib/wampproto/joiner.rb +78 -0
- data/lib/wampproto/message/abort.rb +32 -0
- data/lib/wampproto/message/authenticate.rb +25 -0
- data/lib/wampproto/message/base.rb +30 -0
- data/lib/wampproto/message/call.rb +33 -0
- data/lib/wampproto/message/challenge.rb +25 -0
- data/lib/wampproto/message/error.rb +27 -0
- data/lib/wampproto/message/event.rb +33 -0
- data/lib/wampproto/message/goodbye.rb +25 -0
- data/lib/wampproto/message/hello.rb +64 -0
- data/lib/wampproto/message/invocation.rb +33 -0
- data/lib/wampproto/message/publish.rb +33 -0
- data/lib/wampproto/message/published.rb +25 -0
- data/lib/wampproto/message/register.rb +26 -0
- data/lib/wampproto/message/registered.rb +25 -0
- data/lib/wampproto/message/result.rb +32 -0
- data/lib/wampproto/message/subscribe.rb +26 -0
- data/lib/wampproto/message/subscribed.rb +25 -0
- data/lib/wampproto/message/unregister.rb +25 -0
- data/lib/wampproto/message/unregistered.rb +24 -0
- data/lib/wampproto/message/unsubscribe.rb +25 -0
- data/lib/wampproto/message/unsubscribed.rb +24 -0
- data/lib/wampproto/message/welcome.rb +41 -0
- data/lib/wampproto/message/yield.rb +32 -0
- data/lib/wampproto/message.rb +108 -0
- data/lib/wampproto/message_with_recipient.rb +13 -0
- data/lib/wampproto/serializer/cbor.rb +18 -0
- data/lib/wampproto/serializer/json.rb +18 -0
- data/lib/wampproto/serializer/msgpack.rb +18 -0
- data/lib/wampproto/serializer.rb +5 -0
- data/lib/wampproto/session.rb +144 -0
- data/lib/wampproto/session_details.rb +24 -0
- data/lib/wampproto/validate.rb +52 -0
- data/lib/wampproto/version.rb +5 -0
- data/lib/wampproto.rb +32 -0
- data/sig/cbor.rbs +5 -0
- data/sig/ed25519/signing_key.rbs +7 -0
- data/sig/ed25519/verify_key.rbs +7 -0
- data/sig/message_pack.rbs +5 -0
- data/sig/wampproto/acceptor/authenticator.rbs +9 -0
- data/sig/wampproto/acceptor/request.rbs +46 -0
- data/sig/wampproto/acceptor/response.rbs +25 -0
- data/sig/wampproto/acceptor.rbs +86 -0
- data/sig/wampproto/auth/anonymous.rbs +13 -0
- data/sig/wampproto/auth/base.rbs +25 -0
- data/sig/wampproto/auth/cra.rbs +34 -0
- data/sig/wampproto/auth/cryptosign.rbs +38 -0
- data/sig/wampproto/auth/helpers.rbs +16 -0
- data/sig/wampproto/auth/ticket.rbs +21 -0
- data/sig/wampproto/broker.rbs +48 -0
- data/sig/wampproto/dealer.rbs +49 -0
- data/sig/wampproto/id_generator.rbs +17 -0
- data/sig/wampproto/joiner.rbs +43 -0
- data/sig/wampproto/message/abort.rbs +31 -0
- data/sig/wampproto/message/authenticate.rbs +20 -0
- data/sig/wampproto/message/base.rbs +14 -0
- data/sig/wampproto/message/call.rbs +34 -0
- data/sig/wampproto/message/challenge.rbs +20 -0
- data/sig/wampproto/message/error.rbs +28 -0
- data/sig/wampproto/message/event.rbs +34 -0
- data/sig/wampproto/message/goodbye.rbs +21 -0
- data/sig/wampproto/message/hello.rbs +39 -0
- data/sig/wampproto/message/invocation.rbs +34 -0
- data/sig/wampproto/message/publish.rbs +32 -0
- data/sig/wampproto/message/published.rbs +20 -0
- data/sig/wampproto/message/register.rbs +24 -0
- data/sig/wampproto/message/registered.rbs +20 -0
- data/sig/wampproto/message/result.rbs +32 -0
- data/sig/wampproto/message/subscribe.rbs +24 -0
- data/sig/wampproto/message/subscribed.rbs +20 -0
- data/sig/wampproto/message/unregister.rbs +20 -0
- data/sig/wampproto/message/unregistered.rbs +16 -0
- data/sig/wampproto/message/unsubscribe.rbs +20 -0
- data/sig/wampproto/message/unsubscribed.rbs +16 -0
- data/sig/wampproto/message/welcome.rbs +36 -0
- data/sig/wampproto/message/yield.rbs +30 -0
- data/sig/wampproto/message.rbs +59 -0
- data/sig/wampproto/message_with_recipient.rbs +15 -0
- data/sig/wampproto/serializer/cbor.rbs +10 -0
- data/sig/wampproto/serializer/json.rbs +11 -0
- data/sig/wampproto/serializer/msgpack.rbs +11 -0
- data/sig/wampproto/session.rbs +43 -0
- data/sig/wampproto/session_details.rbs +25 -0
- data/sig/wampproto/validate.rbs +18 -0
- data/sig/wampproto.rbs +17 -0
- data/wampproto.gemspec +39 -0
- metadata +196 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "message/base"
|
4
|
+
require_relative "message/hello"
|
5
|
+
require_relative "message/welcome"
|
6
|
+
require_relative "message/abort"
|
7
|
+
require_relative "message/challenge"
|
8
|
+
require_relative "message/authenticate"
|
9
|
+
require_relative "message/goodbye"
|
10
|
+
|
11
|
+
require_relative "message/error"
|
12
|
+
|
13
|
+
require_relative "message/publish"
|
14
|
+
require_relative "message/published"
|
15
|
+
|
16
|
+
require_relative "message/subscribe"
|
17
|
+
require_relative "message/subscribed"
|
18
|
+
require_relative "message/unsubscribe"
|
19
|
+
require_relative "message/unsubscribed"
|
20
|
+
require_relative "message/event"
|
21
|
+
|
22
|
+
require_relative "message/call"
|
23
|
+
require_relative "message/result"
|
24
|
+
|
25
|
+
require_relative "message/register"
|
26
|
+
require_relative "message/registered"
|
27
|
+
require_relative "message/unregister"
|
28
|
+
require_relative "message/unregistered"
|
29
|
+
|
30
|
+
require_relative "message/invocation"
|
31
|
+
require_relative "message/yield"
|
32
|
+
|
33
|
+
module Wampproto
|
34
|
+
# message root
|
35
|
+
module Message
|
36
|
+
module Type
|
37
|
+
HELLO = 1
|
38
|
+
WELCOME = 2
|
39
|
+
ABORT = 3
|
40
|
+
CHALLENGE = 4
|
41
|
+
AUTHENTICATE = 5
|
42
|
+
GOODBYE = 6
|
43
|
+
|
44
|
+
ERROR = 8
|
45
|
+
|
46
|
+
PUBLISH = 16
|
47
|
+
PUBLISHED = 17
|
48
|
+
|
49
|
+
SUBSCRIBE = 32
|
50
|
+
SUBSCRIBED = 33
|
51
|
+
UNSUBSCRIBE = 34
|
52
|
+
UNSUBSCRIBED = 35
|
53
|
+
EVENT = 36
|
54
|
+
|
55
|
+
CALL = 48
|
56
|
+
CANCEL = 49
|
57
|
+
RESULT = 50
|
58
|
+
|
59
|
+
REGISTER = 64
|
60
|
+
REGISTERED = 65
|
61
|
+
UNREGISTER = 66
|
62
|
+
UNREGISTERED = 67
|
63
|
+
INVOCATION = 68
|
64
|
+
INTERRUPT = 69
|
65
|
+
YIELD = 70
|
66
|
+
end
|
67
|
+
|
68
|
+
HANDLER = {
|
69
|
+
Type::HELLO => Hello,
|
70
|
+
Type::WELCOME => Welcome,
|
71
|
+
Type::ABORT => Abort,
|
72
|
+
Type::CHALLENGE => Challenge,
|
73
|
+
Type::AUTHENTICATE => Authenticate,
|
74
|
+
Type::GOODBYE => Goodbye,
|
75
|
+
|
76
|
+
Type::ERROR => Error,
|
77
|
+
|
78
|
+
Type::PUBLISH => Publish,
|
79
|
+
Type::PUBLISHED => Published,
|
80
|
+
|
81
|
+
Type::SUBSCRIBE => Subscribe,
|
82
|
+
Type::SUBSCRIBED => Subscribed,
|
83
|
+
Type::UNSUBSCRIBE => Unsubscribe,
|
84
|
+
Type::UNSUBSCRIBED => Unsubscribed,
|
85
|
+
Type::EVENT => Event,
|
86
|
+
|
87
|
+
Type::CALL => Call,
|
88
|
+
Type::RESULT => Result,
|
89
|
+
|
90
|
+
Type::REGISTER => Register,
|
91
|
+
Type::REGISTERED => Registered,
|
92
|
+
Type::UNREGISTER => Unregister,
|
93
|
+
Type::UNREGISTERED => Unregistered,
|
94
|
+
Type::INVOCATION => Invocation,
|
95
|
+
Type::YIELD => Yield
|
96
|
+
}.freeze
|
97
|
+
|
98
|
+
def self.resolve(wamp_message)
|
99
|
+
type, = Validate.array!("Wamp Message", wamp_message)
|
100
|
+
begin
|
101
|
+
HANDLER[type].parse(wamp_message)
|
102
|
+
rescue StandardError => e
|
103
|
+
p wamp_message
|
104
|
+
raise e
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wampproto
|
4
|
+
# handler class for dealer and broker responses
|
5
|
+
class MessageWithRecipient
|
6
|
+
attr_reader :message, :recipient
|
7
|
+
|
8
|
+
def initialize(message, recipient)
|
9
|
+
@message = message
|
10
|
+
@recipient = recipient
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cbor"
|
4
|
+
|
5
|
+
module Wampproto
|
6
|
+
module Serializer
|
7
|
+
# Add common API for serializer
|
8
|
+
class Cbor
|
9
|
+
def self.serialize(message)
|
10
|
+
CBOR.encode(message.marshal).unpack("c*")
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.deserialize(message)
|
14
|
+
CBOR.decode(message.pack("c*")).then { Message.resolve(_1) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Wampproto
|
6
|
+
module Serializer
|
7
|
+
# Add common API for serializer
|
8
|
+
class JSON
|
9
|
+
def self.serialize(message)
|
10
|
+
::JSON.dump(message.marshal)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.deserialize(message)
|
14
|
+
::JSON.parse(message).then { Message.resolve(_1) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "msgpack"
|
4
|
+
|
5
|
+
module Wampproto
|
6
|
+
module Serializer
|
7
|
+
# Add common API for serializer
|
8
|
+
class Msgpack
|
9
|
+
def self.serialize(message)
|
10
|
+
::MessagePack.pack(message.marshal).unpack("c*")
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.deserialize(message)
|
14
|
+
::MessagePack.unpack(message.pack("c*")).then { Message.resolve(_1) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wampproto
|
4
|
+
# Session
|
5
|
+
class Session # rubocop:disable Metrics/ClassLength
|
6
|
+
attr_reader :serializer
|
7
|
+
|
8
|
+
def initialize(serializer = Serializer::JSON)
|
9
|
+
@serializer = serializer
|
10
|
+
init_state
|
11
|
+
end
|
12
|
+
|
13
|
+
ACCESSORS = %i[
|
14
|
+
call_requests
|
15
|
+
register_requests
|
16
|
+
registrations
|
17
|
+
invocation_requests
|
18
|
+
unregister_requests
|
19
|
+
|
20
|
+
publish_requests
|
21
|
+
subscribe_requests
|
22
|
+
subscriptions
|
23
|
+
unsubscribe_requests
|
24
|
+
].freeze
|
25
|
+
|
26
|
+
def send_message(msg) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
|
27
|
+
case msg
|
28
|
+
when Message::Call
|
29
|
+
call_requests[msg.request_id] = msg.request_id
|
30
|
+
when Message::Register
|
31
|
+
register_requests[msg.request_id] = msg.request_id
|
32
|
+
when Message::Unregister
|
33
|
+
unregister_requests[msg.request_id] = msg.registration_id
|
34
|
+
when Message::Yield
|
35
|
+
unless invocation_requests.include?(msg.request_id)
|
36
|
+
raise ValueError, "cannot yield for unknown invocation request"
|
37
|
+
end
|
38
|
+
|
39
|
+
invocation_requests.delete(msg.request_id)
|
40
|
+
when Message::Publish
|
41
|
+
publish_requests[msg.request_id] = msg.request_id if msg.options.fetch(:acknowledge, false)
|
42
|
+
when Message::Subscribe
|
43
|
+
subscribe_requests[msg.request_id] = msg.request_id
|
44
|
+
when Message::Unsubscribe
|
45
|
+
unsubscribe_requests[msg.request_id] = msg.subscription_id
|
46
|
+
when Message::Error
|
47
|
+
error_message = "send only supported for invocation error"
|
48
|
+
raise ValueError, error_message if msg.message_type != Message::Invocation.type
|
49
|
+
|
50
|
+
invocation_requests.delete(msg.request_id)
|
51
|
+
end
|
52
|
+
|
53
|
+
serializer.serialize(msg)
|
54
|
+
end
|
55
|
+
|
56
|
+
def receive(data)
|
57
|
+
msg = serializer.deserialize(data)
|
58
|
+
receive_message(msg)
|
59
|
+
end
|
60
|
+
|
61
|
+
def receive_message(msg) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
62
|
+
case msg
|
63
|
+
when Message::Result
|
64
|
+
error_message = "received RESULT for invalid request_id"
|
65
|
+
raise ValueError, error_message unless call_requests.delete(msg.request_id)
|
66
|
+
when Message::Registered
|
67
|
+
error_message = "received REGISTERED for invalid request_id"
|
68
|
+
raise ValueError, error_message unless register_requests.delete(msg.request_id)
|
69
|
+
|
70
|
+
registrations[msg.registration_id] = msg.registration_id
|
71
|
+
when Message::Unregistered
|
72
|
+
error_message = "received UNREGISTERED for invalid request_id"
|
73
|
+
registration_id = unregister_requests.delete(msg.request_id)
|
74
|
+
raise ValueError, error_message unless registration_id
|
75
|
+
|
76
|
+
error_message = "received UNREGISTERED for invalid registration_id"
|
77
|
+
raise ValueError, error_message unless registrations.delete(registration_id)
|
78
|
+
when Message::Invocation
|
79
|
+
error_message = "received INVOCATION for invalid registration_id"
|
80
|
+
raise ValueError, error_message unless registrations.delete(msg.registration_id)
|
81
|
+
|
82
|
+
invocation_requests[msg.request_id] = msg.request_id
|
83
|
+
when Message::Published
|
84
|
+
error_message = "received PUBLISHED for invalid topic"
|
85
|
+
raise ValueError, error_message unless publish_requests.delete(msg.request_id)
|
86
|
+
when Message::Subscribed
|
87
|
+
error_message = "received SUBSCRIBED for invalid request_id"
|
88
|
+
raise ValueError, error_message unless subscribe_requests.delete(msg.request_id)
|
89
|
+
|
90
|
+
subscriptions[msg.subscription_id] = msg.subscription_id
|
91
|
+
when Message::Unsubscribed
|
92
|
+
error_message = "received UNSUBSCRIBED for invalid request_id"
|
93
|
+
subscription_id = unsubscribe_requests.delete(msg.request_id)
|
94
|
+
raise ValueError, error_message unless subscription_id
|
95
|
+
|
96
|
+
error_message = "received UNSUBSCRIBED for invalid subscription_id"
|
97
|
+
raise ValueError, error_message unless subscriptions.delete(subscription_id)
|
98
|
+
when Message::Event
|
99
|
+
error_message = "received EVENT for invalid subscription_id"
|
100
|
+
raise ValueError, error_message unless subscriptions.include?(msg.subscription_id)
|
101
|
+
when Message::Error
|
102
|
+
case msg.message_type
|
103
|
+
when Message::Call.type
|
104
|
+
error_message = "received ERROR for invalid call request"
|
105
|
+
raise ValueError, error_message unless call_requests.delete(msg.request_id)
|
106
|
+
when Message::Register.type
|
107
|
+
error_message = "received ERROR for invalid register request"
|
108
|
+
raise ValueError, error_message unless register_requests.delete(msg.request_id)
|
109
|
+
when Message::Unregister.type
|
110
|
+
error_message = "received ERROR for invalid unregister request"
|
111
|
+
raise ValueError, error_message unless unregister_requests.delete(msg.request_id)
|
112
|
+
when Message::Subscribe.type
|
113
|
+
error_message = "received ERROR for invalid subscribe request"
|
114
|
+
raise ValueError, error_message unless subscribe_requests.delete(msg.request_id)
|
115
|
+
when Message::Unsubscribe.type
|
116
|
+
error_message = "received ERROR for invalid unsubscribe request"
|
117
|
+
raise ValueError, error_message unless unsubscribe_requests.delete(msg.request_id)
|
118
|
+
when Message::Publish.type
|
119
|
+
error_message = "received ERROR for invalid publish request"
|
120
|
+
raise ValueError, error_message unless publish_requests.delete(msg.request_id)
|
121
|
+
else
|
122
|
+
error_message = "unknown error message type #{msg.class}"
|
123
|
+
raise ValueError, error_message
|
124
|
+
end
|
125
|
+
when Message::Abort
|
126
|
+
p [:session, :abort, msg]
|
127
|
+
else
|
128
|
+
raise ValueError, "unknown message #{msg.class}"
|
129
|
+
end
|
130
|
+
|
131
|
+
msg
|
132
|
+
end
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
attr_reader(*ACCESSORS)
|
137
|
+
|
138
|
+
def init_state
|
139
|
+
ACCESSORS.each do |attr|
|
140
|
+
instance_variable_set("@#{attr}", {})
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wampproto
|
4
|
+
# Session Details
|
5
|
+
class SessionDetails
|
6
|
+
attr_reader :session_id, :realm, :authid, :authrole
|
7
|
+
|
8
|
+
def initialize(session_id, realm, authid, authrole)
|
9
|
+
@session_id = session_id
|
10
|
+
@realm = realm
|
11
|
+
@authid = authid
|
12
|
+
@authrole = authrole
|
13
|
+
end
|
14
|
+
|
15
|
+
def ==(other)
|
16
|
+
return false unless other.instance_of?(SessionDetails)
|
17
|
+
|
18
|
+
session_id == other.session_id &&
|
19
|
+
realm == other.realm &&
|
20
|
+
authid == other.authid &&
|
21
|
+
authrole == other.authrole
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wampproto
|
4
|
+
# validation
|
5
|
+
class Validate
|
6
|
+
class << self
|
7
|
+
def int!(name, value)
|
8
|
+
return value if value.is_a?(Integer)
|
9
|
+
|
10
|
+
raise ArgumentError, "The #{name} argument should be an integer."
|
11
|
+
end
|
12
|
+
|
13
|
+
def string!(name, value)
|
14
|
+
return value if value.is_a?(String)
|
15
|
+
|
16
|
+
raise ArgumentError, "The #{name} argument should be a string."
|
17
|
+
end
|
18
|
+
|
19
|
+
def hash!(name, value)
|
20
|
+
return value.transform_keys(&:to_sym) if value.is_a?(Hash)
|
21
|
+
|
22
|
+
raise ArgumentError, "The #{name} argument should be a dictionary."
|
23
|
+
end
|
24
|
+
|
25
|
+
def array!(name, value)
|
26
|
+
return value if value.is_a?(Array)
|
27
|
+
|
28
|
+
raise ArgumentError, "The #{name} argument should be a list."
|
29
|
+
end
|
30
|
+
|
31
|
+
def length!(array, expected_length)
|
32
|
+
return array if array.length == expected_length
|
33
|
+
|
34
|
+
raise ArgumentError, "The response message length should be #{expected_length} but got #{array.length} "
|
35
|
+
end
|
36
|
+
|
37
|
+
def greater_than_equal!(array, expected_length)
|
38
|
+
return array if array.length >= expected_length
|
39
|
+
|
40
|
+
raise ArgumentError, "The response message length is #{array.length} but it should be #{expected_length} "
|
41
|
+
end
|
42
|
+
|
43
|
+
def options!(options, valid_keys)
|
44
|
+
options.each_key do |key|
|
45
|
+
raise ArgumentError, "Unrecognized option: #{key.inspect}" unless valid_keys.include?(key)
|
46
|
+
end
|
47
|
+
|
48
|
+
options
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/wampproto.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "wampproto/version"
|
4
|
+
require_relative "wampproto/validate"
|
5
|
+
require_relative "wampproto/message"
|
6
|
+
require_relative "wampproto/serializer"
|
7
|
+
require_relative "wampproto/auth"
|
8
|
+
require_relative "wampproto/id_generator"
|
9
|
+
require_relative "wampproto/session_details"
|
10
|
+
require_relative "wampproto/joiner"
|
11
|
+
require_relative "wampproto/acceptor"
|
12
|
+
require_relative "wampproto/session"
|
13
|
+
require_relative "wampproto/message_with_recipient"
|
14
|
+
require_relative "wampproto/dealer"
|
15
|
+
require_relative "wampproto/broker"
|
16
|
+
|
17
|
+
module Wampproto
|
18
|
+
class Error < StandardError; end
|
19
|
+
|
20
|
+
# ProtocolViolation Exception
|
21
|
+
class ProtocolViolation < StandardError
|
22
|
+
attr_reader :uri
|
23
|
+
|
24
|
+
def initialize(msg = "Protocol Violation", uri = "wamp.error.protocol_violation")
|
25
|
+
@uri = uri
|
26
|
+
super(msg)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class ValueError < StandardError
|
31
|
+
end
|
32
|
+
end
|
data/sig/cbor.rbs
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Wampproto
|
2
|
+
class Acceptor
|
3
|
+
# Request object sent for authentication
|
4
|
+
class Request
|
5
|
+
@hello: Message::Hello
|
6
|
+
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
attr_reader realm: String
|
10
|
+
|
11
|
+
attr_reader authid: String
|
12
|
+
|
13
|
+
attr_reader authextra: Hash[Symbol, untyped]
|
14
|
+
|
15
|
+
attr_reader hello: Message::Hello
|
16
|
+
|
17
|
+
def initialize: (Message::Hello hello) -> void
|
18
|
+
|
19
|
+
def authmethod: () -> Symbol
|
20
|
+
|
21
|
+
def public_key: () -> String
|
22
|
+
|
23
|
+
def secret: () -> nil
|
24
|
+
|
25
|
+
def ticket: () -> nil
|
26
|
+
end
|
27
|
+
|
28
|
+
# AuthenticateRequest
|
29
|
+
class AuthenticateRequest < Request
|
30
|
+
@authenticate: Message::Authenticate
|
31
|
+
|
32
|
+
@hello_request: Request
|
33
|
+
|
34
|
+
extend Forwardable
|
35
|
+
|
36
|
+
attr_reader authenticate: Message::Authenticate
|
37
|
+
|
38
|
+
def initialize: (Message::Authenticate authenticate, Request hello_request) -> void
|
39
|
+
|
40
|
+
def ticket: () -> (String | nil)
|
41
|
+
|
42
|
+
def secret: () -> (String | nil)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Wampproto
|
2
|
+
class Acceptor
|
3
|
+
# Request object sent for authentication
|
4
|
+
class Response
|
5
|
+
@authid: String
|
6
|
+
|
7
|
+
@authrole: String
|
8
|
+
|
9
|
+
@secret: String
|
10
|
+
|
11
|
+
attr_reader authid: String
|
12
|
+
|
13
|
+
attr_reader authrole: String
|
14
|
+
|
15
|
+
attr_reader secret: String
|
16
|
+
|
17
|
+
def initialize: (String authid, String authrole, ?String? secret) -> void
|
18
|
+
|
19
|
+
alias ticket secret
|
20
|
+
|
21
|
+
alias public_key secret
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Wampproto
|
2
|
+
# Accepts Request
|
3
|
+
class Acceptor
|
4
|
+
type serializerTypes = (singleton(Serializer::JSON) | singleton(Serializer::Msgpack) | singleton(Serializer::Cbor))
|
5
|
+
# type authenticatorsType = Auth::Anonymous | Auth::Ticket | Auth::Cra | Auth::Cryptosign
|
6
|
+
|
7
|
+
@serializer: serializerTypes
|
8
|
+
|
9
|
+
@authenticator: singleton(Authenticator)
|
10
|
+
|
11
|
+
@state: Integer
|
12
|
+
|
13
|
+
@session_id: Integer
|
14
|
+
|
15
|
+
@hello: Message::Hello
|
16
|
+
|
17
|
+
@authid: String
|
18
|
+
|
19
|
+
@authmethod: String
|
20
|
+
|
21
|
+
@request: Request
|
22
|
+
|
23
|
+
@response: Response
|
24
|
+
|
25
|
+
@challenge: String
|
26
|
+
|
27
|
+
@public_key: String
|
28
|
+
|
29
|
+
@auth_request: AuthenticateRequest
|
30
|
+
|
31
|
+
STATE_NONE: 0
|
32
|
+
|
33
|
+
STATE_HELLO_RECEIVED: 1
|
34
|
+
|
35
|
+
STATE_CHALLENGE_SENT: 2
|
36
|
+
|
37
|
+
STATE_WELCOME_SENT: 3
|
38
|
+
|
39
|
+
STATE_ERROR: 4
|
40
|
+
|
41
|
+
ROUTER_ROLES: { dealer: ::Hash[untyped, untyped], broker: ::Hash[untyped, untyped] }
|
42
|
+
|
43
|
+
attr_reader serializer: serializerTypes
|
44
|
+
|
45
|
+
attr_reader session_id: Integer
|
46
|
+
|
47
|
+
attr_reader authmethod: String
|
48
|
+
|
49
|
+
attr_reader authenticator: singleton(Authenticator)
|
50
|
+
|
51
|
+
attr_accessor state: Integer
|
52
|
+
|
53
|
+
attr_accessor session_details: SessionDetails
|
54
|
+
|
55
|
+
def initialize: (?serializerTypes serializer, ?singleton(Authenticator) authenticator) -> void
|
56
|
+
|
57
|
+
def receive: (untyped data) -> untyped
|
58
|
+
|
59
|
+
def receive_message: (Message::Base msg) -> Message::Base
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def handle_hello_message: (Message::Hello msg) -> (Message::Challenge | Message::Welcome | Message::Abort)
|
64
|
+
|
65
|
+
def handle_wampcra_hello: (Message::Hello msg) -> Message::Challenge
|
66
|
+
|
67
|
+
def handle_ticket_hello: (Message::Hello _msg) -> Message::Challenge
|
68
|
+
|
69
|
+
def handle_cryptosign_hello: (Message::Hello msg) -> Message::Challenge
|
70
|
+
|
71
|
+
def handle_anonymous_hello: (Message::Hello msg) -> Message::Welcome
|
72
|
+
|
73
|
+
def handle_authenticate_message: (Message::Authenticate msg) -> (Message::Welcome | Message::Abort)
|
74
|
+
|
75
|
+
def handle_wampcra_authenticate: (Message::Authenticate msg) -> (Message::Welcome | Message::Abort)
|
76
|
+
|
77
|
+
def abort_message: () -> Message::Abort
|
78
|
+
|
79
|
+
def handle_ticket_authenticate: (Message::Authenticate msg) -> (Message::Welcome | Message::Abort)
|
80
|
+
|
81
|
+
def handle_cryptosign_authenticate: (Message::Authenticate msg) -> (Message::Welcome | Message::Abort)
|
82
|
+
|
83
|
+
def create_session_id: () -> Integer
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Wampproto
|
2
|
+
module Auth
|
3
|
+
# Auth Base
|
4
|
+
class Base
|
5
|
+
@authmethod: String
|
6
|
+
|
7
|
+
@authid: String
|
8
|
+
|
9
|
+
@authextra: Hash[Symbol, untyped]
|
10
|
+
|
11
|
+
attr_reader authmethod: String
|
12
|
+
|
13
|
+
attr_reader authid: String
|
14
|
+
|
15
|
+
attr_reader authextra: Hash[Symbol, untyped]
|
16
|
+
|
17
|
+
attr_reader details: Hash[Symbol, untyped]
|
18
|
+
|
19
|
+
def initialize: (String method, String authid, Hash[Symbol, untyped] authextra) -> void
|
20
|
+
|
21
|
+
def authenticate: (Message::Challenge _challenge) -> String
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|