Quellcode durchsuchen

[peerdist] Add individual block download mechanism

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown vor 9 Jahren
Ursprung
Commit
4d032d5db8
4 geänderte Dateien mit 1523 neuen und 0 gelöschten Zeilen
  1. 12
    0
      src/config/fault.h
  2. 1
    0
      src/include/ipxe/errfile.h
  3. 144
    0
      src/include/ipxe/peerblk.h
  4. 1366
    0
      src/net/peerblk.c

+ 12
- 0
src/config/fault.h Datei anzeigen

@@ -17,6 +17,18 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
17 17
 /* Drop every N transmitted or received PeerDist discovery packets */
18 18
 #define PEERDISC_DISCARD_RATE 0
19 19
 
20
+/* Annul every N PeerDist download attempts */
21
+#define PEERBLK_ANNUL_RATE 0
22
+
23
+/* Stall every N PeerDist download attempts */
24
+#define PEERBLK_STALL_RATE 0
25
+
26
+/* Abort every N PeerDist download attempts */
27
+#define PEERBLK_ABORT_RATE 0
28
+
29
+/* Corrupt every N received PeerDist packets */
30
+#define PEERBLK_CORRUPT_RATE 0
31
+
20 32
 #include <config/local/fault.h>
21 33
 
22 34
 #endif /* CONFIG_FAULT_H */

+ 1
- 0
src/include/ipxe/errfile.h Datei anzeigen

@@ -253,6 +253,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
253 253
 #define ERRFILE_httpbasic		( ERRFILE_NET | 0x00430000 )
254 254
 #define ERRFILE_httpdigest		( ERRFILE_NET | 0x00440000 )
255 255
 #define ERRFILE_peerdisc		( ERRFILE_NET | 0x00450000 )
256
+#define ERRFILE_peerblk			( ERRFILE_NET | 0x00460000 )
256 257
 
257 258
 #define ERRFILE_image		      ( ERRFILE_IMAGE | 0x00000000 )
258 259
 #define ERRFILE_elf		      ( ERRFILE_IMAGE | 0x00010000 )

+ 144
- 0
src/include/ipxe/peerblk.h Datei anzeigen

@@ -0,0 +1,144 @@
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
+
12
+#include <stdint.h>
13
+#include <ipxe/refcnt.h>
14
+#include <ipxe/interface.h>
15
+#include <ipxe/crypto.h>
16
+#include <ipxe/aes.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>
22
+
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 */
28
+	size_t offset;
29
+	/** Length to use from data transfer buffer */
30
+	size_t len;
31
+};
32
+
33
+/** PeerDist retrieval protocol decryption data transfer buffer indices */
34
+enum peerdist_block_decrypt_index {
35
+	/** Data before the trimmed content */
36
+	PEERBLK_BEFORE = 0,
37
+	/** Data within the trimmed content */
38
+	PEERBLK_DURING,
39
+	/** Data after the trimmed content */
40
+	PEERBLK_AFTER,
41
+	/** Number of decryption buffers */
42
+	PEERBLK_NUM_BUFFERS
43
+};
44
+
45
+/** A PeerDist block download */
46
+struct peerdist_block {
47
+	/** Reference count */
48
+	struct refcnt refcnt;
49
+	/** Data transfer interface */
50
+	struct interface xfer;
51
+	/** Raw data interface */
52
+	struct interface raw;
53
+	/** Retrieval protocol interface */
54
+	struct interface retrieval;
55
+
56
+	/** Original URI */
57
+	struct uri *uri;
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 */
63
+	size_t offset;
64
+
65
+	/** Digest algorithm */
66
+	struct digest_algorithm *digest;
67
+	/** Digest size
68
+	 *
69
+	 * Note that this may be shorter than the digest size of the
70
+	 * digest algorithm.
71
+	 */
72
+	size_t digestsize;
73
+	/** Digest context (statically allocated at instantiation time) */
74
+	void *digestctx;
75
+
76
+	/** Cipher algorithm */
77
+	struct cipher_algorithm *cipher;
78
+	/** Cipher context (dynamically allocated as needed) */
79
+	void *cipherctx;
80
+
81
+	/** Segment index */
82
+	unsigned int segment;
83
+	/** Segment identifier */
84
+	uint8_t id[PEERDIST_DIGEST_MAX_SIZE];
85
+	/** Segment secret */
86
+	uint8_t secret[PEERDIST_DIGEST_MAX_SIZE];
87
+	/** Block index */
88
+	unsigned int block;
89
+	/** Block hash */
90
+	uint8_t hash[PEERDIST_DIGEST_MAX_SIZE];
91
+
92
+	/** Current position (relative to incoming data stream) */
93
+	size_t pos;
94
+	/** Start of trimmed content (relative to incoming data stream) */
95
+	size_t start;
96
+	/** End of trimmed content (relative to incoming data stream) */
97
+	size_t end;
98
+	/** Data buffer */
99
+	struct xfer_buffer buffer;
100
+
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;
109
+
110
+	/** Discovery client */
111
+	struct peerdisc_client discovery;
112
+	/** Current position in discovered peer list */
113
+	struct peerdisc_peer *peer;
114
+	/** Retry timer */
115
+	struct retry_timer timer;
116
+	/** Number of full attempt cycles completed */
117
+	unsigned int cycles;
118
+	/** Most recent attempt failure */
119
+	int rc;
120
+
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;
125
+};
126
+
127
+/** Retrieval protocol block fetch response (including transport header)
128
+ *
129
+ * @v digestsize	Digest size
130
+ * @v len		Data block length
131
+ * @v vrf_len		Length of uselessness
132
+ * @v blksize		Cipher block size
133
+ */
134
+#define peerblk_msg_blk_t( digestsize, len, vrf_len, blksize )		\
135
+	struct {							\
136
+		struct peerdist_msg_transport_header hdr;		\
137
+		peerdist_msg_blk_t ( digestsize, len, vrf_len,		\
138
+				     blksize ) msg;			\
139
+	} __attribute__ (( packed ))
140
+
141
+extern int peerblk_open ( struct interface *xfer, struct uri *uri,
142
+			  struct peerdist_info_block *block );
143
+
144
+#endif /* _IPXE_PEERBLK_H */

+ 1366
- 0
src/net/peerblk.c
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


Laden…
Abbrechen
Speichern