drb 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +95 -0
- data/Rakefile +17 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/drb.gemspec +30 -0
- data/lib/drb.rb +3 -0
- data/lib/drb/acl.rb +239 -0
- data/lib/drb/drb.rb +1937 -0
- data/lib/drb/eq.rb +15 -0
- data/lib/drb/extserv.rb +44 -0
- data/lib/drb/extservm.rb +92 -0
- data/lib/drb/gw.rb +161 -0
- data/lib/drb/invokemethod.rb +35 -0
- data/lib/drb/observer.rb +26 -0
- data/lib/drb/ssl.rb +344 -0
- data/lib/drb/timeridconv.rb +97 -0
- data/lib/drb/unix.rb +118 -0
- data/lib/drb/version.rb +3 -0
- data/lib/drb/weakidconv.rb +59 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6a0bd1846737aa885de7878f8d513b5a3b44af1d01c1783952eb433211c5b4bb
|
4
|
+
data.tar.gz: 9dc38382cfbca00371b3fd3ce55a30ab65eea7fcac9ec1424b50e7b6e437a600
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 653e0ac3da1ecde53a30302ef2671981ac53fcf55e5975837fc5964a621472cc556d741b9d4323f9e587220c29926e980aa4c5be04e63bfc69cceda307748bb5
|
7
|
+
data.tar.gz: 72cefc32044638df298e7c736b082e6190bc7c3dcb71679e936be0b13a1d27eb7310aab6269fd13494bb9759ee398158013fd45ae2d881adaf3b719ab65c8226
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# Distributed Ruby: dRuby
|
2
|
+
|
3
|
+
dRuby is a distributed object system for Ruby. It allows an object in one
|
4
|
+
Ruby process to invoke methods on an object in another Ruby process on the
|
5
|
+
same or a different machine.
|
6
|
+
|
7
|
+
The Ruby standard library contains the core classes of the dRuby package.
|
8
|
+
However, the full package also includes access control lists and the
|
9
|
+
Rinda tuple-space distributed task management system, as well as a
|
10
|
+
large number of samples. The full dRuby package can be downloaded from
|
11
|
+
the dRuby home page (see *References*).
|
12
|
+
|
13
|
+
For an introduction and examples of usage see the documentation to the
|
14
|
+
DRb module.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'drb'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle install
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install drb
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### dRuby in client/server mode
|
35
|
+
|
36
|
+
This illustrates setting up a simple client-server drb
|
37
|
+
system. Run the server and client code in different terminals,
|
38
|
+
starting the server code first.
|
39
|
+
|
40
|
+
#### Server code
|
41
|
+
|
42
|
+
```
|
43
|
+
require 'drb/drb'
|
44
|
+
|
45
|
+
# The URI for the server to connect to
|
46
|
+
URI="druby://localhost:8787"
|
47
|
+
|
48
|
+
class TimeServer
|
49
|
+
|
50
|
+
def get_current_time
|
51
|
+
return Time.now
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
# The object that handles requests on the server
|
57
|
+
FRONT_OBJECT=TimeServer.new
|
58
|
+
|
59
|
+
DRb.start_service(URI, FRONT_OBJECT)
|
60
|
+
# Wait for the drb server thread to finish before exiting.
|
61
|
+
DRb.thread.join
|
62
|
+
```
|
63
|
+
|
64
|
+
#### Client code
|
65
|
+
|
66
|
+
```
|
67
|
+
require 'drb/drb'
|
68
|
+
|
69
|
+
# The URI to connect to
|
70
|
+
SERVER_URI="druby://localhost:8787"
|
71
|
+
|
72
|
+
# Start a local DRbServer to handle callbacks.
|
73
|
+
|
74
|
+
# Not necessary for this small example, but will be required
|
75
|
+
# as soon as we pass a non-marshallable object as an argument
|
76
|
+
# to a dRuby call.
|
77
|
+
|
78
|
+
# Note: this must be called at least once per process to take any effect.
|
79
|
+
# This is particularly important if your application forks.
|
80
|
+
DRb.start_service
|
81
|
+
|
82
|
+
timeserver = DRbObject.new_with_uri(SERVER_URI)
|
83
|
+
puts timeserver.get_current_time
|
84
|
+
```
|
85
|
+
|
86
|
+
## Development
|
87
|
+
|
88
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
89
|
+
|
90
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/drb.
|
95
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test/lib"
|
6
|
+
t.ruby_opts << "-rhelper"
|
7
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
8
|
+
end
|
9
|
+
|
10
|
+
task :sync_tool do
|
11
|
+
require 'fileutils'
|
12
|
+
FileUtils.cp "../ruby/tool/lib/test/unit/core_assertions.rb", "./test/lib"
|
13
|
+
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
|
14
|
+
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
|
15
|
+
end
|
16
|
+
|
17
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "drb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/drb.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
begin
|
2
|
+
require_relative "lib/drb/version"
|
3
|
+
rescue LoadError # Fallback to load version file in ruby core repository
|
4
|
+
require_relative "version"
|
5
|
+
end
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "drb"
|
9
|
+
spec.version = DRb::VERSION
|
10
|
+
spec.authors = ["Masatoshi SEKI"]
|
11
|
+
spec.email = ["seki@ruby-lang.org"]
|
12
|
+
|
13
|
+
spec.summary = %q{Distributed object system for Ruby}
|
14
|
+
spec.description = %q{Distributed object system for Ruby}
|
15
|
+
spec.homepage = "https://github.com/ruby/drb"
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
17
|
+
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
end
|
data/lib/drb.rb
ADDED
data/lib/drb/acl.rb
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
# Copyright (c) 2000,2002,2003 Masatoshi SEKI
|
3
|
+
#
|
4
|
+
# acl.rb is copyrighted free software by Masatoshi SEKI.
|
5
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
6
|
+
|
7
|
+
require 'ipaddr'
|
8
|
+
|
9
|
+
##
|
10
|
+
# Simple Access Control Lists.
|
11
|
+
#
|
12
|
+
# Access control lists are composed of "allow" and "deny" halves to control
|
13
|
+
# access. Use "all" or "*" to match any address. To match a specific address
|
14
|
+
# use any address or address mask that IPAddr can understand.
|
15
|
+
#
|
16
|
+
# Example:
|
17
|
+
#
|
18
|
+
# list = %w[
|
19
|
+
# deny all
|
20
|
+
# allow 192.168.1.1
|
21
|
+
# allow ::ffff:192.168.1.2
|
22
|
+
# allow 192.168.1.3
|
23
|
+
# ]
|
24
|
+
#
|
25
|
+
# # From Socket#peeraddr, see also ACL#allow_socket?
|
26
|
+
# addr = ["AF_INET", 10, "lc630", "192.168.1.3"]
|
27
|
+
#
|
28
|
+
# acl = ACL.new
|
29
|
+
# p acl.allow_addr?(addr) # => true
|
30
|
+
#
|
31
|
+
# acl = ACL.new(list, ACL::DENY_ALLOW)
|
32
|
+
# p acl.allow_addr?(addr) # => true
|
33
|
+
|
34
|
+
class ACL
|
35
|
+
|
36
|
+
##
|
37
|
+
# The current version of ACL
|
38
|
+
|
39
|
+
VERSION=["2.0.0"]
|
40
|
+
|
41
|
+
##
|
42
|
+
# An entry in an ACL
|
43
|
+
|
44
|
+
class ACLEntry
|
45
|
+
|
46
|
+
##
|
47
|
+
# Creates a new entry using +str+.
|
48
|
+
#
|
49
|
+
# +str+ may be "*" or "all" to match any address, an IP address string
|
50
|
+
# to match a specific address, an IP address mask per IPAddr, or one
|
51
|
+
# containing "*" to match part of an IPv4 address.
|
52
|
+
#
|
53
|
+
# IPAddr::InvalidPrefixError may be raised when an IP network
|
54
|
+
# address with an invalid netmask/prefix is given.
|
55
|
+
|
56
|
+
def initialize(str)
|
57
|
+
if str == '*' or str == 'all'
|
58
|
+
@pat = [:all]
|
59
|
+
elsif str.include?('*')
|
60
|
+
@pat = [:name, dot_pat(str)]
|
61
|
+
else
|
62
|
+
begin
|
63
|
+
@pat = [:ip, IPAddr.new(str)]
|
64
|
+
rescue IPAddr::InvalidPrefixError
|
65
|
+
# In this case, `str` shouldn't be a host name pattern
|
66
|
+
# because it contains a slash.
|
67
|
+
raise
|
68
|
+
rescue ArgumentError
|
69
|
+
@pat = [:name, dot_pat(str)]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
##
|
77
|
+
# Creates a regular expression to match IPv4 addresses
|
78
|
+
|
79
|
+
def dot_pat_str(str)
|
80
|
+
list = str.split('.').collect { |s|
|
81
|
+
(s == '*') ? '.+' : s
|
82
|
+
}
|
83
|
+
list.join("\\.")
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
##
|
89
|
+
# Creates a Regexp to match an address.
|
90
|
+
|
91
|
+
def dot_pat(str)
|
92
|
+
/\A#{dot_pat_str(str)}\z/
|
93
|
+
end
|
94
|
+
|
95
|
+
public
|
96
|
+
|
97
|
+
##
|
98
|
+
# Matches +addr+ against this entry.
|
99
|
+
|
100
|
+
def match(addr)
|
101
|
+
case @pat[0]
|
102
|
+
when :all
|
103
|
+
true
|
104
|
+
when :ip
|
105
|
+
begin
|
106
|
+
ipaddr = IPAddr.new(addr[3])
|
107
|
+
ipaddr = ipaddr.ipv4_mapped if @pat[1].ipv6? && ipaddr.ipv4?
|
108
|
+
rescue ArgumentError
|
109
|
+
return false
|
110
|
+
end
|
111
|
+
(@pat[1].include?(ipaddr)) ? true : false
|
112
|
+
when :name
|
113
|
+
(@pat[1] =~ addr[2]) ? true : false
|
114
|
+
else
|
115
|
+
false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# A list of ACLEntry objects. Used to implement the allow and deny halves
|
122
|
+
# of an ACL
|
123
|
+
|
124
|
+
class ACLList
|
125
|
+
|
126
|
+
##
|
127
|
+
# Creates an empty ACLList
|
128
|
+
|
129
|
+
def initialize
|
130
|
+
@list = []
|
131
|
+
end
|
132
|
+
|
133
|
+
public
|
134
|
+
|
135
|
+
##
|
136
|
+
# Matches +addr+ against each ACLEntry in this list.
|
137
|
+
|
138
|
+
def match(addr)
|
139
|
+
@list.each do |e|
|
140
|
+
return true if e.match(addr)
|
141
|
+
end
|
142
|
+
false
|
143
|
+
end
|
144
|
+
|
145
|
+
public
|
146
|
+
|
147
|
+
##
|
148
|
+
# Adds +str+ as an ACLEntry in this list
|
149
|
+
|
150
|
+
def add(str)
|
151
|
+
@list.push(ACLEntry.new(str))
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
##
|
157
|
+
# Default to deny
|
158
|
+
|
159
|
+
DENY_ALLOW = 0
|
160
|
+
|
161
|
+
##
|
162
|
+
# Default to allow
|
163
|
+
|
164
|
+
ALLOW_DENY = 1
|
165
|
+
|
166
|
+
##
|
167
|
+
# Creates a new ACL from +list+ with an evaluation +order+ of DENY_ALLOW or
|
168
|
+
# ALLOW_DENY.
|
169
|
+
#
|
170
|
+
# An ACL +list+ is an Array of "allow" or "deny" and an address or address
|
171
|
+
# mask or "all" or "*" to match any address:
|
172
|
+
#
|
173
|
+
# %w[
|
174
|
+
# deny all
|
175
|
+
# allow 192.0.2.2
|
176
|
+
# allow 192.0.2.128/26
|
177
|
+
# ]
|
178
|
+
|
179
|
+
def initialize(list=nil, order = DENY_ALLOW)
|
180
|
+
@order = order
|
181
|
+
@deny = ACLList.new
|
182
|
+
@allow = ACLList.new
|
183
|
+
install_list(list) if list
|
184
|
+
end
|
185
|
+
|
186
|
+
public
|
187
|
+
|
188
|
+
##
|
189
|
+
# Allow connections from Socket +soc+?
|
190
|
+
|
191
|
+
def allow_socket?(soc)
|
192
|
+
allow_addr?(soc.peeraddr)
|
193
|
+
end
|
194
|
+
|
195
|
+
public
|
196
|
+
|
197
|
+
##
|
198
|
+
# Allow connections from addrinfo +addr+? It must be formatted like
|
199
|
+
# Socket#peeraddr:
|
200
|
+
#
|
201
|
+
# ["AF_INET", 10, "lc630", "192.0.2.1"]
|
202
|
+
|
203
|
+
def allow_addr?(addr)
|
204
|
+
case @order
|
205
|
+
when DENY_ALLOW
|
206
|
+
return true if @allow.match(addr)
|
207
|
+
return false if @deny.match(addr)
|
208
|
+
return true
|
209
|
+
when ALLOW_DENY
|
210
|
+
return false if @deny.match(addr)
|
211
|
+
return true if @allow.match(addr)
|
212
|
+
return false
|
213
|
+
else
|
214
|
+
false
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
public
|
219
|
+
|
220
|
+
##
|
221
|
+
# Adds +list+ of ACL entries to this ACL.
|
222
|
+
|
223
|
+
def install_list(list)
|
224
|
+
i = 0
|
225
|
+
while i < list.size
|
226
|
+
permission, domain = list.slice(i,2)
|
227
|
+
case permission.downcase
|
228
|
+
when 'allow'
|
229
|
+
@allow.add(domain)
|
230
|
+
when 'deny'
|
231
|
+
@deny.add(domain)
|
232
|
+
else
|
233
|
+
raise "Invalid ACL entry #{list}"
|
234
|
+
end
|
235
|
+
i += 2
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|