iPXE
Functions | Variables
peerdist.c File Reference

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

#include <stdio.h>
#include <ipxe/http.h>
#include <ipxe/settings.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. More...
 
static int http_format_p2p_peerdist (struct http_transaction *http, char *buf, size_t len)
 Format HTTP "X-P2P-PeerDist" header. More...
 
static int http_format_p2p_peerdistex (struct http_transaction *http, char *buf, size_t len)
 Format HTTP "X-P2P-PeerDistEx" header. More...
 
static int http_peerdist_init (struct http_transaction *http)
 Initialise PeerDist content encoding. More...
 
const struct setting peerdist_setting __setting (SETTING_MISC, peerdist)
 PeerDist enabled setting. More...
 
static int apply_peerdist_settings (void)
 Apply PeerDist settings. More...
 

Variables

static long peerdist_enabled = 1
 PeerDist is globally enabled. More...
 
struct http_request_header http_request_p2p_peerdist __http_request_header
 HTTP "X-P2P-PeerDist" header. More...
 
struct http_content_encoding peerdist_encoding __http_content_encoding
 PeerDist HTTP content encoding. More...
 
struct settings_applicator peerdist_applicator __settings_applicator
 PeerDist settings applicator. More...
 

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()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ http_peerdist_supported()

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 48 of file peerdist.c.

48  {
49 
50  /* Allow PeerDist to be globally enabled/disabled */
51  if ( ! peerdist_enabled )
52  return 0;
53 
54  /* Support PeerDist encoding only if we can directly access an
55  * underlying data transfer buffer. Direct access is required
56  * in order to support decryption of data received via the
57  * retrieval protocol (which provides the AES initialisation
58  * vector only after all of the encrypted data has been
59  * received).
60  *
61  * This test simultaneously ensures that we do not attempt to
62  * use PeerDist encoding on a request which is itself a
63  * PeerDist individual block download, since the individual
64  * block downloads do not themselves provide direct access to
65  * an underlying data transfer buffer.
66  */
67  return ( xfer_buffer ( &http->xfer ) != NULL );
68 }
struct interface xfer
Data transfer interface.
Definition: http.h:421
A data transfer buffer.
Definition: xferbuf.h:19
static long peerdist_enabled
PeerDist is globally enabled.
Definition: peerdist.c:40
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References NULL, peerdist_enabled, and http_transaction::xfer.

Referenced by http_format_p2p_peerdist(), and http_format_p2p_peerdistex().

◆ http_format_p2p_peerdist()

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 78 of file peerdist.c.

79  {
80  int supported = http_peerdist_supported ( http );
81  int missing;
82 
83  /* PeerDist wants us to inform the server whenever we make a
84  * request for data that was missing from local peers
85  * (presumably for statistical purposes only). We use the
86  * heuristic of assuming that the combination of "this request
87  * may not itself use PeerDist content encoding" and "this is
88  * a range request" probably indicates that we are making a
89  * PeerDist block raw range request for missing data.
90  */
91  missing = ( http->request.range.len && ( ! supported ) );
92 
93  /* Omit header if PeerDist encoding is not supported and we
94  * are not reporting a missing data request.
95  */
96  if ( ! ( supported || missing ) )
97  return 0;
98 
99  /* Construct header */
100  return snprintf ( buf, len, "Version=1.1%s",
101  ( missing ? ", MissingDataRequest=true" : "" ) );
102 }
struct http_request_range range
Range descriptor.
Definition: http.h:220
struct http_request request
Request.
Definition: http.h:436
size_t len
Range length, or zero for no range request.
Definition: http.h:141
uint32_t len
Length.
Definition: ena.h:14
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
static int http_peerdist_supported(struct http_transaction *http)
Check whether or not to support PeerDist encoding for this request.
Definition: peerdist.c:48

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

◆ http_format_p2p_peerdistex()

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 118 of file peerdist.c.

119  {
120  int supported = http_peerdist_supported ( http );
121 
122  /* Omit header if PeerDist encoding is not supported */
123  if ( ! supported )
124  return 0;
125 
126  /* Construct header */
127  return snprintf ( buf, len, ( "MinContentInformation=1.0, "
128  "MaxContentInformation=2.0" ) );
129 }
uint32_t len
Length.
Definition: ena.h:14
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
static int http_peerdist_supported(struct http_transaction *http)
Check whether or not to support PeerDist encoding for this request.
Definition: peerdist.c:48

References http_peerdist_supported(), len, and snprintf().

◆ http_peerdist_init()

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 143 of file peerdist.c.

143  {
144 
145  return peermux_filter ( &http->content, &http->transfer, http->uri );
146 }
int peermux_filter(struct interface *xfer, struct interface *info, struct uri *uri)
Add PeerDist content-encoding filter.
Definition: peermux.c:411
struct uri * uri
Request URI.
Definition: http.h:434
struct interface content
Content-decoded interface.
Definition: http.h:423
struct interface transfer
Transfer-decoded interface.
Definition: http.h:425

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

◆ __setting()

const struct setting peerdist_setting __setting ( SETTING_MISC  ,
peerdist   
)

PeerDist enabled setting.

◆ apply_peerdist_settings()

static int apply_peerdist_settings ( void  )
static

Apply PeerDist settings.

Return values
rcReturn status code

Definition at line 167 of file peerdist.c.

167  {
168 
169  /* Fetch global PeerDist enabled setting */
170  if ( fetch_int_setting ( NULL, &peerdist_setting,
171  &peerdist_enabled ) < 0 ) {
172  peerdist_enabled = 1;
173  }
174  DBGC ( &peerdist_enabled, "PEERDIST is %s\n",
175  ( peerdist_enabled ? "enabled" : "disabled" ) );
176 
177  return 0;
178 }
#define DBGC(...)
Definition: compiler.h:505
static long peerdist_enabled
PeerDist is globally enabled.
Definition: peerdist.c:40
int fetch_int_setting(struct settings *settings, const struct setting *setting, long *value)
Fetch value of signed integer setting.
Definition: settings.c:1027
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBGC, fetch_int_setting(), NULL, and peerdist_enabled.

Variable Documentation

◆ peerdist_enabled

long peerdist_enabled = 1
static

PeerDist is globally enabled.

Definition at line 40 of file peerdist.c.

Referenced by apply_peerdist_settings(), and http_peerdist_supported().

◆ __http_request_header

struct http_request_header http_request_p2p_peerdistex __http_request_header
Initial value:
= {
.name = "X-P2P-PeerDist",
}
static int http_format_p2p_peerdist(struct http_transaction *http, char *buf, size_t len)
Format HTTP "X-P2P-PeerDist" header.
Definition: peerdist.c:78

HTTP "X-P2P-PeerDist" header.

Definition at line 105 of file peerdist.c.

◆ __http_content_encoding

struct http_content_encoding peerdist_encoding __http_content_encoding
Initial value:
= {
.name = "peerdist",
}
static int http_peerdist_init(struct http_transaction *http)
Initialise PeerDist content encoding.
Definition: peerdist.c:143
static int http_peerdist_supported(struct http_transaction *http)
Check whether or not to support PeerDist encoding for this request.
Definition: peerdist.c:48

PeerDist HTTP content encoding.

Definition at line 149 of file peerdist.c.

◆ __settings_applicator

struct settings_applicator peerdist_applicator __settings_applicator
Initial value:
= {
}
static int apply_peerdist_settings(void)
Apply PeerDist settings.
Definition: peerdist.c:167

PeerDist settings applicator.

Definition at line 181 of file peerdist.c.