Module: Dizby

Defined in:
lib/dizby/error.rb,
lib/dizby/version.rb,
lib/dizby/service.rb,
lib/dizby/access/list.rb,
lib/dizby/utility/log.rb,
lib/dizby/server/basic.rb,
lib/dizby/access/entry.rb,
lib/dizby/tunnel/basic.rb,
lib/dizby/protocols/tcp.rb,
lib/dizby/stream/client.rb,
lib/dizby/worker/server.rb,
lib/dizby/utility/string.rb,
lib/dizby/tunnel/spawned.rb,
lib/dizby/protocol/basic.rb,
lib/dizby/protocols/unix.rb,
lib/dizby/tunnel/factory.rb,
lib/dizby/protocols/dead.rb,
lib/dizby/converter/timed.rb,
lib/dizby/access/insecure.rb,
lib/dizby/stream/readable.rb,
lib/dizby/stream/writable.rb,
lib/dizby/server/abstract.rb,
lib/dizby/utility/monitor.rb,
lib/dizby/tunnel/abstract.rb,
lib/dizby/stream/messenger.rb,
lib/dizby/converter/simple.rb,
lib/dizby/protocols/secure.rb,
lib/dizby/protocol/refined.rb,
lib/dizby/protocol/manager.rb,
lib/dizby/stream/query_ref.rb,
lib/dizby/stream/connection.rb,
lib/dizby/utility/self_pipe.rb,
lib/dizby/utility/delegator.rb,
lib/dizby/worker/connection.rb,
lib/dizby/distributed/array.rb,
lib/dizby/distributed/proxy.rb,
lib/dizby/tunnel/basic_spawn.rb,
lib/dizby/distributed/object.rb,
lib/dizby/utility/force_bind.rb,
lib/dizby/utility/semi_built.rb,
lib/dizby/utility/io_barrier.rb,
lib/dizby/utility/timed_state.rb,
lib/dizby/distributed/unknown.rb,
lib/dizby/access/control_list.rb,
lib/dizby/server/registration.rb,
lib/dizby/utility/configurable.rb,
lib/dizby/worker/invoke_method.rb,
lib/dizby/tunnel/spawn_command.rb,
lib/dizby/tunnel/local_strategy.rb,
lib/dizby/distributed/undumpable.rb,
lib/dizby/utility/classic_access.rb,
lib/dizby/distributed/semi_proxy.rb,
lib/dizby/tunnel/tunnelable_local.rb,
lib/dizby/utility/timed_collection.rb,
lib/dizby/tunnel/tunnelable_remote.rb,
lib/dizby/utility/polymorphic_delegated.rb,
lib/dizby/tunnel/bidirectional_strategy.rb

Overview

Copyright (c) 2016 Nathan Currier

Defined Under Namespace

Modules: Access, BasicProtocol, ClassicAttributeAccess, Configurable, PolymorphicDelegated, ReadableStream, TunnelableLocal, TunnelableRemote, UndumpableObject, WritableStream Classes: AbstractServer, AbstractTunnel, BadScheme, BadURI, BasicClient, BasicConnection, BasicServer, BasicSpawnTunnel, BasicTunnel, BidirectionalTunnelStrategy, ConnectionError, ConnectionWorker, DeadProtocol, Delegator, DistributedArray, DistributedError, DistributedObject, IOBarrier, IdConverter, InvalidIdentifier, InvokeMethod, LocalServerShutdown, LocalTunnelStrategy, Messenger, NonAcceptingServer, ObjectProxy, ProtocolManager, QueryRef, RefinedProtocol, RemoteDistributedError, RemoteServerShutdown, SecureProtocol, SelfPipe, SemiObjectProxy, SemibuiltObject, ServerNotFound, Service, ServiceWorker, SpawnCommand, SpawnError, Spawned, TCProtocol, TimedCollection, TimedIdConverter, TimedState, TunnelFactory, UnixProtocol, UnknownObject, UnknownObjectError

Constant Summary collapse

VERSION =
'1.4.0'
INSECURE_METHODS =
[:__send__]
PROTOCOL_REGEX =
{
  user: '(?:(.+?)@)',
  host: '(.*?)',
  port: '(?::(\d+))',
  file: '(.+?)',
  query: '(?:\?(.*?))'
}

Class Method Summary collapse

Class Method Details

.any_to_s(obj)


5
6
7
8
9
# File 'lib/dizby/utility/string.rb', line 5

def self.any_to_s(obj)
  "#{obj}:#{obj.class}"
rescue
  format '#<%s:0x%1x>', obj.class, obj.__id__
end

.check_hidden_method(obj, msg_id)


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dizby/access/insecure.rb', line 21

def self.check_hidden_method(obj, msg_id)
  if obj.private_methods.include?(msg_id)
    desc = Dizby.any_to_s(obj)
    fail NoMethodError, "private method `#{msg_id}' called for #{desc}"
  elsif obj.protected_methods.include?(msg_id)
    desc = Dizby.any_to_s(obj)
    fail NoMethodError, "protected method `#{msg_id}' called for #{desc}"
  else
    true
  end
end

.check_insecure_method(obj, msg_id)


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dizby/access/insecure.rb', line 9

def self.check_insecure_method(obj, msg_id)
  unless msg_id.is_a?(Symbol)
    fail ArgumentError, "#{Dizby.any_to_s(msg_id)} is not a symbol"
  end

  if INSECURE_METHODS.include?(msg_id)
    fail SecurityError, "insecure method `#{msg_id}'"
  end

  check_hidden_method(obj, msg_id)
end

.create_logger(output: $stderr, level: Logger::ERROR, &transformer)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dizby/utility/log.rb', line 7

def self.create_logger(output: $stderr, level: Logger::ERROR, &transformer)
  log = Logger.new(output)

  default_formatter = Logger::Formatter.new
  log.formatter = proc do |severity, datetime, progname, msg|
    msg = transformer.call(msg) if transformer
    default_formatter.call(severity, datetime, progname, msg)
  end

  log.level = level

  log.define_singleton_method(:backtrace) do |exception|
    error(exception.inspect)
    exception.backtrace.each { |trace| error(trace) }
  end

  log
end

.get_obj(uri, ref)

returns [success, object]


18
19
20
21
22
23
24
# File 'lib/dizby/server/registration.rb', line 18

def self.get_obj(uri, ref)
  @servers.synchronize do
    local_server = @servers.find { |server| server && server.here?(uri) }

    [!local_server.nil?, local_server && local_server.to_obj(ref)]
  end
end

.monitor(obj)


7
8
9
10
# File 'lib/dizby/utility/monitor.rb', line 7

def self.monitor(obj)
  obj.extend(MonitorMixin)
  obj
end

.proxy_backtrace(prefix, exception)


37
38
39
40
41
42
# File 'lib/dizby/distributed/proxy.rb', line 37

def self.proxy_backtrace(prefix, exception)
  bt = exception.backtrace.reject { |trace| /`__send__'$/ =~ trace }
  bt.map { |trace| %r{\(drb://} =~ trace ? trace : "#{prefix}#{trace}" }
  # TODO: why do we only add the prefix if the trace doesn't start with drb?
  # What about the other schemes?
end

.register_server(server)


9
10
11
# File 'lib/dizby/server/registration.rb', line 9

def self.register_server(server)
  @servers.synchronize { @servers << server }
end

.unregister_server(server)


13
14
15
# File 'lib/dizby/server/registration.rb', line 13

def self.unregister_server(server)
  @servers.synchronize { @servers.delete(server) }
end