wampus 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wampus/backends/redis.rb +4 -0
- data/lib/wampus/pubsub/server_ext.rb +35 -20
- data/lib/wampus/rpc/server_ext.rb +28 -18
- data/lib/wampus/servers/wamp_cra.rb +26 -7
- data/lib/wampus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1344ac9b431935be7e6eb17811b05b32553b216f
|
4
|
+
data.tar.gz: 4f0633e43c52ca041dadd7f77f54a8b99233b506
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2049c1ac5788a583a73b0441cb87c0b4986dc2824bc42b767e3bd0cfe65e5872c92cfcab6b5293635adfec7f4e71407519344dea0bb2365225052afd96020b38
|
7
|
+
data.tar.gz: 33e317dd4d990ef424176be6207cf89f83fce62574c810e14433139f3b0b2f0eabf566ede047e5c6d4ef55ceb7039282ca67a0389014ed6ce8eaa441c8af6c78
|
@@ -82,16 +82,15 @@ module Wampus
|
|
82
82
|
if handler[2].nil? && handler[3].nil?
|
83
83
|
topic.add_subscriber connection
|
84
84
|
else
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
EM.defer lambda {
|
86
|
+
run_subscribe_deferred connection, handler, topic_uri
|
87
|
+
}, lambda { |result|
|
88
|
+
if result.is_a? Exception
|
89
|
+
# TODO Log errors
|
90
|
+
elsif result
|
91
|
+
topic.add_subscriber connection
|
90
92
|
end
|
91
|
-
|
92
|
-
rescue => error
|
93
|
-
# Nothing
|
94
|
-
end
|
93
|
+
}
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
@@ -121,19 +120,15 @@ module Wampus
|
|
121
120
|
if handler[2].nil? && handler[3].nil?
|
122
121
|
dispatch_event topic.uri, event, exclude, include
|
123
122
|
else
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
123
|
+
EM.defer lambda {
|
124
|
+
run_publish_deferred connection, handler, topic_uri, event
|
125
|
+
}, lambda {|result|
|
126
|
+
if result.is_a? Exception
|
127
|
+
# TODO Log errors
|
128
|
+
elsif result
|
131
129
|
dispatch_event topic.uri, event, exclude, include
|
132
|
-
rescue => error
|
133
|
-
puts error.message
|
134
|
-
# Nothing
|
135
130
|
end
|
136
|
-
|
131
|
+
}
|
137
132
|
end
|
138
133
|
end
|
139
134
|
|
@@ -146,6 +141,26 @@ module Wampus
|
|
146
141
|
|
147
142
|
private
|
148
143
|
|
144
|
+
def run_subscribe_deferred(connection, handler, topic_uri)
|
145
|
+
if handler[2]
|
146
|
+
handler[2].send handler[3], connection, topic_uri
|
147
|
+
elsif handler[3].is_a? Proc
|
148
|
+
handler[3].call connection, topic_uri
|
149
|
+
end
|
150
|
+
rescue => error
|
151
|
+
error
|
152
|
+
end
|
153
|
+
|
154
|
+
def run_publish_deferred(connection, handler, topic_uri, event)
|
155
|
+
if handler[2]
|
156
|
+
handler[2].send handler[3], [connection, topic_uri, event]
|
157
|
+
elsif handler[3].is_a? Proc
|
158
|
+
handler[3].call connection, topic_uri, event
|
159
|
+
end
|
160
|
+
rescue => error
|
161
|
+
error
|
162
|
+
end
|
163
|
+
|
149
164
|
def topic_for_uri(topic_uri)
|
150
165
|
uri = topics.keys.select { |uri| topic_uri.include? uri }.sort_by(&:length).last
|
151
166
|
topics[uri]
|
@@ -47,25 +47,25 @@ module Wampus
|
|
47
47
|
uri = connection.resolve_prefix proc_uri
|
48
48
|
handler = rpcs[uri]
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'NoSuchRPCEndpoint', 'Missing Method')
|
55
|
-
end
|
56
|
-
if handler[0]
|
57
|
-
result = handler[0].send handler[1], connection, call_id, *args
|
58
|
-
elsif handler[1].is_a? Proc
|
59
|
-
result = handler[1].call connection, call_id, *args
|
60
|
-
end
|
61
|
-
result = on_after_call_success connection, result
|
62
|
-
connection.write call_result_msg call_id, result
|
63
|
-
rescue => error
|
64
|
-
error = on_after_call_error connection, error
|
65
|
-
msg = call_error_msg call_id, *error.to_call_error
|
66
|
-
connection.write msg
|
67
|
-
on_after_send_call_error connection, msg
|
50
|
+
rpc_call_exists = rpcs.has_key?(uri)
|
51
|
+
uri, args = on_before_call connection, call_id, uri, args, rpc_call_exists
|
52
|
+
unless rpc_call_exists
|
53
|
+
raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'NoSuchRPCEndpoint', 'Missing Method')
|
68
54
|
end
|
55
|
+
|
56
|
+
EM.defer lambda {
|
57
|
+
run_rpc_deferred connection, handler, args
|
58
|
+
}, lambda { |result|
|
59
|
+
if result.is_a? StandardError
|
60
|
+
error = on_after_call_error connection, result
|
61
|
+
msg = call_error_msg call_id, *error.to_call_error
|
62
|
+
connection.write msg
|
63
|
+
on_after_send_call_error connection, msg
|
64
|
+
else
|
65
|
+
result = on_after_call_success connection, result
|
66
|
+
connection.write call_result_msg call_id, result
|
67
|
+
end
|
68
|
+
}
|
69
69
|
end
|
70
70
|
|
71
71
|
# -- RPC Hooks
|
@@ -90,6 +90,16 @@ module Wampus
|
|
90
90
|
|
91
91
|
private
|
92
92
|
|
93
|
+
def run_rpc_deferred(connection, handler, args)
|
94
|
+
if handler[0]
|
95
|
+
handler[0].send handler[1], connection, *args
|
96
|
+
elsif handler[1].is_a? Proc
|
97
|
+
handler[1].call connection, *args
|
98
|
+
end
|
99
|
+
rescue => error
|
100
|
+
error
|
101
|
+
end
|
102
|
+
|
93
103
|
def proc_for_uri(rpc_uri)
|
94
104
|
uri = rpcs.keys.select { |uri| uri.include? rpc_uri }.sort_by(&:length).last
|
95
105
|
rpcs[uri]
|
@@ -10,28 +10,33 @@ module Wampus
|
|
10
10
|
|
11
11
|
after_init do
|
12
12
|
register_rpc_method Wampus::Protocols::WampCra::URI_PROCEDURE+'authRequest', self, :auth_request
|
13
|
+
register_rpc_method Wampus::Protocols::WampCra::URI_PROCEDURE+'authStatus', self, :auth_status
|
13
14
|
register_rpc_method Wampus::Protocols::WampCra::URI_PROCEDURE+'auth', self, :auth
|
14
15
|
end
|
15
16
|
|
17
|
+
# Implement in your server
|
16
18
|
def get_auth_permissions(connection, auth_key, auth_extra)
|
17
19
|
{:permissions => { :pubsub => [], :rpc => [] } }
|
18
20
|
end
|
19
21
|
|
22
|
+
# Implement in your server
|
20
23
|
def get_auth_secret(connection, auth_key)
|
21
24
|
nil
|
22
25
|
end
|
23
26
|
|
27
|
+
# Implement in your server
|
24
28
|
def on_auth_timeout(connection)
|
25
29
|
# Nothing
|
26
30
|
end
|
27
31
|
|
32
|
+
# Implement in your server
|
28
33
|
def on_authenticated(connection, auth_key, permissions)
|
29
34
|
# Nothing
|
30
35
|
end
|
31
36
|
|
32
37
|
def on_session_open(connection)
|
33
38
|
if client_auth_timeout > 0
|
34
|
-
connection.auth_timeout_call = EventMachine.add_timer
|
39
|
+
connection.auth_timeout_call = EventMachine.add_timer(client_auth_timeout) {
|
35
40
|
on_auth_timeout(connection)
|
36
41
|
}
|
37
42
|
end
|
@@ -46,6 +51,7 @@ module Wampus
|
|
46
51
|
raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'authentication-already-requested', 'Authentication Already Requested')
|
47
52
|
end
|
48
53
|
|
54
|
+
extra = {} if extra.nil?
|
49
55
|
unless extra.is_a? Hash
|
50
56
|
raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'invalid-argument', 'Extra is not a Dictionary/Hash')
|
51
57
|
end
|
@@ -58,6 +64,18 @@ module Wampus
|
|
58
64
|
on_get_auth_secret_ok connection, auth_secret, auth_key, extra
|
59
65
|
end
|
60
66
|
|
67
|
+
def auth_status(connection)
|
68
|
+
if connection.authenticated
|
69
|
+
return :authenticated
|
70
|
+
end
|
71
|
+
|
72
|
+
unless connection.pending_auth.nil?
|
73
|
+
return :pending
|
74
|
+
end
|
75
|
+
|
76
|
+
:unauthenticated
|
77
|
+
end
|
78
|
+
|
61
79
|
def auth(connection, signature = nil)
|
62
80
|
if connection.authenticated
|
63
81
|
raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'already-authenticated', 'Already Authenticated')
|
@@ -70,12 +88,12 @@ module Wampus
|
|
70
88
|
if connection.pending_auth[1] != signature
|
71
89
|
connection.pending_auth = nil
|
72
90
|
|
73
|
-
return EventMachine.add_timer
|
74
|
-
raise Wampus::Errors::CallError.new
|
91
|
+
return EventMachine.add_timer(expo(1.25)) {
|
92
|
+
raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'invalid-signature', 'Signature for authentication request is invalid')
|
75
93
|
}
|
76
94
|
end
|
77
95
|
|
78
|
-
permissions = connection.pending_auth
|
96
|
+
permissions = connection.pending_auth[2]
|
79
97
|
auth_key = connection.pending_auth[0][:auth_key]
|
80
98
|
connection.authenticated = true
|
81
99
|
connection.pending_auth = nil
|
@@ -86,7 +104,7 @@ module Wampus
|
|
86
104
|
|
87
105
|
on_authenticated connection, auth_key, permissions
|
88
106
|
|
89
|
-
|
107
|
+
permissions[:permissions]
|
90
108
|
end
|
91
109
|
|
92
110
|
private
|
@@ -107,9 +125,10 @@ module Wampus
|
|
107
125
|
auth_info[:auth_extra] = results[:auth_extra] if results.has_key? :auth_extra
|
108
126
|
|
109
127
|
if auth_key
|
110
|
-
|
128
|
+
auth_json = auth_info.to_json
|
129
|
+
auth_sig = auth_signature auth_json, auth_secret
|
111
130
|
connection.pending_auth = [auth_info, auth_sig, results]
|
112
|
-
return
|
131
|
+
return auth_json
|
113
132
|
else
|
114
133
|
connection.pending_auth = [auth_info, nil, results]
|
115
134
|
return nil
|
data/lib/wampus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wampus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Stack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|