dizby 1.5.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rubocop.yml +2 -47
- data/.travis.yml +7 -7
- data/.yardopts +1 -16
- data/Gemfile +2 -17
- data/Rakefile +2 -8
- data/dizby.gemspec +9 -2
- data/lib/dizby.rb +0 -1
- data/lib/dizby/access/control_list.rb +1 -2
- data/lib/dizby/access/entry.rb +1 -2
- data/lib/dizby/access/insecure.rb +4 -5
- data/lib/dizby/access/list.rb +0 -1
- data/lib/dizby/converter/simple.rb +0 -1
- data/lib/dizby/converter/timed.rb +0 -1
- data/lib/dizby/distributed/array.rb +0 -1
- data/lib/dizby/distributed/object.rb +9 -9
- data/lib/dizby/distributed/proxy.rb +7 -7
- data/lib/dizby/distributed/semi_proxy.rb +2 -2
- data/lib/dizby/distributed/undumpable.rb +1 -2
- data/lib/dizby/distributed/unknown.rb +0 -1
- data/lib/dizby/error.rb +0 -1
- data/lib/dizby/protocol/basic.rb +0 -1
- data/lib/dizby/protocol/manager.rb +17 -20
- data/lib/dizby/protocol/refined.rb +0 -1
- data/{gemfiles/Gemfile.ci → lib/dizby/protocol/structs.rb} +4 -5
- data/lib/dizby/protocols/dead.rb +3 -4
- data/lib/dizby/protocols/secure.rb +18 -12
- data/lib/dizby/protocols/tcp.rb +19 -15
- data/lib/dizby/protocols/unix.rb +15 -15
- data/lib/dizby/server/abstract.rb +7 -5
- data/lib/dizby/server/basic.rb +5 -9
- data/lib/dizby/server/registration.rb +0 -1
- data/lib/dizby/service.rb +10 -8
- data/lib/dizby/stream/client.rb +0 -1
- data/lib/dizby/stream/connection.rb +2 -3
- data/lib/dizby/stream/messenger.rb +0 -1
- data/lib/dizby/stream/query_ref.rb +0 -1
- data/lib/dizby/stream/readable.rb +5 -6
- data/lib/dizby/stream/writable.rb +0 -1
- data/lib/dizby/tunnel/abstract.rb +10 -18
- data/lib/dizby/tunnel/basic.rb +2 -3
- data/lib/dizby/tunnel/basic_spawn.rb +4 -5
- data/lib/dizby/tunnel/bidirectional_strategy.rb +0 -1
- data/lib/dizby/tunnel/factory.rb +0 -1
- data/lib/dizby/tunnel/local_strategy.rb +0 -1
- data/lib/dizby/tunnel/spawn_command.rb +0 -1
- data/lib/dizby/tunnel/spawned.rb +0 -1
- data/lib/dizby/tunnel/tunnelable_local.rb +0 -1
- data/lib/dizby/tunnel/tunnelable_remote.rb +1 -2
- data/lib/dizby/utility/configurable.rb +0 -1
- data/lib/dizby/utility/io_barrier.rb +0 -1
- data/lib/dizby/utility/log.rb +0 -1
- data/lib/dizby/utility/monitor.rb +0 -1
- data/lib/dizby/utility/self_pipe.rb +0 -1
- data/lib/dizby/utility/semi_built.rb +0 -1
- data/lib/dizby/utility/string.rb +0 -1
- data/lib/dizby/utility/timed_collection.rb +0 -1
- data/lib/dizby/utility/timed_state.rb +0 -1
- data/lib/dizby/version.rb +1 -2
- data/lib/dizby/worker/connection.rb +0 -1
- data/lib/dizby/worker/invoke_method.rb +1 -2
- data/lib/dizby/worker/server.rb +0 -1
- data/test/test_helper.rb +1 -14
- metadata +93 -19
- data/gemfiles/Gemfile.doc +0 -12
- data/lib/dizby/utility/classic_access.rb +0 -31
- data/lib/dizby/utility/delegator.rb +0 -34
- data/lib/dizby/utility/force_bind.rb +0 -27
- data/lib/dizby/utility/polymorphic_delegated.rb +0 -65
- data/tasks/ghpages.rake +0 -33
- data/tasks/rubocop.rake +0 -14
- data/tasks/test.rake +0 -25
- data/tasks/yard.rake +0 -13
@@ -1,12 +1,11 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# Copyright (c) 2016 Nathan Currier
|
3
2
|
|
4
3
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
5
4
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
6
5
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
module Dizby
|
8
|
+
ServerArguments = Struct.new(:uri, :front, :config)
|
9
|
+
ClientArguments = Struct.new(:uri, :options)
|
10
|
+
SpawnArguments = Struct.new(:uri, :command, :options)
|
12
11
|
end
|
data/lib/dizby/protocols/dead.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# Copyright (c) 2016 Nathan Currier
|
3
2
|
|
4
3
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
@@ -15,15 +14,15 @@ module Dizby
|
|
15
14
|
self.scheme = ''
|
16
15
|
|
17
16
|
refine(:server, '') do |_, config|
|
18
|
-
|
17
|
+
raise NonAcceptingServer, Server.new(config)
|
19
18
|
end
|
20
19
|
|
21
20
|
class Server < AbstractServer
|
22
21
|
# A DeadProtocol server doesn't allow backwards connections
|
23
22
|
# therefore, making a distributed object goes against that.
|
24
23
|
def make_distributed(*_)
|
25
|
-
|
26
|
-
|
24
|
+
raise DistributedError,
|
25
|
+
'distributed objects not supported from DeadProtocol'
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# Copyright (c) 2016 Nathan Currier
|
3
2
|
|
4
3
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
@@ -10,6 +9,7 @@ require 'dizby/stream/client'
|
|
10
9
|
require 'dizby/stream/connection'
|
11
10
|
require 'dizby/server/basic'
|
12
11
|
require 'dizby/tunnel/basic'
|
12
|
+
require 'dizby/tunnel/basic_spawn'
|
13
13
|
require 'dizby/tunnel/factory'
|
14
14
|
|
15
15
|
require 'socket'
|
@@ -20,30 +20,36 @@ module Dizby
|
|
20
20
|
|
21
21
|
self.scheme = 'drbsec'
|
22
22
|
|
23
|
-
refine(
|
24
|
-
|
25
|
-
|
23
|
+
refine(
|
24
|
+
:spawn,
|
25
|
+
"#{scheme}://%{user}?%{host}%{port}?%{query}?"
|
26
|
+
) do |args, server, (user, host, port, query)|
|
27
|
+
port &&= port.to_i
|
28
|
+
|
26
29
|
factory = TunnelFactory.new(server, port)
|
27
|
-
tunnel = factory.create(BasicSpawnTunnel).with(
|
30
|
+
tunnel = factory.create(BasicSpawnTunnel).with(user, host, args)
|
28
31
|
|
29
32
|
socket = TCPSocket.open('localhost', tunnel.local_port)
|
30
33
|
TCProtocol.apply_sockopt(socket)
|
31
34
|
|
32
35
|
delegate = delegatable_tunnel(factory, server, tunnel)
|
33
|
-
client = BasicClient.new(
|
34
|
-
|
36
|
+
client = BasicClient.new(
|
37
|
+
delegate, socket, "#{scheme}://#{host}:#{tunnel.remote_port}"
|
38
|
+
)
|
39
|
+
|
35
40
|
query &&= QueryRef.new(query)
|
36
41
|
|
37
42
|
[client, query]
|
38
43
|
end
|
39
44
|
|
40
|
-
refine(
|
41
|
-
|
42
|
-
|
45
|
+
refine(
|
46
|
+
:client,
|
47
|
+
"#{scheme}://%{user}?%{host}%{port}%{query}?"
|
48
|
+
) do |args, server, (user, host, port, query)|
|
43
49
|
port &&= port.to_i
|
44
50
|
|
45
51
|
factory = TunnelFactory.new(server, port)
|
46
|
-
tunnel = factory.create(BasicTunnel).with(user, host)
|
52
|
+
tunnel = factory.create(BasicTunnel).with(user, host, args)
|
47
53
|
|
48
54
|
socket = TCPSocket.open('localhost', tunnel.local_port)
|
49
55
|
TCProtocol.apply_sockopt(socket)
|
@@ -63,7 +69,7 @@ module Dizby
|
|
63
69
|
end
|
64
70
|
end
|
65
71
|
|
66
|
-
class DirectTunnel < Delegator
|
72
|
+
class DirectTunnel < PolyDelegate::Delegator
|
67
73
|
def initialize(server, tunnel)
|
68
74
|
super(server)
|
69
75
|
|
data/lib/dizby/protocols/tcp.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# Copyright (c) 2016 Nathan Currier
|
3
2
|
|
4
3
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
@@ -18,17 +17,19 @@ module Dizby
|
|
18
17
|
|
19
18
|
self.scheme = 'drb'
|
20
19
|
|
21
|
-
refine(
|
22
|
-
|
23
|
-
|
20
|
+
refine(
|
21
|
+
:server,
|
22
|
+
"#{scheme}://%{host}?%{port}?"
|
23
|
+
) do |args, (host, port)|
|
24
24
|
port &&= port.to_i
|
25
25
|
|
26
|
-
Server.new
|
26
|
+
Server.new args, host, port
|
27
27
|
end
|
28
28
|
|
29
|
-
refine(
|
30
|
-
|
31
|
-
|
29
|
+
refine(
|
30
|
+
:client,
|
31
|
+
"#{scheme}://%{host}?%{port}?%{query}?"
|
32
|
+
) do |_args, server, (host, port, query)|
|
32
33
|
port &&= port.to_i
|
33
34
|
|
34
35
|
socket = TCPSocket.open(host, port)
|
@@ -53,9 +54,7 @@ module Dizby
|
|
53
54
|
end
|
54
55
|
|
55
56
|
class Server < BasicServer
|
56
|
-
|
57
|
-
|
58
|
-
def initialize(front, config, host, port)
|
57
|
+
def initialize(args, host, port)
|
59
58
|
port ||= 0
|
60
59
|
|
61
60
|
if host.empty?
|
@@ -65,9 +64,10 @@ module Dizby
|
|
65
64
|
socket = TCPServer.open(host, port)
|
66
65
|
end
|
67
66
|
|
68
|
-
port = socket.addr[1] if port
|
67
|
+
port = socket.addr[1] if port.zero?
|
69
68
|
|
70
|
-
|
69
|
+
args.uri = "drb://#{host}:#{port}"
|
70
|
+
super(args, socket)
|
71
71
|
|
72
72
|
TCProtocol.apply_sockopt(socket)
|
73
73
|
|
@@ -89,10 +89,14 @@ module Dizby
|
|
89
89
|
end
|
90
90
|
|
91
91
|
config_reader :tcp_acl
|
92
|
+
private :tcp_acl
|
92
93
|
|
93
94
|
def self.open_socket_inaddr_any(host, port)
|
94
|
-
infos = Socket.getaddrinfo(
|
95
|
-
|
95
|
+
infos = Socket.getaddrinfo(
|
96
|
+
host, nil, Socket::AF_UNSPEC,
|
97
|
+
Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE
|
98
|
+
)
|
99
|
+
|
96
100
|
families = Hash[*infos.map { |af, *_| af }.uniq.zip([]).flatten]
|
97
101
|
return TCPServer.open('0.0.0.0', port) if families.key?('AF_INET')
|
98
102
|
return TCPServer.open('::', port) if families.key?('AF_INET6')
|
data/lib/dizby/protocols/unix.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# Copyright (c) 2016 Nathan Currier
|
3
2
|
|
4
3
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
@@ -13,7 +12,7 @@ require 'dizby/server/basic'
|
|
13
12
|
require 'socket'
|
14
13
|
require 'tempfile'
|
15
14
|
|
16
|
-
|
15
|
+
raise LoadError, 'UNIXServer is required' unless defined?(UNIXServer)
|
17
16
|
|
18
17
|
module Dizby
|
19
18
|
class UnixProtocol
|
@@ -21,15 +20,17 @@ module Dizby
|
|
21
20
|
|
22
21
|
self.scheme = 'drbunix'
|
23
22
|
|
24
|
-
refine(
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
refine(
|
24
|
+
:server,
|
25
|
+
"#{scheme}:%{file}?"
|
26
|
+
) do |args, (filename)|
|
27
|
+
Server.new args, filename
|
28
28
|
end
|
29
29
|
|
30
|
-
refine(
|
31
|
-
|
32
|
-
|
30
|
+
refine(
|
31
|
+
:client,
|
32
|
+
"#{scheme}:%{file}%{query}?"
|
33
|
+
) do |_args, server, (filename, query)|
|
33
34
|
socket = UNIXSocket.open(filename)
|
34
35
|
UnixProtocol.apply_sockopt(socket)
|
35
36
|
|
@@ -44,11 +45,9 @@ module Dizby
|
|
44
45
|
end
|
45
46
|
|
46
47
|
class Server < BasicServer
|
47
|
-
|
48
|
-
|
49
|
-
def initialize(front, config, filename)
|
48
|
+
def initialize(args, filename)
|
50
49
|
unless filename
|
51
|
-
temp = Tempfile.new(%w(
|
50
|
+
temp = Tempfile.new(%w(dizby-unix .socket))
|
52
51
|
filename = temp.path
|
53
52
|
temp.close!
|
54
53
|
end
|
@@ -56,9 +55,10 @@ module Dizby
|
|
56
55
|
socket = UNIXServer.open(filename)
|
57
56
|
UnixProtocol.apply_sockopt(socket)
|
58
57
|
|
59
|
-
|
58
|
+
args.uri = "drbunix:#{filename}"
|
59
|
+
super(args, socket)
|
60
60
|
|
61
|
-
self.class.set_permissions(filename, config)
|
61
|
+
self.class.set_permissions(filename, args.config)
|
62
62
|
end
|
63
63
|
|
64
64
|
def close
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# Copyright (c) 2016 Nathan Currier
|
3
2
|
|
4
3
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
@@ -10,8 +9,11 @@ require 'dizby/distributed/object'
|
|
10
9
|
require 'dizby/utility/configurable'
|
11
10
|
require 'dizby/utility/log'
|
12
11
|
|
12
|
+
require 'poly_delegate'
|
13
|
+
|
13
14
|
module Dizby
|
14
15
|
class AbstractServer
|
16
|
+
include PolyDelegate::Delegated
|
15
17
|
extend Configurable
|
16
18
|
|
17
19
|
def initialize(config, &log_transform)
|
@@ -22,12 +24,12 @@ module Dizby
|
|
22
24
|
attr_reader :log
|
23
25
|
config_reader :load_limit
|
24
26
|
|
25
|
-
def connect_to(
|
26
|
-
ProtocolManager.open_client(self,
|
27
|
+
def connect_to(client_args)
|
28
|
+
ProtocolManager.open_client(self, client_args)
|
27
29
|
end
|
28
30
|
|
29
|
-
def spawn_on(
|
30
|
-
ProtocolManager.spawn_server(self,
|
31
|
+
def spawn_on(spawn_args)
|
32
|
+
ProtocolManager.spawn_server(self, spawn_args)
|
31
33
|
end
|
32
34
|
|
33
35
|
def shutdown; end
|
data/lib/dizby/server/basic.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# Copyright (c) 2016 Nathan Currier
|
3
2
|
|
4
3
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
@@ -6,7 +5,6 @@
|
|
6
5
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
7
6
|
|
8
7
|
require 'dizby/stream/query_ref'
|
9
|
-
require 'dizby/utility/polymorphic_delegated'
|
10
8
|
require 'dizby/utility/self_pipe'
|
11
9
|
require 'dizby/utility/monitor'
|
12
10
|
|
@@ -14,13 +12,11 @@ require 'io/wait'
|
|
14
12
|
|
15
13
|
module Dizby
|
16
14
|
class BasicServer < AbstractServer
|
17
|
-
|
15
|
+
def initialize(args, stream)
|
16
|
+
super(args.config) { |msg| "#{args.uri} : #{msg}" }
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@uri = uri
|
23
|
-
@front = front
|
18
|
+
@uri = args.uri
|
19
|
+
@front = args.front
|
24
20
|
@stream = stream
|
25
21
|
|
26
22
|
@exported_uri = Dizby.monitor([@uri])
|
@@ -45,7 +41,7 @@ module Dizby
|
|
45
41
|
|
46
42
|
def accept
|
47
43
|
readables, = IO.select([stream, shutdown_pipe.read])
|
48
|
-
|
44
|
+
raise LocalServerShutdown if readables.include? shutdown_pipe.read
|
49
45
|
log.debug('Accepting connection')
|
50
46
|
stream.accept
|
51
47
|
end
|
data/lib/dizby/service.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# Copyright (c) 2016 Nathan Currier
|
3
2
|
|
4
3
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
@@ -12,10 +11,11 @@ require 'dizby/utility/log'
|
|
12
11
|
|
13
12
|
module Dizby
|
14
13
|
class Service
|
15
|
-
def initialize(uri
|
14
|
+
def initialize(uri: '', front: nil, **config)
|
16
15
|
config = DEFAULT_CONFIG.merge(config)
|
17
16
|
|
18
|
-
|
17
|
+
args = ServerArguments.new(uri, front, config)
|
18
|
+
self.server = ProtocolManager.open_server(args)
|
19
19
|
rescue NonAcceptingServer => err
|
20
20
|
# This is to allow servers that don't accept connections
|
21
21
|
# Not all servers will allow connections back to them, so don't allow it
|
@@ -27,12 +27,14 @@ module Dizby
|
|
27
27
|
Dizby.register_server(@server)
|
28
28
|
end
|
29
29
|
|
30
|
-
def connect_to(uri)
|
31
|
-
|
30
|
+
def connect_to(uri:, **options)
|
31
|
+
args = ClientArguments.new(uri, options)
|
32
|
+
ObjectProxy.new(*@server.connect_to(args))
|
32
33
|
end
|
33
34
|
|
34
|
-
def spawn_on(command
|
35
|
-
|
35
|
+
def spawn_on(uri:, command:, **options)
|
36
|
+
args = SpawnArguments.new(uri, command, options)
|
37
|
+
ObjectProxy.new(*@server.spawn_on(args))
|
36
38
|
end
|
37
39
|
|
38
40
|
def close
|
@@ -59,7 +61,7 @@ module Dizby
|
|
59
61
|
private
|
60
62
|
|
61
63
|
def server=(srvr)
|
62
|
-
|
64
|
+
raise DistributedError, 'server could not be opened' unless srvr
|
63
65
|
@server = srvr
|
64
66
|
end
|
65
67
|
end
|
data/lib/dizby/stream/client.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# Copyright (c) 2016 Nathan Currier
|
3
2
|
|
4
3
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
@@ -26,7 +25,7 @@ module Dizby
|
|
26
25
|
ref, msg, argc = Array.new(3) { read }
|
27
26
|
|
28
27
|
@server.log.debug("called through proxy: #{ref} #{msg}")
|
29
|
-
|
28
|
+
raise ConnectionError, 'too many arguments' if @server.argc_limit < argc
|
30
29
|
|
31
30
|
argv = Array.new(argc) { read }
|
32
31
|
block = read
|
@@ -59,7 +58,7 @@ module Dizby
|
|
59
58
|
|
60
59
|
def wait_for_stream
|
61
60
|
readable, = IO.select([@stream, shutdown_pipe.read])
|
62
|
-
|
61
|
+
raise RemoteServerShutdown if readable.include?(shutdown_pipe.read)
|
63
62
|
rescue IOError
|
64
63
|
raise RemoteServerShutdown
|
65
64
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# Copyright (c) 2016 Nathan Currier
|
3
2
|
|
4
3
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
@@ -13,10 +12,10 @@ module Dizby
|
|
13
12
|
sz = check_packet_size(load_size)
|
14
13
|
str = load_packet(sz)
|
15
14
|
|
16
|
-
|
15
|
+
raise ConnectionError, 'connection closed' unless str
|
17
16
|
|
18
17
|
if str.size < sz
|
19
|
-
|
18
|
+
raise ConnectionError, 'premature marshal format(can\'t read)'
|
20
19
|
end
|
21
20
|
|
22
21
|
load_obj(str)
|
@@ -54,15 +53,15 @@ module Dizby
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def check_packet_size(sz)
|
57
|
-
|
58
|
-
|
56
|
+
raise RemoteServerShutdown unless sz
|
57
|
+
raise ConnectionError, 'premature header' if sz.size < 4
|
59
58
|
|
60
59
|
sz = sz.unpack('N')[0]
|
61
60
|
|
62
61
|
# load_limit must be greater than the size of the packet
|
63
62
|
# or the load_limit can be 0 or less to be considered "infinite"
|
64
63
|
if @server.load_limit.between?(0, sz)
|
65
|
-
|
64
|
+
raise ConnectionError, "too large packet for #{sz}"
|
66
65
|
end
|
67
66
|
|
68
67
|
sz
|