dizby 1.5.1 → 2.0.0
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 +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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 38bb5b303f7f0773cd06e2cfaaa4f155444d046f
|
|
4
|
+
data.tar.gz: 72c687978802a978963575d4269c1f1dfa85eb9b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a5a08a6e1f17ee01d269167cb3e1ffeec8a4dd32471ca6cd4965b3819681e4c1be564fafdca6ce58a0663ef96733d1560bd3f81c5c2d3b845d45eda9a8c86a36
|
|
7
|
+
data.tar.gz: c94f327e1100ee6eb4361686dbd5fe15f10e2961ad8ea0226657f2c95e0de2afbb6af32c4b7f7eb3815137baf0bafa00f4bf35043815c25430190c10abcdd98e
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -1,52 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
- 'gemfiles/*'
|
|
6
|
-
- 'tasks/*'
|
|
7
|
-
|
|
8
|
-
Style/Documentation:
|
|
9
|
-
Enabled: false
|
|
3
|
+
inherit_gem:
|
|
4
|
+
rideliner: .rubocop.yml
|
|
10
5
|
|
|
11
6
|
Metrics/MethodLength:
|
|
12
7
|
Max: 12
|
|
13
|
-
|
|
14
|
-
Style/SpecialGlobalVars:
|
|
15
|
-
Enabled: false
|
|
16
|
-
|
|
17
|
-
Style/AutoResourceCleanup:
|
|
18
|
-
Enabled: true
|
|
19
|
-
|
|
20
|
-
Style/CollectionMethods:
|
|
21
|
-
Enabled: true
|
|
22
|
-
|
|
23
|
-
Style/Copyright:
|
|
24
|
-
Enabled: true
|
|
25
|
-
Notice: '^# Copyright \(c\) 2\d{3} .+$'
|
|
26
|
-
|
|
27
|
-
Style/Encoding:
|
|
28
|
-
Enabled: true
|
|
29
|
-
|
|
30
|
-
Style/MethodCalledOnDoEndBlock:
|
|
31
|
-
Enabled: true
|
|
32
|
-
|
|
33
|
-
Style/MultilineArrayBraceLayout:
|
|
34
|
-
Enabled: true
|
|
35
|
-
|
|
36
|
-
Style/MultilineAssignmentLayout:
|
|
37
|
-
Enabled: true
|
|
38
|
-
|
|
39
|
-
Style/OptionHash:
|
|
40
|
-
Enabled: true
|
|
41
|
-
|
|
42
|
-
Style/Send:
|
|
43
|
-
Enabled: true
|
|
44
|
-
|
|
45
|
-
Style/StringMethods:
|
|
46
|
-
Enabled: true
|
|
47
|
-
|
|
48
|
-
Style/SymbolArray:
|
|
49
|
-
Enabled: true
|
|
50
|
-
|
|
51
|
-
Lint/LiteralInInterpolation:
|
|
52
|
-
Enabled: true
|
data/.travis.yml
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
language: ruby
|
|
2
|
-
bundler_args: "--without lint --jobs=3 --retry=3"
|
|
3
2
|
cache: bundler
|
|
3
|
+
dist: trusty
|
|
4
|
+
sudo: required
|
|
4
5
|
before_install:
|
|
5
6
|
- gem update --system
|
|
6
7
|
- gem install bundler
|
|
8
|
+
gemfile: Gemfile
|
|
9
|
+
rvm:
|
|
10
|
+
- 2.2.0
|
|
11
|
+
- rbx
|
|
12
|
+
script: bundle exec rake test
|
|
7
13
|
matrix:
|
|
8
14
|
include:
|
|
9
15
|
- rvm: 2.3.0
|
|
10
|
-
gemfile: gemfiles/Gemfile.ci
|
|
11
16
|
script: bundle exec rake ci
|
|
12
|
-
- rvm: rbx-3.14
|
|
13
|
-
gemfile: Gemfile
|
|
14
|
-
script: bundle exec rake test
|
|
15
17
|
- rvm: 2.3.0
|
|
16
|
-
gemfile: gemfiles/Gemfile.doc
|
|
17
18
|
script: bundle exec rake yard:deploy
|
|
18
19
|
env: DOCS=true
|
|
19
|
-
sudo: false
|
|
20
20
|
env:
|
|
21
21
|
global:
|
|
22
22
|
- secure: eYfZEZYiVMyeIJ9r3jAxgtF9vXDO2jMMJok9PL5tkKIDdi5XmkF2V1cwzzLI69DAPwuhfkPWVbiDgqjD0OHexOJMYipmdpgoZ/2AsSDnbzUDAbfuxjhGCvghD80U4lvb9B/VYWxhcubTsUXjBaivaik859wmajqLi0ROwD3jgm/0AF5oXpyHiIqEkFxQJ7E8D2pUm9kx4IH9uTP+lqrzBOdto2aGc+8XqgewcImC5Qp5ycikbZyPpvEKQDRYp6dHpcInrj+6TpiGW/HCs7R/Luf7BUILIgrV3NT4eFeGRvhdk2ON2v84ke0O8FDtrGje9uQWVn/dT2jL6wAekUyxS5CW225DzKjA6IIr54nQDizFjduFNPFDN4xWZr33e6EfWKe8uAJTOMepCVJ5Gr3jeGkT3xn8VXZLwZ0OZJ4BuKWzDcQqQZd0EQWKhOlhtm32jJ+YrSBWX4tLl8ma9qCLSy2dVKd5qVjIvX221Pg/rsGwO1MpNnV0OL3QUihKQxHPFbL/NNTGkGFnL/lMN85OdPXm6lmPYFS09GUYRYty7zOmBmQI53w7vsIxXjTKxE42od6smvWm3yicH/EKXzHcGmepPDILBWjazEsuXwvAi21y66fOTl1hWPE26+y9UWWmUEPU4uEq1oEFSjrM7qPhc1ZnLNUCY1gSFxQ5KCU1bXc=
|
data/.yardopts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
--readme README.md
|
|
2
1
|
--title Dizby Documentation
|
|
3
|
-
--charset utf-8
|
|
4
|
-
|
|
5
|
-
--markup markdown
|
|
6
|
-
--markup-provider kramdown
|
|
7
|
-
--output-dir _yardoc
|
|
8
|
-
|
|
9
|
-
--protected
|
|
10
|
-
--private
|
|
11
|
-
--default-return ''
|
|
12
|
-
|
|
13
2
|
--plugin yard_dizby
|
|
14
|
-
|
|
15
|
-
lib/**/*.rb
|
|
16
|
-
-
|
|
17
|
-
doc/*.md
|
|
18
|
-
LICENSE.md
|
|
3
|
+
--plugin yard_rideliner
|
data/Gemfile
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
|
|
@@ -7,21 +6,7 @@
|
|
|
7
6
|
|
|
8
7
|
source 'https://rubygems.org'
|
|
9
8
|
|
|
10
|
-
gemspec
|
|
9
|
+
gemspec
|
|
11
10
|
|
|
12
11
|
gem 'force_bind', require: false, platforms: :mri
|
|
13
|
-
|
|
14
|
-
group :development do
|
|
15
|
-
gem 'rake', require: false
|
|
16
|
-
|
|
17
|
-
# lint
|
|
18
|
-
gem 'rubocop', '>= 0.36.0', require: false
|
|
19
|
-
|
|
20
|
-
# test
|
|
21
|
-
gem 'minitest', require: false
|
|
22
|
-
gem 'simplecov', require: false
|
|
23
|
-
|
|
24
|
-
# doc
|
|
25
|
-
gem 'yard_dizby', require: false
|
|
26
|
-
gem 'kramdown', require: false
|
|
27
|
-
end
|
|
12
|
+
gem 'force_bind_rbx', require: false, platforms: :rbx
|
data/Rakefile
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
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
|
-
require 'rubygems'
|
|
9
7
|
require 'bundler'
|
|
10
8
|
|
|
11
9
|
Bundler.setup(:default, :development)
|
|
12
10
|
|
|
13
|
-
require '
|
|
14
|
-
|
|
15
|
-
Dir.glob('tasks/*.rake').each { |task| import task }
|
|
16
|
-
|
|
17
|
-
task default: %i(rubocop test)
|
|
18
|
-
task ci: 'test:coverage'
|
|
11
|
+
require 'rideliner/tasks'
|
|
12
|
+
require 'yard_rideliner/tasks'
|
data/dizby.gemspec
CHANGED
|
@@ -25,7 +25,14 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
26
26
|
spec.require_paths = ['lib']
|
|
27
27
|
|
|
28
|
-
spec.add_runtime_dependency 'net-ssh'
|
|
28
|
+
spec.add_runtime_dependency 'net-ssh', '~> 4.0.beta'
|
|
29
|
+
spec.add_runtime_dependency 'poly_delegate'
|
|
29
30
|
|
|
30
|
-
spec.
|
|
31
|
+
spec.add_development_dependency 'rideliner'
|
|
32
|
+
spec.add_development_dependency 'yard_rideliner'
|
|
33
|
+
spec.add_development_dependency 'yard_dizby'
|
|
34
|
+
|
|
35
|
+
spec.add_runtime_dependency 'rbnacl', '~> 3.4.0'
|
|
36
|
+
spec.add_runtime_dependency 'rbnacl-libsodium', '~> 1.0.10'
|
|
37
|
+
spec.add_runtime_dependency 'bcrypt_pbkdf', '~> 1.0.0.alpha1'
|
|
31
38
|
end
|
data/lib/dizby.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
|
|
@@ -51,7 +50,7 @@ module Dizby
|
|
|
51
50
|
when 'deny'
|
|
52
51
|
@deny.push(domain)
|
|
53
52
|
else
|
|
54
|
-
|
|
53
|
+
raise ArgumentError, "Invalid ACL entry #{list}"
|
|
55
54
|
end
|
|
56
55
|
end
|
|
57
56
|
end
|
data/lib/dizby/access/entry.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
|
|
@@ -44,7 +43,7 @@ module Dizby
|
|
|
44
43
|
|
|
45
44
|
def pattern(str)
|
|
46
45
|
pattern = str.split('.')
|
|
47
|
-
pattern.map! { |segment|
|
|
46
|
+
pattern.map! { |segment| segment == '*' ? '.+' : segment }
|
|
48
47
|
/^#{pattern.join('\\.')}$/
|
|
49
48
|
end
|
|
50
49
|
|
|
@@ -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,11 +11,11 @@ module Dizby
|
|
|
12
11
|
|
|
13
12
|
def self.check_insecure_method(obj, msg_id)
|
|
14
13
|
unless msg_id.is_a?(Symbol)
|
|
15
|
-
|
|
14
|
+
raise ArgumentError, "#{Dizby.any_to_s(msg_id)} is not a symbol"
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
if INSECURE_METHODS.include?(msg_id)
|
|
19
|
-
|
|
18
|
+
raise SecurityError, "insecure method `#{msg_id}'"
|
|
20
19
|
end
|
|
21
20
|
|
|
22
21
|
check_hidden_method(obj, msg_id)
|
|
@@ -25,10 +24,10 @@ module Dizby
|
|
|
25
24
|
def self.check_hidden_method(obj, msg_id)
|
|
26
25
|
if obj.private_methods.include?(msg_id)
|
|
27
26
|
desc = Dizby.any_to_s(obj)
|
|
28
|
-
|
|
27
|
+
raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
|
|
29
28
|
elsif obj.protected_methods.include?(msg_id)
|
|
30
29
|
desc = Dizby.any_to_s(obj)
|
|
31
|
-
|
|
30
|
+
raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
|
|
32
31
|
else
|
|
33
32
|
true
|
|
34
33
|
end
|
data/lib/dizby/access/list.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
|
|
@@ -23,10 +22,15 @@ module Dizby
|
|
|
23
22
|
@server = server
|
|
24
23
|
end
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
# rubocop:disable Style/MethodMissing
|
|
26
|
+
def method_missing(msg_id, *args, &block)
|
|
27
|
+
@server.log.debug("calling: #{msg_id} #{args.join ', '}")
|
|
28
|
+
Dizby.check_insecure_method(@obj, msg_id)
|
|
29
|
+
@obj.__send__(msg_id, *args, &block)
|
|
30
|
+
end
|
|
31
|
+
# rubocop:enable Style/MethodMissing
|
|
28
32
|
|
|
29
|
-
def
|
|
33
|
+
def respond_to_missing?(msg_id, priv = false)
|
|
30
34
|
responds =
|
|
31
35
|
case msg_id
|
|
32
36
|
when :_dump
|
|
@@ -41,10 +45,6 @@ module Dizby
|
|
|
41
45
|
responds
|
|
42
46
|
end
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
@server.log.debug("calling: #{msg_id} #{args.join ', '}")
|
|
46
|
-
Dizby.check_insecure_method(@obj, msg_id)
|
|
47
|
-
@obj.__send__(msg_id, *args, &block)
|
|
48
|
-
end
|
|
48
|
+
undef :to_s
|
|
49
49
|
end
|
|
50
50
|
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
|
|
@@ -14,25 +13,26 @@ module Dizby
|
|
|
14
13
|
@conn = conn
|
|
15
14
|
end
|
|
16
15
|
|
|
16
|
+
# rubocop:disable Style/MethodMissing
|
|
17
17
|
def method_missing(msg_id, *args, &block)
|
|
18
18
|
@conn.server.log.debug("calling through proxy: #{msg_id} #{args}")
|
|
19
19
|
@conn.send_request(@ref, msg_id, *args, &block)
|
|
20
20
|
succ, result = @conn.recv_reply
|
|
21
21
|
|
|
22
22
|
return result if succ
|
|
23
|
-
|
|
23
|
+
raise result if result.is_a?(UnknownObject)
|
|
24
24
|
|
|
25
25
|
bt = Dizby.proxy_backtrace(@conn.remote_uri, result)
|
|
26
26
|
result.set_backtrace(bt + caller)
|
|
27
|
-
|
|
27
|
+
raise result
|
|
28
28
|
end
|
|
29
|
+
# rubocop:enable Style/MethodMissing
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
undef :to_a if respond_to?(:to_a)
|
|
32
|
-
|
|
33
|
-
def respond_to?(msg_id, priv = false)
|
|
31
|
+
def respond_to_missing?(msg_id, priv = false)
|
|
34
32
|
method_missing(:respond_to?, msg_id, priv)
|
|
35
33
|
end
|
|
34
|
+
|
|
35
|
+
undef :to_s
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def self.proxy_backtrace(prefix, exception)
|
|
@@ -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
|
|
@@ -7,6 +6,7 @@
|
|
|
7
6
|
|
|
8
7
|
require 'dizby/server/registration'
|
|
9
8
|
require 'dizby/distributed/proxy'
|
|
9
|
+
require 'dizby/protocol/structs'
|
|
10
10
|
|
|
11
11
|
module Dizby
|
|
12
12
|
class SemiObjectProxy
|
|
@@ -24,7 +24,7 @@ module Dizby
|
|
|
24
24
|
obj
|
|
25
25
|
else
|
|
26
26
|
server.log.debug("creating proxy to #{@ref} on #{@uri}")
|
|
27
|
-
client, = server.connect_to(@uri)
|
|
27
|
+
client, _ref = server.connect_to(ClientArguments.new(@uri, {}))
|
|
28
28
|
ObjectProxy.new(client, @ref)
|
|
29
29
|
end
|
|
30
30
|
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
|
|
@@ -8,7 +7,7 @@
|
|
|
8
7
|
module Dizby
|
|
9
8
|
module UndumpableObject
|
|
10
9
|
def _dump(_)
|
|
11
|
-
|
|
10
|
+
raise TypeError, 'can\'t dump'
|
|
12
11
|
end
|
|
13
12
|
end
|
|
14
13
|
end
|
data/lib/dizby/error.rb
CHANGED
data/lib/dizby/protocol/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,6 +5,7 @@
|
|
|
6
5
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
7
6
|
|
|
8
7
|
require 'dizby/error'
|
|
8
|
+
require 'dizby/protocol/structs'
|
|
9
9
|
|
|
10
10
|
module Dizby
|
|
11
11
|
class ProtocolManager
|
|
@@ -15,49 +15,46 @@ module Dizby
|
|
|
15
15
|
@protocols << klass
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def open_client(server,
|
|
19
|
-
call_refined(
|
|
18
|
+
def open_client(server, client_args)
|
|
19
|
+
call_refined(:client, client_args, server)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def open_server(
|
|
23
|
-
call_refined(
|
|
22
|
+
def open_server(server_args)
|
|
23
|
+
call_refined(:server, server_args)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def spawn_server(server,
|
|
27
|
-
call_refined(
|
|
26
|
+
def spawn_server(server, spawn_args)
|
|
27
|
+
call_refined(:spawn, spawn_args, server)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
private
|
|
31
31
|
|
|
32
|
-
def call_refined(
|
|
33
|
-
klass = get_protocol(uri)
|
|
32
|
+
def call_refined(refiner, base_args, *bonus_args)
|
|
33
|
+
klass = get_protocol(base_args.uri)
|
|
34
34
|
refined = refine_protocol(klass, refiner)
|
|
35
|
-
args = get_arguments(refined, uri)
|
|
36
|
-
refined.call(
|
|
35
|
+
args = get_arguments(refined, base_args.uri)
|
|
36
|
+
refined.call(base_args, *bonus_args, args)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def get_protocol(uri)
|
|
40
40
|
scheme = '' if uri.empty?
|
|
41
41
|
scheme ||= uri.split(':').first
|
|
42
|
-
|
|
42
|
+
raise BadScheme, "can't retrieve scheme: #{uri}" unless scheme
|
|
43
43
|
|
|
44
44
|
protocol = @protocols.find { |klass| klass.scheme == scheme }
|
|
45
|
-
protocol ||
|
|
45
|
+
protocol || raise(BadScheme, "scheme not found: #{scheme}")
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def refine_protocol(protocol, refinement)
|
|
49
49
|
refined = protocol.get_refinement(refinement)
|
|
50
|
+
return refined if refined
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"#{refinement} refinement not supported for #{protocol}"
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
refined
|
|
52
|
+
raise NotImplementedError,
|
|
53
|
+
"#{refinement} refinement not supported for #{protocol}"
|
|
57
54
|
end
|
|
58
55
|
|
|
59
56
|
def get_arguments(refined, uri)
|
|
60
|
-
|
|
57
|
+
raise BadURI, "can't parse uri: #{uri}" unless refined.regex =~ uri
|
|
61
58
|
|
|
62
59
|
$~[1..-1]
|
|
63
60
|
end
|