Module: Arachni::RPC::Protocol

Includes:
Reactor::Connection::TLS
Included in:
Client::Handler, Server::Handler
Defined in:
lib/arachni/rpc/protocol.rb

Overview

Provides helper transport methods for Message transmission.

Author:

Instance Method Summary collapse

Instance Method Details

#on_connectObject

Initializes an SSL session once the connection has been established and sets #status to ‘:ready`.



22
23
24
25
26
27
28
29
30
# File 'lib/arachni/rpc/protocol.rb', line 22

def on_connect
    start_tls(
        ca:          @opts[:ssl_ca],
        private_key: @opts[:ssl_pkey],
        certificate: @opts[:ssl_cert]
    )

    @status = :ready
end

#on_read(data) ⇒ Object

Receives data from the network.

Rhe data will be chunks of a serialized object which will be buffered until the whole transmission has finished.

It will then unserialize it and pass it to #receive_object.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/arachni/rpc/protocol.rb', line 46

def on_read( data )
    (@buf ||= '') << data

    while @buf.size >= 4
        if @buf.size >= 4 + ( size = @buf.unpack( 'N' ).first )
            @buf.slice!( 0, 4 )
            receive_object( unserialize( @buf.slice!( 0, size ) ) )
        else
            break
        end
    end
end

#send_message(msg) ⇒ Object Also known as: send_request, send_response

Parameters:

  • msg (Message)

    Message to send to the peer.



34
35
36
# File 'lib/arachni/rpc/protocol.rb', line 34

def send_message( msg )
    send_object( msg.prepare_for_tx )
end