|
@@ -45,6 +45,24 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
45
|
45
|
/** Define inline raw data */
|
46
|
46
|
#define DATA(...) { __VA_ARGS__ }
|
47
|
47
|
|
|
48
|
+/**
|
|
49
|
+ * Define an inline content range
|
|
50
|
+ *
|
|
51
|
+ * @v START Start offset
|
|
52
|
+ * @v END End offset
|
|
53
|
+ * @ret range Content range
|
|
54
|
+ */
|
|
55
|
+#define RANGE( START, END ) { .start = START, .end = END }
|
|
56
|
+
|
|
57
|
+/**
|
|
58
|
+ * Define an inline trimmed content range
|
|
59
|
+ *
|
|
60
|
+ * @v START Start offset
|
|
61
|
+ * @v END End offset
|
|
62
|
+ * @ret trim Trimmed content range
|
|
63
|
+ */
|
|
64
|
+#define TRIM( START, END ) { .start = START, .end = END }
|
|
65
|
+
|
48
|
66
|
/** A content information test */
|
49
|
67
|
struct peerdist_info_test {
|
50
|
68
|
/** Raw content information */
|
|
@@ -55,6 +73,8 @@ struct peerdist_info_test {
|
55
|
73
|
struct digest_algorithm *expected_digest;
|
56
|
74
|
/** Expected digest size */
|
57
|
75
|
size_t expected_digestsize;
|
|
76
|
+ /** Expected content range */
|
|
77
|
+ struct peerdist_range expected_range;
|
58
|
78
|
/** Expected trimmed content range */
|
59
|
79
|
struct peerdist_range expected_trim;
|
60
|
80
|
/** Expected number of segments */
|
|
@@ -68,8 +88,8 @@ struct peerdist_info_test {
|
68
|
88
|
* @v DATA Raw content information
|
69
|
89
|
* @v DIGEST Expected digest algorithm
|
70
|
90
|
* @v DIGESTSIZE Expected digest size
|
71
|
|
- * @v START Expected trimmed content range start offset
|
72
|
|
- * @v END Expected trimmed content range end offset
|
|
91
|
+ * @v RANGE Expected content range
|
|
92
|
+ * @v TRIM Expected trimmer content range
|
73
|
93
|
* @v SEGMENTS Expected number of segments
|
74
|
94
|
* @ret test Content information test
|
75
|
95
|
*
|
|
@@ -93,18 +113,16 @@ struct peerdist_info_test {
|
93
|
113
|
* X-P2P-PeerDist: Version=1.1
|
94
|
114
|
* X-P2P-PeerDistEx: MinContentInformation=2.0, MaxContentInformation=2.0
|
95
|
115
|
*/
|
96
|
|
-#define PEERDIST_INFO_TEST( name, DATA, DIGEST, DIGESTSIZE, START, END, \
|
97
|
|
- SEGMENTS ) \
|
|
116
|
+#define PEERDIST_INFO_TEST( name, DATA, DIGEST, DIGESTSIZE, RANGE, \
|
|
117
|
+ TRIM, SEGMENTS ) \
|
98
|
118
|
static const uint8_t name ## _data[] = DATA; \
|
99
|
119
|
static struct peerdist_info_test name = { \
|
100
|
120
|
.data = name ## _data, \
|
101
|
121
|
.len = sizeof ( name ## _data ), \
|
102
|
122
|
.expected_digest = DIGEST, \
|
103
|
123
|
.expected_digestsize = DIGESTSIZE, \
|
104
|
|
- .expected_trim = { \
|
105
|
|
- .start = START, \
|
106
|
|
- .end = END, \
|
107
|
|
- }, \
|
|
124
|
+ .expected_range = RANGE, \
|
|
125
|
+ .expected_trim = TRIM, \
|
108
|
126
|
.expected_segments = SEGMENTS, \
|
109
|
127
|
}
|
110
|
128
|
|
|
@@ -131,8 +149,7 @@ struct peerdist_info_segment_test {
|
131
|
149
|
*
|
132
|
150
|
* @v name Test name
|
133
|
151
|
* @v INDEX Segment index
|
134
|
|
- * @v START Expected content range start offset
|
135
|
|
- * @v END Expected content range end offset
|
|
152
|
+ * @v RANGE Expected content range
|
136
|
153
|
* @v BLOCKS Expected number of blocks
|
137
|
154
|
* @v BLKSIZE Expected block size
|
138
|
155
|
* @v HASH Expected segment hash of data
|
|
@@ -140,14 +157,11 @@ struct peerdist_info_segment_test {
|
140
|
157
|
* @v ID Expected segment identifier
|
141
|
158
|
* @ret test Content information segment test
|
142
|
159
|
*/
|
143
|
|
-#define PEERDIST_INFO_SEGMENT_TEST( name, INDEX, START, END, BLOCKS, \
|
|
160
|
+#define PEERDIST_INFO_SEGMENT_TEST( name, INDEX, RANGE, BLOCKS, \
|
144
|
161
|
BLKSIZE, HASH, SECRET, ID ) \
|
145
|
162
|
static struct peerdist_info_segment_test name = { \
|
146
|
163
|
.index = INDEX, \
|
147
|
|
- .expected_range = { \
|
148
|
|
- .start = START, \
|
149
|
|
- .end = END, \
|
150
|
|
- }, \
|
|
164
|
+ .expected_range = RANGE, \
|
151
|
165
|
.expected_blocks = BLOCKS, \
|
152
|
166
|
.expected_blksize = BLKSIZE, \
|
153
|
167
|
.expected_hash = HASH, \
|
|
@@ -161,6 +175,8 @@ struct peerdist_info_block_test {
|
161
|
175
|
unsigned int index;
|
162
|
176
|
/** Expected content range */
|
163
|
177
|
struct peerdist_range expected_range;
|
|
178
|
+ /** Expected trimmed content range */
|
|
179
|
+ struct peerdist_range expected_trim;
|
164
|
180
|
/** Expected hash of data */
|
165
|
181
|
uint8_t expected_hash[PEERDIST_DIGEST_MAX_SIZE];
|
166
|
182
|
};
|
|
@@ -170,18 +186,16 @@ struct peerdist_info_block_test {
|
170
|
186
|
*
|
171
|
187
|
* @v name Test name
|
172
|
188
|
* @v INDEX Block index
|
173
|
|
- * @v START Expected content range start offset
|
174
|
|
- * @v END Expected content range end offset
|
|
189
|
+ * @v RANGE Expected content range
|
|
190
|
+ * @v TRIM Expected trimmed content range
|
175
|
191
|
* @v HASH Expected hash of data
|
176
|
192
|
* @ret test Content information block test
|
177
|
193
|
*/
|
178
|
|
-#define PEERDIST_INFO_BLOCK_TEST( name, INDEX, START, END, HASH ) \
|
|
194
|
+#define PEERDIST_INFO_BLOCK_TEST( name, INDEX, RANGE, TRIM, HASH ) \
|
179
|
195
|
static struct peerdist_info_block_test name = { \
|
180
|
196
|
.index = INDEX, \
|
181
|
|
- .expected_range = { \
|
182
|
|
- .start = START, \
|
183
|
|
- .end = END, \
|
184
|
|
- }, \
|
|
197
|
+ .expected_range = RANGE, \
|
|
198
|
+ .expected_trim = TRIM, \
|
185
|
199
|
.expected_hash = HASH, \
|
186
|
200
|
}
|
187
|
201
|
|
|
@@ -242,11 +256,11 @@ PEERDIST_INFO_TEST ( iis_85_png_v1,
|
242
|
256
|
0xaf, 0xe4, 0x57, 0xa9, 0x50, 0x3b, 0x45, 0x48, 0xf6, 0x6e, 0xd3,
|
243
|
257
|
0xb1, 0x88, 0xdc, 0xfd, 0xa0, 0xac, 0x38, 0x2b, 0x09, 0x71, 0x1a,
|
244
|
258
|
0xcc ),
|
245
|
|
- &sha256_algorithm, 32, 0, 99710, 1 );
|
|
259
|
+ &sha256_algorithm, 32, RANGE ( 0, 99710 ), TRIM ( 0, 99710 ), 1 );
|
246
|
260
|
|
247
|
261
|
/** IIS logo (iis-85.png) content information version 1 segment 0 */
|
248
|
262
|
PEERDIST_INFO_SEGMENT_TEST ( iis_85_png_v1_s0, 0,
|
249
|
|
- 0, 99710, 2, 65536,
|
|
263
|
+ RANGE ( 0, 99710 ), 2, 65536,
|
250
|
264
|
DATA ( 0xd8, 0xd9, 0x76, 0x35, 0x4a, 0x48, 0x72, 0xe9, 0x25, 0x76, 0x18,
|
251
|
265
|
0x03, 0xf4, 0x58, 0xd9, 0xda, 0xaa, 0x67, 0xf8, 0xe3, 0x1c, 0x63,
|
252
|
266
|
0x0f, 0xb7, 0x4e, 0x6a, 0x31, 0x2e, 0xf8, 0xa2, 0x5a, 0xba ),
|
|
@@ -259,14 +273,16 @@ PEERDIST_INFO_SEGMENT_TEST ( iis_85_png_v1_s0, 0,
|
259
|
273
|
|
260
|
274
|
/** IIS logo (iis-85.png) content information version 1 segment 0 block 0 */
|
261
|
275
|
PEERDIST_INFO_BLOCK_TEST ( iis_85_png_v1_s0_b0, 0,
|
262
|
|
- 0, 65536,
|
|
276
|
+ RANGE ( 0, 65536 ),
|
|
277
|
+ TRIM ( 0, 65536 ),
|
263
|
278
|
DATA ( 0x73, 0xc1, 0x8a, 0xb8, 0x54, 0x91, 0x10, 0xf8, 0xe9, 0x0e, 0x71,
|
264
|
279
|
0xbb, 0xc3, 0xab, 0x2a, 0xa8, 0xc4, 0x4d, 0x13, 0xf4, 0x92, 0x94,
|
265
|
280
|
0x99, 0x25, 0x5b, 0x66, 0x0f, 0x24, 0xec, 0x77, 0x80, 0x0b ) );
|
266
|
281
|
|
267
|
282
|
/** IIS logo (iis-85.png) content information version 1 segment 0 block 1 */
|
268
|
283
|
PEERDIST_INFO_BLOCK_TEST ( iis_85_png_v1_s0_b1, 1,
|
269
|
|
- 65536, 99710,
|
|
284
|
+ RANGE ( 65536, 99710 ),
|
|
285
|
+ TRIM ( 65536, 99710 ),
|
270
|
286
|
DATA ( 0x97, 0x4b, 0xdd, 0x65, 0x56, 0x7f, 0xde, 0xec, 0xcd, 0xaf, 0xe4,
|
271
|
287
|
0x57, 0xa9, 0x50, 0x3b, 0x45, 0x48, 0xf6, 0x6e, 0xd3, 0xb1, 0x88,
|
272
|
288
|
0xdc, 0xfd, 0xa0, 0xac, 0x38, 0x2b, 0x09, 0x71, 0x1a, 0xcc ) );
|
|
@@ -289,11 +305,11 @@ PEERDIST_INFO_TEST ( iis_85_png_v2,
|
289
|
305
|
0x77, 0x83, 0xe4, 0xf8, 0x07, 0x64, 0x7b, 0x63, 0xf1, 0x46, 0xb5,
|
290
|
306
|
0x2f, 0x4a, 0xc8, 0x9c, 0xcc, 0x7a, 0xbf, 0x5f, 0xa1, 0x1a, 0xca,
|
291
|
307
|
0xfc, 0x2a, 0xcf, 0x50, 0x28, 0x58, 0x6c ),
|
292
|
|
- &sha512_algorithm, 32, 0, 99710, 2 );
|
|
308
|
+ &sha512_algorithm, 32, RANGE ( 0, 99710 ), TRIM ( 0, 99710 ), 2 );
|
293
|
309
|
|
294
|
310
|
/** IIS logo (iis-85.png) content information version 2 segment 0 */
|
295
|
311
|
PEERDIST_INFO_SEGMENT_TEST ( iis_85_png_v2_s0, 0,
|
296
|
|
- 0, 39390, 1, 39390,
|
|
312
|
+ RANGE ( 0, 39390 ), 1, 39390,
|
297
|
313
|
DATA ( 0xe0, 0xd0, 0xc3, 0x58, 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32,
|
298
|
314
|
0xb5, 0xf1, 0x97, 0x87, 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e,
|
299
|
315
|
0x78, 0x1f, 0xae, 0x71, 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4 ),
|
|
@@ -306,14 +322,15 @@ PEERDIST_INFO_SEGMENT_TEST ( iis_85_png_v2_s0, 0,
|
306
|
322
|
|
307
|
323
|
/** IIS logo (iis-85.png) content information version 2 segment 0 block 0 */
|
308
|
324
|
PEERDIST_INFO_BLOCK_TEST ( iis_85_png_v2_s0_b0, 0,
|
309
|
|
- 0, 39390,
|
|
325
|
+ RANGE ( 0, 39390 ),
|
|
326
|
+ TRIM ( 0, 39390 ),
|
310
|
327
|
DATA ( 0xe0, 0xd0, 0xc3, 0x58, 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32,
|
311
|
328
|
0xb5, 0xf1, 0x97, 0x87, 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e,
|
312
|
329
|
0x78, 0x1f, 0xae, 0x71, 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4 ) );
|
313
|
330
|
|
314
|
331
|
/** IIS logo (iis-85.png) content information version 2 segment 1 */
|
315
|
332
|
PEERDIST_INFO_SEGMENT_TEST ( iis_85_png_v2_s1, 1,
|
316
|
|
- 39390, 99710, 1, 60320,
|
|
333
|
+ RANGE ( 39390, 99710 ), 1, 60320,
|
317
|
334
|
DATA ( 0x33, 0x81, 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21,
|
318
|
335
|
0x0f, 0x37, 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96,
|
319
|
336
|
0xa1, 0x30, 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc ),
|
|
@@ -326,7 +343,8 @@ PEERDIST_INFO_SEGMENT_TEST ( iis_85_png_v2_s1, 1,
|
326
|
343
|
|
327
|
344
|
/** IIS logo (iis-85.png) content information version 2 segment 1 block 0 */
|
328
|
345
|
PEERDIST_INFO_BLOCK_TEST ( iis_85_png_v2_s1_b0, 0,
|
329
|
|
- 39390, 99710,
|
|
346
|
+ RANGE ( 39390, 99710 ),
|
|
347
|
+ TRIM ( 39390, 99710 ),
|
330
|
348
|
DATA ( 0x33, 0x81, 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21,
|
331
|
349
|
0x0f, 0x37, 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96,
|
332
|
350
|
0xa1, 0x30, 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc ) );
|
|
@@ -352,10 +370,12 @@ static void peerdist_info_okx ( struct peerdist_info_test *test,
|
352
|
370
|
okx ( info->raw.len == test->len, file, line );
|
353
|
371
|
okx ( info->digest == test->expected_digest, file, line );
|
354
|
372
|
okx ( info->digestsize == test->expected_digestsize, file, line );
|
355
|
|
- okx ( info->trim.start >= info->range.start, file, line );
|
|
373
|
+ okx ( info->range.start == test->expected_range.start, file, line );
|
|
374
|
+ okx ( info->range.end == test->expected_range.end, file, line );
|
356
|
375
|
okx ( info->trim.start == test->expected_trim.start, file, line );
|
357
|
|
- okx ( info->trim.end <= info->range.end, file, line );
|
358
|
376
|
okx ( info->trim.end == test->expected_trim.end, file, line );
|
|
377
|
+ okx ( info->trim.start >= info->range.start, file, line );
|
|
378
|
+ okx ( info->trim.end <= info->range.end, file, line );
|
359
|
379
|
okx ( info->segments == test->expected_segments, file, line );
|
360
|
380
|
}
|
361
|
381
|
#define peerdist_info_ok( test, info ) \
|
|
@@ -423,6 +443,8 @@ peerdist_info_block_okx ( struct peerdist_info_block_test *test,
|
423
|
443
|
okx ( block->index == test->index, file, line );
|
424
|
444
|
okx ( block->range.start == test->expected_range.start, file, line );
|
425
|
445
|
okx ( block->range.end == test->expected_range.end, file, line );
|
|
446
|
+ okx ( block->trim.start == test->expected_trim.start, file, line );
|
|
447
|
+ okx ( block->trim.end == test->expected_trim.end, file, line );
|
426
|
448
|
okx ( memcmp ( block->hash, test->expected_hash,
|
427
|
449
|
digestsize ) == 0, file, line );
|
428
|
450
|
}
|