Skip to content

Commit 726f26f

Browse files
committedFeb 27, 2025·
test passes after debugging.
1 parent a4a2ddb commit 726f26f

7 files changed

+53
-43
lines changed
 

‎picoquic/frames.c

-1
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,6 @@ picoquic_stream_head_t* picoquic_find_ready_stream_path(picoquic_cnx_t* cnx, pic
13411341
picoquic_stream_head_t* stream = first_stream;
13421342
picoquic_stream_head_t* found_stream = NULL;
13431343

1344-
13451344
/* Look for a ready stream */
13461345
while (stream != NULL) {
13471346
int has_data = 0;

‎picoquic/picoquic_internal.h

-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ typedef struct st_picoquic_stream_data_node_t {
374374
*/
375375

376376
typedef struct st_picoquic_stream_queue_node_t {
377-
picoquic_quic_t* quic;
378377
struct st_picoquic_stream_queue_node_t* next_stream_data;
379378
picoquic_block_sent_fn block_sent_fn;
380379
void* block_sent_ctx;

‎picoquic/quicctx.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3357,7 +3357,7 @@ picoquic_stream_head_t* picoquic_find_stream(picoquic_cnx_t* cnx, uint64_t strea
33573357
void picoquic_add_output_streams(picoquic_cnx_t* cnx, uint64_t old_limit, uint64_t new_limit, unsigned int is_bidir)
33583358
{
33593359
uint64_t old_rank = STREAM_RANK_FROM_ID(old_limit);
3360-
uint64_t first_new_id = STREAM_ID_FROM_RANK(old_rank + 1ull, cnx->client_mode, !is_bidir);
3360+
uint64_t first_new_id = STREAM_ID_FROM_RANK(old_rank + (is_bidir && cnx->client_mode)?1ull:0ull, cnx->client_mode, !is_bidir);
33613361
picoquic_stream_head_t* stream = picoquic_find_stream(cnx, first_new_id );
33623362

33633363
while (stream) {

‎picoquic/sender.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,14 @@ int picoquic_mark_high_priority_stream(picoquic_cnx_t * cnx, uint64_t stream_id,
214214
*/
215215
picoquic_stream_queue_node_t* picoquic_release_stream_queue_node(picoquic_stream_queue_node_t* stream_data)
216216
{
217-
picoquic_stream_queue_node_t* next = stream_data->next_stream_data;
217+
picoquic_stream_queue_node_t* next;
218218
if (stream_data->block_sent_fn) {
219219
stream_data->block_sent_fn(stream_data->bytes, stream_data->block_sent_ctx);
220220
}
221221
else {
222222
free(stream_data->bytes);
223223
}
224+
next = stream_data->next_stream_data;
224225
free(stream_data);
225226
return next;
226227
}
@@ -283,6 +284,8 @@ int picoquic_add_block_to_stream(picoquic_cnx_t* cnx, uint64_t stream_id,
283284
next = next->next_stream_data;
284285
}
285286
*pprevious = stream_data;
287+
/* add stream to output streams */
288+
picoquic_insert_output_stream(cnx, stream);
286289
}
287290
/* Reschedule the connection */
288291
picoquic_reinsert_by_wake_time(cnx->quic, cnx, picoquic_get_quic_time(cnx->quic));

‎picoquictest/add_block_test.c

+44-39
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
* - verify that the received content matches what was sent.
4040
*/
4141

42+
#define ADD_BLOCK_TEST_ALPN "ADD_BLOCK_TEST"
4243
#define add_block_test_unique_1 0x1111111111111111uul
4344
#define add_block_test_unique_2 0x2222222222222222uul
4445
#define add_block_test_max_block_nb 10
45-
#define add_block_test_max_sent size_t(1<<20)
46+
#define add_block_test_max_sent 0x100000
4647

4748
#define add_block_test_block_unknown 1
4849
#define add_block_test_block_not_sent 2
@@ -64,7 +65,7 @@ typedef struct st_add_block_test_stream_t {
6465

6566
typedef struct st_add_block_test_block_t {
6667
/* we only use one stream, but we use this data type to test that the context is passed correctly */
67-
add_block_test_ctx_t* block_test_ctx;
68+
struct st_add_block_test_ctx_t* block_test_ctx;
6869
int block_id;
6970
int block_was_sent;
7071
int block_was_confirmed;
@@ -87,6 +88,7 @@ typedef struct st_add_block_test_ctx_t {
8788
int fin_sent;
8889
int fin_recv;
8990
add_block_test_block_t block[add_block_test_max_block_nb];
91+
int next_block_id;
9092
add_block_test_stream_t client_stream;
9193
add_block_test_stream_t server_stream;
9294
} add_block_test_ctx_t;
@@ -100,20 +102,20 @@ int picoquic_add_block_to_stream(picoquic_cnx_t* cnx, uint64_t stream_id,
100102
const uint8_t* data, size_t length, int set_fin, void* app_stream_ctx,
101103
picoquic_block_sent_fn block_sent_fn, void* block_sent_ctx);
102104

103-
void add_block_test_sent_fn(const uint8_t* data, void* v_add_block_ctx)
105+
void add_block_test_sent_fn(const uint8_t* data, void* v_block_sent_ctx)
104106
{
105107
add_block_test_block_t* block_sent_ctx = (add_block_test_block_t*)v_block_sent_ctx;
106108

107109
if (block_sent_ctx->block_test_ctx != current_ctx ||
108110
block_sent_ctx->block_id >= add_block_test_max_block_nb ||
109-
&block_sent_ctx->block[block_sent_ctx->block_id] != block_sent_ctx) {
111+
&block_sent_ctx->block_test_ctx->block[block_sent_ctx->block_id] != block_sent_ctx) {
110112
/* This is really bad. */
111113
error_found |= add_block_test_block_unknown;
112114
}
113115
else if (!block_sent_ctx->block_was_sent) {
114116
error_found |= add_block_test_block_not_sent;
115117
}
116-
else if (!block_sent_ctx->block_was_confirmed) {
118+
else if (block_sent_ctx->block_was_confirmed) {
117119
error_found |= add_block_test_block_already_reported;
118120
}
119121
else {
@@ -126,8 +128,8 @@ void add_block_test_sent_fn(const uint8_t* data, void* v_add_block_ctx)
126128

127129
void add_block_test_send(add_block_test_ctx_t* add_block_ctx, int block_id)
128130
{
129-
for (int i = 0; i < block_id; i++) {
130-
int new_id = block_id + i;
131+
for (int i = 0; i <= block_id; i++) {
132+
int new_id = add_block_ctx->next_block_id;
131133

132134
if (new_id >= add_block_test_max_block_nb || add_block_ctx->send_offset >= add_block_ctx->test_data_length) {
133135
/* we are done */
@@ -150,13 +152,16 @@ void add_block_test_send(add_block_test_ctx_t* add_block_ctx, int block_id)
150152
set_fin = 1;
151153
}
152154
add_block_ctx->block[new_id].block_was_sent = 1;
153-
add_block_ctx->block[new_id].is_trigger = (i == 0);
155+
add_block_ctx->block[new_id].block_is_trigger = (i == 0);
154156
add_block_ctx->block[new_id].block_id = new_id;
157+
add_block_ctx->block[new_id].block_test_ctx = add_block_ctx;
158+
add_block_ctx->next_block_id = new_id + 1;
159+
155160
if (picoquic_add_block_to_stream(add_block_ctx->cnx_client,
156161
add_block_ctx->stream_id,
157162
add_block_ctx->test_data + add_block_ctx->send_offset,
158163
length, set_fin, &add_block_ctx->client_stream,
159-
add_block_test_sent_fn, &add_block_ctx->block[new_id]) == 0) {
164+
add_block_test_sent_fn, &add_block_ctx->block[new_id]) != 0) {
160165
error_found |= add_block_test_block_send_failed;
161166
break;
162167
}
@@ -169,15 +174,17 @@ void add_block_test_send(add_block_test_ctx_t* add_block_ctx, int block_id)
169174

170175
int add_block_test_recv(picoquic_cnx_t* cnx,
171176
uint64_t stream_id, uint8_t* bytes, size_t length,
172-
picoquic_call_back_event_t fin_or_event, void* add_block_ctx, void* v_stream_ctx)
177+
picoquic_call_back_event_t fin_or_event, add_block_test_ctx_t* add_block_ctx, void* v_stream_ctx)
173178
{
179+
int ret = 0;
180+
174181
if (cnx == add_block_ctx->cnx_client) {
175182
/* the client is not expected to receive data. It MAY receive a FIN mark */
176183
if (fin_or_event != picoquic_callback_stream_fin || length > 0) {
177184
ret = -1;
178185
}
179186
}
180-
else if (picoquic_get_quic(cnx) != add_block_ctx->quic[0]) {
187+
else if (cnx->quic != add_block_ctx->quic[1]) {
181188
/* Not from the expected server */
182189
ret = -1;
183190
}
@@ -190,20 +197,23 @@ int add_block_test_recv(picoquic_cnx_t* cnx,
190197
ret = -1;
191198
}
192199
else {
193-
memcpy(add_block_ctx->recv_data + add_block_ctx->recv_length, bytes, length);
200+
if (length > 0) {
201+
memcpy(add_block_ctx->recv_data + add_block_ctx->recv_length, bytes, length);
202+
}
194203
add_block_ctx->recv_length += length;
195204
if (fin_or_event == picoquic_callback_stream_fin) {
196205
add_block_ctx->fin_recv = 1;
197206
}
198207
}
208+
return ret;
199209
}
200210

201211
int add_block_test_callback(picoquic_cnx_t* cnx,
202212
uint64_t stream_id, uint8_t* bytes, size_t length,
203213
picoquic_call_back_event_t fin_or_event, void* callback_ctx, void* v_stream_ctx)
204214
{
205215
int ret = 0;
206-
add_block_test_ctx_t* add_block_ctx = (sample_add_block_ctx_t*)callback_ctx;
216+
add_block_test_ctx_t* add_block_ctx = (add_block_test_ctx_t*)callback_ctx;
207217

208218
if (add_block_ctx == NULL) {
209219
/* This should never happen, because the callback context is initialized
@@ -216,7 +226,7 @@ int add_block_test_callback(picoquic_cnx_t* cnx,
216226
case picoquic_callback_stream_data:
217227
case picoquic_callback_stream_fin:
218228
/* Data arrival on stream #x, maybe with fin mark */
219-
229+
ret = add_block_test_recv(cnx, stream_id, bytes, length, fin_or_event, add_block_ctx, v_stream_ctx);
220230
break;
221231
case picoquic_callback_stop_sending: /* Should not happen, treated as reset */
222232
ret = -1;
@@ -229,7 +239,8 @@ int add_block_test_callback(picoquic_cnx_t* cnx,
229239
case picoquic_callback_application_close: /* Received application close */
230240
fprintf(stdout, "Connection closed.\n");
231241
/* Mark the connection as completed */
232-
add_block_ctx->is_disconnected = 1;
242+
add_block_ctx->fin_sent = 1;
243+
add_block_ctx->fin_recv = 1;
233244
/* Remove the application callback */
234245
picoquic_set_callback(cnx, NULL, NULL);
235246
break;
@@ -406,10 +417,6 @@ int add_block_test_is_finished(add_block_test_ctx_t* add_block_ctx)
406417

407418
void add_block_test_delete_ctx(add_block_test_ctx_t* add_block_ctx)
408419
{
409-
/* Delete the connections */
410-
while (add_block_ctx->first_cnx != NULL) {
411-
add_block_test_delete_cnx_context(add_block_ctx->first_cnx);
412-
}
413420
/* Delete the links */
414421
for (int i = 0; i < 2; i++) {
415422
if (add_block_ctx->link[i] != NULL) {
@@ -429,23 +436,22 @@ void add_block_test_delete_ctx(add_block_test_ctx_t* add_block_ctx)
429436
}
430437

431438
if (add_block_ctx->recv_data) {
432-
free(add_block_ctx->test_data);
433-
add_block_ctx->test_data = NULL;
439+
free(add_block_ctx->recv_data);
440+
add_block_ctx->recv_data = NULL;
434441
}
435442

436443
/* Free the context */
437444
free(add_block_ctx);
438445
}
439446

440-
add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test_spec_t* spec)
447+
add_block_test_ctx_t* add_block_test_configure()
441448
{
442449
int ret = 0;
443450
add_block_test_ctx_t* add_block_ctx = NULL;
444451
char test_server_cert_file[512];
445452
char test_server_key_file[512];
446453
char test_server_cert_store_file[512];
447-
picoquic_connection_id_t icid = { { 0xed, 0x1a, 0x7e, 0x57, 0, 0, 0, 0}, 8 };
448-
icid.id[4] = media_test_id;
454+
picoquic_connection_id_t icid = { { 0xad, 0xdb, 0x10, 0xc8, 0, 0, 0, 0}, 8 };
449455

450456
ret = picoquic_get_input_path(test_server_cert_file, sizeof(test_server_cert_file), picoquic_solution_dir, PICOQUIC_TEST_FILE_SERVER_CERT);
451457

@@ -473,18 +479,11 @@ add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test
473479
add_block_ctx->quic[1] = picoquic_create(4,
474480
test_server_cert_file, test_server_key_file, test_server_cert_store_file,
475481
ADD_BLOCK_TEST_ALPN, add_block_test_callback, (void*)add_block_ctx, NULL, NULL, NULL,
476-
add_block_ctx->simulated_time, &add_block_ctx->simulated_time, NULL, add_block_test_ticket_encrypt_key, sizeof(add_block_test_ticket_encrypt_key));
482+
add_block_ctx->simulated_time, &add_block_ctx->simulated_time, NULL, NULL, 0);
477483

478484
if (add_block_ctx->quic[0] == NULL || add_block_ctx->quic[1] == NULL) {
479485
ret = -1;
480486
}
481-
482-
if (spec->ccalgo != NULL) {
483-
for (int i = 0; i < 2 && ret == 0; i++) {
484-
picoquic_set_default_congestion_algorithm(add_block_ctx->quic[i], spec->ccalgo);
485-
ret = picoquic_set_binlog(add_block_ctx->quic[i], ".");
486-
}
487-
}
488487
}
489488

490489
if (ret == 0) {
@@ -498,8 +497,7 @@ add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test
498497
}
499498
/* register the links */
500499
for (int i = 0; i < 2; i++) {
501-
add_block_ctx->link[i] = picoquictest_sim_link_create(0.01,
502-
(spec->link_latency == 0) ? 10000 : spec->link_latency, NULL, 0, 0);
500+
add_block_ctx->link[i] = picoquictest_sim_link_create(0.01, 10000, NULL, 0, 0);
503501
if (add_block_ctx->link[i] == NULL) {
504502
ret = -1;
505503
break;
@@ -515,9 +513,15 @@ add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test
515513
ret = -1;
516514
}
517515
else {
516+
uint64_t rdx = 0xdeeddaadd00dd11dull;
518517
add_block_ctx->test_data_length = add_block_test_max_sent;
519518

520-
picoquic_public_random(add_block_ctx->test_data, add_block_ctx->test_data_length);
519+
for (size_t i = 0; i < add_block_ctx->test_data_length; i++) {
520+
add_block_ctx->test_data[i] = (uint8_t)(rdx & 0xff);
521+
rdx *= 101;
522+
rdx += 0xbadc0ffee;
523+
rdx += i;
524+
}
521525
memset(add_block_ctx->recv_data, 0, add_block_ctx->test_data_length);
522526
}
523527
}
@@ -528,7 +532,7 @@ add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test
528532
icid, picoquic_null_connection_id,
529533
(struct sockaddr*)&add_block_ctx->addr[1], add_block_ctx->simulated_time, 0, PICOQUIC_TEST_SNI, ADD_BLOCK_TEST_ALPN, 1);
530534
/* Start the connection and create the context */
531-
if (add_block_ctx->cnx_client = NULL) {
535+
if (add_block_ctx->cnx_client == NULL) {
532536
ret = -1;
533537
}
534538
else {
@@ -537,8 +541,8 @@ add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test
537541
/* Queue the first block */
538542
add_block_test_send(add_block_ctx, 0);
539543
/* start the connection */
540-
if (picoquic_start_client_cnx(cnx) != 0) {
541-
picoquic_delete_cnx(cnx);
544+
if (picoquic_start_client_cnx(add_block_ctx->cnx_client) != 0) {
545+
picoquic_delete_cnx(add_block_ctx->cnx_client);
542546
ret = -1;
543547
}
544548
}
@@ -582,7 +586,8 @@ int add_block_test()
582586
int is_finished = 0;
583587

584588
/* set the configuration */
585-
add_block_test_ctx_t* add_block_ctx = add_block_test_configure(media_test_id, spec);
589+
add_block_test_ctx_t* add_block_ctx = add_block_test_configure();
590+
current_ctx = add_block_ctx;
586591
if (add_block_ctx == NULL) {
587592
ret = -1;
588593
}

‎picoquictest/picoquictest.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
<ItemGroup>
150150
<ClCompile Include="ack_frequency_test.c" />
151151
<ClCompile Include="ack_of_ack_test.c" />
152+
<ClCompile Include="add_block_test.c" />
152153
<ClCompile Include="app_limited.c" />
153154
<ClCompile Include="bytestream_test.c" />
154155
<ClCompile Include="cc_compete_test.c" />

‎picoquictest/picoquictest.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@
201201
<ClCompile Include="picoquic_ns.c">
202202
<Filter>Source Files</Filter>
203203
</ClCompile>
204+
<ClCompile Include="add_block_test.c">
205+
<Filter>Source Files</Filter>
206+
</ClCompile>
204207
</ItemGroup>
205208
<ItemGroup>
206209
<ClInclude Include="picoquictest.h">

0 commit comments

Comments
 (0)
Please sign in to comment.