ji2p 0.0.4-universal-java-11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/bundle +15 -0
- data/bin/ctxirb +119 -0
- data/bin/simple_http_server +20 -0
- data/bin/simple_outproxy +96 -0
- data/lib/actor_system/actor.rb +10 -0
- data/lib/actor_system/concurrent/processor.rb +21 -0
- data/lib/actor_system/concurrent/worker.rb +13 -0
- data/lib/actor_system/core/minimal.rb +84 -0
- data/lib/actor_system/core/observable_implementation.rb +58 -0
- data/lib/actor_system/core/props.rb +45 -0
- data/lib/actor_system/dispatcher.rb +12 -0
- data/lib/actor_system/mailbox.rb +7 -0
- data/lib/actor_system/message.rb +60 -0
- data/lib/core_ext.rb +41 -0
- data/lib/gen_server.rb +57 -0
- data/lib/ji2p.rb +37 -0
- data/lib/ji2p/bundler.rb +165 -0
- data/lib/ji2p/cluster.rb +6 -0
- data/lib/ji2p/cluster/etcd.rb +5 -0
- data/lib/ji2p/cluster/etcd/version3.rb +6 -0
- data/lib/ji2p/cluster/kubernetes.rb +5 -0
- data/lib/ji2p/cluster/kubernetes/kube_api.rb +6 -0
- data/lib/ji2p/concurrent.rb +24 -0
- data/lib/ji2p/concurrent_executor.rb +56 -0
- data/lib/ji2p/config.rb +15 -0
- data/lib/ji2p/control.rb +15 -0
- data/lib/ji2p/control/client_manager.rb +14 -0
- data/lib/ji2p/control/dest.rb +34 -0
- data/lib/ji2p/control/keypair.rb +176 -0
- data/lib/ji2p/control/server.rb +80 -0
- data/lib/ji2p/control/socket_manager.rb +77 -0
- data/lib/ji2p/control/tunnel_manager.rb +62 -0
- data/lib/ji2p/environment.rb +35 -0
- data/lib/ji2p/package/gem_installer.rb +91 -0
- data/lib/ji2p/package/gemfile.rb +234 -0
- data/lib/ji2p/package/jar_dependencies.rb +23 -0
- data/lib/ji2p/package/proxy_support.rb +50 -0
- data/lib/ji2p/rspec.rb +16 -0
- data/lib/ji2p/server.rb +10 -0
- data/lib/ji2p/server/api.rb +14 -0
- data/lib/ji2p/server/database.rb +66 -0
- data/lib/ji2p/server/http.rb +69 -0
- data/lib/ji2p/server/http_server.rb +37 -0
- data/lib/ji2p/server/initializer.rb +4 -0
- data/lib/ji2p/server/launcher.rb +40 -0
- data/lib/ji2p/server/models.rb +9 -0
- data/lib/ji2p/server/models/base_record.rb +7 -0
- data/lib/ji2p/server/models/keypair.rb +32 -0
- data/lib/ji2p/server/models/tunnel.rb +4 -0
- data/lib/ji2p/startup.rb +12 -0
- data/lib/ji2p/startup/bootstrap.rb +60 -0
- data/lib/ji2p/startup/client_application.rb +20 -0
- data/lib/ji2p/startup/router_manager.rb +21 -0
- data/lib/ji2p/startup/sinatra_app.rb +61 -0
- data/lib/ji2p/startup/worker.rb +63 -0
- data/lib/ji2p/utils/blocking_queue.rb +32 -0
- data/lib/ji2p/utils/byte_value.rb +61 -0
- data/lib/ji2p/version.rb +3 -0
- data/lib/ji2p_jars.rb +16 -0
- data/lib/maybe.rb +148 -0
- data/lib/net/i2p/client/mstreaming/0.9.43/mstreaming-0.9.43.jar +0 -0
- data/lib/net/i2p/client/streaming/0.9.43/streaming-0.9.43.jar +0 -0
- data/lib/net/i2p/i2p/0.9.43/i2p-0.9.43.jar +0 -0
- data/lib/net/i2p/router/0.9.43/router-0.9.43.jar +0 -0
- metadata +392 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "uri"
|
3
|
+
require "java"
|
4
|
+
require "erb"
|
5
|
+
|
6
|
+
module Ji2p
|
7
|
+
module Package
|
8
|
+
module ProxySupport
|
9
|
+
extend self
|
10
|
+
|
11
|
+
# Apply HTTP_PROXY and HTTPS_PROXY to the current environment
|
12
|
+
# this will be used by any JRUBY calls
|
13
|
+
def apply_env_proxy_settings(settings)
|
14
|
+
$stderr.puts("Using proxy #{settings}") if ENV["DEBUG"]
|
15
|
+
scheme = settings[:protocol].downcase
|
16
|
+
java.lang.System.setProperty("#{scheme}.proxyHost", settings[:host])
|
17
|
+
java.lang.System.setProperty("#{scheme}.proxyPort", settings[:port].to_s)
|
18
|
+
java.lang.System.setProperty("#{scheme}.proxyUsername", settings[:username].to_s)
|
19
|
+
java.lang.System.setProperty("#{scheme}.proxyPassword", settings[:password].to_s)
|
20
|
+
end
|
21
|
+
|
22
|
+
def extract_proxy_values_from_uri(proxy_uri)
|
23
|
+
{
|
24
|
+
:protocol => proxy_uri.scheme,
|
25
|
+
:host => proxy_uri.host,
|
26
|
+
:port => proxy_uri.port,
|
27
|
+
:username => proxy_uri.user,
|
28
|
+
:password => proxy_uri.password
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_proxy_string(proxy_string)
|
33
|
+
proxy_uri = URI.parse(proxy_string)
|
34
|
+
if proxy_uri.kind_of?(URI::HTTP) # URI::HTTPS is already a subclass of URI::HTTP
|
35
|
+
proxy_uri
|
36
|
+
else
|
37
|
+
raise "Invalid proxy `#{proxy_uri}`. The URI is not HTTP/HTTPS."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_proxy(key)
|
42
|
+
ENV[key.downcase] || ENV[key.upcase]
|
43
|
+
end
|
44
|
+
|
45
|
+
def proxy_string_exists?(proxy)
|
46
|
+
!proxy.nil? && !proxy.strip.empty?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/ji2p/rspec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'environment'
|
2
|
+
Ji2p::Bundler.setup!({:without => [:build]})
|
3
|
+
require 'ji2p'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.join(Ji2p::Environment::JI2P_CORE, "spec"))
|
6
|
+
|
7
|
+
require 'rspec/core'
|
8
|
+
require 'rspec'
|
9
|
+
|
10
|
+
RSpec.world.reset # if multiple rspec runs occur in a single process, the RSpec "world" state needs to be reset.
|
11
|
+
|
12
|
+
status = RSpec::Core::Runner.run(ARGV.empty? ? ($JUNIT_ARGV || ["spec"]) : ARGV).to_i
|
13
|
+
if ENV["IS_JUNIT_RUN"]
|
14
|
+
return status
|
15
|
+
end
|
16
|
+
exit status if status != 0
|
data/lib/ji2p/server.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
module Ji2p
|
2
|
+
module Server
|
3
|
+
autoload :Api, File.expand_path('server/api.rb', __dir__)
|
4
|
+
autoload :Database, File.expand_path('server/database.rb', __dir__)
|
5
|
+
autoload :HTTP, File.expand_path('server/http.rb', __dir__)
|
6
|
+
autoload :HttpServer, File.expand_path('server/http_server.rb', __dir__)
|
7
|
+
autoload :Launcher, File.expand_path('server/launcher.rb', __dir__)
|
8
|
+
autoload :Models, File.expand_path('server/models.rb', __dir__)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Ji2p::Server
|
4
|
+
module Database
|
5
|
+
@@connections = Hash.new
|
6
|
+
@@default_connection = nil
|
7
|
+
|
8
|
+
def self.connect! db=':memory:', db_type='sqlite3'
|
9
|
+
conn = ActiveRecord::Base.establish_connection(database: db, adapter: db_type)
|
10
|
+
key = "#{db}/#{db_type}/#{Ji2p::Control.unique_id.to_s}"
|
11
|
+
@@connections[key] = conn
|
12
|
+
@@default_connection = conn if @@default_connection.nil?
|
13
|
+
define_state_schema!
|
14
|
+
conn
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.connect_with_local_path! name
|
18
|
+
java_import 'net.i2p.I2PAppContext'
|
19
|
+
ctx = Java::NetI2p::I2PAppContext.getGlobalContext
|
20
|
+
path = File.join ctx.getConfigDir.toString, name
|
21
|
+
connect! path
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.flush
|
25
|
+
@@default_connection.flush
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.default
|
29
|
+
@@default_connection
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.is_connected?
|
33
|
+
get_connections.size > 0
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_connections
|
37
|
+
@@connections
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.define_state_schema! b_force=false
|
41
|
+
ActiveRecord::Schema.define do
|
42
|
+
create_table :keypairs, force: b_force do |t|
|
43
|
+
t.string :strid
|
44
|
+
t.string :name
|
45
|
+
t.text :destination
|
46
|
+
t.string :base32
|
47
|
+
t.text :private_key_data
|
48
|
+
t.json :metadata
|
49
|
+
t.timestamps
|
50
|
+
end unless ActiveRecord::Base.connection.table_exists? 'keypairs' or b_force
|
51
|
+
create_table :tunnels, force: b_force do |t|
|
52
|
+
t.string :name
|
53
|
+
t.text :description
|
54
|
+
t.json :metadata
|
55
|
+
t.references :keypair
|
56
|
+
t.string :tunnel_type
|
57
|
+
t.integer :listen_port
|
58
|
+
t.integer :target_port
|
59
|
+
t.string :listen_interface
|
60
|
+
t.string :target_host
|
61
|
+
t.timestamps
|
62
|
+
end unless ActiveRecord::Base.connection.table_exists? 'tunnels' or b_force
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Ji2p::Server
|
4
|
+
class HTTP
|
5
|
+
VERSION = "HTTP/1.1" unless defined? VERSION
|
6
|
+
CRLF = "\r\n" unless defined? CRLF
|
7
|
+
|
8
|
+
def initialize(socket, application)
|
9
|
+
@socket = socket
|
10
|
+
@application = application
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
matches = /\A(?<method>\S+)\s+(?<uri>\S+)\s+(?<version>\S+)#{CRLF}\Z/.match(@socket.readline)
|
15
|
+
uri = URI.parse(matches[:uri])
|
16
|
+
|
17
|
+
env = {
|
18
|
+
"rack.errors" => $stderr,
|
19
|
+
"rack.version" => Rack::VERSION,
|
20
|
+
"rack.url_scheme" => uri.scheme || "http",
|
21
|
+
"REQUEST_METHOD" => matches[:method],
|
22
|
+
"REQUEST_URI" => matches[:uri],
|
23
|
+
"HTTP_VERSION" => matches[:version],
|
24
|
+
"QUERY_STRING" => uri.query || "",
|
25
|
+
"SERVER_PORT" => uri.port || 80,
|
26
|
+
"SERVER_NAME" => uri.host || "localhost",
|
27
|
+
"PATH_INFO" => uri.path || "",
|
28
|
+
"SCRIPT_NAME" => "",
|
29
|
+
}
|
30
|
+
|
31
|
+
while matches = /\A(?<key>[^:]+):\s*(?<value>.+)#{CRLF}\Z/.match(hl = @socket.readline)
|
32
|
+
case matches[:key]
|
33
|
+
when Rack::ContentType then env["CONTENT_TYPE"] = matches[:value]
|
34
|
+
when Rack::ContentLength then env["CONTENT_LENGTH"] = Integer(matches[:value])
|
35
|
+
else env["HTTP_" + matches[:key].tr("-", "_").upcase] ||= matches[:value]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
env["rack.input"] = StringIO.new(@socket.read(env["CONTENT_LENGTH"] || 0))
|
40
|
+
|
41
|
+
return env #.map { |_,v| String.new v }
|
42
|
+
end
|
43
|
+
|
44
|
+
def handle
|
45
|
+
env = parse
|
46
|
+
|
47
|
+
status, headers, body = @application.call(env)
|
48
|
+
|
49
|
+
time = Time.now.httpdate
|
50
|
+
|
51
|
+
@socket.write "#{env['HTTP_VERSION']} #{status} #{Rack::Utils::HTTP_STATUS_CODES.fetch(status.to_i) { 'UNKNOWN' }}#{CRLF}"
|
52
|
+
@socket.write "Date: #{time}#{CRLF}"
|
53
|
+
@socket.write "Connection: close#{CRLF}"
|
54
|
+
|
55
|
+
headers.each do |key, value|
|
56
|
+
@socket.write "#{key}: #{value}#{CRLF}"
|
57
|
+
end
|
58
|
+
|
59
|
+
@socket.write(CRLF)
|
60
|
+
|
61
|
+
body.each do |chunk|
|
62
|
+
@socket.write(chunk)
|
63
|
+
end
|
64
|
+
|
65
|
+
Ji2p.logger.info("[#{time}] '#{env["REQUEST_METHOD"]} #{env["REQUEST_URI"]} #{env["HTTP_VERSION"]}' #{status}")
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'http.rb'
|
2
|
+
|
3
|
+
module Ji2p::Server
|
4
|
+
class HttpServer
|
5
|
+
|
6
|
+
def initialize(application, socket)
|
7
|
+
@application = application
|
8
|
+
@socket = socket
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
loop do
|
13
|
+
begin
|
14
|
+
monitor
|
15
|
+
rescue Interrupt
|
16
|
+
Ji2p.logger.log("INTERRUPTED")
|
17
|
+
return
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def monitor
|
23
|
+
#selections, = IO.select(@sockets)
|
24
|
+
#io, = selections
|
25
|
+
io = @socket
|
26
|
+
|
27
|
+
begin
|
28
|
+
socket = io.accept
|
29
|
+
http = Ji2p::Server::HTTP::new(socket, @application)
|
30
|
+
http.handle
|
31
|
+
ensure
|
32
|
+
socket.close
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Ji2p::Server
|
4
|
+
class Launcher
|
5
|
+
|
6
|
+
def initialize privateKeyData=nil
|
7
|
+
generate_keypair if privateKeyData.nil?
|
8
|
+
load_keypair privateKeyData unless privateKeyData.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def generate_keypair
|
14
|
+
@keypair = Ji2p::Control::Keypair.generate!
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_keypair privateKeyData
|
18
|
+
@keypair = Ji2p::Control::Keypair.load_from_stream! StringIO.new(privateKeyData)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class RackConfigLauncher < Launcher
|
24
|
+
|
25
|
+
def initialize privateKeyData, rackfile
|
26
|
+
super(privateKeyData)
|
27
|
+
@rack_config = rackfile.dup
|
28
|
+
end
|
29
|
+
|
30
|
+
def rack_application
|
31
|
+
raw = File.read(@rack_config)
|
32
|
+
builder = <<~BUILDER
|
33
|
+
Rack::Builder.new do
|
34
|
+
#{raw}
|
35
|
+
end
|
36
|
+
BUILDER
|
37
|
+
eval(builder, nil, @rack_config)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Ji2p::Server
|
4
|
+
module Models
|
5
|
+
autoload :BaseRecord, File.expand_path('models/base_record.rb', __dir__)
|
6
|
+
autoload :Keypair, File.expand_path('models/keypair.rb', __dir__)
|
7
|
+
autoload :Tunnel, File.expand_path('models/tunnel.rb', __dir__)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module Ji2p::Server::Models
|
5
|
+
Ji2p::Control::Keypair.class_eval do
|
6
|
+
def to_activerecord
|
7
|
+
row = Ji2p::Server::Models::Keypair.new
|
8
|
+
row.destination = @dest.base64
|
9
|
+
row.base32 = @dest.base32
|
10
|
+
row.private_key_data = Base64.encode64(@data)
|
11
|
+
row
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def write_dummy_stream obj
|
17
|
+
s = StringIO.new
|
18
|
+
obj.writeBytes(s.to_outputstream)
|
19
|
+
Base64.encode64 s.string
|
20
|
+
end
|
21
|
+
end
|
22
|
+
class Keypair < BaseRecord
|
23
|
+
|
24
|
+
def pk_data
|
25
|
+
Base64.decode64(private_key_data)
|
26
|
+
end
|
27
|
+
|
28
|
+
def getKeypairInstance
|
29
|
+
Ji2p::Control::Keypair.load_from_stream! StringIO.new(pk_data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/ji2p/startup.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Ji2p
|
2
|
+
module Startup
|
3
|
+
autoload :Bootstrap, File.expand_path('startup/bootstrap.rb', __dir__)
|
4
|
+
autoload :RouterManager, File.expand_path('startup/router_manager.rb', __dir__)
|
5
|
+
|
6
|
+
TMPDIR = File.expand_path('../../tmp', __dir__) unless defined? TMPDIR
|
7
|
+
|
8
|
+
def self.tmp_dir
|
9
|
+
TMPDIR
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'java'
|
2
|
+
|
3
|
+
module Ji2p::Startup
|
4
|
+
java_import java.lang.ClassLoader
|
5
|
+
java_import java.lang.System
|
6
|
+
|
7
|
+
class Bootstrap
|
8
|
+
def initialize defaults={'i2p.dir.config' => TMPDIR}
|
9
|
+
@defaults = defaults
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_system_property key, value
|
13
|
+
System.setProperty key.to_s, value.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_system_property value
|
17
|
+
System.getProperty[value.to_s]
|
18
|
+
end
|
19
|
+
|
20
|
+
def load_jars
|
21
|
+
java_import java.lang.Thread
|
22
|
+
java_import java.net.URL
|
23
|
+
cl = Thread.currentThread.getContextClassLoader
|
24
|
+
dirname = System.getProperties['i2p.dir.base']
|
25
|
+
Dir["#{dirname}/lib/**.jar"].each do |jar|
|
26
|
+
u = Java::JavaNet::URL.new "file://#{jar}"
|
27
|
+
cl.addURL u
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def i2p_loaded?
|
32
|
+
java_import java.lang.Thread
|
33
|
+
cl = Thread.currentThread.getContextClassLoader
|
34
|
+
cl.getURLs.select { |item| item.to_s.include? 'i2p.jar' }.size > 0
|
35
|
+
end
|
36
|
+
|
37
|
+
def check_and_set_props!
|
38
|
+
if System.getProperties['i2p.dir.base'].nil?
|
39
|
+
unless ENV['I2PDIR'].nil?
|
40
|
+
System.setProperty 'i2p.dir.base', ENV['I2PDIR'].to_s
|
41
|
+
else
|
42
|
+
raise ArgumentError, 'The system property i2p.dir.base is missing!', caller if @defaults['i2p.dir.base'].nil?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
if System.getProperties['i2p.dir.config'].nil?
|
46
|
+
raise ArgumentError, 'The system property i2p.dir.config is missing!', caller if @defaults['i2p.dir.config'].nil?
|
47
|
+
System.setProperty 'i2p.dir.config', @defaults['i2p.dir.config']
|
48
|
+
end
|
49
|
+
System.setProperty 'java.awt.headless', 'true' if System.getProperties['java.awt.headless'].nil?
|
50
|
+
System.setProperty 'java.library.path', "#{System.getProperties['i2p.dir.base']}/lib" if System.getProperties['java.library.path'].nil?
|
51
|
+
end
|
52
|
+
|
53
|
+
def boot!
|
54
|
+
check_and_set_props!
|
55
|
+
load_jars unless i2p_loaded?
|
56
|
+
RouterManager.start_router!
|
57
|
+
RouterManager.router_context
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|