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

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

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

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

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

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

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

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

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

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

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

144  {
145 
146  return peermux_filter ( &http->content, &http->transfer, http->uri );
147 }
int peermux_filter(struct interface *xfer, struct interface *info, struct uri *uri)
Add PeerDist content-encoding filter.
Definition: peermux.c:413
struct uri * uri
Request URI.
Definition: http.h:435
struct interface content
Content-decoded interface.
Definition: http.h:422
struct interface transfer
Transfer-decoded interface.
Definition: http.h:424

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

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

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 41 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:79

HTTP "X-P2P-PeerDist" header.

Definition at line 106 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:144
static int http_peerdist_supported(struct http_transaction *http)
Check whether or not to support PeerDist encoding for this request.
Definition: peerdist.c:49

PeerDist HTTP content encoding.

Definition at line 150 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:168

PeerDist settings applicator.

Definition at line 182 of file peerdist.c.