iPXE
Functions | Variables
peerdist.c File Reference

Peer Content Caching and Retrieval (PeerDist) protocol. More...

#include <stdio.h>
#include <ipxe/http.h>
#include <ipxe/peermux.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int http_peerdist_supported (struct http_transaction *http)
 Check whether or not to support PeerDist encoding for this request.
static int http_format_p2p_peerdist (struct http_transaction *http, char *buf, size_t len)
 Format HTTP "X-P2P-PeerDist" header.
static int http_format_p2p_peerdistex (struct http_transaction *http, char *buf, size_t len)
 Format HTTP "X-P2P-PeerDistEx" header.
static int http_peerdist_init (struct http_transaction *http)
 Initialise PeerDist content encoding.

Variables

struct http_request_header
http_request_p2p_peerdist 
__http_request_header
 HTTP "X-P2P-PeerDist" header.
struct http_content_encoding
peerdist_encoding 
__http_content_encoding
 PeerDist HTTP content encoding.

Detailed Description

Peer Content Caching and Retrieval (PeerDist) protocol.

This is quite possibly the ugliest protocol I have ever had the misfortune to encounter, and I've encountered multicast TFTP.

Definition in file peerdist.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int http_peerdist_supported ( struct http_transaction http) [static]

Check whether or not to support PeerDist encoding for this request.

Parameters:
httpHTTP transaction
Return values:
supportedPeerDist encoding is supported for this request

Definition at line 44 of file peerdist.c.

References NULL, and http_transaction::xfer.

Referenced by http_format_p2p_peerdist(), and http_format_p2p_peerdistex().

                                                                     {

        /* Support PeerDist encoding only if we can directly access an
         * underlying data transfer buffer.  Direct access is required
         * in order to support decryption of data received via the
         * retrieval protocol (which provides the AES initialisation
         * vector only after all of the encrypted data has been
         * received).
         *
         * This test simultaneously ensures that we do not attempt to
         * use PeerDist encoding on a request which is itself a
         * PeerDist individual block download, since the individual
         * block downloads do not themselves provide direct access to
         * an underlying data transfer buffer.
         */
        return ( xfer_buffer ( &http->xfer ) != NULL );
}
static int http_format_p2p_peerdist ( struct http_transaction http,
char *  buf,
size_t  len 
) [static]

Format HTTP "X-P2P-PeerDist" header.

Parameters:
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values:
lenLength of header value, or negative error

Definition at line 70 of file peerdist.c.

References http_peerdist_supported(), http_request_range::len, http_request::range, http_transaction::request, and snprintf().

                                                              {
        int supported = http_peerdist_supported ( http );
        int missing;

        /* PeerDist wants us to inform the server whenever we make a
         * request for data that was missing from local peers
         * (presumably for statistical purposes only).  We use the
         * heuristic of assuming that the combination of "this request
         * may not itself use PeerDist content encoding" and "this is
         * a range request" probably indicates that we are making a
         * PeerDist block raw range request for missing data.
         */
        missing = ( http->request.range.len && ( ! supported ) );

        /* Omit header if PeerDist encoding is not supported and we
         * are not reporting a missing data request.
         */
        if ( ! ( supported || missing ) )
                return 0;

        /* Construct header */
        return snprintf ( buf, len, "Version=1.1%s",
                          ( missing ? ", MissingDataRequest=true" : "" ) );
}
static int http_format_p2p_peerdistex ( struct http_transaction http,
char *  buf,
size_t  len 
) [static]

Format HTTP "X-P2P-PeerDistEx" header.

Parameters:
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values:
lenLength of header value, or negative error

Definition at line 110 of file peerdist.c.

References http_peerdist_supported(), and snprintf().

                                                                {
        int supported = http_peerdist_supported ( http );

        /* Omit header if PeerDist encoding is not supported */
        if ( ! supported )
                return 0;

        /* Construct header */
        return snprintf ( buf, len, ( "MinContentInformation=1.0, "
                                      "MaxContentInformation=2.0" ) );
}
static int http_peerdist_init ( struct http_transaction http) [static]

Initialise PeerDist content encoding.

Parameters:
httpHTTP transaction
Return values:
rcReturn status code

Definition at line 135 of file peerdist.c.

References http_transaction::content, peermux_filter(), http_transaction::transfer, and http_transaction::uri.

                                                                {

        return peermux_filter ( &http->content, &http->transfer, http->uri );
}

Variable Documentation

struct http_request_header http_request_p2p_peerdistex __http_request_header
Initial value:
 {
        .name = "X-P2P-PeerDist",
        .format = http_format_p2p_peerdist,
}

HTTP "X-P2P-PeerDist" header.

Definition at line 97 of file peerdist.c.

Initial value:
 {
        .name = "peerdist",
        .supported = http_peerdist_supported,
        .init = http_peerdist_init,
}

PeerDist HTTP content encoding.

Definition at line 141 of file peerdist.c.