POE::Component::TFTPd - A tftp-server, implemented through POE
0.0302
POE::Session->create( inline_states => { _start => sub { POE::Component::TFTPd->create; $_[KERNEL]->post($alias => 'start'); }, tftpd_init => sub { my($client, $fh) = ($_[ARG0], undef); open($fh, "<", $client->filename) if($client->rrq); open($fh, ">", $client->filename) if($client->wrq); $client->{'fh'} = $fh; }, tftpd_done => sub { my $client = $_[ARG0]; close $client->{'fh'}; }, tftpd_send => sub { my $client = $_[ARG0]; if ($client->{'fh'}) { seek $client->{'fh'}, $client->last_block * $client->block_size, 0; read $client->{'fh'}, my $data, $client->block_size; $_[KERNEL]->post($alias => send_data => $client, $data); } }, tftpd_receive => sub { my($client, $data) = @_[ARG0,ARG1]; print { $client->{'fh'} } $data; $_[KERNEL]->post($alias => send_ack => $client); }, tftpd_log => sub { my($level, $client, $msg) = @_[ARG0..ARG2]; warn(sprintf "%s - %s:%i - %s\n", $level, $client->address, $client->port, $msg, ); }, }, );
Component constructor.
Args:
Name => default # Comment -------------------------------------------------------------------- alias => TFTPd # Alias for the POE session address => 127.0.0.1 # Address to listen to port => 69 # Port to listen to timeout => 10 # Seconds between block sent and ACK retries => 3 # How many retries before giving up on host max_clients => undef # Maximum concurrent connections
Returns a hash-ref, containing all the clients:
$client_id => $client_obj
See POE::Component::TFTPd::Client for details
POE::Component::TFTPd::Client
Pointer to max number of concurrent clients:
print $self->max_clients; $self->max_clients = 4;
Pointer to the number of retries:
print $self->retries; $self->retries = 4;
Pointer to the timeout in seconds:
print $self->timeout; $self->timeout = 4;
Returns the address the server listens to.
The alias for the POE session.
Method alias for $_[KERNEL].
$_[KERNEL]
Returns the local port
Returns the sender session.
Returns the server: POE::Wheel::UDP.
POE::Wheel::UDP
Returns this session.
1. Logs that the server is done with the client 2. deletes the client from C<$self-E<gt>clients> 3. Calls C<tftpd_done> event in sender session
Calls SENDER with event name 'tftpd_log' and these arguments:
$_[ARG0] = $level $_[ARG1] = $client $_[ARG2] = $msg
$level is the same as Log::Log4perl use.
$level
Log::Log4perl
Starts the server, by setting up POE::Wheel::UDP.
Stops the TFTPd server, by deleting the UDP wheel.
Checks for connections that have timed out, and destroys them. This is done periodically, every second.
Takes some input, figure out the opcode and pass the request on to the next stage.
opcode | event | method -------|----------|------------- rrq | init_rrq | init_request wrq | init_wrq | init_request ack | get_ack | get_data data | get_data | get_data
Sends data to the client. Used for both ACK and DATA. It resends data automatically on failure, and decreases $client->retries.
$client->retries
Handles both ACK and DATA packets.
If correct packet-number:
1. Logs the packet number 2. Calls C<tftpd_receive> / C<tftpd_send> in sender session
On failure:
1. Logs failure 2. Resends the last packet
1. Checks if max_clients limit is reached. If not, sets up $client->filename = $file; # the filename to read/write $client->mode = uc $mode; # only OCTET is valid $client->rfc = [ ... ]; $client->timestamp = time; 2. Calls C<tftpd_init> in sender session. 3. Calls C<tftpd_send> in sender session, if read-request from client
Sends an error to the client.
$error_key referes to C<%TFTP_ERROR> $args is an array ref that can be used to replace %x in the error string
Jan Henning Thorsen, <jhthorsen-at-cpan-org>
<jhthorsen-at-cpan-org>
Copyright 2007 Jan Henning Thorsen, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install POE::Component::TFTPd, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::TFTPd
CPAN shell
perl -MCPAN -e shell install POE::Component::TFTPd
For more information on module installation, please visit the detailed CPAN module installation guide.