lib/arachni/rpc/em/server.rb in arachni-rpc-em-0.1.1 vs lib/arachni/rpc/em/server.rb in arachni-rpc-em-0.1.2

- old
+ new

@@ -17,34 +17,26 @@ # - performing and handling a few thousands requests per second (depending on call size, network conditions and the like) # - TLS encryption # - asynchronous and synchronous requests # - handling asynchronous methods that require a block # -# @author: Tasos "Zapotek" Laskos -# <tasos.laskos@gmail.com> -# <zapotek@segfault.gr> -# @version: 0.1 +# @author: Tasos "Zapotek" Laskos <tasos.laskos@gmail.com> # class Server - include ::Arachni::RPC::Exceptions # # Handles EventMachine's connection stuff. # # It's responsible for TLS, serializing, transmitting and receiving objects, # as well as authenticating the client using the token. # # It also handles and forwards exceptions. # - # @author: Tasos "Zapotek" Laskos - # <tasos.laskos@gmail.com> - # <zapotek@segfault.gr> - # @version: 0.1 + # @author: Tasos "Zapotek" Laskos <tasos.laskos@gmail.com> # class Proxy < EventMachine::Connection - include ::Arachni::RPC::EM::Protocol include ::Arachni::RPC::Exceptions include ::Arachni::RPC::EM::ConnectionUtilities INACTIVITY_TIMEOUT = 10 @@ -154,11 +146,11 @@ @server.logger.error( 'Authenticator' ){ msg + " [on behalf of #{peer_ip_addr}]" } - raise( InvalidToken.new( msg ) ) + raise InvalidToken.new( msg ) end end # # Compares the authentication token in the param with the one of the server. @@ -267,15 +259,14 @@ def add_handler( name, obj ) @objects[name] = obj @methods[name] = Set.new # no lookup overhead please :) @async_methods[name] = Set.new - obj.class.public_instance_methods( false ).each { - |method| + obj.class.public_instance_methods( false ).each do |method| @methods[name] << method.to_s @async_methods[name] << method.to_s if async_check( obj.method( method ) ) - } + end end # # Clears all handlers and their associated information like methods # and async check blocks. @@ -290,14 +281,12 @@ # # Runs the server and blocks. # def run - Arachni::RPC::EM.add_to_reactor { - start - } - Arachni::RPC::EM.block! + Arachni::RPC::EM.schedule { start } + Arachni::RPC::EM.block end # # Starts the server but does not block. # @@ -336,25 +325,24 @@ res.async! if async?( obj_name, meth_name ) if !res.async? res.obj = @objects[obj_name].send( meth_name.to_sym, *args ) else - @objects[obj_name].send( meth_name.to_sym, *args ){ - |obj| + @objects[obj_name].send( meth_name.to_sym, *args ) do |obj| res.obj = obj connection.send_response( res ) - } + end end - return res + res end # # @return [TrueClass] # def alive? - return true + true end # # Shuts down the server after 2 seconds # @@ -363,25 +351,22 @@ @logger.info( 'System' ){ "Shutting down in #{wait_for} seconds..." } # don't die before returning EventMachine::add_timer( wait_for ) { ::EM.stop } - return true + true end private def async?( objname, method ) @async_methods[objname].include?( method ) end def async_check( method ) - @async_checks.each { - |check| - return true if check.call( method ) - } - return false + @async_checks.each { |check| return true if check.call( method ) } + false end def log_call( peer_ip_addr, expr, *args ) msg = "#{expr}" @@ -397,10 +382,9 @@ @logger.info( 'Call' ){ msg } end def parse_expr( expr ) parts = expr.to_s.split( '.' ) - # method name, object name [ parts.pop, parts.join( '.' ) ] end def object_exist?( obj_name )