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 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. /** Retry timer */
  102. struct retry_timer timer;
  103. /** Number of full attempt cycles completed */
  104. unsigned int cycles;
  105. /** Most recent attempt failure */
  106. int rc;
  107. /** Time at which block download was started */
  108. unsigned long started;
  109. /** Time at which most recent attempt was started */
  110. unsigned long attempted;
  111. };
  112. /** Retrieval protocol block fetch response (including transport header)
  113. *
  114. * @v digestsize Digest size
  115. * @v len Data block length
  116. * @v vrf_len Length of uselessness
  117. * @v blksize Cipher block size
  118. */
  119. #define peerblk_msg_blk_t( digestsize, len, vrf_len, blksize ) \
  120. struct { \
  121. struct peerdist_msg_transport_header hdr; \
  122. peerdist_msg_blk_t ( digestsize, len, vrf_len, \
  123. blksize ) msg; \
  124. } __attribute__ (( packed ))
  125. extern int peerblk_open ( struct interface *xfer, struct uri *uri,
  126. struct peerdist_info_block *block );
  127. #endif /* _IPXE_PEERBLK_H */