1 #ifndef _IPXE_PEERBLK_H
2 #define _IPXE_PEERBLK_H
6 * Peer Content Caching and Retrieval (PeerDist) protocol block downloads
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13 #include <ipxe/refcnt.h>
14 #include <ipxe/interface.h>
15 #include <ipxe/crypto.h>
17 #include <ipxe/xferbuf.h>
18 #include <ipxe/retry.h>
19 #include <ipxe/process.h>
20 #include <ipxe/pccrc.h>
21 #include <ipxe/peerdisc.h>
23 /** A PeerDist retrieval protocol decryption buffer descriptor */
24 struct peerdist_block_decrypt {
25 /** Data transfer buffer */
26 struct xfer_buffer *xferbuf;
27 /** Offset within data transfer buffer */
29 /** Length to use from data transfer buffer */
33 /** PeerDist retrieval protocol decryption data transfer buffer indices */
34 enum peerdist_block_decrypt_index {
35 /** Data before the trimmed content */
37 /** Data within the trimmed content */
39 /** Data after the trimmed content */
41 /** Number of decryption buffers */
45 /** A PeerDist block download */
46 struct peerdist_block {
47 /** Reference count */
49 /** Data transfer interface */
50 struct interface xfer;
51 /** Raw data interface */
53 /** Retrieval protocol interface */
54 struct interface retrieval;
58 /** Content range of this block */
59 struct peerdist_range range;
60 /** Trimmed range of this block */
61 struct peerdist_range trim;
62 /** Offset of first byte in trimmed range within overall download */
65 /** Digest algorithm */
66 struct digest_algorithm *digest;
69 * Note that this may be shorter than the digest size of the
73 /** Digest context (statically allocated at instantiation time) */
76 /** Cipher algorithm */
77 struct cipher_algorithm *cipher;
78 /** Cipher context (dynamically allocated as needed) */
83 /** Segment identifier */
84 uint8_t id[PEERDIST_DIGEST_MAX_SIZE];
86 uint8_t secret[PEERDIST_DIGEST_MAX_SIZE];
90 uint8_t hash[PEERDIST_DIGEST_MAX_SIZE];
92 /** Current position (relative to incoming data stream) */
94 /** Start of trimmed content (relative to incoming data stream) */
96 /** End of trimmed content (relative to incoming data stream) */
99 struct xfer_buffer buffer;
101 /** Decryption process */
102 struct process process;
103 /** Decryption data buffer descriptors */
104 struct peerdist_block_decrypt decrypt[PEERBLK_NUM_BUFFERS];
105 /** Remaining decryption length */
106 size_t cipher_remaining;
107 /** Remaining digest length (excluding AES padding bytes) */
108 size_t digest_remaining;
110 /** Discovery client */
111 struct peerdisc_client discovery;
112 /** Current position in discovered peer list */
113 struct peerdisc_peer *peer;
115 struct retry_timer timer;
116 /** Number of full attempt cycles completed */
118 /** Most recent attempt failure */
121 /** Time at which block download was started */
122 unsigned long started;
123 /** Time at which most recent attempt was started */
124 unsigned long attempted;
127 /** Retrieval protocol block fetch response (including transport header)
129 * @v digestsize Digest size
130 * @v len Data block length
131 * @v vrf_len Length of uselessness
132 * @v blksize Cipher block size
134 #define peerblk_msg_blk_t( digestsize, len, vrf_len, blksize ) \
136 struct peerdist_msg_transport_header hdr; \
137 peerdist_msg_blk_t ( digestsize, len, vrf_len, \
139 } __attribute__ (( packed ))
141 extern int peerblk_open ( struct interface *xfer, struct uri *uri,
142 struct peerdist_info_block *block );
144 #endif /* _IPXE_PEERBLK_H */