Parent

Included Modules

Arachni::RPC::EM::Server::Handler

Receives `Arachni::RPC::Request` objects and transmits `Arachni::RPC::Response` objects.

@author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>

Attributes

request[R]

@return [Arachni::RPC::Request] Working RPC request.

Public Class Methods

new( server ) click to toggle source

@param [Server] server RPC server.

# File lib/arachni/rpc/em/server/handler.rb, line 30
def initialize( server )
    super

    @server  = server
    @opts    = server.opts.dup
    @request = nil

    assume_server_role!

    # Do not tolerate long periods of inactivity in order to avoid zombie
    # connections.
    #set_comm_inactivity_timeout( INACTIVITY_TIMEOUT )
end

Public Instance Methods

post_init() click to toggle source

Initializes an SSL session once the connection has been established.

@private

# File lib/arachni/rpc/em/server/handler.rb, line 47
def post_init
    start_ssl
end
receive_request( req ) click to toggle source
  • Handles a `Arachni::RPC::Request`

  • Sets the {request}.

  • Sends back a `Arachni::RPC::Response`.

@param [Arachni::RPC::EM::Request] req

# File lib/arachni/rpc/em/server/handler.rb, line 66
def receive_request( req )
    @request = req

    # Create an empty response to be filled in little by little.
    res  = ::Arachni::RPC::Response.new
    peer = peer_ip_addr

    begin
        # Make sure the client is allowed to make RPC calls.
        authenticate!

        # Grab the partially filled in response which includes the result
        # of the RPC call and merge it with out prepared response.
        res.merge!( @server.call( self ) )

    # Handle exceptions and convert them to a simple hash, ready to be
    # passed to the client.
    rescue Exception => e
        type = ''

        # If it's an RPC exception pass the type along as is...
        if e.rpc_exception?
            type = e.class.name.split( ':' )[-1]

        # ...otherwise set it to a RemoteException.
        else
            type = 'RemoteException'
        end

        # RPC conventions for exception transmission.
        res.obj = {
            'exception' => e.to_s,
            'backtrace' => e.backtrace,
            'type'      => type
        }

        msg = "#{e.to_s}\n#{e.backtrace.join( "\n" )}"
        @server.logger.error( 'Exception' ){ msg + " [on behalf of #{peer}]" }
    end

    # Pass the result of the RPC call back to the client but *only* if it
    # wasn't async, otherwise {Server#call} will have already taken care of it
    send_response( res ) if !res.async?
end
unbind() click to toggle source

Handles closed connections and cleans up the SSL session.

@private

# File lib/arachni/rpc/em/server/handler.rb, line 54
def unbind
    end_ssl
    @server = nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.