tor_extend 1.0.2

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.
Files changed (56) hide show
  1. data/Change.log +12 -0
  2. data/ReadME.txt +190 -0
  3. data/doc/ReadME_txt.html +301 -0
  4. data/doc/Tor.html +140 -0
  5. data/doc/Tor/Bridge.html +145 -0
  6. data/doc/Tor/CachedDesc.html +472 -0
  7. data/doc/Tor/Constants.html +185 -0
  8. data/doc/Tor/Router.html +146 -0
  9. data/doc/Tor/StatsObj.html +1209 -0
  10. data/doc/Tor/TController.html +1111 -0
  11. data/doc/created.rid +7 -0
  12. data/doc/images/add.png +0 -0
  13. data/doc/images/brick.png +0 -0
  14. data/doc/images/brick_link.png +0 -0
  15. data/doc/images/bug.png +0 -0
  16. data/doc/images/bullet_black.png +0 -0
  17. data/doc/images/bullet_toggle_minus.png +0 -0
  18. data/doc/images/bullet_toggle_plus.png +0 -0
  19. data/doc/images/date.png +0 -0
  20. data/doc/images/delete.png +0 -0
  21. data/doc/images/find.png +0 -0
  22. data/doc/images/loadingAnimation.gif +0 -0
  23. data/doc/images/macFFBgHack.png +0 -0
  24. data/doc/images/package.png +0 -0
  25. data/doc/images/page_green.png +0 -0
  26. data/doc/images/page_white_text.png +0 -0
  27. data/doc/images/page_white_width.png +0 -0
  28. data/doc/images/plugin.png +0 -0
  29. data/doc/images/ruby.png +0 -0
  30. data/doc/images/tag_blue.png +0 -0
  31. data/doc/images/tag_green.png +0 -0
  32. data/doc/images/transparent.png +0 -0
  33. data/doc/images/wrench.png +0 -0
  34. data/doc/images/wrench_orange.png +0 -0
  35. data/doc/images/zoom.png +0 -0
  36. data/doc/index.html +90 -0
  37. data/doc/js/darkfish.js +153 -0
  38. data/doc/js/jquery.js +18 -0
  39. data/doc/js/navigation.js +142 -0
  40. data/doc/js/search.js +94 -0
  41. data/doc/js/search_index.js +1 -0
  42. data/doc/js/searcher.js +228 -0
  43. data/doc/lib/constants_rb.html +96 -0
  44. data/doc/lib/httpmod_rb.html +95 -0
  45. data/doc/lib/tcontroller_rb.html +93 -0
  46. data/doc/lib/tor_extend_rb.html +97 -0
  47. data/doc/lib/tstats_rb.html +93 -0
  48. data/doc/rdoc.css +543 -0
  49. data/doc/table_of_contents.html +159 -0
  50. data/lib/constants.rb +106 -0
  51. data/lib/httpmod.rb +89 -0
  52. data/lib/tcontroller.rb +475 -0
  53. data/lib/tor_extend.rb +189 -0
  54. data/lib/tstats.rb +514 -0
  55. data/tor_extend.gemspec +26 -0
  56. metadata +138 -0
@@ -0,0 +1,12 @@
1
+ Changes since version 1.0.1 -> 1.0.2
2
+ ~~~~~~~~~~~~~~~~~~~~~~~
3
+
4
+ 1. Added Tor::TController.ds : returns ["w.x.y.z:port", ...]
5
+ 2. Removed the Tor::Cacheddesc.ds
6
+ 3. Removed the database column for dssource
7
+ 4. Added a few more documentation to the source
8
+
9
+ # version 1.0.3
10
+ Added circuit.rb
11
+ added class Circuit, and methods including Circuit.built?
12
+ -extending.... almost done
@@ -0,0 +1,190 @@
1
+ Please see the Unlicence disclaimer in Bendiken's tor-ruby gem.
2
+
3
+ <b>Installation instruction </b>
4
+
5
+ Run "gem install tor_extend"
6
+
7
+ If internet connection is available, it will install the Bendiken's Tor gem as well if it is not already installed. As well as socksify
8
+ For offline users, obtain a local copy of the Tor gem and install before proceeding.
9
+ Visit Bendiken's page[http://cypherpunk.rubyforge.org/tor/] for details on .
10
+
11
+ ri documentation included with examples.
12
+ Run "ri Tor::TController" after install to see examples.
13
+
14
+ <b>Examples</b>.
15
+
16
+ - How to use Tor control
17
+
18
+ require 'tor_extend'
19
+ proxy_config={:type=>'tor' ,:port=>9050,:addr=>'127.0.0.1'},
20
+ tor_config={:host=>'127.0.0.1',:port => 9051}
21
+ x=Tor::TController.new(tor_config)
22
+ x.connect
23
+ x.authenticate("\"test1234\"")
24
+ x.authenticate("\"TorCtrlPasswd\"")
25
+ x.setconf("__DisablePredictedCircuits",1)
26
+ x.setconf('orport',9001)
27
+ x.signal("HUP")
28
+ x.cir_status
29
+ x.net_status
30
+ x.getinfo("stream-status")
31
+ x.getconf('orport')
32
+ x.sr(:resetconf,'orport')
33
+ x.extendcir(0, [A,B,C,D,E,F,G] )
34
+ x.extendcir_slowly([A,B,C,D,E,F,G] )
35
+ x.ds => ["a.b.c.d:z", "e.f.g.h:y",...]
36
+
37
+ *Note*: The sr() function sends protocol messages and retrieves the response up to the next "250 OK" or error "5YZ".
38
+ It can send the setevents protocol command, but more work has to be done to receive and filter the events.
39
+ The delay used by between extendcir_slowly() can be altered by setting Tor::EXTEND_DELAY. The default is 2 seconds.
40
+
41
+
42
+ - Reading cached descriptor.
43
+
44
+ require "tor_extend"
45
+ geoipdb=["/home/seun/dat/GeoLiteCityAug.dat","/home/seun/dat/GeoLiteCityJuly.dat"]
46
+ cacheddf = Tor::CachedDesc.new geoipdb
47
+ Tor::CachedDesc.dbconnect
48
+ dbconfig={:adapter => "sqlite3",:database => "db.sqlite3"}
49
+ Tor::CachedDesc.dbconnect(dbconfig)
50
+ Tor::CachedDesc.readall("cached_descriptor_filename")
51
+ Tor::CachedDesc.stat.get_latlng "countrycode" = [latitude, longitude]
52
+ Tor::CachedDesc.stat.continent_list
53
+ Tor::CachedDesc.stat.continent_stat(Tor::CachedDesc.stat.continent_list)
54
+ Tor::CachedDesc.stat.continent_stat(["EU","NA","AS"])
55
+ Tor::CachedDesc.stat.continent_stat_uniq(["EU","NA","AS"])
56
+ Tor::CachedDesc.stat.continent_stat_uniq("EU", "UNIX")
57
+ Tor::CachedDesc.stat.continent_count "EU"
58
+ Tor::CachedDesc.stat.continent_count_uniq "EU"
59
+ Tor::CachedDesc.stat.continent_getfingerprint "EU"
60
+ Tor::CachedDesc.country_count("FR")
61
+ Tor::CachedDesc.country_count("FR","UNIX")
62
+ Tor::CachedDesc.country_count( ["FR","DE"] ,[ "UNIX", "LINUX" ] )
63
+ Tor::CachedDesc.stat.country_stat(Tor::CachedDesc.stat.country_list)
64
+ Tor::CachedDesc.stat.country_stat(Tor::CachedDesc.stat.country_list, "UNIX")
65
+ Tor::CachedDesc.stat.country_stat_uniq(["FR","UK"])
66
+ Tor::CachedDesc.stat.country_stat(["FR","UK"], "WINDOWS")
67
+ Tor::CachedDesc.stat.country_stat_uniq(["FR","UK"], ["WINDOWS","UNIX"])
68
+ Tor::CachedDesc.stat.country_stat(["FR","UK"], "OTHERS")
69
+ Tor::CachedDesc.stat.topcountries(10)
70
+ Tor::CachedDesc.stat.topcountries_uniq(10)
71
+ Tor::CachedDesc.stat.topcountries_uniq(10,"UNIX")
72
+ Tor::CachedDesc.stat.topcountries_uniq(10,["UNIX","LINUX"])
73
+ Tor::CachedDesc.stat.country_getip("FR")
74
+ xml = Tor::CachedDesc.stat.genkml("Onion Routers")
75
+ xml = Tor::CachedDesc.stat.genkml("Windows Onion Routers","WINDOWS")
76
+ Tor::CachedDesc.each{ } => each Router table entry
77
+ Tor::CachedDesc.ors => active record table if you know what you're doing
78
+ Tor::CachedDesc.ors =>
79
+ proxy_config={:type=>'polipo' ,:port=>8118,:addr=>'127.0.0.1'},
80
+ url = URI.parse "https://bridges.torproject.org/
81
+ x.getbridges(url, cachedf, proxy_config)
82
+
83
+ Tor::Router(id: integer, ipaddr: string, platform: text, fingerprint: string, city: string, country: string,
84
+ country_code: string, continent: string, dssource: string, lat: decimal, lng: decimal,
85
+ published_at: datetime, created_at: datetime, updated_at: datetime)
86
+
87
+
88
+ - <b>KML</b>
89
+
90
+ Only uniq ORs are placed in the KML string returned. Two tours are also generated; the first going around the world, using
91
+ different countries as the center, with ballons popping up at some locations if available.
92
+
93
+ The locations in each country are numbered from 1 to country_count_uniq(), which is the order they appear in Google Earth
94
+ under each folder. The keys represent the view centres that are used when opening ballon descriptions of the values.
95
+ The default tour is shown below
96
+
97
+ WORLDTOUR={"ZA" => ["ZA1","NA1","KE1"],
98
+ "BJ" => ["BJ1","A11","NG1","CI1","SN1","DZ1","MA1","EG1","TN1"],
99
+ "CH" => ["FR1","ES1","LU1","GB1","BE1","NL1","DE1","IT1","IE1","AT1","SE1","DK1","UA1"],
100
+ "UA" => ["SA1","TR1","SY1","RU1","IR1"],
101
+ "IN" => ["IN1","KZ1","CN1","TH1","PK1"],
102
+ "AU" => ["AU1","NC1"],
103
+ "PY" => ["PY1","BR1","AR1","CL1"],
104
+ "US" => ["US1","US2","US3","US4","CA1","MX1"],
105
+ "FR" => ["FR1"] }
106
+
107
+ A different tour can be set by defining WORLDTOUR constant in the Tor moodule
108
+
109
+ Tor::WORLDTOUR = {"AU"=>["GB1","FR1","US1","DE1"]}
110
+
111
+
112
+ The second tour uses a coordinate(:lat,:lng) as centre, and 2 arrays of 'red' ORs and 'black'. All locations remain green, The 'red' points are set black, and all 'black' location goes from green to black one at a time every 2 seconds.
113
+ Tor::Constants::ATTACK_TOUR is used by default. This can also be changed by defining Tor::ATTACK_TOUR constant.
114
+ The default attack tour is shown below
115
+
116
+ ATTACK_TOUR = {:lat => 46.0,
117
+ :lng => 2.0,
118
+ "red" => (1..90).collect{|eachnum| "FR" + eachnum.to_s},
119
+ "black"=> (91..200).collect{|eachnum| "FR" + eachnum.to_s} }
120
+
121
+ - <b>Customizing the Tour</b>.
122
+
123
+ Tor::ATTACK_TOUR = { :lat =>cachedf.stat.get_latlng("US")[0],
124
+ :lng =>cachedf.stat.get_latlng("US")[1],
125
+ 'red' =>['US1','US2','US3','US10'],
126
+ 'black' =>['US4','US5','US6','US12']}
127
+
128
+ *OR*
129
+
130
+ Tor::ATTACK_TOUR = { :lat =>Tor::Constants::COUNLATLNG["US"][:lat],
131
+ :lng =>Tor::Constants::COUNLATLNG["US"][:lng],
132
+ 'red' =>['US1','US2','US3','US10'],
133
+ 'black' =>['US4','US5','US6','US12']}
134
+
135
+ - <b>Reset using this</b>:
136
+ Tor::ATTACK_TOUR=Tor::Constants::ATTACK_TOUR
137
+ if the country is not defined, define a constant Tor::COUNLATLNG, get_latlng() will check it automatically.
138
+
139
+ cachedf.stat.get_latlng("AV")
140
+ AV, - not in the country-latitude file, using cordinates(0,0)
141
+ => [0.0, 0.0]
142
+
143
+ Tor::COUNLATLNG = {"AV"=>{:lat=>1, :lng=>1}}
144
+ cachedf.stat.get_latlng("AV")
145
+ => [1, 1]
146
+
147
+
148
+
149
+ <b> Obtain bridges</b>.
150
+
151
+ Some of these fingerprints might have changed, but you can obtain fast relays for the test below
152
+
153
+ require 'tor_extend'
154
+ geoipdb=["/home/seun/dat/GeoLiteCityOct.dat","/home/seun/dat/GeoLiteCityJuly.dat"]
155
+ cachedf = Tor::CachedDesc.new geoipdb
156
+ cachedf.dbconnect
157
+ cachedf.readall("/home/seun/.tor/cached-descriptors")
158
+ cachedf.readall("/home/seun/.tor/cached-descriptors.new")
159
+ tctrl={:host=>'127.0.0.1',:port => 9051}
160
+ ctrlpasswd="mycontrolpassword"
161
+ proxyconfig={:type=>'polipo' ,:port=>8118, :addr=>'127.0.0.1'}
162
+ mytor=Tor::TController.new(tctrl)
163
+ # mytor.connect
164
+ mytor.authenticate "\"#{ctrlpasswd}\""
165
+ mytor.closeallcircuits
166
+ puts mytor.cir_status
167
+ A= [ "FateTestarrosa", "mindfields", "BeMyGuest" , "$AE55AECC4C68573F32F0ECFF6303A3FAEFFCD70E" ] + mytor.get_entryguards
168
+ # A can be mytor.get_purposeip("fast guard")
169
+ B= ["GreenLantern", "atlgonyovLi", "bauruine1" ]
170
+ # or use B = mytor.get_purposeip("fast !exit !guard")
171
+ # But B can also be an guard or exit relay, no restrictions
172
+ C = mytor.get_purposeip("exit fast")
173
+ url = URI.parse "https://bridges.torproject.org/"
174
+ C.count.times{|z|
175
+ entryg = A[rand(A.count)]
176
+ relayg = B[rand(B.count)]
177
+ exitn = C[z]
178
+ circuit1 = [entryg,relayg, exitn]
179
+ cir_num = mytor.extendcir(0, circuit1)
180
+ if mytor.cir_status.detect{|p| p =~ /#{cir_num} BUILT/}
181
+ mytor.get_bridges(url,cachedf)
182
+ else
183
+ sleep(2)
184
+ puts mytor.get_bridges( url, cachedf ) #bridges are added to the database automatically
185
+ end
186
+ }
187
+
188
+
189
+ more results can be obtained using all exits, instead of just fast exits.
190
+ Or other distributed networks.
@@ -0,0 +1,301 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>ReadME</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body class="file">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="./index.html">Home</a>
28
+ <a href="./table_of_contents.html#classes">Classes</a>
29
+ <a href="./table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="project-metadata">
47
+ <nav id="fileindex-section" class="section project-section">
48
+ <h3 class="section-header">Pages</h3>
49
+
50
+ <ul>
51
+
52
+ <li class="file"><a href="./ReadME_txt.html">ReadME</a>
53
+
54
+ </ul>
55
+ </nav>
56
+
57
+ <nav id="classindex-section" class="section project-section">
58
+ <h3 class="section-header">Class and Module Index</h3>
59
+
60
+ <ul class="link-list">
61
+
62
+ <li><a href="./Tor.html">Tor</a>
63
+
64
+ <li><a href="./Tor/Bridge.html">Tor::Bridge</a>
65
+
66
+ <li><a href="./Tor/CachedDesc.html">Tor::CachedDesc</a>
67
+
68
+ <li><a href="./Tor/Constants.html">Tor::Constants</a>
69
+
70
+ <li><a href="./Tor/Router.html">Tor::Router</a>
71
+
72
+ <li><a href="./Tor/StatsObj.html">Tor::StatsObj</a>
73
+
74
+ <li><a href="./Tor/TController.html">Tor::TController</a>
75
+
76
+ </ul>
77
+ </nav>
78
+
79
+ </div>
80
+ </nav>
81
+
82
+ <div id="documentation" class="description">
83
+
84
+ <p>Please see the Unlicence disclaimer in Bendiken’s tor-ruby gem.</p>
85
+
86
+ <p><strong>Installation instruction </strong></p>
87
+
88
+ <p>Run “gem install tor_extend”</p>
89
+
90
+ <p>If internet connection is available, it will install the Bendiken’s <a
91
+ href="Tor.html">Tor</a> gem as well if it is not already installed. As well
92
+ as socksify For offline users, obtain a local copy of the <a
93
+ href="Tor.html">Tor</a> gem and install before proceeding. Visit
94
+ Bendiken’s <a href="http://cypherpunk.rubyforge.org/tor/">page</a> for
95
+ details on .</p>
96
+
97
+ <p>ri documentation included with examples. Run “ri Tor::TController” after
98
+ install to see examples.</p>
99
+
100
+ <p><strong>Examples</strong>.</p>
101
+ <ul><li>
102
+ <p>How to use <a href="Tor.html">Tor</a> control</p>
103
+
104
+ <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'tor_extend'</span>
105
+ <span class="ruby-identifier">proxy_config</span>={:<span class="ruby-identifier">type=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">'tor'</span> ,:<span class="ruby-identifier">port=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">9050</span>,:<span class="ruby-identifier">addr=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">'127.0.0.1'</span>},
106
+ <span class="ruby-identifier">tor_config</span>={:<span class="ruby-identifier">host=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">'127.0.0.1'</span>,:<span class="ruby-identifier">port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">9051</span>}
107
+ <span class="ruby-identifier">x</span>=<span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">TController</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">tor_config</span>)
108
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">connect</span>
109
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">authenticate</span>(<span class="ruby-string">&quot;\&quot;test1234\&quot;&quot;</span>)
110
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">authenticate</span>(<span class="ruby-string">&quot;\&quot;TorCtrlPasswd\&quot;&quot;</span>)
111
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">setconf</span>(<span class="ruby-string">&quot;__DisablePredictedCircuits&quot;</span>,<span class="ruby-value">1</span>)
112
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">setconf</span>(<span class="ruby-string">'orport'</span>,<span class="ruby-value">9001</span>)
113
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">signal</span>(<span class="ruby-string">&quot;HUP&quot;</span>)
114
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">cir_status</span>
115
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">net_status</span>
116
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">getinfo</span>(<span class="ruby-string">&quot;stream-status&quot;</span>)
117
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">getconf</span>(<span class="ruby-string">'orport'</span>)
118
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">sr</span>(:<span class="ruby-identifier">resetconf</span>,<span class="ruby-string">'orport'</span>)
119
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">extendcir</span>(<span class="ruby-value">0</span>, [<span class="ruby-constant">A</span>,<span class="ruby-constant">B</span>,<span class="ruby-constant">C</span>,<span class="ruby-constant">D</span>,<span class="ruby-constant">E</span>,<span class="ruby-constant">F</span>,<span class="ruby-constant">G</span>] )
120
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">extendcir_slowly</span>([<span class="ruby-constant">A</span>,<span class="ruby-constant">B</span>,<span class="ruby-constant">C</span>,<span class="ruby-constant">D</span>,<span class="ruby-constant">E</span>,<span class="ruby-constant">F</span>,<span class="ruby-constant">G</span>] )
121
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">ds</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-string">&quot;a.b.c.d:z&quot;</span>, <span class="ruby-string">&quot;e.f.g.h:y&quot;</span>,<span class="ruby-operator">...</span>]
122
+ </pre>
123
+ </li></ul>
124
+
125
+ <p><strong>Note</strong>: The sr() function sends protocol messages and
126
+ retrieves the response up to the next "250 OK" or error "5YZ". It can send
127
+ the setevents protocol command, but more work has to be done to receive and
128
+ filter the events. The delay used by between extendcir_slowly() can be
129
+ altered by setting Tor::EXTEND_DELAY. The default is 2 seconds.</p>
130
+ <ul><li>
131
+ <p>Reading cached descriptor.</p>
132
+
133
+ <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;tor_extend&quot;</span>
134
+ <span class="ruby-identifier">geoipdb</span>=[<span class="ruby-string">&quot;/home/seun/dat/GeoLiteCityAug.dat&quot;</span>,<span class="ruby-string">&quot;/home/seun/dat/GeoLiteCityJuly.dat&quot;</span>]
135
+ <span class="ruby-identifier">cacheddf</span> = <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">geoipdb</span>
136
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">dbconnect</span>
137
+ <span class="ruby-identifier">dbconfig</span>={:<span class="ruby-identifier">adapter</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&quot;sqlite3&quot;</span>,:<span class="ruby-identifier">database</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&quot;db.sqlite3&quot;</span>}
138
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">dbconnect</span>(<span class="ruby-identifier">dbconfig</span>)
139
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">readall</span>(<span class="ruby-string">&quot;cached_descriptor_filename&quot;</span>)
140
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">get_latlng</span> <span class="ruby-string">&quot;countrycode&quot;</span> = [<span class="ruby-identifier">latitude</span>, <span class="ruby-identifier">longitude</span>]
141
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">continent_list</span>
142
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">continent_stat</span>(<span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">continent_list</span>)
143
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">continent_stat</span>([<span class="ruby-string">&quot;EU&quot;</span>,<span class="ruby-string">&quot;NA&quot;</span>,<span class="ruby-string">&quot;AS&quot;</span>])
144
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">continent_stat_uniq</span>([<span class="ruby-string">&quot;EU&quot;</span>,<span class="ruby-string">&quot;NA&quot;</span>,<span class="ruby-string">&quot;AS&quot;</span>])
145
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">continent_stat_uniq</span>(<span class="ruby-string">&quot;EU&quot;</span>, <span class="ruby-string">&quot;UNIX&quot;</span>)
146
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">continent_count</span> <span class="ruby-string">&quot;EU&quot;</span>
147
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">continent_count_uniq</span> <span class="ruby-string">&quot;EU&quot;</span>
148
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">continent_getfingerprint</span> <span class="ruby-string">&quot;EU&quot;</span>
149
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">country_count</span>(<span class="ruby-string">&quot;FR&quot;</span>)
150
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">country_count</span>(<span class="ruby-string">&quot;FR&quot;</span>,<span class="ruby-string">&quot;UNIX&quot;</span>)
151
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">country_count</span>( [<span class="ruby-string">&quot;FR&quot;</span>,<span class="ruby-string">&quot;DE&quot;</span>] ,[ <span class="ruby-string">&quot;UNIX&quot;</span>, <span class="ruby-string">&quot;LINUX&quot;</span> ] )
152
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">country_stat</span>(<span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">country_list</span>)
153
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">country_stat</span>(<span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">country_list</span>, <span class="ruby-string">&quot;UNIX&quot;</span>)
154
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">country_stat_uniq</span>([<span class="ruby-string">&quot;FR&quot;</span>,<span class="ruby-string">&quot;UK&quot;</span>])
155
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">country_stat</span>([<span class="ruby-string">&quot;FR&quot;</span>,<span class="ruby-string">&quot;UK&quot;</span>], <span class="ruby-string">&quot;WINDOWS&quot;</span>)
156
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">country_stat_uniq</span>([<span class="ruby-string">&quot;FR&quot;</span>,<span class="ruby-string">&quot;UK&quot;</span>], [<span class="ruby-string">&quot;WINDOWS&quot;</span>,<span class="ruby-string">&quot;UNIX&quot;</span>])
157
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">country_stat</span>([<span class="ruby-string">&quot;FR&quot;</span>,<span class="ruby-string">&quot;UK&quot;</span>], <span class="ruby-string">&quot;OTHERS&quot;</span>)
158
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">topcountries</span>(<span class="ruby-value">10</span>)
159
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">topcountries_uniq</span>(<span class="ruby-value">10</span>)
160
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">topcountries_uniq</span>(<span class="ruby-value">10</span>,<span class="ruby-string">&quot;UNIX&quot;</span>)
161
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">topcountries_uniq</span>(<span class="ruby-value">10</span>,[<span class="ruby-string">&quot;UNIX&quot;</span>,<span class="ruby-string">&quot;LINUX&quot;</span>])
162
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">country_getip</span>(<span class="ruby-string">&quot;FR&quot;</span>)
163
+ <span class="ruby-identifier">xml</span> = <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">genkml</span>(<span class="ruby-string">&quot;Onion Routers&quot;</span>)
164
+ <span class="ruby-identifier">xml</span> = <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">genkml</span>(<span class="ruby-string">&quot;Windows Onion Routers&quot;</span>,<span class="ruby-string">&quot;WINDOWS&quot;</span>)
165
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">each</span>{ } =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">each</span> <span class="ruby-constant">Router</span> <span class="ruby-identifier">table</span> <span class="ruby-identifier">entry</span>
166
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">ors</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">active</span> <span class="ruby-identifier">record</span> <span class="ruby-identifier">table</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">you</span> <span class="ruby-identifier">know</span> <span class="ruby-identifier">what</span> <span class="ruby-identifier">you</span><span class="ruby-string">'re doing
167
+ Tor::CachedDesc.ors =&gt;
168
+ proxy_config={:type=&gt;'</span><span class="ruby-identifier">polipo</span><span class="ruby-string">' ,:port=&gt;8118,:addr=&gt;'</span><span class="ruby-value">127.0</span><span class="ruby-value">.0</span><span class="ruby-value">.1</span><span class="ruby-string">'},
169
+ url = URI.parse &quot;https://bridges.torproject.org/
170
+ x.getbridges(url, cachedf, proxy_config)
171
+ Tor::Router(id: integer, ipaddr: string, platform: text, fingerprint: string, city: string, country: string,
172
+ country_code: string, continent: string, dssource: string, lat: decimal, lng: decimal,
173
+ published_at: datetime, created_at: datetime, updated_at: datetime)
174
+ </span></pre>
175
+ </li><li>
176
+ <p><strong>KML</strong></p>
177
+ </li></ul>
178
+
179
+ <p>Only uniq ORs are placed in the KML string returned. Two tours are also
180
+ generated; the first going around the world, using different countries as
181
+ the center, with ballons popping up at some locations if available.</p>
182
+
183
+ <p>The locations in each country are numbered from 1 to country_count_uniq(),
184
+ which is the order they appear in Google Earth under each folder. The keys
185
+ represent the view centres that are used when opening ballon descriptions
186
+ of the values. The default tour is shown below</p>
187
+
188
+ <pre class="ruby"><span class="ruby-constant">WORLDTOUR</span>={<span class="ruby-string">&quot;ZA&quot;</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-string">&quot;ZA1&quot;</span>,<span class="ruby-string">&quot;NA1&quot;</span>,<span class="ruby-string">&quot;KE1&quot;</span>],
189
+ <span class="ruby-string">&quot;BJ&quot;</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-string">&quot;BJ1&quot;</span>,<span class="ruby-string">&quot;A11&quot;</span>,<span class="ruby-string">&quot;NG1&quot;</span>,<span class="ruby-string">&quot;CI1&quot;</span>,<span class="ruby-string">&quot;SN1&quot;</span>,<span class="ruby-string">&quot;DZ1&quot;</span>,<span class="ruby-string">&quot;MA1&quot;</span>,<span class="ruby-string">&quot;EG1&quot;</span>,<span class="ruby-string">&quot;TN1&quot;</span>],
190
+ <span class="ruby-string">&quot;CH&quot;</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-string">&quot;FR1&quot;</span>,<span class="ruby-string">&quot;ES1&quot;</span>,<span class="ruby-string">&quot;LU1&quot;</span>,<span class="ruby-string">&quot;GB1&quot;</span>,<span class="ruby-string">&quot;BE1&quot;</span>,<span class="ruby-string">&quot;NL1&quot;</span>,<span class="ruby-string">&quot;DE1&quot;</span>,<span class="ruby-string">&quot;IT1&quot;</span>,<span class="ruby-string">&quot;IE1&quot;</span>,<span class="ruby-string">&quot;AT1&quot;</span>,<span class="ruby-string">&quot;SE1&quot;</span>,<span class="ruby-string">&quot;DK1&quot;</span>,<span class="ruby-string">&quot;UA1&quot;</span>],
191
+ <span class="ruby-string">&quot;UA&quot;</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-string">&quot;SA1&quot;</span>,<span class="ruby-string">&quot;TR1&quot;</span>,<span class="ruby-string">&quot;SY1&quot;</span>,<span class="ruby-string">&quot;RU1&quot;</span>,<span class="ruby-string">&quot;IR1&quot;</span>],
192
+ <span class="ruby-string">&quot;IN&quot;</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-string">&quot;IN1&quot;</span>,<span class="ruby-string">&quot;KZ1&quot;</span>,<span class="ruby-string">&quot;CN1&quot;</span>,<span class="ruby-string">&quot;TH1&quot;</span>,<span class="ruby-string">&quot;PK1&quot;</span>],
193
+ <span class="ruby-string">&quot;AU&quot;</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-string">&quot;AU1&quot;</span>,<span class="ruby-string">&quot;NC1&quot;</span>],
194
+ <span class="ruby-string">&quot;PY&quot;</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-string">&quot;PY1&quot;</span>,<span class="ruby-string">&quot;BR1&quot;</span>,<span class="ruby-string">&quot;AR1&quot;</span>,<span class="ruby-string">&quot;CL1&quot;</span>],
195
+ <span class="ruby-string">&quot;US&quot;</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-string">&quot;US1&quot;</span>,<span class="ruby-string">&quot;US2&quot;</span>,<span class="ruby-string">&quot;US3&quot;</span>,<span class="ruby-string">&quot;US4&quot;</span>,<span class="ruby-string">&quot;CA1&quot;</span>,<span class="ruby-string">&quot;MX1&quot;</span>],
196
+ <span class="ruby-string">&quot;FR&quot;</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-string">&quot;FR1&quot;</span>] }
197
+ </pre>
198
+
199
+ <p>A different tour can be set by defining WORLDTOUR constant in the <a
200
+ href="Tor.html">Tor</a> moodule</p>
201
+
202
+ <pre class="ruby"><span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">WORLDTOUR</span> = {<span class="ruby-string">&quot;AU&quot;</span>=<span class="ruby-operator">&gt;</span>[<span class="ruby-string">&quot;GB1&quot;</span>,<span class="ruby-string">&quot;FR1&quot;</span>,<span class="ruby-string">&quot;US1&quot;</span>,<span class="ruby-string">&quot;DE1&quot;</span>]}
203
+ </pre>
204
+
205
+ <p>The second tour uses a coordinate(:lat,:lng) as centre, and 2 arrays of
206
+ ‘red’ ORs and ‘black’. All locations remain green, The ‘red’ points are set
207
+ black, and all ‘black’ location goes from green to black one at a time
208
+ every 2 seconds. Tor::Constants::ATTACK_TOUR is used by default. This can
209
+ also be changed by defining Tor::ATTACK_TOUR constant. The default attack
210
+ tour is shown below</p>
211
+
212
+ <pre class="ruby"><span class="ruby-constant">ATTACK_TOUR</span> = {:<span class="ruby-identifier">lat</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">46.0</span>,
213
+ :<span class="ruby-identifier">lng</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">2.0</span>,
214
+ <span class="ruby-string">&quot;red&quot;</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">90</span>).<span class="ruby-identifier">collect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">eachnum</span><span class="ruby-operator">|</span> <span class="ruby-string">&quot;FR&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">eachnum</span>.<span class="ruby-identifier">to_s</span>},
215
+ <span class="ruby-string">&quot;black&quot;</span>=<span class="ruby-operator">&gt;</span> (<span class="ruby-value">91</span><span class="ruby-operator">..</span><span class="ruby-value">200</span>).<span class="ruby-identifier">collect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">eachnum</span><span class="ruby-operator">|</span> <span class="ruby-string">&quot;FR&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">eachnum</span>.<span class="ruby-identifier">to_s</span>} }
216
+ </pre>
217
+ <ul><li>
218
+ <p><strong>Customizing the Tour</strong>.</p>
219
+ </li></ul>
220
+
221
+ <pre class="ruby"><span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">ATTACK_TOUR</span> = { :<span class="ruby-identifier">lat</span> =<span class="ruby-operator">&gt;</span><span class="ruby-identifier">cachedf</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">get_latlng</span>(<span class="ruby-string">&quot;US&quot;</span>)[<span class="ruby-value">0</span>],
222
+ :<span class="ruby-identifier">lng</span> =<span class="ruby-operator">&gt;</span><span class="ruby-identifier">cachedf</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">get_latlng</span>(<span class="ruby-string">&quot;US&quot;</span>)[<span class="ruby-value">1</span>],
223
+ <span class="ruby-string">'red'</span> =<span class="ruby-operator">&gt;</span>[<span class="ruby-string">'US1'</span>,<span class="ruby-string">'US2'</span>,<span class="ruby-string">'US3'</span>,<span class="ruby-string">'US10'</span>],
224
+ <span class="ruby-string">'black'</span> =<span class="ruby-operator">&gt;</span>[<span class="ruby-string">'US4'</span>,<span class="ruby-string">'US5'</span>,<span class="ruby-string">'US6'</span>,<span class="ruby-string">'US12'</span>]}
225
+ </pre>
226
+
227
+ <p><strong>OR</strong></p>
228
+
229
+ <pre class="ruby"><span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">ATTACK_TOUR</span> = { :<span class="ruby-identifier">lat</span> =<span class="ruby-operator">&gt;</span><span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">Constants</span><span class="ruby-operator">::</span><span class="ruby-constant">COUNLATLNG</span>[<span class="ruby-string">&quot;US&quot;</span>][:<span class="ruby-identifier">lat</span>],
230
+ :<span class="ruby-identifier">lng</span> =<span class="ruby-operator">&gt;</span><span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">Constants</span><span class="ruby-operator">::</span><span class="ruby-constant">COUNLATLNG</span>[<span class="ruby-string">&quot;US&quot;</span>][:<span class="ruby-identifier">lng</span>],
231
+ <span class="ruby-string">'red'</span> =<span class="ruby-operator">&gt;</span>[<span class="ruby-string">'US1'</span>,<span class="ruby-string">'US2'</span>,<span class="ruby-string">'US3'</span>,<span class="ruby-string">'US10'</span>],
232
+ <span class="ruby-string">'black'</span> =<span class="ruby-operator">&gt;</span>[<span class="ruby-string">'US4'</span>,<span class="ruby-string">'US5'</span>,<span class="ruby-string">'US6'</span>,<span class="ruby-string">'US12'</span>]}
233
+ </pre>
234
+ <ul><li>
235
+ <p><strong>Reset using this</strong>:</p>
236
+ </li></ul>
237
+
238
+ <pre class="ruby"><span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">ATTACK_TOUR</span>=<span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">Constants</span><span class="ruby-operator">::</span><span class="ruby-constant">ATTACK_TOUR</span>
239
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">the</span> <span class="ruby-identifier">country</span> <span class="ruby-identifier">is</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">defined</span>, <span class="ruby-identifier">define</span> <span class="ruby-identifier">a</span> <span class="ruby-identifier">constant</span> <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">COUNLATLNG</span>, <span class="ruby-identifier">get_latlng</span>() <span class="ruby-identifier">will</span> <span class="ruby-identifier">check</span> <span class="ruby-identifier">it</span> <span class="ruby-identifier">automatically</span>.
240
+ <span class="ruby-identifier">cachedf</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">get_latlng</span>(<span class="ruby-string">&quot;AV&quot;</span>)
241
+ <span class="ruby-constant">AV</span>, <span class="ruby-operator">-</span> <span class="ruby-keyword">not</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">the</span> <span class="ruby-identifier">country</span><span class="ruby-operator">-</span><span class="ruby-identifier">latitude</span> <span class="ruby-identifier">file</span>, <span class="ruby-identifier">using</span> <span class="ruby-identifier">cordinates</span>(<span class="ruby-value">0</span>,<span class="ruby-value">0</span>)
242
+ =<span class="ruby-operator">&gt;</span> [<span class="ruby-value">0.0</span>, <span class="ruby-value">0.0</span>]
243
+ <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">COUNLATLNG</span> = {<span class="ruby-string">&quot;AV&quot;</span>=<span class="ruby-operator">&gt;</span>{:<span class="ruby-identifier">lat=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">1</span>, :<span class="ruby-identifier">lng=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">1</span>}}
244
+ <span class="ruby-identifier">cachedf</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">get_latlng</span>(<span class="ruby-string">&quot;AV&quot;</span>)
245
+ =<span class="ruby-operator">&gt;</span> [<span class="ruby-value">1</span>, <span class="ruby-value">1</span>]
246
+ </pre>
247
+
248
+ <p><strong> Obtain bridges</strong>.</p>
249
+
250
+ <p>Some of these fingerprints might have changed, but you can obtain fast
251
+ relays for the test below</p>
252
+
253
+ <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'tor_extend'</span>
254
+ <span class="ruby-identifier">geoipdb</span>=[<span class="ruby-string">&quot;/home/seun/dat/GeoLiteCityOct.dat&quot;</span>,<span class="ruby-string">&quot;/home/seun/dat/GeoLiteCityJuly.dat&quot;</span>]
255
+ <span class="ruby-identifier">cachedf</span> = <span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">CachedDesc</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">geoipdb</span>
256
+ <span class="ruby-identifier">cachedf</span>.<span class="ruby-identifier">dbconnect</span>
257
+ <span class="ruby-identifier">cachedf</span>.<span class="ruby-identifier">readall</span>(<span class="ruby-string">&quot;/home/seun/.tor/cached-descriptors&quot;</span>)
258
+ <span class="ruby-identifier">cachedf</span>.<span class="ruby-identifier">readall</span>(<span class="ruby-string">&quot;/home/seun/.tor/cached-descriptors.new&quot;</span>)
259
+ <span class="ruby-identifier">tctrl</span>={:<span class="ruby-identifier">host=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">'127.0.0.1'</span>,:<span class="ruby-identifier">port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">9051</span>}
260
+ <span class="ruby-identifier">ctrlpasswd</span>=<span class="ruby-string">&quot;mycontrolpassword&quot;</span>
261
+ <span class="ruby-identifier">proxyconfig</span>={:<span class="ruby-identifier">type=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">'polipo'</span> ,:<span class="ruby-identifier">port=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">8118</span>, :<span class="ruby-identifier">addr=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">'127.0.0.1'</span>}
262
+ <span class="ruby-identifier">mytor</span>=<span class="ruby-constant">Tor</span><span class="ruby-operator">::</span><span class="ruby-constant">TController</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">tctrl</span>)
263
+ <span class="ruby-comment"># mytor.connect</span>
264
+ <span class="ruby-identifier">mytor</span>.<span class="ruby-identifier">authenticate</span> <span class="ruby-node">&quot;\&quot;#{ctrlpasswd}\&quot;&quot;</span>
265
+ <span class="ruby-identifier">mytor</span>.<span class="ruby-identifier">closeallcircuits</span>
266
+ <span class="ruby-identifier">puts</span> <span class="ruby-identifier">mytor</span>.<span class="ruby-identifier">cir_status</span>
267
+ <span class="ruby-constant">A</span>= [ <span class="ruby-string">&quot;FateTestarrosa&quot;</span>, <span class="ruby-string">&quot;mindfields&quot;</span>, <span class="ruby-string">&quot;BeMyGuest&quot;</span> , <span class="ruby-string">&quot;$AE55AECC4C68573F32F0ECFF6303A3FAEFFCD70E&quot;</span> ] <span class="ruby-operator">+</span> <span class="ruby-identifier">mytor</span>.<span class="ruby-identifier">get_entryguards</span>
268
+ <span class="ruby-comment"># A can be mytor.get_purposeip(&quot;fast guard&quot;)</span>
269
+ <span class="ruby-constant">B</span>= [<span class="ruby-string">&quot;GreenLantern&quot;</span>, <span class="ruby-string">&quot;atlgonyovLi&quot;</span>, <span class="ruby-string">&quot;bauruine1&quot;</span> ]
270
+ <span class="ruby-comment"># or use B = mytor.get_purposeip(&quot;fast !exit !guard&quot;)</span>
271
+ <span class="ruby-comment"># But B can also be an guard or exit relay, no restrictions</span>
272
+ <span class="ruby-constant">C</span> = <span class="ruby-identifier">mytor</span>.<span class="ruby-identifier">get_purposeip</span>(<span class="ruby-string">&quot;exit fast&quot;</span>)
273
+ <span class="ruby-identifier">url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span> <span class="ruby-string">&quot;https://bridges.torproject.org/&quot;</span>
274
+ <span class="ruby-constant">C</span>.<span class="ruby-identifier">count</span>.<span class="ruby-identifier">times</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">z</span><span class="ruby-operator">|</span>
275
+ <span class="ruby-identifier">entryg</span> = <span class="ruby-constant">A</span>[<span class="ruby-identifier">rand</span>(<span class="ruby-constant">A</span>.<span class="ruby-identifier">count</span>)]
276
+ <span class="ruby-identifier">relayg</span> = <span class="ruby-constant">B</span>[<span class="ruby-identifier">rand</span>(<span class="ruby-constant">B</span>.<span class="ruby-identifier">count</span>)]
277
+ <span class="ruby-identifier">exitn</span> = <span class="ruby-constant">C</span>[<span class="ruby-identifier">z</span>]
278
+ <span class="ruby-identifier">circuit1</span> = [<span class="ruby-identifier">entryg</span>,<span class="ruby-identifier">relayg</span>, <span class="ruby-identifier">exitn</span>]
279
+ <span class="ruby-identifier">cir_num</span> = <span class="ruby-identifier">mytor</span>.<span class="ruby-identifier">extendcir</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">circuit1</span>)
280
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">mytor</span>.<span class="ruby-identifier">cir_status</span>.<span class="ruby-identifier">detect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-operator">=~</span> <span class="ruby-node">/#{cir_num} BUILT/</span>}
281
+ <span class="ruby-identifier">mytor</span>.<span class="ruby-identifier">get_bridges</span>(<span class="ruby-identifier">url</span>,<span class="ruby-identifier">cachedf</span>)
282
+ <span class="ruby-keyword">else</span>
283
+ <span class="ruby-identifier">sleep</span>(<span class="ruby-value">2</span>)
284
+ <span class="ruby-identifier">puts</span> <span class="ruby-identifier">mytor</span>.<span class="ruby-identifier">get_bridges</span>( <span class="ruby-identifier">url</span>, <span class="ruby-identifier">cachedf</span> ) <span class="ruby-comment">#bridges are added to the database automatically</span>
285
+ <span class="ruby-keyword">end</span>
286
+ }
287
+ </pre>
288
+
289
+ <p>more results can be obtained using all exits, instead of just fast exits.
290
+ Or other distributed networks.</p>
291
+
292
+ </div>
293
+
294
+
295
+
296
+ <footer id="validator-badges">
297
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
298
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11.
299
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
300
+ </footer>
301
+