dizby 1.5.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.rubocop.yml +2 -47
  4. data/.travis.yml +7 -7
  5. data/.yardopts +1 -16
  6. data/Gemfile +2 -17
  7. data/Rakefile +2 -8
  8. data/dizby.gemspec +9 -2
  9. data/lib/dizby.rb +0 -1
  10. data/lib/dizby/access/control_list.rb +1 -2
  11. data/lib/dizby/access/entry.rb +1 -2
  12. data/lib/dizby/access/insecure.rb +4 -5
  13. data/lib/dizby/access/list.rb +0 -1
  14. data/lib/dizby/converter/simple.rb +0 -1
  15. data/lib/dizby/converter/timed.rb +0 -1
  16. data/lib/dizby/distributed/array.rb +0 -1
  17. data/lib/dizby/distributed/object.rb +9 -9
  18. data/lib/dizby/distributed/proxy.rb +7 -7
  19. data/lib/dizby/distributed/semi_proxy.rb +2 -2
  20. data/lib/dizby/distributed/undumpable.rb +1 -2
  21. data/lib/dizby/distributed/unknown.rb +0 -1
  22. data/lib/dizby/error.rb +0 -1
  23. data/lib/dizby/protocol/basic.rb +0 -1
  24. data/lib/dizby/protocol/manager.rb +17 -20
  25. data/lib/dizby/protocol/refined.rb +0 -1
  26. data/{gemfiles/Gemfile.ci → lib/dizby/protocol/structs.rb} +4 -5
  27. data/lib/dizby/protocols/dead.rb +3 -4
  28. data/lib/dizby/protocols/secure.rb +18 -12
  29. data/lib/dizby/protocols/tcp.rb +19 -15
  30. data/lib/dizby/protocols/unix.rb +15 -15
  31. data/lib/dizby/server/abstract.rb +7 -5
  32. data/lib/dizby/server/basic.rb +5 -9
  33. data/lib/dizby/server/registration.rb +0 -1
  34. data/lib/dizby/service.rb +10 -8
  35. data/lib/dizby/stream/client.rb +0 -1
  36. data/lib/dizby/stream/connection.rb +2 -3
  37. data/lib/dizby/stream/messenger.rb +0 -1
  38. data/lib/dizby/stream/query_ref.rb +0 -1
  39. data/lib/dizby/stream/readable.rb +5 -6
  40. data/lib/dizby/stream/writable.rb +0 -1
  41. data/lib/dizby/tunnel/abstract.rb +10 -18
  42. data/lib/dizby/tunnel/basic.rb +2 -3
  43. data/lib/dizby/tunnel/basic_spawn.rb +4 -5
  44. data/lib/dizby/tunnel/bidirectional_strategy.rb +0 -1
  45. data/lib/dizby/tunnel/factory.rb +0 -1
  46. data/lib/dizby/tunnel/local_strategy.rb +0 -1
  47. data/lib/dizby/tunnel/spawn_command.rb +0 -1
  48. data/lib/dizby/tunnel/spawned.rb +0 -1
  49. data/lib/dizby/tunnel/tunnelable_local.rb +0 -1
  50. data/lib/dizby/tunnel/tunnelable_remote.rb +1 -2
  51. data/lib/dizby/utility/configurable.rb +0 -1
  52. data/lib/dizby/utility/io_barrier.rb +0 -1
  53. data/lib/dizby/utility/log.rb +0 -1
  54. data/lib/dizby/utility/monitor.rb +0 -1
  55. data/lib/dizby/utility/self_pipe.rb +0 -1
  56. data/lib/dizby/utility/semi_built.rb +0 -1
  57. data/lib/dizby/utility/string.rb +0 -1
  58. data/lib/dizby/utility/timed_collection.rb +0 -1
  59. data/lib/dizby/utility/timed_state.rb +0 -1
  60. data/lib/dizby/version.rb +1 -2
  61. data/lib/dizby/worker/connection.rb +0 -1
  62. data/lib/dizby/worker/invoke_method.rb +1 -2
  63. data/lib/dizby/worker/server.rb +0 -1
  64. data/test/test_helper.rb +1 -14
  65. metadata +93 -19
  66. data/gemfiles/Gemfile.doc +0 -12
  67. data/lib/dizby/utility/classic_access.rb +0 -31
  68. data/lib/dizby/utility/delegator.rb +0 -34
  69. data/lib/dizby/utility/force_bind.rb +0 -27
  70. data/lib/dizby/utility/polymorphic_delegated.rb +0 -65
  71. data/tasks/ghpages.rake +0 -33
  72. data/tasks/rubocop.rake +0 -14
  73. data/tasks/test.rake +0 -25
  74. data/tasks/yard.rake +0 -13
@@ -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
@@ -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
- eval_gemfile File.expand_path('../Gemfile', __dir__)
9
-
10
- group :development do
11
- gem 'codecov', require: false
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
@@ -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
- fail NonAcceptingServer, Server.new(config)
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
- fail DistributedError,
26
- 'distributed objects not supported from DeadProtocol'
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(:spawn,
24
- "#{scheme}://%{user}?%{host}%{port}?%{query}?"
25
- ) do |server, command, (user, host, port, query)|
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(command, user, host)
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(delegate, socket,
34
- "#{scheme}://#{host}:#{tunnel.remote_port}")
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(:client,
41
- "#{scheme}://%{user}?%{host}%{port}%{query}?"
42
- ) do |server, (user, host, port, query)|
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
 
@@ -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(:server,
22
- "#{scheme}://%{host}?%{port}?"
23
- ) do |front, config, (host, port)|
20
+ refine(
21
+ :server,
22
+ "#{scheme}://%{host}?%{port}?"
23
+ ) do |args, (host, port)|
24
24
  port &&= port.to_i
25
25
 
26
- Server.new front, config, host, port
26
+ Server.new args, host, port
27
27
  end
28
28
 
29
- refine(:client,
30
- "#{scheme}://%{host}?%{port}?%{query}?"
31
- ) do |server, (host, port, query)|
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
- include PolymorphicDelegated
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 == 0
67
+ port = socket.addr[1] if port.zero?
69
68
 
70
- super("drb://#{host}:#{port}", front, socket, config)
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(host, nil, Socket::AF_UNSPEC,
95
- Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE)
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')
@@ -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
- fail LoadError, 'UNIXServer is required' unless defined?(UNIXServer)
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(:server,
25
- "#{scheme}:%{file}?"
26
- ) do |front, config, (filename)|
27
- Server.new front, config, filename
23
+ refine(
24
+ :server,
25
+ "#{scheme}:%{file}?"
26
+ ) do |args, (filename)|
27
+ Server.new args, filename
28
28
  end
29
29
 
30
- refine(:client,
31
- "#{scheme}:%{file}%{query}?"
32
- ) do |server, (filename, query)|
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
- include PolymorphicDelegated
48
-
49
- def initialize(front, config, filename)
48
+ def initialize(args, filename)
50
49
  unless filename
51
- temp = Tempfile.new(%w( dizby-unix .socket ))
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
- super("drbunix:#{filename}", front, socket, config)
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(uri)
26
- ProtocolManager.open_client(self, uri)
27
+ def connect_to(client_args)
28
+ ProtocolManager.open_client(self, client_args)
27
29
  end
28
30
 
29
- def spawn_on(command, uri)
30
- ProtocolManager.spawn_server(self, command, uri)
31
+ def spawn_on(spawn_args)
32
+ ProtocolManager.spawn_server(self, spawn_args)
31
33
  end
32
34
 
33
35
  def shutdown; 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
@@ -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
- extend ClassicAttributeAccess
15
+ def initialize(args, stream)
16
+ super(args.config) { |msg| "#{args.uri} : #{msg}" }
18
17
 
19
- def initialize(uri, front, stream, config)
20
- super(config) { |msg| "#{uri} : #{msg}" }
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
- fail LocalServerShutdown if readables.include? shutdown_pipe.read
44
+ raise LocalServerShutdown if readables.include? shutdown_pipe.read
49
45
  log.debug('Accepting connection')
50
46
  stream.accept
51
47
  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
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 = '', front = nil, config = {})
14
+ def initialize(uri: '', front: nil, **config)
16
15
  config = DEFAULT_CONFIG.merge(config)
17
16
 
18
- self.server = ProtocolManager.open_server(uri, front, config)
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
- ObjectProxy.new(*@server.connect_to(uri))
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, uri)
35
- ObjectProxy.new(*@server.spawn_on(command, uri))
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
- fail DistributedError, 'server could not be opened' unless srvr
64
+ raise DistributedError, 'server could not be opened' unless srvr
63
65
  @server = srvr
64
66
  end
65
67
  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
@@ -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
- fail ConnectionError, 'too many arguments' if @server.argc_limit < argc
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
- fail RemoteServerShutdown if readable.include?(shutdown_pipe.read)
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
@@ -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
@@ -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
- fail ConnectionError, 'connection closed' unless str
15
+ raise ConnectionError, 'connection closed' unless str
17
16
 
18
17
  if str.size < sz
19
- fail ConnectionError, 'premature marshal format(can\'t read)'
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
- fail RemoteServerShutdown unless sz
58
- fail ConnectionError, 'premature header' if sz.size < 4
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
- fail ConnectionError, "too large packet for #{sz}"
64
+ raise ConnectionError, "too large packet for #{sz}"
66
65
  end
67
66
 
68
67
  sz