Class: Tor::LongCircuit
- Inherits:
-
Object
- Object
- Tor::LongCircuit
- Defined in:
- lib/circuits.rb
Overview
This creates a Long circuit comprising of multiple sub-circuits. Methods include LongCircuit.built?, LongCircuit.extend,LongCircuit..attach_streams,
Instance Method Summary collapse
-
#attach_streams ⇒ Object
This tries to attach all streams to to a single pre-established circuit.
-
#built? ⇒ Boolean
Checks if the subcircuits have been built.
-
#circuit ⇒ Object
Returns the array of Tor::Circuit instances that make up the LongCircuit instance.
-
#cirnum ⇒ Object
Returns the circuit number of the entry circuit.
-
#close_apps ⇒ Object
This closes all the sub-circuits.
-
#extend(*startcir) ⇒ Object
Extend circuits from startcir position in the circuit array.
-
#initialize(tcontrolarray = [], circuitarray = [], proxyconfig) ⇒ LongCircuit
constructor
Creates an instance of Tor::LongCircuit and initialises the attributes of the instance including the cirnum, @built and @circuitarray containing an sub-circuits that are instances of Tor::Circuit.
Constructor Details
#initialize(tcontrolarray = [], circuitarray = [], proxyconfig) ⇒ LongCircuit
Creates an instance of Tor::LongCircuit and initialises the attributes of the instance including the cirnum, @built and @circuitarray containing an sub-circuits that are instances of Tor::Circuit
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/circuits.rb', line 253 def initialize( tcontrolarray=[], circuitarray=[], proxyconfig ) # Would it be better to get proxyconfig from mytor.getconf("SocksPort") @built = false @cirnum = 0 @circuitarray = [] i = 0; j = 2; k=0 while i < circuitarray.count if tcontrolarray[k] if k == 0 @circuitarray << Circuit.new( tcontrolarray[k], circuitarray[ i..j ] , nil ) else @circuitarray << Circuit.new( tcontrolarray[k], circuitarray[ i..j ] , proxyconfig + k ) end i +=3 j +=3 k +=1 end end end |
Instance Method Details
#attach_streams ⇒ Object
This tries to attach all streams to to a single pre-established circuit.
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/circuits.rb', line 274 def attach_streams # fork_reactor runs the reactor in a new thread thus allowing other methods to e run. Should I store the pid? When do I close the pid? # EM.fork_reactor{ EM.run { # @counter = 0 if not defined?(@seun) # To count how many times an event has been triggered @timer=Array.new(@circuitarray.count) 0.upto(@circuitarray.count - 1){|z| if ! @circuitarray[z].launched? @circuitarray[z].launch end # Periodic timer to fire an event, in this case launch/attach sub circuits. If a custom value (Tor::PERIODIC_TIMER) is defined, use it instead timer = (defined? Tor::PERIODIC_TIMER) ? Tor::PERIODIC_TIMER : Tor::Constants::PERIODIC_TIMER # Keep checking if any of the subcircuits has been closed using the timer duration @timer[z] = EventMachine::PeriodicTimer.new(timer) do @timer[z].cancel if @circuitarray[z].closed? # puts "Counter = #{@counter+=1}\n" @circuitarray[z].start end } } y = ( built? ).index(false) puts "#{y} - #{built?}\n" extend y return nil end |
#built? ⇒ Boolean
Checks if the subcircuits have been built.
309 310 311 312 313 314 |
# File 'lib/circuits.rb', line 309 def built? @built = true truth_table = @circuitarray.collect{|each_circuit| each_circuit.built? } # To know where the circuit is failing truth_table.each{|truth_value| @built = @built & truth_value } truth_table end |
#circuit ⇒ Object
Returns the array of Tor::Circuit instances that make up the LongCircuit instance.
324 325 326 |
# File 'lib/circuits.rb', line 324 def circuit @circuitarray end |
#cirnum ⇒ Object
Returns the circuit number of the entry circuit.
329 330 331 |
# File 'lib/circuits.rb', line 329 def cirnum @circuitarray[0].cirnum end |
#close_apps ⇒ Object
This closes all the sub-circuits.
317 318 319 320 321 |
# File 'lib/circuits.rb', line 317 def close_apps @circuitarray.each{|z| z.close_apps } end |
#extend(*startcir) ⇒ Object
Extend circuits from startcir position in the circuit array. This is used internally by Tor.attach_streams There is no need to call this directly, instead use attach_streams method.
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/circuits.rb', line 334 def extend(*startcir) if startcir.empty? tmp=0 elsif startcir[0].nil? tmp=0 else tmp = startcir[0] end # Extend all sub-circuits or extend only circuits from startcir index. tmp.upto(@circuitarray.count - 1 ){ |y| each_circuit = @circuitarray[y] counter_z=0 while ! each_circuit.built? and counter_z < 15 # Try up to 15 times to build the same circuit before giving up # each_circuit.launch if y != 0 # here I need to launch tor and polipo in this method with the right config file after adding tmpdir path and configs cirnum = each_circuit.extend if each_circuit.built? next else sleep( 2 * @circuitarray.index(each_circuit) + 2 ) # arithmetic progression time possible delay between each circuits [2,4,6,8,10,12]... next if each_circuit.built? end z += 1 end if z == 15 puts "Circuit failed \n" return nil else cirnum end } end |