onion 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/{README.rdoc → License.txt} +2 -19
- data/README.txt +34 -0
- data/lib/onion.rb +2 -2
- data/lib/onion/control_client.rb +87 -0
- data/lib/onion/elements.rb +4 -0
- data/lib/onion/elements/circuit.rb +11 -0
- data/lib/onion/elements/circuit_list.rb +18 -0
- data/lib/onion/elements/router.rb +3 -3
- data/lib/onion/elements/router_list.rb +4 -6
- data/lib/onion/elements/stream.rb +12 -0
- data/lib/onion/elements/stream_list.rb +20 -0
- data/lib/onion/parsers/circuit_lists.rb +491 -0
- data/lib/onion/parsers/circuit_lists.treetop +53 -0
- data/lib/onion/parsers/common.rb +1692 -0
- data/lib/onion/parsers/common.treetop +127 -0
- data/lib/onion/parsers/router_statuses.rb +1035 -0
- data/lib/onion/parsers/router_statuses.treetop +111 -0
- data/lib/onion/parsers/stream_lists.rb +356 -0
- data/lib/onion/parsers/stream_lists.treetop +32 -0
- data/lib/tasks/treetop.rake +1 -1
- metadata +18 -5
- data/lib/onion/parsers/router_lists.treetop +0 -133
@@ -0,0 +1,111 @@
|
|
1
|
+
module Onion
|
2
|
+
grammar RouterStatuses
|
3
|
+
include Common
|
4
|
+
|
5
|
+
rule router_statuses
|
6
|
+
(getinfo_error_response / router_status)+ {
|
7
|
+
def routers
|
8
|
+
routers = []
|
9
|
+
self.elements.each do |entry|
|
10
|
+
unless entry.extension_modules.join.include?("Error")
|
11
|
+
if entry.extra_info.elements != []
|
12
|
+
entry.extra_info.elements.each do |info|
|
13
|
+
# TODO: Is there a better way to differeniate between extra info?
|
14
|
+
if info.extension_modules.join.include?("::Status")
|
15
|
+
routers << Router.new(entry.r.nick, entry.r.fingerprint, info.flags)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
else
|
19
|
+
routers << Router.new(entry.r.nick, entry.r.fingerprint, nil)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return routers
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
rule getinfo_error_response
|
29
|
+
"552" [ /0-9a-zA-Z\-=,"]+ NL
|
30
|
+
end
|
31
|
+
|
32
|
+
rule command_ack
|
33
|
+
"250 OK\r\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
rule response_start
|
37
|
+
"250+" [/0-9a-zA-Z]+ "=\r\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
rule response_end
|
41
|
+
".\r\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
rule router_status
|
45
|
+
response_start r:router extra_info:(extra_info*) response_end command_ack
|
46
|
+
end
|
47
|
+
|
48
|
+
rule router
|
49
|
+
"r" SP n:Nickname SP f:Identity SP Digest SP Publication SP IP SP ORPort SP DirPort NL {
|
50
|
+
def nick
|
51
|
+
n.text_value.strip
|
52
|
+
end
|
53
|
+
|
54
|
+
def fingerprint
|
55
|
+
f.text_value.strip
|
56
|
+
end
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
rule Identity
|
61
|
+
Base64Hash
|
62
|
+
end
|
63
|
+
|
64
|
+
rule Digest
|
65
|
+
Base64Hash
|
66
|
+
end
|
67
|
+
|
68
|
+
rule Publication
|
69
|
+
DateTime
|
70
|
+
end
|
71
|
+
|
72
|
+
rule extra_info
|
73
|
+
status / bandwidth / policy
|
74
|
+
end
|
75
|
+
|
76
|
+
rule status
|
77
|
+
"s" (SP flag:status_flag)+ NL {
|
78
|
+
def flags
|
79
|
+
results = []
|
80
|
+
self.elements[1].elements.each do |e|
|
81
|
+
if e.respond_to? :flag
|
82
|
+
results << e.flag.text_value
|
83
|
+
end
|
84
|
+
end
|
85
|
+
return results
|
86
|
+
end
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
rule status_flag
|
91
|
+
documented_status_flag / undocumented_status_flag
|
92
|
+
end
|
93
|
+
|
94
|
+
rule documented_status_flag
|
95
|
+
"Authority" / "BadExit" / "BadDirectory" / "Exit" / "Fast"
|
96
|
+
/ "Guard" / "Named" / "Stable" / "Running" / "Valid" / "V2Dir"
|
97
|
+
end
|
98
|
+
|
99
|
+
rule undocumented_status_flag
|
100
|
+
[a-zA-Z]+
|
101
|
+
end
|
102
|
+
|
103
|
+
rule bandwidth
|
104
|
+
"w" [ /0-9a-zA-Z\-=]+ NL
|
105
|
+
end
|
106
|
+
|
107
|
+
rule policy
|
108
|
+
"p" [ /0-9a-zA-Z\-=,]+ NL
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,356 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Onion
|
5
|
+
module StreamLists
|
6
|
+
include Treetop::Runtime
|
7
|
+
|
8
|
+
def root
|
9
|
+
@root ||= :stream_list
|
10
|
+
end
|
11
|
+
|
12
|
+
include Common
|
13
|
+
|
14
|
+
module StreamList0
|
15
|
+
def streams
|
16
|
+
streams = []
|
17
|
+
self.elements.each do |stream|
|
18
|
+
streams << Stream.new(stream.s_id.text_value.strip, stream.c_id.text_value.strip)
|
19
|
+
end
|
20
|
+
return streams
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def _nt_stream_list
|
25
|
+
start_index = index
|
26
|
+
if node_cache[:stream_list].has_key?(index)
|
27
|
+
cached = node_cache[:stream_list][index]
|
28
|
+
if cached
|
29
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
30
|
+
@index = cached.interval.end
|
31
|
+
end
|
32
|
+
return cached
|
33
|
+
end
|
34
|
+
|
35
|
+
s0, i0 = [], index
|
36
|
+
loop do
|
37
|
+
r1 = _nt_stream_list_entry
|
38
|
+
if r1
|
39
|
+
s0 << r1
|
40
|
+
else
|
41
|
+
break
|
42
|
+
end
|
43
|
+
end
|
44
|
+
if s0.empty?
|
45
|
+
@index = i0
|
46
|
+
r0 = nil
|
47
|
+
else
|
48
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
49
|
+
r0.extend(StreamList0)
|
50
|
+
end
|
51
|
+
|
52
|
+
node_cache[:stream_list][start_index] = r0
|
53
|
+
|
54
|
+
r0
|
55
|
+
end
|
56
|
+
|
57
|
+
module StreamListEntry0
|
58
|
+
def s_id
|
59
|
+
elements[0]
|
60
|
+
end
|
61
|
+
|
62
|
+
def SP1
|
63
|
+
elements[1]
|
64
|
+
end
|
65
|
+
|
66
|
+
def s
|
67
|
+
elements[2]
|
68
|
+
end
|
69
|
+
|
70
|
+
def SP2
|
71
|
+
elements[3]
|
72
|
+
end
|
73
|
+
|
74
|
+
def c_id
|
75
|
+
elements[4]
|
76
|
+
end
|
77
|
+
|
78
|
+
def SP3
|
79
|
+
elements[5]
|
80
|
+
end
|
81
|
+
|
82
|
+
def t
|
83
|
+
elements[6]
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
def _nt_stream_list_entry
|
89
|
+
start_index = index
|
90
|
+
if node_cache[:stream_list_entry].has_key?(index)
|
91
|
+
cached = node_cache[:stream_list_entry][index]
|
92
|
+
if cached
|
93
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
94
|
+
@index = cached.interval.end
|
95
|
+
end
|
96
|
+
return cached
|
97
|
+
end
|
98
|
+
|
99
|
+
i0, s0 = index, []
|
100
|
+
r1 = _nt_StreamID
|
101
|
+
s0 << r1
|
102
|
+
if r1
|
103
|
+
r2 = _nt_SP
|
104
|
+
s0 << r2
|
105
|
+
if r2
|
106
|
+
r3 = _nt_StreamStatus
|
107
|
+
s0 << r3
|
108
|
+
if r3
|
109
|
+
r4 = _nt_SP
|
110
|
+
s0 << r4
|
111
|
+
if r4
|
112
|
+
r5 = _nt_CircuitID
|
113
|
+
s0 << r5
|
114
|
+
if r5
|
115
|
+
r6 = _nt_SP
|
116
|
+
s0 << r6
|
117
|
+
if r6
|
118
|
+
r7 = _nt_Target
|
119
|
+
s0 << r7
|
120
|
+
if r7
|
121
|
+
if has_terminal?("\r\n", false, index)
|
122
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
123
|
+
@index += 2
|
124
|
+
else
|
125
|
+
terminal_parse_failure("\r\n")
|
126
|
+
r8 = nil
|
127
|
+
end
|
128
|
+
s0 << r8
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
if s0.last
|
137
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
138
|
+
r0.extend(StreamListEntry0)
|
139
|
+
else
|
140
|
+
@index = i0
|
141
|
+
r0 = nil
|
142
|
+
end
|
143
|
+
|
144
|
+
node_cache[:stream_list_entry][start_index] = r0
|
145
|
+
|
146
|
+
r0
|
147
|
+
end
|
148
|
+
|
149
|
+
def _nt_StreamStatus
|
150
|
+
start_index = index
|
151
|
+
if node_cache[:StreamStatus].has_key?(index)
|
152
|
+
cached = node_cache[:StreamStatus][index]
|
153
|
+
if cached
|
154
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
155
|
+
@index = cached.interval.end
|
156
|
+
end
|
157
|
+
return cached
|
158
|
+
end
|
159
|
+
|
160
|
+
i0 = index
|
161
|
+
if has_terminal?("NEW", false, index)
|
162
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
163
|
+
@index += 3
|
164
|
+
else
|
165
|
+
terminal_parse_failure("NEW")
|
166
|
+
r1 = nil
|
167
|
+
end
|
168
|
+
if r1
|
169
|
+
r0 = r1
|
170
|
+
else
|
171
|
+
if has_terminal?("NEWRESOLVE", false, index)
|
172
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 10))
|
173
|
+
@index += 10
|
174
|
+
else
|
175
|
+
terminal_parse_failure("NEWRESOLVE")
|
176
|
+
r2 = nil
|
177
|
+
end
|
178
|
+
if r2
|
179
|
+
r0 = r2
|
180
|
+
else
|
181
|
+
if has_terminal?("REMAP", false, index)
|
182
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
183
|
+
@index += 5
|
184
|
+
else
|
185
|
+
terminal_parse_failure("REMAP")
|
186
|
+
r3 = nil
|
187
|
+
end
|
188
|
+
if r3
|
189
|
+
r0 = r3
|
190
|
+
else
|
191
|
+
if has_terminal?("SENTCONNECT", false, index)
|
192
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 11))
|
193
|
+
@index += 11
|
194
|
+
else
|
195
|
+
terminal_parse_failure("SENTCONNECT")
|
196
|
+
r4 = nil
|
197
|
+
end
|
198
|
+
if r4
|
199
|
+
r0 = r4
|
200
|
+
else
|
201
|
+
if has_terminal?("SENTRESOLVE", false, index)
|
202
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 11))
|
203
|
+
@index += 11
|
204
|
+
else
|
205
|
+
terminal_parse_failure("SENTRESOLVE")
|
206
|
+
r5 = nil
|
207
|
+
end
|
208
|
+
if r5
|
209
|
+
r0 = r5
|
210
|
+
else
|
211
|
+
if has_terminal?("SUCCEEDED", false, index)
|
212
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 9))
|
213
|
+
@index += 9
|
214
|
+
else
|
215
|
+
terminal_parse_failure("SUCCEEDED")
|
216
|
+
r6 = nil
|
217
|
+
end
|
218
|
+
if r6
|
219
|
+
r0 = r6
|
220
|
+
else
|
221
|
+
if has_terminal?("FAILED", false, index)
|
222
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + 6))
|
223
|
+
@index += 6
|
224
|
+
else
|
225
|
+
terminal_parse_failure("FAILED")
|
226
|
+
r7 = nil
|
227
|
+
end
|
228
|
+
if r7
|
229
|
+
r0 = r7
|
230
|
+
else
|
231
|
+
if has_terminal?("CLOSED", false, index)
|
232
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 6))
|
233
|
+
@index += 6
|
234
|
+
else
|
235
|
+
terminal_parse_failure("CLOSED")
|
236
|
+
r8 = nil
|
237
|
+
end
|
238
|
+
if r8
|
239
|
+
r0 = r8
|
240
|
+
else
|
241
|
+
if has_terminal?("DETACHED", false, index)
|
242
|
+
r9 = instantiate_node(SyntaxNode,input, index...(index + 8))
|
243
|
+
@index += 8
|
244
|
+
else
|
245
|
+
terminal_parse_failure("DETACHED")
|
246
|
+
r9 = nil
|
247
|
+
end
|
248
|
+
if r9
|
249
|
+
r0 = r9
|
250
|
+
else
|
251
|
+
@index = i0
|
252
|
+
r0 = nil
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
node_cache[:StreamStatus][start_index] = r0
|
264
|
+
|
265
|
+
r0
|
266
|
+
end
|
267
|
+
|
268
|
+
module Target0
|
269
|
+
end
|
270
|
+
|
271
|
+
def _nt_Target
|
272
|
+
start_index = index
|
273
|
+
if node_cache[:Target].has_key?(index)
|
274
|
+
cached = node_cache[:Target][index]
|
275
|
+
if cached
|
276
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
277
|
+
@index = cached.interval.end
|
278
|
+
end
|
279
|
+
return cached
|
280
|
+
end
|
281
|
+
|
282
|
+
i0, s0 = index, []
|
283
|
+
s1, i1 = [], index
|
284
|
+
loop do
|
285
|
+
if has_terminal?('\G[$0-9a-zA-Z\\.\\-]', true, index)
|
286
|
+
r2 = true
|
287
|
+
@index += 1
|
288
|
+
else
|
289
|
+
r2 = nil
|
290
|
+
end
|
291
|
+
if r2
|
292
|
+
s1 << r2
|
293
|
+
else
|
294
|
+
break
|
295
|
+
end
|
296
|
+
end
|
297
|
+
if s1.empty?
|
298
|
+
@index = i1
|
299
|
+
r1 = nil
|
300
|
+
else
|
301
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
302
|
+
end
|
303
|
+
s0 << r1
|
304
|
+
if r1
|
305
|
+
if has_terminal?(":", false, index)
|
306
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
307
|
+
@index += 1
|
308
|
+
else
|
309
|
+
terminal_parse_failure(":")
|
310
|
+
r3 = nil
|
311
|
+
end
|
312
|
+
s0 << r3
|
313
|
+
if r3
|
314
|
+
s4, i4 = [], index
|
315
|
+
loop do
|
316
|
+
if has_terminal?('\G[0-9]', true, index)
|
317
|
+
r5 = true
|
318
|
+
@index += 1
|
319
|
+
else
|
320
|
+
r5 = nil
|
321
|
+
end
|
322
|
+
if r5
|
323
|
+
s4 << r5
|
324
|
+
else
|
325
|
+
break
|
326
|
+
end
|
327
|
+
end
|
328
|
+
if s4.empty?
|
329
|
+
@index = i4
|
330
|
+
r4 = nil
|
331
|
+
else
|
332
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
333
|
+
end
|
334
|
+
s0 << r4
|
335
|
+
end
|
336
|
+
end
|
337
|
+
if s0.last
|
338
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
339
|
+
r0.extend(Target0)
|
340
|
+
else
|
341
|
+
@index = i0
|
342
|
+
r0 = nil
|
343
|
+
end
|
344
|
+
|
345
|
+
node_cache[:Target][start_index] = r0
|
346
|
+
|
347
|
+
r0
|
348
|
+
end
|
349
|
+
|
350
|
+
end
|
351
|
+
|
352
|
+
class StreamListsParser < Treetop::Runtime::CompiledParser
|
353
|
+
include StreamLists
|
354
|
+
end
|
355
|
+
|
356
|
+
end
|