rtor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ Copyright (C) 2011 by Tim Sally
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
@@ -0,0 +1 @@
1
+ A Ruby library for interacting with Tor.
@@ -0,0 +1,20 @@
1
+ require 'rake/testtask'
2
+ require 'spec/rake/spectask'
3
+
4
+ task :default => :spec
5
+
6
+ Spec::Rake::SpecTask.new(:spec) do |t|
7
+ t.warning = true
8
+ t.spec_files = FileList["#{File.dirname(__FILE__)}/spec/**/*_spec.rb"]
9
+ t.spec_opts = %w(--backtrace --color)
10
+ end
11
+
12
+ desc "Build a gem file."
13
+ task :build do
14
+ system "gem build rtor.gemspec"
15
+ end
16
+
17
+ # Load custom rake tasks.
18
+ Dir["#{File.dirname(__FILE__)}/lib/tasks/**/*.rake"].sort.each do |task|
19
+ load task
20
+ end
@@ -0,0 +1,15 @@
1
+ module RTor
2
+ grammars = %w[ primitives ]
3
+ grammars.each do |g|
4
+ begin
5
+ # If there is a pre-compiled grammar, load it.
6
+ require 'treetop/runtime'
7
+ require "rtor/#{g}"
8
+ rescue LoadError
9
+ # Otherwise, compile the grammar with Treetop."
10
+ require 'treetop/runtime'
11
+ require 'treetop/compiler'
12
+ Treetop.load(File.join(File.dirname(__FILE__) + "/rtor/#{g}"))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module RTor
2
+ module DirspecV2
3
+ grammar NetworkStatus
4
+ include Primitives
5
+
6
+ rule NetworkStatusVersion
7
+ "network-status-version 2"
8
+ end
9
+
10
+ rule DirSourceLine
11
+ "dir-source" SP Hostname SP IPv4Address SP DirPort
12
+ end
13
+
14
+ rule FingerprintLine
15
+ "fingerprint" SP Fingerprint
16
+ end
17
+
18
+ rule PublishedLine
19
+ "published" SP DateTime
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,231 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module RTor
5
+ module DirspecV2
6
+ module NetworkStatus
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :NetworkStatusVersion
11
+ end
12
+
13
+ include Primitives
14
+
15
+ def _nt_NetworkStatusVersion
16
+ start_index = index
17
+ if node_cache[:NetworkStatusVersion].has_key?(index)
18
+ cached = node_cache[:NetworkStatusVersion][index]
19
+ if cached
20
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
21
+ @index = cached.interval.end
22
+ end
23
+ return cached
24
+ end
25
+
26
+ if has_terminal?("network-status-version 2", false, index)
27
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 24))
28
+ @index += 24
29
+ else
30
+ terminal_parse_failure("network-status-version 2")
31
+ r0 = nil
32
+ end
33
+
34
+ node_cache[:NetworkStatusVersion][start_index] = r0
35
+
36
+ r0
37
+ end
38
+
39
+ module DirSourceLine0
40
+ def SP1
41
+ elements[1]
42
+ end
43
+
44
+ def Hostname
45
+ elements[2]
46
+ end
47
+
48
+ def SP2
49
+ elements[3]
50
+ end
51
+
52
+ def IPv4Address
53
+ elements[4]
54
+ end
55
+
56
+ def SP3
57
+ elements[5]
58
+ end
59
+
60
+ def DirPort
61
+ elements[6]
62
+ end
63
+ end
64
+
65
+ def _nt_DirSourceLine
66
+ start_index = index
67
+ if node_cache[:DirSourceLine].has_key?(index)
68
+ cached = node_cache[:DirSourceLine][index]
69
+ if cached
70
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
71
+ @index = cached.interval.end
72
+ end
73
+ return cached
74
+ end
75
+
76
+ i0, s0 = index, []
77
+ if has_terminal?("dir-source", false, index)
78
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 10))
79
+ @index += 10
80
+ else
81
+ terminal_parse_failure("dir-source")
82
+ r1 = nil
83
+ end
84
+ s0 << r1
85
+ if r1
86
+ r2 = _nt_SP
87
+ s0 << r2
88
+ if r2
89
+ r3 = _nt_Hostname
90
+ s0 << r3
91
+ if r3
92
+ r4 = _nt_SP
93
+ s0 << r4
94
+ if r4
95
+ r5 = _nt_IPv4Address
96
+ s0 << r5
97
+ if r5
98
+ r6 = _nt_SP
99
+ s0 << r6
100
+ if r6
101
+ r7 = _nt_DirPort
102
+ s0 << r7
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ if s0.last
110
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
111
+ r0.extend(DirSourceLine0)
112
+ else
113
+ @index = i0
114
+ r0 = nil
115
+ end
116
+
117
+ node_cache[:DirSourceLine][start_index] = r0
118
+
119
+ r0
120
+ end
121
+
122
+ module FingerprintLine0
123
+ def SP
124
+ elements[1]
125
+ end
126
+
127
+ def Fingerprint
128
+ elements[2]
129
+ end
130
+ end
131
+
132
+ def _nt_FingerprintLine
133
+ start_index = index
134
+ if node_cache[:FingerprintLine].has_key?(index)
135
+ cached = node_cache[:FingerprintLine][index]
136
+ if cached
137
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
138
+ @index = cached.interval.end
139
+ end
140
+ return cached
141
+ end
142
+
143
+ i0, s0 = index, []
144
+ if has_terminal?("fingerprint", false, index)
145
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 11))
146
+ @index += 11
147
+ else
148
+ terminal_parse_failure("fingerprint")
149
+ r1 = nil
150
+ end
151
+ s0 << r1
152
+ if r1
153
+ r2 = _nt_SP
154
+ s0 << r2
155
+ if r2
156
+ r3 = _nt_Fingerprint
157
+ s0 << r3
158
+ end
159
+ end
160
+ if s0.last
161
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
162
+ r0.extend(FingerprintLine0)
163
+ else
164
+ @index = i0
165
+ r0 = nil
166
+ end
167
+
168
+ node_cache[:FingerprintLine][start_index] = r0
169
+
170
+ r0
171
+ end
172
+
173
+ module PublishedLine0
174
+ def SP
175
+ elements[1]
176
+ end
177
+
178
+ def DateTime
179
+ elements[2]
180
+ end
181
+ end
182
+
183
+ def _nt_PublishedLine
184
+ start_index = index
185
+ if node_cache[:PublishedLine].has_key?(index)
186
+ cached = node_cache[:PublishedLine][index]
187
+ if cached
188
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
189
+ @index = cached.interval.end
190
+ end
191
+ return cached
192
+ end
193
+
194
+ i0, s0 = index, []
195
+ if has_terminal?("published", false, index)
196
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 9))
197
+ @index += 9
198
+ else
199
+ terminal_parse_failure("published")
200
+ r1 = nil
201
+ end
202
+ s0 << r1
203
+ if r1
204
+ r2 = _nt_SP
205
+ s0 << r2
206
+ if r2
207
+ r3 = _nt_DateTime
208
+ s0 << r3
209
+ end
210
+ end
211
+ if s0.last
212
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
213
+ r0.extend(PublishedLine0)
214
+ else
215
+ @index = i0
216
+ r0 = nil
217
+ end
218
+
219
+ node_cache[:PublishedLine][start_index] = r0
220
+
221
+ r0
222
+ end
223
+
224
+ end
225
+
226
+ class NetworkStatusParser < Treetop::Runtime::CompiledParser
227
+ include NetworkStatus
228
+ end
229
+
230
+ end
231
+ end
@@ -0,0 +1,32 @@
1
+ module RTor
2
+ module DirspecV2
3
+ grammar RouterDescriptor
4
+ include Primitives
5
+
6
+ rule Descriptor
7
+ RouterItem / NL
8
+ end
9
+
10
+ rule RouterItem
11
+ "router" Nickname Address ORPort SocksPort DirPort
12
+ end
13
+
14
+ rule BandwidthItem
15
+ "bandwidth" BandwidthAvg BandwidthBurst BandwidthObserved
16
+ end
17
+
18
+ rule PlatformItem
19
+ "platform" String
20
+ end
21
+
22
+ rule PublishedItem
23
+ "published" DateTime
24
+ end
25
+
26
+ rule HibernatingItem
27
+ "hibernating" Boolean
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,315 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module RTor
5
+ module DirspecV2
6
+ module RouterDescriptor
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :Descriptor
11
+ end
12
+
13
+ include Primitives
14
+
15
+ def _nt_Descriptor
16
+ start_index = index
17
+ if node_cache[:Descriptor].has_key?(index)
18
+ cached = node_cache[:Descriptor][index]
19
+ if cached
20
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
21
+ @index = cached.interval.end
22
+ end
23
+ return cached
24
+ end
25
+
26
+ i0 = index
27
+ r1 = _nt_RouterItem
28
+ if r1
29
+ r0 = r1
30
+ else
31
+ r2 = _nt_NL
32
+ if r2
33
+ r0 = r2
34
+ else
35
+ @index = i0
36
+ r0 = nil
37
+ end
38
+ end
39
+
40
+ node_cache[:Descriptor][start_index] = r0
41
+
42
+ r0
43
+ end
44
+
45
+ module RouterItem0
46
+ def Nickname
47
+ elements[1]
48
+ end
49
+
50
+ def Address
51
+ elements[2]
52
+ end
53
+
54
+ def ORPort
55
+ elements[3]
56
+ end
57
+
58
+ def SocksPort
59
+ elements[4]
60
+ end
61
+
62
+ def DirPort
63
+ elements[5]
64
+ end
65
+ end
66
+
67
+ def _nt_RouterItem
68
+ start_index = index
69
+ if node_cache[:RouterItem].has_key?(index)
70
+ cached = node_cache[:RouterItem][index]
71
+ if cached
72
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
73
+ @index = cached.interval.end
74
+ end
75
+ return cached
76
+ end
77
+
78
+ i0, s0 = index, []
79
+ if has_terminal?("router", false, index)
80
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 6))
81
+ @index += 6
82
+ else
83
+ terminal_parse_failure("router")
84
+ r1 = nil
85
+ end
86
+ s0 << r1
87
+ if r1
88
+ r2 = _nt_Nickname
89
+ s0 << r2
90
+ if r2
91
+ r3 = _nt_Address
92
+ s0 << r3
93
+ if r3
94
+ r4 = _nt_ORPort
95
+ s0 << r4
96
+ if r4
97
+ r5 = _nt_SocksPort
98
+ s0 << r5
99
+ if r5
100
+ r6 = _nt_DirPort
101
+ s0 << r6
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ if s0.last
108
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
109
+ r0.extend(RouterItem0)
110
+ else
111
+ @index = i0
112
+ r0 = nil
113
+ end
114
+
115
+ node_cache[:RouterItem][start_index] = r0
116
+
117
+ r0
118
+ end
119
+
120
+ module BandwidthItem0
121
+ def BandwidthAvg
122
+ elements[1]
123
+ end
124
+
125
+ def BandwidthBurst
126
+ elements[2]
127
+ end
128
+
129
+ def BandwidthObserved
130
+ elements[3]
131
+ end
132
+ end
133
+
134
+ def _nt_BandwidthItem
135
+ start_index = index
136
+ if node_cache[:BandwidthItem].has_key?(index)
137
+ cached = node_cache[:BandwidthItem][index]
138
+ if cached
139
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
140
+ @index = cached.interval.end
141
+ end
142
+ return cached
143
+ end
144
+
145
+ i0, s0 = index, []
146
+ if has_terminal?("bandwidth", false, index)
147
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 9))
148
+ @index += 9
149
+ else
150
+ terminal_parse_failure("bandwidth")
151
+ r1 = nil
152
+ end
153
+ s0 << r1
154
+ if r1
155
+ r2 = _nt_BandwidthAvg
156
+ s0 << r2
157
+ if r2
158
+ r3 = _nt_BandwidthBurst
159
+ s0 << r3
160
+ if r3
161
+ r4 = _nt_BandwidthObserved
162
+ s0 << r4
163
+ end
164
+ end
165
+ end
166
+ if s0.last
167
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
168
+ r0.extend(BandwidthItem0)
169
+ else
170
+ @index = i0
171
+ r0 = nil
172
+ end
173
+
174
+ node_cache[:BandwidthItem][start_index] = r0
175
+
176
+ r0
177
+ end
178
+
179
+ module PlatformItem0
180
+ def String
181
+ elements[1]
182
+ end
183
+ end
184
+
185
+ def _nt_PlatformItem
186
+ start_index = index
187
+ if node_cache[:PlatformItem].has_key?(index)
188
+ cached = node_cache[:PlatformItem][index]
189
+ if cached
190
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
191
+ @index = cached.interval.end
192
+ end
193
+ return cached
194
+ end
195
+
196
+ i0, s0 = index, []
197
+ if has_terminal?("platform", false, index)
198
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 8))
199
+ @index += 8
200
+ else
201
+ terminal_parse_failure("platform")
202
+ r1 = nil
203
+ end
204
+ s0 << r1
205
+ if r1
206
+ r2 = _nt_String
207
+ s0 << r2
208
+ end
209
+ if s0.last
210
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
211
+ r0.extend(PlatformItem0)
212
+ else
213
+ @index = i0
214
+ r0 = nil
215
+ end
216
+
217
+ node_cache[:PlatformItem][start_index] = r0
218
+
219
+ r0
220
+ end
221
+
222
+ module PublishedItem0
223
+ def DateTime
224
+ elements[1]
225
+ end
226
+ end
227
+
228
+ def _nt_PublishedItem
229
+ start_index = index
230
+ if node_cache[:PublishedItem].has_key?(index)
231
+ cached = node_cache[:PublishedItem][index]
232
+ if cached
233
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
234
+ @index = cached.interval.end
235
+ end
236
+ return cached
237
+ end
238
+
239
+ i0, s0 = index, []
240
+ if has_terminal?("published", false, index)
241
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 9))
242
+ @index += 9
243
+ else
244
+ terminal_parse_failure("published")
245
+ r1 = nil
246
+ end
247
+ s0 << r1
248
+ if r1
249
+ r2 = _nt_DateTime
250
+ s0 << r2
251
+ end
252
+ if s0.last
253
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
254
+ r0.extend(PublishedItem0)
255
+ else
256
+ @index = i0
257
+ r0 = nil
258
+ end
259
+
260
+ node_cache[:PublishedItem][start_index] = r0
261
+
262
+ r0
263
+ end
264
+
265
+ module HibernatingItem0
266
+ def Boolean
267
+ elements[1]
268
+ end
269
+ end
270
+
271
+ def _nt_HibernatingItem
272
+ start_index = index
273
+ if node_cache[:HibernatingItem].has_key?(index)
274
+ cached = node_cache[:HibernatingItem][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
+ if has_terminal?("hibernating", false, index)
284
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 11))
285
+ @index += 11
286
+ else
287
+ terminal_parse_failure("hibernating")
288
+ r1 = nil
289
+ end
290
+ s0 << r1
291
+ if r1
292
+ r2 = _nt_Boolean
293
+ s0 << r2
294
+ end
295
+ if s0.last
296
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
297
+ r0.extend(HibernatingItem0)
298
+ else
299
+ @index = i0
300
+ r0 = nil
301
+ end
302
+
303
+ node_cache[:HibernatingItem][start_index] = r0
304
+
305
+ r0
306
+ end
307
+
308
+ end
309
+
310
+ class RouterDescriptorParser < Treetop::Runtime::CompiledParser
311
+ include RouterDescriptor
312
+ end
313
+
314
+ end
315
+ end