ji2p 0.0.4-universal-java-11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 563acf41129f561bc21498f4b986bcc83c77de6f50b2670f19752c84dfb65705
|
4
|
+
data.tar.gz: 6e7d8d1f4d0148a02b0cc617b13bc9dcba4f35d4b9d8939ce2e75a96f9e5637d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccf9a3813689bcdf558696ef73903e1abd84bff54579bdc01bcb1b3e39ce72bdc49feec5a6a251200de647dac850585661e94f0fc3356b9f93cde5425df13403
|
7
|
+
data.tar.gz: 4f1e9d56595040753aa47024fd9c35a26ff6d33b92c29175c2f8d5e5e81cf12a0ef33c2c37b57de0a79b8eabda025374c517836def69c4004f63360e47e719c4
|
data/bin/bundle
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
# Exit cleanly from an early interrupt
|
3
|
+
Signal.trap("INT") { exit 1 }
|
4
|
+
|
5
|
+
require_relative "../lib/ji2p/environment"
|
6
|
+
require_relative "../lib/ji2p/bundler"
|
7
|
+
|
8
|
+
Ji2p::Bundler.setup!
|
9
|
+
|
10
|
+
require "bundler/cli"
|
11
|
+
require "bundler/friendly_errors"
|
12
|
+
|
13
|
+
::Bundler.with_friendly_errors do
|
14
|
+
::Bundler::CLI.start(ARGV, :debug => true)
|
15
|
+
end
|
data/bin/ctxirb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
3
|
+
require 'bundler/setup'
|
4
|
+
lib = File.expand_path("../lib", __dir__)
|
5
|
+
$:.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
#puts $:
|
7
|
+
|
8
|
+
#require 'active_support'
|
9
|
+
#require 'active_support/core_ext'
|
10
|
+
|
11
|
+
require 'irb'
|
12
|
+
require 'irb/completion'
|
13
|
+
require 'irb/ext/save-history'
|
14
|
+
|
15
|
+
# Method to pretty-print object methods
|
16
|
+
# Coded by sebastian delmont
|
17
|
+
# http://snippets.dzone.com/posts/show/2916
|
18
|
+
class Object
|
19
|
+
ANSI_BOLD = "\033[1m"
|
20
|
+
ANSI_RESET = "\033[0m"
|
21
|
+
ANSI_LGRAY = "\033[0;37m"
|
22
|
+
ANSI_GRAY = "\033[1;30m"
|
23
|
+
# Print object's methods
|
24
|
+
def pm(*options)
|
25
|
+
methods = self.methods
|
26
|
+
methods -= Object.methods unless options.include? :more
|
27
|
+
filter = options.select {|opt| opt.kind_of? Regexp}.first
|
28
|
+
methods = methods.select {|name| name =~ filter} if filter
|
29
|
+
|
30
|
+
data = methods.sort.collect do |name|
|
31
|
+
method = self.method(name)
|
32
|
+
if method.arity == 0
|
33
|
+
args = "()"
|
34
|
+
elsif method.arity > 0
|
35
|
+
n = method.arity
|
36
|
+
args = "(#{(1..n).collect {|i| "arg#{i}"}.join(", ")})"
|
37
|
+
elsif method.arity < 0
|
38
|
+
n = -method.arity
|
39
|
+
args = "(#{(1..n).collect {|i| "arg#{i}"}.join(", ")}, ...)"
|
40
|
+
end
|
41
|
+
klass = $1 if method.inspect =~ /Method: (.*?)#/
|
42
|
+
[name, args, klass]
|
43
|
+
end
|
44
|
+
max_name = data.collect {|item| item[0].size}.max
|
45
|
+
max_args = data.collect {|item| item[1].size}.max
|
46
|
+
data.each do |item|
|
47
|
+
print " #{ANSI_BOLD}#{item[0].to_s.rjust(max_name)}#{ANSI_RESET}"
|
48
|
+
print "#{ANSI_GRAY}#{item[1].ljust(max_args)}#{ANSI_RESET}"
|
49
|
+
print " #{ANSI_LGRAY}#{item[2]}#{ANSI_RESET}\n"
|
50
|
+
end
|
51
|
+
data.size
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module IRB # :nodoc:
|
56
|
+
def self.start_session(binding)
|
57
|
+
unless @__initialized
|
58
|
+
args = ARGV
|
59
|
+
ARGV.replace(ARGV.dup)
|
60
|
+
IRB.setup(nil)
|
61
|
+
ARGV.replace(args)
|
62
|
+
@__initialized = true
|
63
|
+
end
|
64
|
+
|
65
|
+
workspace = WorkSpace.new(binding)
|
66
|
+
|
67
|
+
irb = Irb.new(workspace)
|
68
|
+
|
69
|
+
@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
|
70
|
+
@CONF[:MAIN_CONTEXT] = irb.context
|
71
|
+
@CONF[:SAVE_HISTORY] = 10000
|
72
|
+
@CONF[:HISTORY_FILE] = File.join(ENV['PWD'], '.irb-history')
|
73
|
+
@CONF[:BACK_TRACE_LIMIT] = 16
|
74
|
+
@CONF[:USE_READLINE] = true
|
75
|
+
@CONF[:AUTO_INDENT] = true
|
76
|
+
histfile = @CONF[:HISTORY_FILE]
|
77
|
+
|
78
|
+
#puts @CONF
|
79
|
+
maxsize = @CONF[:SAVE_HISTORY]
|
80
|
+
|
81
|
+
if File::exists?(histfile)
|
82
|
+
lines = IO::readlines(histfile).collect { |line| line.chomp }
|
83
|
+
puts "Read #{lines.nitems} saved history commands from '#{histfile}'." if $VERBOSE
|
84
|
+
Readline::HISTORY.push(*lines)
|
85
|
+
end
|
86
|
+
|
87
|
+
Kernel::at_exit do
|
88
|
+
lines = Readline::HISTORY.to_a.reverse.uniq.reverse
|
89
|
+
lines = lines[-maxsize, maxsize] if lines.length > maxsize
|
90
|
+
puts "Saving #{lines.length} history lines to '#{histfile}'."
|
91
|
+
File::open(histfile, File::WRONLY|File::CREAT|File::TRUNC) { |io| io.puts lines.join("\n") }
|
92
|
+
end
|
93
|
+
|
94
|
+
catch(:IRB_EXIT) do
|
95
|
+
irb.eval_input
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
require 'ji2p'
|
101
|
+
|
102
|
+
#Module.class_eval { def instance_methods(value);[];end } unless Module.methods.include? 'instance_methods'
|
103
|
+
|
104
|
+
def reload!(print = true)
|
105
|
+
puts 'Reloading ...' if print
|
106
|
+
# Main project directory.
|
107
|
+
root_dir = File.expand_path('..', __dir__)
|
108
|
+
# Directories within the project that should be reloaded.
|
109
|
+
reload_dirs = %w{lib}
|
110
|
+
# Loop through and reload every file in all relevant project directories.
|
111
|
+
reload_dirs.each do |dir|
|
112
|
+
Dir.glob("#{root_dir}/#{dir}/**/*.rb").each { |f| load(f) }
|
113
|
+
end
|
114
|
+
# Return true when complete.
|
115
|
+
true
|
116
|
+
end
|
117
|
+
|
118
|
+
IRB.start_session(binding)
|
119
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
3
|
+
require 'bundler/setup'
|
4
|
+
lib = File.expand_path("../lib", __dir__)
|
5
|
+
$:.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
#puts $:
|
7
|
+
|
8
|
+
require 'ji2p'
|
9
|
+
|
10
|
+
app = Proc.new { |env| ['200', {'Content-Type' => 'text/html'}, ['get rack\'d']] }
|
11
|
+
|
12
|
+
kp = Ji2p::Control::Keypair.generate!
|
13
|
+
ssmgr = Ji2p::Control::SocketManager.defineManager! "testing", kp
|
14
|
+
ssmgr.connectTunnel
|
15
|
+
socket = ssmgr.getServerSocket
|
16
|
+
server = Ji2p::Server::HttpServer.new(app, socket)
|
17
|
+
|
18
|
+
puts "Your destination: #{kp.dest.base32}"
|
19
|
+
|
20
|
+
server.run
|
data/bin/simple_outproxy
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
3
|
+
require 'bundler/setup'
|
4
|
+
lib = File.expand_path("../lib", __dir__)
|
5
|
+
$:.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
#puts $:
|
7
|
+
|
8
|
+
require 'socket'
|
9
|
+
require 'uri'
|
10
|
+
require 'ji2p'
|
11
|
+
|
12
|
+
class Proxy
|
13
|
+
def run socket
|
14
|
+
begin
|
15
|
+
@socket = socket
|
16
|
+
|
17
|
+
# Handle every request in another thread
|
18
|
+
loop do
|
19
|
+
s = @socket.accept
|
20
|
+
Thread.new s, &method(:handle_request)
|
21
|
+
end
|
22
|
+
|
23
|
+
# CTRL-C
|
24
|
+
rescue Interrupt
|
25
|
+
puts 'Got Interrupt..'
|
26
|
+
# Ensure that we release the socket on errors
|
27
|
+
ensure
|
28
|
+
if @socket
|
29
|
+
@socket.close
|
30
|
+
puts 'Socked closed..'
|
31
|
+
end
|
32
|
+
puts 'Quitting.'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def handle_request to_client
|
37
|
+
request_line = to_client.readline
|
38
|
+
|
39
|
+
verb = request_line[/^\w+/]
|
40
|
+
url = request_line[/^\w+\s+(\S+)/, 1]
|
41
|
+
version = request_line[/HTTP\/(1\.\d)\s*$/, 1]
|
42
|
+
uri = URI::parse url
|
43
|
+
|
44
|
+
# Show what got requested
|
45
|
+
puts((" %4s "%verb) + url)
|
46
|
+
|
47
|
+
to_server = TCPSocket.new(uri.host, (uri.port.nil? ? 80 : uri.port))
|
48
|
+
to_server.write("#{verb} #{uri.path}?#{uri.query} HTTP/#{version}\r\n")
|
49
|
+
|
50
|
+
content_len = 0
|
51
|
+
|
52
|
+
loop do
|
53
|
+
line = to_client.readline
|
54
|
+
|
55
|
+
if line =~ /^Content-Length:\s+(\d+)\s*$/
|
56
|
+
content_len = $1.to_i
|
57
|
+
end
|
58
|
+
|
59
|
+
# Strip proxy headers
|
60
|
+
if line =~ /^proxy/i
|
61
|
+
next
|
62
|
+
elsif line.strip.empty?
|
63
|
+
to_server.write("Connection: close\r\n\r\n")
|
64
|
+
|
65
|
+
if content_len >= 0
|
66
|
+
to_server.write(to_client.read(content_len))
|
67
|
+
end
|
68
|
+
|
69
|
+
break
|
70
|
+
else
|
71
|
+
to_server.write(line)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
buff = ""
|
76
|
+
loop do
|
77
|
+
to_server.read(4048, buff)
|
78
|
+
to_client.write(buff)
|
79
|
+
break if buff.size < 4048
|
80
|
+
end
|
81
|
+
|
82
|
+
# Close the sockets
|
83
|
+
to_client.close
|
84
|
+
to_server.close
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
kp = Ji2p::Control::Keypair.generate!
|
91
|
+
ssmgr = Ji2p::Control::SocketManager.defineManager! "testing", kp
|
92
|
+
ssmgr.connectTunnel
|
93
|
+
socket = ssmgr.getServerSocket
|
94
|
+
puts "Your destination: #{kp.dest.base32}"
|
95
|
+
|
96
|
+
Proxy.new.run socket
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActorSystem
|
2
|
+
module Concurrent
|
3
|
+
class Processor
|
4
|
+
def self.start(concurrency = 1)
|
5
|
+
concurrency.times { |n| new("Processor #{n}") }
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(name)
|
9
|
+
thread = Thread.new do
|
10
|
+
loop do
|
11
|
+
payload = Magique.backend.pop
|
12
|
+
worker_class = payload[:worker]
|
13
|
+
worker_class.new.perform(*payload[:args])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
thread.name = name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
3
|
+
module ActorSystem
|
4
|
+
module Minimal
|
5
|
+
|
6
|
+
module Actor # To use this, you'd include Actor instead of Celluloid
|
7
|
+
module ClassMethods
|
8
|
+
def new(*args, &block)
|
9
|
+
Proxy.new(super)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def included(klass)
|
15
|
+
klass.extend(ClassMethods)
|
16
|
+
end
|
17
|
+
|
18
|
+
def current
|
19
|
+
Thread.current[:actor]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Proxy
|
24
|
+
def initialize(target)
|
25
|
+
@target = target
|
26
|
+
@mailbox = Queue.new
|
27
|
+
@mutex = Mutex.new
|
28
|
+
@running = true
|
29
|
+
|
30
|
+
@async_proxy = AsyncProxy.new(self)
|
31
|
+
|
32
|
+
@thread = Thread.new do
|
33
|
+
Thread.current[:actor] = self
|
34
|
+
process_inbox
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def async
|
39
|
+
@async_proxy
|
40
|
+
end
|
41
|
+
|
42
|
+
def send_later(meth, *args)
|
43
|
+
@mailbox << [meth, args]
|
44
|
+
end
|
45
|
+
|
46
|
+
def terminate
|
47
|
+
@running = false
|
48
|
+
end
|
49
|
+
|
50
|
+
def method_missing(meth, *args)
|
51
|
+
process_message(meth, *args)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def process_inbox
|
57
|
+
while @running
|
58
|
+
meth, args = @mailbox.pop
|
59
|
+
process_message(meth, *args)
|
60
|
+
end
|
61
|
+
|
62
|
+
rescue Exception => ex
|
63
|
+
puts "Error while running actor: #{ex}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def process_message(meth, *args)
|
67
|
+
@mutex.synchronize do
|
68
|
+
@target.public_send(meth, *args)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class AsyncProxy
|
74
|
+
def initialize(actor)
|
75
|
+
@actor = actor
|
76
|
+
end
|
77
|
+
|
78
|
+
def method_missing(meth, *args)
|
79
|
+
@actor.send_later(meth, *args)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module ActorSystem
|
2
|
+
module Core
|
3
|
+
module ObservableImplementation
|
4
|
+
def observers
|
5
|
+
@observers || @observers = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def notify_observers(*args)
|
9
|
+
observers.each do |observer|
|
10
|
+
mutex.synchronize do
|
11
|
+
observer.observer_update(*args) if observer.respond_to? :observer_update
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_observer(object)
|
17
|
+
mutex.synchronize do
|
18
|
+
observers << object
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def mutex
|
25
|
+
@mutex ||= Mutex.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class ObservableExample
|
30
|
+
include ObservableImplementation
|
31
|
+
attr_accessor :counter
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
self.counter = 0
|
35
|
+
end
|
36
|
+
|
37
|
+
def tick
|
38
|
+
self.counter += 1
|
39
|
+
notify_observers(counter)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class ObserverExample
|
44
|
+
def initialize(observable)
|
45
|
+
observable.add_observer(self)
|
46
|
+
end
|
47
|
+
|
48
|
+
def observer_update(counter)
|
49
|
+
puts "Count has increased by: #{counter}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# observable = Observable.new
|
54
|
+
# observer1 = Observer.new(observable)
|
55
|
+
# observer2 = Observer.new(observable)
|
56
|
+
# observable.tick
|
57
|
+
end
|
58
|
+
end
|