iPXE
peerblk.h
Go to the documentation of this file.
1 #ifndef _IPXE_PEERBLK_H
2 #define _IPXE_PEERBLK_H
3 
4 /** @file
5  *
6  * Peer Content Caching and Retrieval (PeerDist) protocol block downloads
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdint.h>
14 #include <ipxe/refcnt.h>
15 #include <ipxe/interface.h>
16 #include <ipxe/crypto.h>
17 #include <ipxe/aes.h>
18 #include <ipxe/xferbuf.h>
19 #include <ipxe/retry.h>
20 #include <ipxe/process.h>
21 #include <ipxe/pccrc.h>
22 #include <ipxe/peerdisc.h>
23 
24 /** A PeerDist retrieval protocol decryption buffer descriptor */
26  /** Data transfer buffer */
28  /** Offset within data transfer buffer */
29  size_t offset;
30  /** Length to use from data transfer buffer */
31  size_t len;
32 };
33 
34 /** PeerDist retrieval protocol decryption data transfer buffer indices */
36  /** Data before the trimmed content */
38  /** Data within the trimmed content */
40  /** Data after the trimmed content */
42  /** Number of decryption buffers */
44 };
45 
46 /** A PeerDist block download */
48  /** Reference count */
49  struct refcnt refcnt;
50  /** Data transfer interface */
51  struct interface xfer;
52  /** Raw data interface */
53  struct interface raw;
54  /** Retrieval protocol interface */
56 
57  /** Original URI */
58  struct uri *uri;
59  /** Content range of this block */
61  /** Trimmed range of this block */
63  /** Offset of first byte in trimmed range within overall download */
64  size_t offset;
65 
66  /** Digest algorithm */
68  /** Digest size
69  *
70  * Note that this may be shorter than the digest size of the
71  * digest algorithm.
72  */
73  size_t digestsize;
74  /** Digest context (statically allocated at instantiation time) */
75  void *digestctx;
76 
77  /** Cipher algorithm */
79  /** Cipher context (dynamically allocated as needed) */
80  void *cipherctx;
81 
82  /** Segment index */
83  unsigned int segment;
84  /** Segment identifier */
86  /** Segment secret */
88  /** Block index */
89  unsigned int block;
90  /** Block hash */
92 
93  /** Current position (relative to incoming data stream) */
94  size_t pos;
95  /** Start of trimmed content (relative to incoming data stream) */
96  size_t start;
97  /** End of trimmed content (relative to incoming data stream) */
98  size_t end;
99  /** Data buffer */
101 
102  /** Decryption process */
103  struct process process;
104  /** Decryption data buffer descriptors */
106  /** Remaining decryption length */
108  /** Remaining digest length (excluding AES padding bytes) */
110 
111  /** Discovery client */
113  /** Current position in discovered peer list */
115  /** Block download queue */
117  /** List of queued block downloads */
119  /** Retry timer */
121  /** Number of full attempt cycles completed */
122  unsigned int cycles;
123  /** Most recent attempt failure */
124  int rc;
125 
126  /** Time at which block download was started */
127  unsigned long started;
128  /** Time at which most recent attempt was started */
129  unsigned long attempted;
130 };
131 
132 /** PeerDist block download queue */
134  /** Download opening process */
135  struct process process;
136  /** List of queued downloads */
137  struct list_head list;
138 
139  /** Number of open downloads */
140  unsigned int count;
141  /** Maximum number of open downloads */
142  unsigned int max;
143 
144  /** Open block download
145  *
146  * @v peerblk PeerDist block download
147  * @ret rc Return status code
148  */
149  int ( * open ) ( struct peerdist_block *peerblk );
150 };
151 
152 /** Retrieval protocol block fetch response (including transport header)
153  *
154  * @v digestsize Digest size
155  * @v len Data block length
156  * @v vrf_len Length of uselessness
157  * @v blksize Cipher block size
158  */
159 #define peerblk_msg_blk_t( digestsize, len, vrf_len, blksize ) \
160  struct { \
161  struct peerdist_msg_transport_header hdr; \
162  peerdist_msg_blk_t ( digestsize, len, vrf_len, \
163  blksize ) msg; \
164  } __attribute__ (( packed ))
165 
166 extern int peerblk_open ( struct interface *xfer, struct uri *uri,
167  struct peerdist_info_block *block );
168 
169 #endif /* _IPXE_PEERBLK_H */
A process.
Definition: process.h:18
struct list_head list
List of queued downloads.
Definition: peerblk.h:137
struct xfer_buffer buffer
Data buffer.
Definition: peerblk.h:100
Data after the trimmed content.
Definition: peerblk.h:41
size_t digest_remaining
Remaining digest length (excluding AES padding bytes)
Definition: peerblk.h:109
A data transfer buffer.
Definition: xferbuf.h:19
Retry timers.
struct interface retrieval
Retrieval protocol interface.
Definition: peerblk.h:55
void * digestctx
Digest context (statically allocated at instantiation time)
Definition: peerblk.h:75
A PeerDist retrieval protocol decryption buffer descriptor.
Definition: peerblk.h:25
size_t offset
Offset of first byte in trimmed range within overall download.
Definition: peerblk.h:64
A retry timer.
Definition: retry.h:22
Cryptographic API.
unsigned int cycles
Number of full attempt cycles completed.
Definition: peerblk.h:122
struct peerdisc_client discovery
Discovery client.
Definition: peerblk.h:112
Peer Content Caching and Retrieval (PeerDist) protocol peer discovery.
struct cipher_algorithm * cipher
Cipher algorithm.
Definition: peerblk.h:78
A doubly-linked list entry (or list head)
Definition: list.h:19
size_t end
End of trimmed content (relative to incoming data stream)
Definition: peerblk.h:98
Data before the trimmed content.
Definition: peerblk.h:37
struct digest_algorithm * digest
Digest algorithm.
Definition: peerblk.h:67
A reference counter.
Definition: refcnt.h:27
A timer.
Definition: timer.h:29
Data within the trimmed content.
Definition: peerblk.h:39
A content information block.
Definition: pccrc.h:394
struct uri * uri
Original URI.
Definition: peerblk.h:58
int rc
Most recent attempt failure.
Definition: peerblk.h:124
struct peerdist_range range
Content range of this block.
Definition: peerblk.h:60
unsigned int max
Maximum number of open downloads.
Definition: peerblk.h:142
A PeerDist block download.
Definition: peerblk.h:47
A PeerDist discovery client.
Definition: peerdisc.h:80
An object interface.
Definition: interface.h:125
int(* open)(struct peerdist_block *peerblk)
Open block download.
Definition: peerblk.h:149
struct peerdist_block_queue * queue
Block download queue.
Definition: peerblk.h:116
Object interfaces.
unsigned int segment
Segment index.
Definition: peerblk.h:83
struct interface raw
Raw data interface.
Definition: peerblk.h:53
size_t offset
Offset within data transfer buffer.
Definition: peerblk.h:29
unsigned int block
Block index.
Definition: peerblk.h:89
struct peerdisc_peer * peer
Current position in discovered peer list.
Definition: peerblk.h:114
struct interface xfer
Data transfer interface.
Definition: peerblk.h:51
uint8_t hash[PEERDIST_DIGEST_MAX_SIZE]
Block hash.
Definition: peerblk.h:91
AES algorithm.
Peer Content Caching and Retrieval: Content Identification [MS-PCCRC].
A content range.
Definition: pccrc.h:309
FILE_SECBOOT(PERMITTED)
void * cipherctx
Cipher context (dynamically allocated as needed)
Definition: peerblk.h:80
PeerDist block download queue.
Definition: peerblk.h:133
struct xfer_buffer * xferbuf
Data transfer buffer.
Definition: peerblk.h:27
Processes.
unsigned char uint8_t
Definition: stdint.h:10
size_t digestsize
Digest size.
Definition: peerblk.h:73
size_t start
Start of trimmed content (relative to incoming data stream)
Definition: peerblk.h:96
unsigned long started
Time at which block download was started.
Definition: peerblk.h:127
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct list_head queued
List of queued block downloads.
Definition: peerblk.h:118
int peerblk_open(struct interface *xfer, struct uri *uri, struct peerdist_info_block *block)
Open PeerDist block download.
Definition: peerblk.c:1434
unsigned long attempted
Time at which most recent attempt was started.
Definition: peerblk.h:129
#define PEERDIST_DIGEST_MAX_SIZE
Maximum digest size for any supported algorithm.
Definition: pccrc.h:298
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
unsigned int count
Number of open downloads.
Definition: peerblk.h:140
struct peerdist_block_decrypt decrypt[PEERBLK_NUM_BUFFERS]
Decryption data buffer descriptors.
Definition: peerblk.h:105
uint8_t secret[PEERDIST_DIGEST_MAX_SIZE]
Segment secret.
Definition: peerblk.h:87
A message digest algorithm.
Definition: crypto.h:19
Reference counting.
A cipher algorithm.
Definition: crypto.h:51
Number of decryption buffers.
Definition: peerblk.h:43
struct peerdist_range trim
Trimmed range of this block.
Definition: peerblk.h:62
A Uniform Resource Identifier.
Definition: uri.h:65
size_t cipher_remaining
Remaining decryption length.
Definition: peerblk.h:107
peerdist_block_decrypt_index
PeerDist retrieval protocol decryption data transfer buffer indices.
Definition: peerblk.h:35
size_t pos
Current position (relative to incoming data stream)
Definition: peerblk.h:94
size_t len
Length to use from data transfer buffer.
Definition: peerblk.h:31
Data transfer buffer.
A PeerDist discovery peer.
Definition: peerdisc.h:72