Bundesamt für Sicherheit in der Informationstechnik > Dicop-Server-3.04 > Dicop::Client

Download:
dicop/Dicop-Server-3.04.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 3.01   Source  

NAME ^

Dicop::Client -- a client object

SYNOPSIS ^

        use Dicop::Client;

        my $client = new Dicop::Client ('config/client.cfg');

        $client->work();        # never returns unless hard error occurs

REQUIRES ^

perl5.004, Dicop::Event, Dicop::Config, Dicop::Item, Dicop::Request, Linux::Cpuinfo, Dicop::Hash

EXPORTS ^

Exports nothing.

DESCRIPTION ^

This module represents a client and manages all communication between servers and client and the client and the workers.

It uses Dicop::Connect for the network connection via HTTP/FTP to the server or proxy.

METHODS ^

new

Create a client object by using the supplied config file (or uses 'config/client.cfg' as default.

work

Main loop. Start working and never return (except in case of fatal errors).

change_root

        $client->change_root();

Uses chroot() to change the root directory to the given directory from the configuration file (or command line). Call before change_user_and_group because chroot() only works for root.

change_user_and_group

        $client->change_user_and_group();

Uses POSIX to change the real user and group id of the process.

architecture

        print $client->architecture();

Return the name of the base arcitecture the client is running on.

full_arch

        print $client->full_arch();

Return the full arcitecture string (including sub_arch). See also sub_arch.

sub_arch

        print $client->sub_arch();

Return the sub architecture string. See also full_arch.

output

        $self->output( "text", "test", "foo");

Prrint a list of texts. Overrided by the testsuite to inhibit unwanted output.

_get_more_work

Adds another request to the queue, unless we already have a request for work in there.

_die_hard

Log an error text to the logfile, and then die finally.

_break_chunk

The server sends us the chunks to work on as a compact string. Ths routine breaks them down into parts and returns a hash containing the pieces.

_work_on_chunks

For all the chunks to work on the server sent us, break them down, then start the worker and insert the result (FAIL, SUCCESS, TIMEOUT or DONE) as request into the sending queue.

_store

Add the given request(s) to the list of to-be-sent items (insert it into the send-queue). The input is a list of Dicop::Requests, or scalars holding strings, the output the number of requests now in the queue.

_parse_responses

Parse the server's response into requests, and throw away any garbage/junk. This also throws away responses with an code lower than 100, as these are only idle chatter.

The input is an response object from the server, or a scalar (for test suite).

This returns a ref to an array which contains in every element [ response_id, response_code, response_text]. So for two responses the array has two entries.

_parse_responses_for_files

This method walks the list of requests/messages/answers we got from the server, and extracts each file we will need to work from them. All the files are entered into a HASH keyed on their filename (to avoid doubles) and the value is the hash of the file we must download.

_handle_responses

From list of the server's responses, clear any request from our send list, that was answered successfully by the server.

After this, anything that needs to be send again will be in the send stack, including our authentication, anything other will be deleted.

Chunks of work or test will be added to our todo list, which is than processed by work_on_chunks.

_clear_send_queue

After an hard error, we clear the send queue from the requests we tried to send and then fill it with our auth request and one request for more work.

This ensures that after some hard error we start with a fresh and new list of requests for the server and forget the old, malformed ones.

Called automatically by _handle_responses.

_extract_result

        ($code,$res,$crc) = $self->_extract_result($rc);

Takes the output of the worker and tries to extract the result, the chunk CRC (checksum) and stopcode from it. Returns -1 for $code when it doesn't find a stopcode, and '' as result when there was no result in the output to be found.

_start_worker

Given a hash representation of a chunk, start the appropiate worker and let it work on the chunk. Returns a request-string to be entered into the send queue and the status code as text.

_talk_to_server

Adds together all the requests we need to send to the server, including our authentication request. Then calls connect_to_server(), parse_responses(), and _handle_responses().

_check_file

        if ($self->_check_file($filename,$hash)
          {
          print "$file is ok.\n";
          }
        else
          {
          print "$file is not there or outdated.\n";
          }

This routine checks if we got the required version of a file. If the file is not there or does not have the proper hash, it will return false.

_retrieve_files

Given a list of filenames in form of a hash reference, will ask server for download locations of all the files, then uses _download_file to download them one by one.

Does not report whether all could be downloaded or not, this needs to be checked on a file-by-file basis to correctly decide which requests from the server we can work on and which are missing files - the same file might be missing for more than one request!.

_download_file

        $self->_download_file($file,$hash, $uris);

Download a file from a given list of URIs and checks via hash that we got the right file. Return 0 for success or 1 for error.

_worker_name

From the architecture name of the client, the worker dir and the worker name supplied by the server (via the request/chunk), construct the path to the worker. If a .exe file exists, this will be returned, otherwise just the executable name as it is.

Returns a list consisting of the path and name of the worker.

_sleeping

When an error occured, or we got no response, or no work, we wait a time to not overload the server. This routine does log the error, prints some information and then sleeps.

_delete_temp_files

Deletes all temporary files that got sent from the server for the current chunk.

Does currently not take into account of we need to work on more than one chunk, so needs to be called after all chunks have been completed.

BUGS ^

None discovered yet.

AUTHOR ^

(c) Bundesamt fuer Sicherheit in der Informationstechnik 1998-2006

DiCoP is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

See http://www.bsi.de/ for more information.