NAME

SRS::EPP::Session - logic for EPP Session State machine

SYNOPSIS

my $session = SRS::EPP::Session->new( io => $socket );

#--- session events:

$session->connected;
$session->input_event;
$session->input_packet($data);
$session->queue_command($command);
$session->process_queue($count);
$session->be_response($srs_rs);
$session->send_pending_replies();
$session->send_reply($response);
$session->output_event;

#--- information messages:

# print RFC3730 state eg 'Waiting for Client',
# 'Prepare Greeting' (see Page 4 of RFC3730)
print $session->state;

# return the credential used for login
print $session->user;

DESCRIPTION

The SRS::EPP::Session class manages the flow of individual connections. It implements the "EPP Server State Machine" from RFC3730, as well as the exchange encapsulation described in RFC3734 "EPP TCP Transport".

This class is designed to be called from within an event-based framework; this is fairly essential in the context of a server given the potential to deadlock if the client does not clear its responses in a timely fashion.

Input commands go through several stages:

  • First, incoming data ready is chunked into complete EPP requests. This is a binary de-chunking, and is based on reading a packet length as a U32, then waiting for that many octets. See "input_event"

  • Complete chunks are passed to the SRS::EPP::Command constructor for validation and object construction. See "input_packet"

  • The constructed object is triaged, and added to an appropriate processing queue. See "queue_command"

  • The request is processed; either locally for requests such as >hello<, or converted to the back-end format (SRS::Request) and placed in the back-end queue (this is normally immediately dispatched). See "process_queue"

  • The response (a SRS::Response object) from the back-end is received; this is converted to a corresponding SRS::EPP::Response object. Outstanding queued back-end requests are then dispatched if they are present (so each session has a maximum of one outstanding request at a time). See "be_response"

  • Prepared SRS::EPP::Response objects are queued, this involves individually converting them to strings, which are sent back to the client, each response its own SSL frame. See "send_reply"

  • If the output blocks, then the responses wait and are sent back as the response queue clears. See "output_event"

METHODS

connected()

This event signals to the Session that the client is now connected. It signals that it is time to issue a >greeting< response, just as if a >hello< message had been received.

input_event()

This event is intended to be invoked whenever there is data ready to read on the input socket. It returns false if not enough data could be read to get a complete subpacket.

input_packet($data)

This message is self-fired with a complete packet of data once it has been read.

queue_command($command)

Enqueues an EPP command for processing and does nothing else.

process_queue($count)

Processes the back-end queue, up to $count at a time. At the end of this, if there are no outstanding back-end transactions, any produced SRS::Request objects are wrapped into an SRS::Transaction object and dispatched to the back-end.

Returns the number of commands remaining to process.

be_response($srs_rs)

This is fired when a back-end response is received. It is responsible for matching responses with commands in the command queue and converting to SRS::EPP::Response objects.

send_pending_replies()

This is called by process_queue() or be_response(), and checks each command for a corresponding SRS::EPP::Response object, dequeues and starts to send them back.

send_reply($response)

This is called by send_pending_replies(), and converts a SRS::EPP::Response object to network form, then starts to send it. Returns the total number of octets which are currently outstanding; if this is non-zero, the caller is expected to watch the output socket for writability and call output_event() once it is writable.

output_event()

This event is intended to be called when the return socket is newly writable; it writes everything it can to the output socket and returns the number of bytes written.

SEE ALSO

SRS::EPP::Command, SRS::EPP::Response