Module: I2P
- Defined in:
- lib/i2p.rb,
lib/i2p/bob.rb,
lib/i2p/sam.rb,
lib/i2p/sdk.rb,
lib/i2p/hosts.rb,
lib/i2p/version.rb,
lib/i2p/data/key.rb,
lib/i2p/streaming.rb,
lib/i2p/bob/client.rb,
lib/i2p/bob/tunnel.rb,
lib/i2p/sam/client.rb,
lib/i2p/data/key_pair.rb,
lib/i2p/data/structure.rb,
lib/i2p/data/public_key.rb,
lib/i2p/data/certificate.rb,
lib/i2p/data/destination.rb,
lib/i2p/data/private_key.rb,
lib/i2p/data/signing_public_key.rb,
lib/i2p/data/signing_private_key.rb
Overview
Defined Under Namespace
Modules: BOB, SAM, SDK, Streaming, VERSION Classes: Certificate, Destination, Hosts, Key, KeyPair, PrivateKey, PublicKey, SigningPrivateKey, SigningPublicKey, Structure
Constant Summary collapse
- PATH =
The path used to locate the ‘i2prouter` executable.
(ENV['I2P_PATH'] || ENV['PATH']).split(File::PATH_SEPARATOR)
Class Method Summary collapse
-
.available? ⇒ Boolean
Returns ‘true` if I2P is available, `false` otherwise.
-
.program_path(program_name = :i2prouter) ⇒ Pathname
Returns the path to the ‘i2prouter` executable.
-
.restart! ⇒ Boolean
Restarts the local I2P router daemon, starting it in case it wasn’t already running.
-
.running? ⇒ Boolean
Returns ‘true` if the I2P router is running locally, `false` otherwise.
-
.start! ⇒ Integer
Starts the local I2P router daemon.
-
.stop! ⇒ Boolean
Stops the local I2P router daemon.
Class Method Details
.available? ⇒ Boolean
Returns ‘true` if I2P is available, `false` otherwise.
This attempts to locate the ‘i2prouter` executable in the user’s current ‘PATH` environment.
65 66 67 |
# File 'lib/i2p.rb', line 65 def self.available? !!program_path end |
.program_path(program_name = :i2prouter) ⇒ Pathname
Returns the path to the ‘i2prouter` executable.
Returns ‘nil` if the program could not be located in any of the directories denoted by the user’s current ‘I2P_PATH` or `PATH` environment variables.
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/i2p.rb', line 166 def self.program_path(program_name = :i2prouter) program_name = program_name.to_s @program_paths ||= {} @program_paths[program_name] ||= begin PATH.find do |dir| if File.executable?(file = File.join(dir, program_name)) break Pathname(file) end end end end |
.restart! ⇒ Boolean
Restarts the local I2P router daemon, starting it in case it wasn’t already running.
Returns ‘true` if the I2P router daemon was successfully restarted, `false` otherwise.
This relies on being able to execute ‘i2prouter restart`, which requires the `i2prouter` executable to be located in the user’s current ‘PATH` environment.
130 131 132 133 134 |
# File 'lib/i2p.rb', line 130 def self.restart! if available? /Starting I2P Service/ === `#{program_path} restart` end end |
.running? ⇒ Boolean
Returns ‘true` if the I2P router is running locally, `false` otherwise.
This first attempts to call ‘i2prouter status` if the executable can be located in the user’s current ‘PATH` environment, falling back to attempting to establish a Simple Anonymous Messaging (SAM) protocol connection to the standard SAM port 7656 on `localhost`.
If I2P isn’t in the ‘PATH` and hasn’t been configured with SAM enabled, this will return ‘false` regardless of whether I2P actually is running or not.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/i2p.rb', line 85 def self.running? if available? /is running/ === `#{program_path} status`.chomp else begin I2P::SAM::Client.open.disconnect true rescue Errno::ECONNREFUSED false end end end |
.start! ⇒ Integer
Starts the local I2P router daemon.
Returns the process identifier (PID) if the I2P router daemon was successfully started, ‘nil` otherwise.
This relies on being able to execute ‘i2prouter start`, which requires the `i2prouter` executable to be located in the user’s current ‘PATH` environment.
110 111 112 113 114 115 |
# File 'lib/i2p.rb', line 110 def self.start! if available? `#{program_path} start` unless running? `#{program_path} status` =~ /is running \((\d+)\)/ ? $1.to_i : nil end end |
.stop! ⇒ Boolean
Stops the local I2P router daemon.
Returns ‘true` if the I2P router daemon was successfully shut down, `false` otherwise.
This relies on being able to execute ‘i2prouter stop`, which requires the `i2prouter` executable to be located in the user’s current ‘PATH` environment.
148 149 150 151 152 |
# File 'lib/i2p.rb', line 148 def self.stop! if available? /Stopped I2P Service/ === `#{program_path} stop` end end |