trisulrp 1.5.7 → 1.5.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/trisulrp/guids.rb +11 -11
- data/lib/trisulrp/keys.rb +271 -269
- data/lib/trisulrp/protocol.rb +296 -292
- data/lib/trisulrp/trp.pb.rb +10 -1
- data/lib/trisulrp/trp.proto +11 -2
- data/lib/trisulrp/utils.rb +111 -111
- data/trisulrp.gemspec +2 -2
- metadata +3 -3
data/lib/trisulrp/protocol.rb
CHANGED
@@ -16,304 +16,308 @@ require 'time'
|
|
16
16
|
#
|
17
17
|
|
18
18
|
module TrisulRP::Protocol
|
19
|
-
|
19
|
+
include TrisulRP::Guids
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
21
|
+
# Establish a TLS connection to a Trisul instance
|
22
|
+
#
|
23
|
+
# [server] IP Address or hostname
|
24
|
+
# [port] TRP port, typically 12001 (see trisulConfig.xml)
|
25
|
+
# [client_cert_file] Client certificate file issued by admin
|
26
|
+
# [client_key_file] Client key file issued by admin
|
27
|
+
#
|
28
|
+
#
|
29
|
+
# ==== Returns
|
30
|
+
# ==== Yields
|
31
|
+
# a connection object that can be used in subsequent calls
|
32
|
+
#
|
33
|
+
# ==== On error
|
34
|
+
# If a connection cannot be established, an exception is thrown which can point
|
35
|
+
# to the actual cause. The most common causes are
|
36
|
+
#
|
37
|
+
# * Trisul is not running
|
38
|
+
# * Trisul is not running in trp mode (see the docs for runmode)
|
39
|
+
# * Using the wrong port ( check netstat to verify trisul remote protocol port - typically 12001)
|
40
|
+
# * The Access Control List does not permit connections from client IP
|
41
|
+
#
|
42
|
+
def connect(server,port,client_cert_file,client_key_file)
|
43
|
+
tcp_sock=TCPSocket.open(server,port)
|
44
|
+
ctx = OpenSSL::SSL::SSLContext.new(:TLSv1)
|
45
|
+
ctx.cert = OpenSSL::X509::Certificate.new(File.read(client_cert_file))
|
46
|
+
ctx.key = OpenSSL::PKey::RSA.new(File.read(client_key_file))
|
47
|
+
ssl_sock = OpenSSL::SSL::SSLSocket.new(tcp_sock, ctx)
|
48
|
+
ssl_sock.connect
|
49
|
+
yield ssl_sock if block_given?
|
50
|
+
return ssl_sock
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
53
|
+
# Dispatch request to server & get response
|
54
|
+
# [conn] TRP connection previously opened via TrisulRP::Protocol::connect
|
55
|
+
# [trp_request] a TRP request object, created directly or using the mk_request helper
|
56
|
+
#
|
57
|
+
# ==== Returns
|
58
|
+
# ==== Yields
|
59
|
+
# a response object, you can then inspect the fields in the response and spawn additional
|
60
|
+
# requests if required
|
61
|
+
#
|
62
|
+
# ==== On error
|
63
|
+
# raises an error if the server returns an ErrorResponse - this contains an error_message field
|
64
|
+
# which can tell you what went wrong
|
65
|
+
#
|
66
|
+
def get_response(conn,trp_request)
|
67
|
+
outbuf=""
|
68
|
+
outbuf=trp_request.serialize_to_string
|
69
|
+
conn.write([outbuf.length].pack("N*"))
|
70
|
+
conn.write(outbuf)
|
71
|
+
inbuf = conn.read(4)
|
72
|
+
buflenarr=inbuf.unpack("N*")
|
73
|
+
datalen=buflenarr[0]
|
74
|
+
dataarray=conn.read(datalen)
|
75
|
+
resp =TRP::Message.new
|
76
|
+
resp.parse dataarray
|
77
|
+
raise resp.error_response if resp.trp_command == TRP::Message::Command::ERROR_RESPONSE
|
78
|
+
yield unwrap_response(resp) if block_given?
|
79
|
+
return unwrap_response(resp)
|
80
|
+
end
|
81
81
|
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
from_tm = Time.at(resp.group_details[0].time_interval.from.tv_sec)
|
109
|
-
to_tm = Time.at(resp.group_details[0].time_interval.to.tv_sec)
|
110
|
-
end
|
111
|
-
return [from_tm,to_tm]
|
112
|
-
end
|
113
|
-
# Helper to create a TRP TimeInterval object
|
114
|
-
#
|
115
|
-
# [tmarr] An array of two Time objects representing a window
|
116
|
-
#
|
117
|
-
# ==== Returns
|
118
|
-
# A TRP::TimeInterval object which can be attached to any :time_interval field of a TRP request
|
119
|
-
#
|
120
|
-
def mk_time_interval(tmarr)
|
121
|
-
tint=TRP::TimeInterval.new
|
122
|
-
tint.from=TRP::Timestamp.new(:tv_sec => tmarr[0].tv_sec, :tv_usec => 0)
|
123
|
-
tint.to=TRP::Timestamp.new(:tv_sec => tmarr[1].tv_sec, :tv_usec => 0)
|
124
|
-
return tint
|
125
|
-
end
|
83
|
+
# Query the total time window available in Trisul
|
84
|
+
#
|
85
|
+
# [conn] TRP connection previously opened via connect
|
86
|
+
#
|
87
|
+
# ==== Returns
|
88
|
+
# returns an array of two Time objects [Time_from, Time_to] representing start and end time
|
89
|
+
#
|
90
|
+
# ==== Typical usage
|
91
|
+
#
|
92
|
+
# You pass the output of this method to mk_time_interval to get an object you can attach to a
|
93
|
+
# TRP request.
|
94
|
+
#
|
95
|
+
# <code>
|
96
|
+
#
|
97
|
+
# tmarr = TrisulRP::Protocol::get_avaiable_time(conn)
|
98
|
+
# req = TrisulRP::Protocol.mk_request( :source_ip => target_ip,...
|
99
|
+
# :time_interval => TrisulRP::Protocol::mk_time_interval(tm_arr))
|
100
|
+
#
|
101
|
+
# </code>
|
102
|
+
#
|
103
|
+
def get_available_time(conn)
|
104
|
+
|
105
|
+
from_tm=to_tm=nil
|
106
|
+
req=mk_request(TRP::Message::Command::COUNTER_GROUP_INFO_REQUEST,
|
107
|
+
:counter_group => TrisulRP::Guids::CG_AGGREGATE)
|
126
108
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
# [cmd_id] The command ID.
|
132
|
-
# [params] A hash containing command parameters
|
133
|
-
#
|
134
|
-
# ==== Typical usage
|
135
|
-
#
|
136
|
-
# <code>
|
137
|
-
#
|
138
|
-
# # create a new command of type KeySessionActivityRequest
|
139
|
-
# req = TrisulRP::Protocol.mk_request(TRP::Message::Command::KEY_SESS_ACTIVITY_REQUEST,
|
140
|
-
# :key => target_key ,
|
141
|
-
# :time_interval => mk_time_interval(tmarr))
|
142
|
-
#
|
143
|
-
# ... now you can use the req object ...
|
144
|
-
#
|
145
|
-
# </code>
|
146
|
-
#
|
147
|
-
# You can also create the request objects directly, just a little too verbose for our liking
|
148
|
-
#
|
149
|
-
# <code>
|
150
|
-
#
|
151
|
-
# # create a new command of type CounterItemRequest
|
152
|
-
# req =TRP::Message.new(:trp_command => TRP::Message::Command::KEY_SESS_ACTIVITY_REQUEST )
|
153
|
-
# req.key_session_activity_request = TRP::KeySessionActivityRequest.new(
|
154
|
-
# :key => target_key ,
|
155
|
-
# :time_interval => mk_time_interval(tmarr))
|
156
|
-
#
|
157
|
-
# ... now you can use the req object ...
|
158
|
-
#
|
159
|
-
# </code>
|
160
|
-
#
|
161
|
-
#
|
162
|
-
def mk_request(cmd_id,params={})
|
163
|
-
req = TRP::Message.new(:trp_command => cmd_id)
|
164
|
-
case cmd_id
|
165
|
-
when TRP::Message::Command::HELLO_REQUEST
|
166
|
-
req.hello_request = TRP::HelloRequest.new(params)
|
167
|
-
when TRP::Message::Command::COUNTER_GROUP_REQUEST
|
168
|
-
req.counter_group_request = TRP::CounterGroupRequest.new(params)
|
169
|
-
when TRP::Message::Command::COUNTER_ITEM_REQUEST
|
170
|
-
req.counter_item_request = TRP::CounterItemRequest.new(params)
|
171
|
-
when TRP::Message::Command::RELEASE_RESOURCE_REQUEST
|
172
|
-
req.release_resource_request = TRP::ReleaseResourceRequest.new(params)
|
173
|
-
when TRP::Message::Command::CONTROLLED_COUNTER_GROUP_REQUEST
|
174
|
-
req.controlled_counter_group_request = TRP::ControlledCounterGroupRequest.new(params)
|
175
|
-
when TRP::Message::Command::FILTERED_DATAGRAMS_REQUEST
|
176
|
-
req.filtered_datagram_request = TRP::FilteredDatagramRequest.new(params)
|
177
|
-
when TRP::Message::Command::CONTROLLED_CONTEXT_REQUEST
|
178
|
-
req.controlled_context_request = TRP::ControlledContextRequest.new(params)
|
179
|
-
when TRP::Message::Command::SEARCH_KEYS_REQUEST
|
180
|
-
req.search_keys_request = TRP::SearchKeysRequest.new(params)
|
181
|
-
when TRP::Message::Command::BULK_COUNTER_ITEM_REQUEST
|
182
|
-
req.bulk_counter_item_request = TRP::BulkCounterItemRequest.new(params)
|
183
|
-
when TRP::Message::Command:: CGMONITOR_REQUEST
|
184
|
-
req.cgmonitor_request = TRP::CgmonitorRequest.new(params)
|
185
|
-
when TRP::Message::Command::TOPPER_SNAPSHOT_REQUEST
|
186
|
-
req.topper_snapshot_request = TRP::TopperSnapshotRequest.new(params)
|
187
|
-
when TRP::Message::Command::UPDATE_KEY_REQUEST
|
188
|
-
req.update_key_request = TRP::UpdateKeyRequest.new(params)
|
189
|
-
when TRP::Message::Command::RING_STATS_REQUEST
|
190
|
-
req.ring_stats_request = TRP::RingStatsRequest.new(params)
|
191
|
-
when TRP::Message::Command::SERVER_STATS_REQUEST
|
192
|
-
req.server_stats_request = TRP::ServerStatsRequest.new(params)
|
193
|
-
when TRP::Message::Command::SESSION_ITEM_REQUEST
|
194
|
-
req.session_item_request = TRP::SessionItemRequest.new(params)
|
195
|
-
when TRP::Message::Command::SESSION_GROUP_REQUEST
|
196
|
-
req.session_group_request = TRP::SessionGroupRequest.new(params)
|
197
|
-
when TRP::Message::Command::ALERT_ITEM_REQUEST
|
198
|
-
req.alert_item_request = TRP::AlertItemRequest.new(params)
|
199
|
-
when TRP::Message::Command::ALERT_GROUP_REQUEST
|
200
|
-
req.alert_group_request = TRP::AlertGroupRequest.new(params)
|
201
|
-
when TRP::Message::Command::RESOURCE_ITEM_REQUEST
|
202
|
-
req.resource_item_request = TRP::ResourceItemRequest.new(params)
|
203
|
-
when TRP::Message::Command::RESOURCE_GROUP_REQUEST
|
204
|
-
req.resource_group_request = TRP::ResourceGroupRequest.new(params)
|
205
|
-
when TRP::Message::Command::KEY_LOOKUP_REQUEST
|
206
|
-
req.key_lookup_request = TRP::KeyLookupRequest.new(params)
|
207
|
-
when TRP::Message::Command::COUNTER_GROUP_INFO_REQUEST
|
208
|
-
req.counter_group_info_request = TRP::CounterGroupInfoRequest.new(params)
|
209
|
-
when TRP::Message::Command::SESSION_TRACKER_REQUEST
|
210
|
-
req.session_tracker_request = TRP::SessionTrackerRequest.new(params)
|
211
|
-
when TRP::Message::Command::KEY_SESS_ACTIVITY_REQUEST
|
212
|
-
req.key_session_activity_request = TRP::KeySessionActivityRequest.new(params)
|
213
|
-
when TRP::Message::Command::GREP_REQUEST
|
214
|
-
req.grep_request = TRP::GrepRequest.new(params)
|
215
|
-
when TRP::Message::Command::KEYSPACE_REQUEST
|
216
|
-
req.keyspace_request = TRP::KeySpaceRequest.new(params)
|
217
|
-
else
|
218
|
-
raise "Unknown TRP command ID"
|
219
|
-
end
|
220
|
-
return req
|
221
|
-
end
|
109
|
+
get_response(conn,req) do |resp|
|
110
|
+
from_tm = Time.at(resp.group_details[0].time_interval.from.tv_sec)
|
111
|
+
to_tm = Time.at(resp.group_details[0].time_interval.to.tv_sec)
|
112
|
+
end
|
222
113
|
|
223
|
-
|
224
|
-
#
|
225
|
-
# All protobuf messages used in TRP have a wrapper containing a command_id which identifies
|
226
|
-
# the type of encapsulated message. This sometimes gets in the way because you have to write
|
227
|
-
# stuff like
|
228
|
-
#
|
229
|
-
# <code>
|
230
|
-
#
|
231
|
-
# response.counter_group_response.blah_blah
|
232
|
-
#
|
233
|
-
# instead of
|
234
|
-
#
|
235
|
-
# response.blah_blah
|
236
|
-
#
|
237
|
-
# </code>
|
238
|
-
#
|
239
|
-
# Read the TRP documentation wiki for a description of each command.
|
240
|
-
#
|
241
|
-
# [resp] The response
|
242
|
-
#
|
243
|
-
# ==== Typical usage
|
244
|
-
#
|
245
|
-
# <code>
|
246
|
-
#
|
247
|
-
# # create a new command of type KeySessionActivityRequest
|
248
|
-
# req = TrisulRP::Protocol.get_response(...) do |resp|
|
249
|
-
#
|
250
|
-
# # here resp points to the inner response without the wrapper
|
251
|
-
# # this allows you to write resp.xyz instead of resp.hello_response.xyz
|
252
|
-
#
|
253
|
-
#
|
254
|
-
# end
|
255
|
-
#
|
256
|
-
# </code>
|
257
|
-
#
|
258
|
-
#
|
259
|
-
def unwrap_response(resp)
|
260
|
-
case resp.trp_command
|
261
|
-
when TRP::Message::Command::HELLO_RESPONSE
|
262
|
-
resp.hello_response
|
263
|
-
when TRP::Message::Command::COUNTER_GROUP_RESPONSE
|
264
|
-
resp.counter_group_response
|
265
|
-
when TRP::Message::Command::COUNTER_ITEM_RESPONSE
|
266
|
-
resp.counter_item_response
|
267
|
-
when TRP::Message::Command::OK_RESPONSE
|
268
|
-
resp.ok_response
|
269
|
-
when TRP::Message::Command::CONTROLLED_COUNTER_GROUP_RESPONSE
|
270
|
-
resp.controlled_counter_group_response
|
271
|
-
when TRP::Message::Command::FILTERED_DATAGRAMS_RESPONSE
|
272
|
-
resp.filtered_datagram_response
|
273
|
-
when TRP::Message::Command::CONTROLLED_CONTEXT_RESPONSE
|
274
|
-
resp.controlled_context_response
|
275
|
-
when TRP::Message::Command::SEARCH_KEYS_RESPONSE
|
276
|
-
resp.search_keys_response
|
277
|
-
when TRP::Message::Command::BULK_COUNTER_ITEM_RESPONSE
|
278
|
-
resp.bulk_counter_item_response
|
279
|
-
when TRP::Message::Command:: CGMONITOR_RESPONSE
|
280
|
-
resp.cgmonitor_response
|
281
|
-
when TRP::Message::Command::TOPPER_SNAPSHOT_RESPONSE
|
282
|
-
resp.topper_snapshot_response
|
283
|
-
when TRP::Message::Command::UPDATE_KEY_RESPONSE
|
284
|
-
resp.update_key_response
|
285
|
-
when TRP::Message::Command::RING_STATS_RESPONSE
|
286
|
-
resp.ring_stats_response
|
287
|
-
when TRP::Message::Command::SERVER_STATS_RESPONSE
|
288
|
-
resp.server_stats_response
|
289
|
-
when TRP::Message::Command::SESSION_ITEM_RESPONSE
|
290
|
-
resp.session_item_response
|
291
|
-
when TRP::Message::Command::SESSION_GROUP_RESPONSE
|
292
|
-
resp.session_group_response
|
293
|
-
when TRP::Message::Command::ALERT_ITEM_RESPONSE
|
294
|
-
resp.alert_item_response
|
295
|
-
when TRP::Message::Command::ALERT_GROUP_RESPONSE
|
296
|
-
resp.alert_group_response
|
297
|
-
when TRP::Message::Command::RESOURCE_ITEM_RESPONSE
|
298
|
-
resp.resource_item_response
|
299
|
-
when TRP::Message::Command::RESOURCE_GROUP_RESPONSE
|
300
|
-
resp.resource_group_response
|
301
|
-
when TRP::Message::Command::KEY_LOOKUP_RESPONSE
|
302
|
-
resp.key_lookup_response
|
303
|
-
when TRP::Message::Command::COUNTER_GROUP_INFO_RESPONSE
|
304
|
-
resp.counter_group_info_response
|
305
|
-
when TRP::Message::Command::SESSION_TRACKER_RESPONSE
|
306
|
-
resp.session_tracker_response
|
307
|
-
when TRP::Message::Command::KEY_SESS_ACTIVITY_RESPONSE
|
308
|
-
resp.key_session_activity_response
|
309
|
-
when TRP::Message::Command::GREP_RESPONSE
|
310
|
-
resp.grep_response
|
311
|
-
when TRP::Message::Command::KEYSPACE_RESPONSE
|
312
|
-
resp.keyspace_response
|
313
|
-
else
|
314
|
-
raise "Unknown TRP command ID"
|
315
|
-
end
|
316
|
-
end
|
114
|
+
return [from_tm,to_tm]
|
317
115
|
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
# Helper to create a TRP TimeInterval object
|
120
|
+
#
|
121
|
+
# [tmarr] An array of two Time objects representing a window
|
122
|
+
#
|
123
|
+
# ==== Returns
|
124
|
+
# A TRP::TimeInterval object which can be attached to any :time_interval field of a TRP request
|
125
|
+
#
|
126
|
+
def mk_time_interval(tmarr)
|
127
|
+
tint=TRP::TimeInterval.new
|
128
|
+
tint.from=TRP::Timestamp.new(:tv_sec => tmarr[0].tv_sec, :tv_usec => 0)
|
129
|
+
tint.to=TRP::Timestamp.new(:tv_sec => tmarr[1].tv_sec, :tv_usec => 0)
|
130
|
+
return tint
|
131
|
+
end
|
132
|
+
|
133
|
+
# Helper to create a TRP request object
|
134
|
+
#
|
135
|
+
# Read the TRP documentation wiki for a description of each command.
|
136
|
+
#
|
137
|
+
# [cmd_id] The command ID.
|
138
|
+
# [params] A hash containing command parameters
|
139
|
+
#
|
140
|
+
# ==== Typical usage
|
141
|
+
#
|
142
|
+
# <code>
|
143
|
+
#
|
144
|
+
# # create a new command of type KeySessionActivityRequest
|
145
|
+
# req = TrisulRP::Protocol.mk_request(TRP::Message::Command::KEY_SESS_ACTIVITY_REQUEST,
|
146
|
+
# :key => target_key ,
|
147
|
+
# :time_interval => mk_time_interval(tmarr))
|
148
|
+
#
|
149
|
+
# ... now you can use the req object ...
|
150
|
+
#
|
151
|
+
# </code>
|
152
|
+
#
|
153
|
+
# You can also create the request objects directly, just a little too verbose for our liking
|
154
|
+
#
|
155
|
+
# <code>
|
156
|
+
#
|
157
|
+
# # create a new command of type CounterItemRequest
|
158
|
+
# req =TRP::Message.new(:trp_command => TRP::Message::Command::KEY_SESS_ACTIVITY_REQUEST )
|
159
|
+
# req.key_session_activity_request = TRP::KeySessionActivityRequest.new(
|
160
|
+
# :key => target_key ,
|
161
|
+
# :time_interval => mk_time_interval(tmarr))
|
162
|
+
#
|
163
|
+
# ... now you can use the req object ...
|
164
|
+
#
|
165
|
+
# </code>
|
166
|
+
#
|
167
|
+
#
|
168
|
+
def mk_request(cmd_id,params={})
|
169
|
+
req = TRP::Message.new(:trp_command => cmd_id)
|
170
|
+
case cmd_id
|
171
|
+
when TRP::Message::Command::HELLO_REQUEST
|
172
|
+
req.hello_request = TRP::HelloRequest.new(params)
|
173
|
+
when TRP::Message::Command::COUNTER_GROUP_REQUEST
|
174
|
+
req.counter_group_request = TRP::CounterGroupRequest.new(params)
|
175
|
+
when TRP::Message::Command::COUNTER_ITEM_REQUEST
|
176
|
+
req.counter_item_request = TRP::CounterItemRequest.new(params)
|
177
|
+
when TRP::Message::Command::RELEASE_RESOURCE_REQUEST
|
178
|
+
req.release_resource_request = TRP::ReleaseResourceRequest.new(params)
|
179
|
+
when TRP::Message::Command::CONTROLLED_COUNTER_GROUP_REQUEST
|
180
|
+
req.controlled_counter_group_request = TRP::ControlledCounterGroupRequest.new(params)
|
181
|
+
when TRP::Message::Command::FILTERED_DATAGRAMS_REQUEST
|
182
|
+
req.filtered_datagram_request = TRP::FilteredDatagramRequest.new(params)
|
183
|
+
when TRP::Message::Command::CONTROLLED_CONTEXT_REQUEST
|
184
|
+
req.controlled_context_request = TRP::ControlledContextRequest.new(params)
|
185
|
+
when TRP::Message::Command::SEARCH_KEYS_REQUEST
|
186
|
+
req.search_keys_request = TRP::SearchKeysRequest.new(params)
|
187
|
+
when TRP::Message::Command::BULK_COUNTER_ITEM_REQUEST
|
188
|
+
req.bulk_counter_item_request = TRP::BulkCounterItemRequest.new(params)
|
189
|
+
when TRP::Message::Command:: CGMONITOR_REQUEST
|
190
|
+
req.cgmonitor_request = TRP::CgmonitorRequest.new(params)
|
191
|
+
when TRP::Message::Command::TOPPER_SNAPSHOT_REQUEST
|
192
|
+
req.topper_snapshot_request = TRP::TopperSnapshotRequest.new(params)
|
193
|
+
when TRP::Message::Command::UPDATE_KEY_REQUEST
|
194
|
+
req.update_key_request = TRP::UpdateKeyRequest.new(params)
|
195
|
+
when TRP::Message::Command::RING_STATS_REQUEST
|
196
|
+
req.ring_stats_request = TRP::RingStatsRequest.new(params)
|
197
|
+
when TRP::Message::Command::SERVER_STATS_REQUEST
|
198
|
+
req.server_stats_request = TRP::ServerStatsRequest.new(params)
|
199
|
+
when TRP::Message::Command::SESSION_ITEM_REQUEST
|
200
|
+
req.session_item_request = TRP::SessionItemRequest.new(params)
|
201
|
+
when TRP::Message::Command::SESSION_GROUP_REQUEST
|
202
|
+
req.session_group_request = TRP::SessionGroupRequest.new(params)
|
203
|
+
when TRP::Message::Command::ALERT_ITEM_REQUEST
|
204
|
+
req.alert_item_request = TRP::AlertItemRequest.new(params)
|
205
|
+
when TRP::Message::Command::ALERT_GROUP_REQUEST
|
206
|
+
req.alert_group_request = TRP::AlertGroupRequest.new(params)
|
207
|
+
when TRP::Message::Command::RESOURCE_ITEM_REQUEST
|
208
|
+
req.resource_item_request = TRP::ResourceItemRequest.new(params)
|
209
|
+
when TRP::Message::Command::RESOURCE_GROUP_REQUEST
|
210
|
+
req.resource_group_request = TRP::ResourceGroupRequest.new(params)
|
211
|
+
when TRP::Message::Command::KEY_LOOKUP_REQUEST
|
212
|
+
req.key_lookup_request = TRP::KeyLookupRequest.new(params)
|
213
|
+
when TRP::Message::Command::COUNTER_GROUP_INFO_REQUEST
|
214
|
+
req.counter_group_info_request = TRP::CounterGroupInfoRequest.new(params)
|
215
|
+
when TRP::Message::Command::SESSION_TRACKER_REQUEST
|
216
|
+
req.session_tracker_request = TRP::SessionTrackerRequest.new(params)
|
217
|
+
when TRP::Message::Command::KEY_SESS_ACTIVITY_REQUEST
|
218
|
+
req.key_session_activity_request = TRP::KeySessionActivityRequest.new(params)
|
219
|
+
when TRP::Message::Command::GREP_REQUEST
|
220
|
+
req.grep_request = TRP::GrepRequest.new(params)
|
221
|
+
when TRP::Message::Command::KEYSPACE_REQUEST
|
222
|
+
req.keyspace_request = TRP::KeySpaceRequest.new(params)
|
223
|
+
else
|
224
|
+
raise "Unknown TRP command ID"
|
225
|
+
end
|
226
|
+
return req
|
227
|
+
end
|
228
|
+
|
229
|
+
# Helper to unwrap a response
|
230
|
+
#
|
231
|
+
# All protobuf messages used in TRP have a wrapper containing a command_id which identifies
|
232
|
+
# the type of encapsulated message. This sometimes gets in the way because you have to write
|
233
|
+
# stuff like
|
234
|
+
#
|
235
|
+
# <code>
|
236
|
+
#
|
237
|
+
# response.counter_group_response.blah_blah
|
238
|
+
#
|
239
|
+
# instead of
|
240
|
+
#
|
241
|
+
# response.blah_blah
|
242
|
+
#
|
243
|
+
# </code>
|
244
|
+
#
|
245
|
+
# Read the TRP documentation wiki for a description of each command.
|
246
|
+
#
|
247
|
+
# [resp] The response
|
248
|
+
#
|
249
|
+
# ==== Typical usage
|
250
|
+
#
|
251
|
+
# <code>
|
252
|
+
#
|
253
|
+
# # create a new command of type KeySessionActivityRequest
|
254
|
+
# req = TrisulRP::Protocol.get_response(...) do |resp|
|
255
|
+
#
|
256
|
+
# # here resp points to the inner response without the wrapper
|
257
|
+
# # this allows you to write resp.xyz instead of resp.hello_response.xyz
|
258
|
+
#
|
259
|
+
# end
|
260
|
+
#
|
261
|
+
# </code>
|
262
|
+
#
|
263
|
+
#
|
264
|
+
def unwrap_response(resp)
|
265
|
+
case resp.trp_command
|
266
|
+
when TRP::Message::Command::HELLO_RESPONSE
|
267
|
+
resp.hello_response
|
268
|
+
when TRP::Message::Command::COUNTER_GROUP_RESPONSE
|
269
|
+
resp.counter_group_response
|
270
|
+
when TRP::Message::Command::COUNTER_ITEM_RESPONSE
|
271
|
+
resp.counter_item_response
|
272
|
+
when TRP::Message::Command::OK_RESPONSE
|
273
|
+
resp.ok_response
|
274
|
+
when TRP::Message::Command::CONTROLLED_COUNTER_GROUP_RESPONSE
|
275
|
+
resp.controlled_counter_group_response
|
276
|
+
when TRP::Message::Command::FILTERED_DATAGRAMS_RESPONSE
|
277
|
+
resp.filtered_datagram_response
|
278
|
+
when TRP::Message::Command::CONTROLLED_CONTEXT_RESPONSE
|
279
|
+
resp.controlled_context_response
|
280
|
+
when TRP::Message::Command::SEARCH_KEYS_RESPONSE
|
281
|
+
resp.search_keys_response
|
282
|
+
when TRP::Message::Command::BULK_COUNTER_ITEM_RESPONSE
|
283
|
+
resp.bulk_counter_item_response
|
284
|
+
when TRP::Message::Command:: CGMONITOR_RESPONSE
|
285
|
+
resp.cgmonitor_response
|
286
|
+
when TRP::Message::Command::TOPPER_SNAPSHOT_RESPONSE
|
287
|
+
resp.topper_snapshot_response
|
288
|
+
when TRP::Message::Command::UPDATE_KEY_RESPONSE
|
289
|
+
resp.update_key_response
|
290
|
+
when TRP::Message::Command::RING_STATS_RESPONSE
|
291
|
+
resp.ring_stats_response
|
292
|
+
when TRP::Message::Command::SERVER_STATS_RESPONSE
|
293
|
+
resp.server_stats_response
|
294
|
+
when TRP::Message::Command::SESSION_ITEM_RESPONSE
|
295
|
+
resp.session_item_response
|
296
|
+
when TRP::Message::Command::SESSION_GROUP_RESPONSE
|
297
|
+
resp.session_group_response
|
298
|
+
when TRP::Message::Command::ALERT_ITEM_RESPONSE
|
299
|
+
resp.alert_item_response
|
300
|
+
when TRP::Message::Command::ALERT_GROUP_RESPONSE
|
301
|
+
resp.alert_group_response
|
302
|
+
when TRP::Message::Command::RESOURCE_ITEM_RESPONSE
|
303
|
+
resp.resource_item_response
|
304
|
+
when TRP::Message::Command::RESOURCE_GROUP_RESPONSE
|
305
|
+
resp.resource_group_response
|
306
|
+
when TRP::Message::Command::KEY_LOOKUP_RESPONSE
|
307
|
+
resp.key_lookup_response
|
308
|
+
when TRP::Message::Command::COUNTER_GROUP_INFO_RESPONSE
|
309
|
+
resp.counter_group_info_response
|
310
|
+
when TRP::Message::Command::SESSION_TRACKER_RESPONSE
|
311
|
+
resp.session_tracker_response
|
312
|
+
when TRP::Message::Command::KEY_SESS_ACTIVITY_RESPONSE
|
313
|
+
resp.key_session_activity_response
|
314
|
+
when TRP::Message::Command::GREP_RESPONSE
|
315
|
+
resp.grep_response
|
316
|
+
when TRP::Message::Command::KEYSPACE_RESPONSE
|
317
|
+
resp.keyspace_response
|
318
|
+
else
|
319
|
+
raise "Unknown TRP command ID"
|
320
|
+
end
|
321
|
+
end
|
318
322
|
end
|
319
323
|
|
data/lib/trisulrp/trp.pb.rb
CHANGED
@@ -84,9 +84,15 @@ module TRP
|
|
84
84
|
UNSNIFF = 2
|
85
85
|
end
|
86
86
|
|
87
|
+
module PcapDisposition
|
88
|
+
include ::ProtocolBuffers::Enum
|
89
|
+
DOWNLOAD = 1
|
90
|
+
SAVE_ON_SERVER = 2
|
91
|
+
end
|
92
|
+
|
87
93
|
class Timestamp < ::ProtocolBuffers::Message
|
88
94
|
required :int64, :tv_sec, 1
|
89
|
-
|
95
|
+
optional :int64, :tv_usec, 2, :default => 0
|
90
96
|
end
|
91
97
|
|
92
98
|
class TimeInterval < ::ProtocolBuffers::Message
|
@@ -358,6 +364,7 @@ module TRP
|
|
358
364
|
optional ::TRP::FilteredDatagramRequest::BySession, :session, 5
|
359
365
|
optional ::TRP::FilteredDatagramRequest::ByAlert, :alert, 6
|
360
366
|
optional ::TRP::FilteredDatagramRequest::ByResource, :resource, 7
|
367
|
+
optional ::TRP::PcapDisposition, :disposition, 8, :default => ::TRP::PcapDisposition::DOWNLOAD
|
361
368
|
end
|
362
369
|
|
363
370
|
class FilteredDatagramResponse < ::ProtocolBuffers::Message
|
@@ -368,6 +375,8 @@ module TRP
|
|
368
375
|
required :int64, :num_bytes, 5
|
369
376
|
required :string, :sha1, 6
|
370
377
|
required :bytes, :contents, 7
|
378
|
+
required ::TRP::PcapDisposition, :disposition, 8
|
379
|
+
optional :string, :path, 9
|
371
380
|
end
|
372
381
|
|
373
382
|
class ControlledContextRequest < ::ProtocolBuffers::Message
|
data/lib/trisulrp/trp.proto
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
// Trisul Remote Protocol (TRP) definition
|
2
2
|
// Based on Google Protocol Buffers
|
3
3
|
// (c) 2010-11, Unleash Networks (http://www.unleashnetworks.com)
|
4
|
-
// $Rev:
|
4
|
+
// $Rev: 5966 $
|
5
5
|
package TRP;
|
6
6
|
|
7
7
|
message Timestamp {
|
8
8
|
required int64 tv_sec=1;
|
9
|
-
|
9
|
+
optional int64 tv_usec=2 [default=0];
|
10
10
|
}
|
11
11
|
|
12
12
|
message TimeInterval {
|
@@ -77,6 +77,11 @@ enum PcapFormat {
|
|
77
77
|
UNSNIFF=2;
|
78
78
|
}
|
79
79
|
|
80
|
+
enum PcapDisposition {
|
81
|
+
DOWNLOAD=1;
|
82
|
+
SAVE_ON_SERVER=2;
|
83
|
+
}
|
84
|
+
|
80
85
|
message Message {
|
81
86
|
enum Command { HELLO_REQUEST=1;
|
82
87
|
HELLO_RESPONSE=2;
|
@@ -309,6 +314,8 @@ message FilteredDatagramRequest{
|
|
309
314
|
required ResourceID resource_id=2;
|
310
315
|
}
|
311
316
|
optional ByResource resource=7;
|
317
|
+
|
318
|
+
optional PcapDisposition disposition=8[default=DOWNLOAD];
|
312
319
|
}
|
313
320
|
|
314
321
|
/////////////////////////////////////
|
@@ -321,6 +328,8 @@ message FilteredDatagramResponse{
|
|
321
328
|
required int64 num_bytes=5;
|
322
329
|
required string sha1=6;
|
323
330
|
required bytes contents=7;
|
331
|
+
required PcapDisposition disposition=8;
|
332
|
+
optional string path=9;
|
324
333
|
}
|
325
334
|
|
326
335
|
//////////////////////////////////////////
|