Class: I2P::BOB::Tunnel
- Inherits:
-
Object
- Object
- I2P::BOB::Tunnel
- Defined in:
- lib/i2p/bob/tunnel.rb
Overview
**I2P Basic Open Bridge (BOB) tunnel manager.**
Instance Attribute Summary collapse
-
#destination ⇒ Destination
readonly
Returns the I2P destination for this tunnel.
-
#inhost ⇒ String
readonly
Returns the inbound host name or IP address for this tunnel.
-
#inport ⇒ Integer
readonly
Returns the inbound port number for this tunnel.
-
#keys ⇒ KeyPair
readonly
Returns the I2P key pair for this tunnel.
-
#nickname ⇒ String
readonly
Returns the nickname for this tunnel.
-
#outhost ⇒ String
readonly
Returns the outbound host name or IP address for this tunnel.
-
#outport ⇒ Integer
readonly
Returns the outbound port number for this tunnel.
Class Method Summary collapse
-
.start(options = {}, &block) ⇒ Tunnel
Starts up a new tunnel.
-
.stop(nickname) ⇒ void
Shuts down an existing tunnel of the given ‘nickname`.
Instance Method Summary collapse
-
#client {|client| ... } ⇒ Client
Returns a Client instance for accessing low-level information about this tunnel.
-
#inbound? ⇒ Boolean
Returns ‘true` if this is an inbound tunnel.
-
#initialize(options = {}) ⇒ Tunnel
constructor
Initializes a new tunnel instance.
-
#outbound? ⇒ Boolean
Returns ‘true` if this is an outbound tunnel.
-
#quiet? ⇒ Boolean
Returns ‘true` if quiet mode is enabled for this tunnel.
-
#running? ⇒ Boolean
(also: #active?)
Returns ‘true` if this tunnel is currently active.
-
#setup(options = {}) ⇒ void
(also: #setup!)
Registers the given tunnel ‘options` with the BOB bridge.
- #socket ⇒ Object
-
#start ⇒ void
(also: #start!)
Starts up this tunnel.
-
#starting? ⇒ Boolean
Returns ‘true` if this tunnel is currently in the process of starting up.
-
#stop ⇒ void
(also: #stop!)
Shuts down this tunnel.
-
#stopping? ⇒ Boolean
Returns ‘true` if this tunnel is currently in the process of shutting down.
Constructor Details
#initialize(options = {}) ⇒ Tunnel #initialize(nickname) ⇒ Tunnel
Initializes a new tunnel instance.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/i2p/bob/tunnel.rb', line 93 def initialize( = {}) case when Hash # Create a new tunnel @nickname = [:nickname] || Time.now.to_i.to_s @debug = [:debug] setup() else # Access an existing tunnel @nickname = .to_s Client.open { |client| client.getnick(@nickname) } end end |
Instance Attribute Details
#destination ⇒ Destination (readonly)
Returns the I2P destination for this tunnel.
119 120 121 |
# File 'lib/i2p/bob/tunnel.rb', line 119 def destination @destination end |
#inhost ⇒ String (readonly)
Returns the inbound host name or IP address for this tunnel.
147 148 149 |
# File 'lib/i2p/bob/tunnel.rb', line 147 def inhost @inhost end |
#inport ⇒ Integer (readonly)
Returns the inbound port number for this tunnel.
159 160 161 |
# File 'lib/i2p/bob/tunnel.rb', line 159 def inport @inport end |
#keys ⇒ KeyPair (readonly)
Returns the I2P key pair for this tunnel.
129 130 131 |
# File 'lib/i2p/bob/tunnel.rb', line 129 def keys @keys end |
#nickname ⇒ String (readonly)
Returns the nickname for this tunnel.
112 113 114 |
# File 'lib/i2p/bob/tunnel.rb', line 112 def nickname @nickname end |
#outhost ⇒ String (readonly)
Returns the outbound host name or IP address for this tunnel.
179 180 181 |
# File 'lib/i2p/bob/tunnel.rb', line 179 def outhost @outhost end |
#outport ⇒ Integer (readonly)
Returns the outbound port number for this tunnel.
191 192 193 |
# File 'lib/i2p/bob/tunnel.rb', line 191 def outport @outport end |
Class Method Details
.start(options = {}, &block) ⇒ Tunnel
Starts up a new tunnel.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/i2p/bob/tunnel.rb', line 53 def self.start( = {}, &block) tunnel = self.new().start if block_given? begin result = block.call(tunnel) ensure tunnel.stop end result else tunnel end end |
.stop(nickname) ⇒ void
This method returns an undefined value.
Shuts down an existing tunnel of the given ‘nickname`.
73 74 75 |
# File 'lib/i2p/bob/tunnel.rb', line 73 def self.stop(nickname) self.new(nickname).stop end |
Instance Method Details
#client {|client| ... } ⇒ Client
Returns a Client instance for accessing low-level information about this tunnel.
299 300 301 |
# File 'lib/i2p/bob/tunnel.rb', line 299 def client(&block) Client.open(:nickname => nickname, :debug => @debug, &block) end |
#inbound? ⇒ Boolean
Returns ‘true` if this is an inbound tunnel.
138 139 140 |
# File 'lib/i2p/bob/tunnel.rb', line 138 def inbound? !!inport end |
#outbound? ⇒ Boolean
Returns ‘true` if this is an outbound tunnel.
170 171 172 |
# File 'lib/i2p/bob/tunnel.rb', line 170 def outbound? !!outport end |
#quiet? ⇒ Boolean
Returns ‘true` if quiet mode is enabled for this tunnel.
This only applies to outbound tunnels and has no effect on inbound tunnels.
206 207 208 209 210 |
# File 'lib/i2p/bob/tunnel.rb', line 206 def quiet? @quiet ||= begin nil # TODO end end |
#running? ⇒ Boolean Also known as: active?
Returns ‘true` if this tunnel is currently active.
243 244 245 |
# File 'lib/i2p/bob/tunnel.rb', line 243 def running? true # FIXME end |
#setup(options = {}) ⇒ void Also known as: setup!
This method returns an undefined value.
Registers the given tunnel ‘options` with the BOB bridge.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/i2p/bob/tunnel.rb', line 217 def setup( = {}) client do |client| if [:keys] client.setkeys([:keys]) else begin client.getkeys rescue Error => e client.newkeys end end client.quiet([:quiet]) if [:quiet] client.inhost([:inhost]) if [:inhost] client.inport([:inport]) if [:inport] client.outhost([:outhost]) if [:outhost] client.outport([:outport]) if [:outport] end self end |
#socket ⇒ Object
288 289 290 |
# File 'lib/i2p/bob/tunnel.rb', line 288 def socket client.socket end |
#start ⇒ void Also known as: start!
This method returns an undefined value.
Starts up this tunnel.
253 254 255 256 |
# File 'lib/i2p/bob/tunnel.rb', line 253 def start client { start } self end |
#starting? ⇒ Boolean
Returns ‘true` if this tunnel is currently in the process of starting up.
264 265 266 |
# File 'lib/i2p/bob/tunnel.rb', line 264 def starting? # TODO end |
#stop ⇒ void Also known as: stop!
This method returns an undefined value.
Shuts down this tunnel.
273 274 275 276 |
# File 'lib/i2p/bob/tunnel.rb', line 273 def stop client { stop } self end |
#stopping? ⇒ Boolean
Returns ‘true` if this tunnel is currently in the process of shutting down.
284 285 286 |
# File 'lib/i2p/bob/tunnel.rb', line 284 def stopping? # TODO end |