You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

peerblk.h 4.4KB

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