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,32 @@
|
|
1
|
+
module Onion
|
2
|
+
grammar StreamLists
|
3
|
+
include Common
|
4
|
+
|
5
|
+
rule stream_list
|
6
|
+
stream_list_entry+ {
|
7
|
+
def streams
|
8
|
+
streams = []
|
9
|
+
self.elements.each do |stream|
|
10
|
+
streams << Stream.new(stream.s_id.text_value.strip, stream.c_id.text_value.strip)
|
11
|
+
end
|
12
|
+
return streams
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
rule stream_list_entry
|
18
|
+
s_id:StreamID SP s:StreamStatus SP c_id:CircuitID SP t:Target "\r\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
rule StreamStatus
|
22
|
+
"NEW" / "NEWRESOLVE" / "REMAP" / "SENTCONNECT" / "SENTRESOLVE" /
|
23
|
+
"SUCCEEDED" / "FAILED" / "CLOSED" / "DETACHED"
|
24
|
+
end
|
25
|
+
|
26
|
+
rule Target
|
27
|
+
[$0-9a-zA-Z\.\-]+ ":" [0-9]+
|
28
|
+
#Address ":" Port
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/tasks/treetop.rake
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
namespace :tt do
|
2
2
|
desc "Generate Ruby parsers from Treetop grammars."
|
3
3
|
task :gen do
|
4
|
-
task_path = File.expand_path('../../
|
4
|
+
task_path = File.expand_path('../../onion/parsers/*.treetop', __FILE__)
|
5
5
|
Dir.glob(task_path) do |filename|
|
6
6
|
# `tt #{filename}`
|
7
7
|
`bundle exec tt #{filename}`
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Poet (Tim Sally)
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-18 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,12 +41,25 @@ extensions: []
|
|
41
41
|
extra_rdoc_files: []
|
42
42
|
|
43
43
|
files:
|
44
|
-
- README.
|
44
|
+
- README.txt
|
45
|
+
- License.txt
|
45
46
|
- Rakefile
|
47
|
+
- lib/onion/control_client.rb
|
48
|
+
- lib/onion/elements/circuit.rb
|
49
|
+
- lib/onion/elements/circuit_list.rb
|
46
50
|
- lib/onion/elements/router.rb
|
47
51
|
- lib/onion/elements/router_list.rb
|
52
|
+
- lib/onion/elements/stream.rb
|
53
|
+
- lib/onion/elements/stream_list.rb
|
48
54
|
- lib/onion/elements.rb
|
49
|
-
- lib/onion/parsers/
|
55
|
+
- lib/onion/parsers/circuit_lists.rb
|
56
|
+
- lib/onion/parsers/circuit_lists.treetop
|
57
|
+
- lib/onion/parsers/common.rb
|
58
|
+
- lib/onion/parsers/common.treetop
|
59
|
+
- lib/onion/parsers/router_statuses.rb
|
60
|
+
- lib/onion/parsers/router_statuses.treetop
|
61
|
+
- lib/onion/parsers/stream_lists.rb
|
62
|
+
- lib/onion/parsers/stream_lists.treetop
|
50
63
|
- lib/onion.rb
|
51
64
|
- lib/tasks/treetop.rake
|
52
65
|
has_rdoc: true
|
@@ -1,133 +0,0 @@
|
|
1
|
-
module Onion
|
2
|
-
grammar RouterLists
|
3
|
-
|
4
|
-
# --- Rule to start matching against. ----------------------------------- #
|
5
|
-
|
6
|
-
rule router_list
|
7
|
-
router_list_entry+ {
|
8
|
-
def routers
|
9
|
-
routers = []
|
10
|
-
self.elements.each do |e|
|
11
|
-
if e.respond_to? :s # Optional status flags are in the entry.
|
12
|
-
routers << Onion::Router.new(e.r.nick, e.r.id_hash, e.s.flags)
|
13
|
-
else
|
14
|
-
routers << Onion::Router.new(e.r_nos.nick, e.r_nos.id_hash, nil)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
return routers
|
18
|
-
end
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
rule router_list_entry
|
23
|
-
r:router "\n" s:status "\n" / r_nos:router "\n"
|
24
|
-
end
|
25
|
-
|
26
|
-
# --- General use rules. ------------------------------------------------ #
|
27
|
-
|
28
|
-
rule base64_char
|
29
|
-
[A-Za-z0-9+/]
|
30
|
-
end
|
31
|
-
|
32
|
-
rule year
|
33
|
-
[0-9] [0-9] [0-9] [0-9]
|
34
|
-
end
|
35
|
-
|
36
|
-
rule month
|
37
|
-
[0] [1-9] / [1] [0-2]
|
38
|
-
end
|
39
|
-
|
40
|
-
rule day
|
41
|
-
[0-2] [0-9] / [3] [0-1]
|
42
|
-
end
|
43
|
-
|
44
|
-
rule hour
|
45
|
-
[0] [1-9] / [1] [0-9] / [2] [0-4]
|
46
|
-
end
|
47
|
-
|
48
|
-
rule minute
|
49
|
-
[0] [0-9] / [1-5] [0-9]
|
50
|
-
end
|
51
|
-
|
52
|
-
rule second
|
53
|
-
[0] [0-9] / [1-5] [0-9]
|
54
|
-
end
|
55
|
-
|
56
|
-
rule ip_addr_byte
|
57
|
-
[2] [5] [0-5] / [2] [0-4] [0-9] / [1] [0-9] [0-9] / [1-9] [0-9] / [0-9]
|
58
|
-
end
|
59
|
-
|
60
|
-
rule sp
|
61
|
-
" "+
|
62
|
-
end
|
63
|
-
|
64
|
-
# --- Rules needed to parse the router lines. --------------------------- #
|
65
|
-
|
66
|
-
rule router
|
67
|
-
"r " n:nick id:id_hash desc_hash desc_time ip_addr or_port dir_port {
|
68
|
-
def nick
|
69
|
-
n.text_value.strip
|
70
|
-
end
|
71
|
-
|
72
|
-
def id_hash
|
73
|
-
id.text_value.strip
|
74
|
-
end
|
75
|
-
}
|
76
|
-
end
|
77
|
-
|
78
|
-
rule nick
|
79
|
-
# TODO: This should be 1-19 alphanumeric chars, but this isn't easy
|
80
|
-
# to do in Treetop.
|
81
|
-
[a-zA-Z0-9]+ sp
|
82
|
-
end
|
83
|
-
|
84
|
-
rule id_hash
|
85
|
-
base64_char+ sp
|
86
|
-
end
|
87
|
-
|
88
|
-
rule desc_hash
|
89
|
-
base64_char+ sp
|
90
|
-
end
|
91
|
-
|
92
|
-
rule desc_time
|
93
|
-
year "-" month "-" day " " hour ":" minute ":" second sp
|
94
|
-
end
|
95
|
-
|
96
|
-
rule ip_addr
|
97
|
-
ip_addr_byte "." ip_addr_byte "." ip_addr_byte "." ip_addr_byte sp
|
98
|
-
end
|
99
|
-
|
100
|
-
rule or_port
|
101
|
-
[0-9]+ sp
|
102
|
-
end
|
103
|
-
|
104
|
-
rule dir_port
|
105
|
-
[0-9]+ sp?
|
106
|
-
end
|
107
|
-
|
108
|
-
# --- Rules needed to parse the status lines. --------------------------- #
|
109
|
-
|
110
|
-
rule status
|
111
|
-
"s " (valid:status_flag sp? / invalid_status_flag sp?)+ {
|
112
|
-
def flags
|
113
|
-
results = []
|
114
|
-
self.elements[1].elements.each do |e|
|
115
|
-
if e.respond_to? :valid
|
116
|
-
results << e.valid.text_value
|
117
|
-
end
|
118
|
-
end
|
119
|
-
return results
|
120
|
-
end
|
121
|
-
}
|
122
|
-
end
|
123
|
-
|
124
|
-
rule status_flag
|
125
|
-
"Authority" / "BadExit" / "BadDirectory" / "Exit" / "Fast"
|
126
|
-
/ "Guard" / "Named" / "Stable" / "Running" / "Valid" / "V2Dir"
|
127
|
-
end
|
128
|
-
|
129
|
-
rule invalid_status_flag
|
130
|
-
[a-zA-Z]+
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|