ji2p 0.0.3-java
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/gem_installer.rb +89 -0
- data/lib/ji2p/jar_dependencies.rb +15 -0
- data/lib/ji2p/proxy_support.rb +46 -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/utils/blocking_queue.rb +32 -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 +375 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'thread'
|
3
|
+
require_relative 'server.rb'
|
4
|
+
|
5
|
+
module Ji2p::Control
|
6
|
+
java_import 'net.i2p.I2PAppContext'
|
7
|
+
java_import 'net.i2p.client.I2PClientFactory'
|
8
|
+
java_import 'net.i2p.client.streaming.I2PSocketManager'
|
9
|
+
java_import 'net.i2p.client.streaming.I2PSocketManagerFactory'
|
10
|
+
java_import 'net.i2p.client.streaming.IncomingConnectionFilter'
|
11
|
+
java_import 'java.util.Properties'
|
12
|
+
java_import 'java.lang.Thread'
|
13
|
+
|
14
|
+
class SocketManager
|
15
|
+
|
16
|
+
def self.defineManager! name, kp, opts=Java::JavaUtil::Properties.new, filter=IncomingConnectionFilter::ALLOW
|
17
|
+
ctx = I2PAppContext.getGlobalContext
|
18
|
+
session = kp.createSession opts
|
19
|
+
new get_impl.new(ctx,session,opts,name,filter)
|
20
|
+
end
|
21
|
+
|
22
|
+
def connectTunnel
|
23
|
+
@smgr.getSession.connect
|
24
|
+
end
|
25
|
+
|
26
|
+
def myDestination
|
27
|
+
@smgr.getSession.myDestination
|
28
|
+
end
|
29
|
+
|
30
|
+
def leaseSet
|
31
|
+
@smgr.getSession.leaseSet
|
32
|
+
end
|
33
|
+
|
34
|
+
def sessionId
|
35
|
+
@smgr.getSession.sessionId
|
36
|
+
end
|
37
|
+
|
38
|
+
def supports_ls2?
|
39
|
+
@smgr.getSession.supports_ls2?
|
40
|
+
end
|
41
|
+
|
42
|
+
def is_closed?
|
43
|
+
@smgr.getSession.closed?
|
44
|
+
end
|
45
|
+
|
46
|
+
def session
|
47
|
+
@smgr.session
|
48
|
+
end
|
49
|
+
|
50
|
+
def destroy
|
51
|
+
@smgr.getSession.destroySession
|
52
|
+
end
|
53
|
+
|
54
|
+
def lookupDest dest
|
55
|
+
@smgr.getSession.lookupDest dest
|
56
|
+
end
|
57
|
+
|
58
|
+
def getServerSocket
|
59
|
+
SocketServer.new @smgr.getServerSocket
|
60
|
+
end
|
61
|
+
|
62
|
+
def raw
|
63
|
+
@smgr
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def self.get_impl
|
69
|
+
java_import('net.i2p.client.streaming.impl.I2PSocketManagerFull').first
|
70
|
+
end
|
71
|
+
|
72
|
+
def initialize smgr
|
73
|
+
@smgr = smgr
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'java'
|
2
|
+
|
3
|
+
require 'java'
|
4
|
+
require 'digest/sha1'
|
5
|
+
|
6
|
+
module Ji2p::Control
|
7
|
+
class TunnelManager
|
8
|
+
@@tunnelctrl = nil
|
9
|
+
include_package 'net.i2p'
|
10
|
+
include_package 'net.i2p.i2ptunnel'
|
11
|
+
include_package 'net.i2p.client'
|
12
|
+
|
13
|
+
def self.context
|
14
|
+
I2PAppContext.getGlobalContext
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.startTunnelWithConfig conf, createPrivKey = false
|
18
|
+
unless ['client','httpclient','server','httpserver','sockstunnel'].include? conf['type']
|
19
|
+
raise ArgumentError, 'Invalid i2p tunnel type!', caller
|
20
|
+
end
|
21
|
+
tctrl = TunnelController.new conf, '', createPrivKey
|
22
|
+
TunnelCtrl.new tctrl, conf
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.createNewConfig hash = Hash.new
|
26
|
+
props = java.util.Properties.new
|
27
|
+
dfl = {
|
28
|
+
'option.maxPosts'=>'3',
|
29
|
+
'option.i2cp.destination.sigType'=>'EdDSA_SHA512_Ed25519',
|
30
|
+
'option.i2p.streaming.limitAction'=>'http',
|
31
|
+
'description'=>'jruby-tunnel',
|
32
|
+
'interface'=>'127.0.0.1',
|
33
|
+
'type'=>'httpserver',
|
34
|
+
'option.outbound.quantity'=>'4',
|
35
|
+
'option.inbound.quantity'=>'4',
|
36
|
+
'option.postBanTime'=>'1800',
|
37
|
+
'targetPort'=>'8000',
|
38
|
+
'option.postTotalBanTime'=>'600',
|
39
|
+
'i2cpHost'=>'127.0.0.1',
|
40
|
+
'option.postCheckTime'=>'300',
|
41
|
+
'option.i2p.streaming.maxConnsPerHour'=>'40',
|
42
|
+
'option.shouldBundleReplyInfo'=>'false',
|
43
|
+
'option.outbound.length'=>'1',
|
44
|
+
'targetHost'=>'127.0.0.1',
|
45
|
+
'option.inbound.length'=>'1',
|
46
|
+
'i2cpPort'=>'7654',
|
47
|
+
'persistentClientKey'=>'true',
|
48
|
+
'option.maxTotalPosts'=>'10',
|
49
|
+
'option.i2p.streaming.maxConnsPerDay'=>'100',
|
50
|
+
'option.i2p.streaming.maxTotalConnsPerMinute'=>'25',
|
51
|
+
'option.i2p.streaming.maxConnsPerMinute'=>'15',
|
52
|
+
'name'=>'jruby-tunnel',
|
53
|
+
'option.i2p.streaming.maxConcurrentStreams'=>'20',
|
54
|
+
'privKeyFile'=>'kake.dat',
|
55
|
+
'listenPort'=>'8000'
|
56
|
+
}
|
57
|
+
merged = dfl.merge(hash)
|
58
|
+
merged.keys.each { |k| props[k.to_s] = merged[k].to_s }
|
59
|
+
props
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Ji2p
|
4
|
+
module Environment
|
5
|
+
extend self
|
6
|
+
JI2P_HOME = ::File.expand_path(::File.join('..','..'), __dir__) unless defined? JI2P_HOME
|
7
|
+
|
8
|
+
BUNDLE_DIR = ::File.join(JI2P_HOME, "vendor", "bundle") unless defined? BUNDLE_DIR
|
9
|
+
GEMFILE_PATH = ::File.join(JI2P_HOME, "Gemfile") unless defined? GEMFILE_PATH
|
10
|
+
LOCAL_GEM_PATH = ::File.join(JI2P_HOME, 'vendor', 'local_gems') unless defined? LOCAL_GEM_PATH
|
11
|
+
CACHE_PATH = ::File.join(JI2P_HOME, "vendor", "cache") unless defined? CACHE_PATH
|
12
|
+
LOCKFILE = Pathname.new(::File.join(JI2P_HOME, "Gemfile.lock")) unless defined? LOCKFILE
|
13
|
+
GEMFILE = Pathname.new(::File.join(JI2P_HOME, "Gemfile")) unless defined? GEMFILE
|
14
|
+
|
15
|
+
def gem_ruby_version
|
16
|
+
RbConfig::CONFIG["ruby_version"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def ruby_abi_version
|
20
|
+
RUBY_VERSION[/(\d+\.\d+)(\.\d+)*/, 1]
|
21
|
+
end
|
22
|
+
|
23
|
+
def ruby_engine
|
24
|
+
RUBY_ENGINE
|
25
|
+
end
|
26
|
+
|
27
|
+
def ji2p_gem_home
|
28
|
+
::File.join(BUNDLE_DIR, ruby_engine, gem_ruby_version)
|
29
|
+
end
|
30
|
+
|
31
|
+
def vendor_path(path)
|
32
|
+
return ::File.join(JI2P_HOME, "vendor", path)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
|
2
|
+
require "pathname"
|
3
|
+
require "rubygems/package"
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
require_relative 'environment.rb'
|
7
|
+
|
8
|
+
module Ji2p
|
9
|
+
class GemInstaller
|
10
|
+
GEM_HOME = Pathname.new(::File.join(Ji2p::Environment::BUNDLE_DIR, "jruby", "2.5.0"))
|
11
|
+
SPECIFICATIONS_DIR = "specifications"
|
12
|
+
GEMS_DIR = "gems"
|
13
|
+
CACHE_DIR = "cache"
|
14
|
+
|
15
|
+
attr_reader :gem_home
|
16
|
+
|
17
|
+
def initialize(gem_file, display_post_install_message = false, gem_home = GEM_HOME)
|
18
|
+
@gem_file = gem_file
|
19
|
+
@gem = ::Gem::Package.new(@gem_file)
|
20
|
+
@gem_home = Pathname.new(gem_home)
|
21
|
+
@display_post_install_message = display_post_install_message
|
22
|
+
end
|
23
|
+
|
24
|
+
def install
|
25
|
+
create_destination_folders
|
26
|
+
extract_files
|
27
|
+
write_specification
|
28
|
+
copy_gem_file_to_cache
|
29
|
+
post_install_message
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.install(gem_file, display_post_install_message = false, gem_home = GEM_HOME)
|
33
|
+
self.new(gem_file, display_post_install_message, gem_home).install
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def spec
|
38
|
+
@gem.spec
|
39
|
+
end
|
40
|
+
|
41
|
+
def spec_dir
|
42
|
+
gem_home.join(SPECIFICATIONS_DIR)
|
43
|
+
end
|
44
|
+
|
45
|
+
def cache_dir
|
46
|
+
gem_home.join(CACHE_DIR)
|
47
|
+
end
|
48
|
+
|
49
|
+
def spec_file
|
50
|
+
spec_dir.join("#{spec.full_name}.gemspec")
|
51
|
+
end
|
52
|
+
|
53
|
+
def gem_dir
|
54
|
+
gem_home.join(GEMS_DIR, spec.full_name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def extract_files
|
58
|
+
@gem.extract_files gem_dir
|
59
|
+
end
|
60
|
+
|
61
|
+
def write_specification
|
62
|
+
::File.open(spec_file, 'w') do |file|
|
63
|
+
spec.installed_by_version = ::Gem.rubygems_version
|
64
|
+
file.puts spec.to_ruby_for_cache
|
65
|
+
file.fsync rescue nil # Force writing to disk
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def post_install_message
|
70
|
+
spec.post_install_message if display_post_install_message?
|
71
|
+
end
|
72
|
+
|
73
|
+
def display_post_install_message?
|
74
|
+
@display_post_install_message && !spec.post_install_message.nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
def copy_gem_file_to_cache
|
78
|
+
destination = ::File.join(cache_dir, ::File.basename(@gem_file))
|
79
|
+
FileUtils.cp(@gem_file, destination)
|
80
|
+
end
|
81
|
+
|
82
|
+
def create_destination_folders
|
83
|
+
FileUtils.mkdir_p(gem_home)
|
84
|
+
FileUtils.mkdir_p(gem_dir)
|
85
|
+
FileUtils.mkdir_p(spec_dir)
|
86
|
+
FileUtils.mkdir_p(cache_dir)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "jar_dependencies"
|
2
|
+
|
3
|
+
def require_jar( *args )
|
4
|
+
return nil unless Jars.require?
|
5
|
+
result = Jars.require_jar( *args )
|
6
|
+
if result.is_a? String
|
7
|
+
# JAR_DEBUG=1 will now show theses
|
8
|
+
Jars.debug { "--- jar coordinate #{args[0..-2].join( ':' )} already loaded with version #{result} - omit version #{args[-1]}" }
|
9
|
+
Jars.debug { " try to load from #{caller.join("\n\t")}" }
|
10
|
+
return false
|
11
|
+
end
|
12
|
+
Jars.debug { " register #{args.inspect} - #{result == true}" }
|
13
|
+
result
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "uri"
|
3
|
+
require "java"
|
4
|
+
require "erb"
|
5
|
+
|
6
|
+
module Ji2p
|
7
|
+
extend self
|
8
|
+
|
9
|
+
# Apply HTTP_PROXY and HTTPS_PROXY to the current environment
|
10
|
+
# this will be used by any JRUBY calls
|
11
|
+
def apply_env_proxy_settings(settings)
|
12
|
+
$stderr.puts("Using proxy #{settings}") if ENV["DEBUG"]
|
13
|
+
scheme = settings[:protocol].downcase
|
14
|
+
java.lang.System.setProperty("#{scheme}.proxyHost", settings[:host])
|
15
|
+
java.lang.System.setProperty("#{scheme}.proxyPort", settings[:port].to_s)
|
16
|
+
java.lang.System.setProperty("#{scheme}.proxyUsername", settings[:username].to_s)
|
17
|
+
java.lang.System.setProperty("#{scheme}.proxyPassword", settings[:password].to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
def extract_proxy_values_from_uri(proxy_uri)
|
21
|
+
{
|
22
|
+
:protocol => proxy_uri.scheme,
|
23
|
+
:host => proxy_uri.host,
|
24
|
+
:port => proxy_uri.port,
|
25
|
+
:username => proxy_uri.user,
|
26
|
+
:password => proxy_uri.password
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_proxy_string(proxy_string)
|
31
|
+
proxy_uri = URI.parse(proxy_string)
|
32
|
+
if proxy_uri.kind_of?(URI::HTTP) # URI::HTTPS is already a subclass of URI::HTTP
|
33
|
+
proxy_uri
|
34
|
+
else
|
35
|
+
raise "Invalid proxy `#{proxy_uri}`. The URI is not HTTP/HTTPS."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_proxy(key)
|
40
|
+
ENV[key.downcase] || ENV[key.upcase]
|
41
|
+
end
|
42
|
+
|
43
|
+
def proxy_string_exists?(proxy)
|
44
|
+
!proxy.nil? && !proxy.strip.empty?
|
45
|
+
end
|
46
|
+
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
|