@@ -265,6 +265,16 @@ imico_maybe_process_params (struct ietf_mini_conn *conn)
265
265
}
266
266
267
267
268
+ static void
269
+ imico_zero_pad (struct lsquic_packet_out * packet_out , size_t pad_size )
270
+ {
271
+ memset (packet_out -> po_data + packet_out -> po_data_sz , 0 , pad_size );
272
+ packet_out -> po_padding_sz = pad_size ;
273
+ packet_out -> po_data_sz += pad_size ;
274
+ packet_out -> po_frame_types |= QUIC_FTBIT_PADDING ;
275
+ }
276
+
277
+
268
278
static int
269
279
imico_generate_ack (struct ietf_mini_conn * conn , enum packnum_space pns ,
270
280
lsquic_time_t now );
@@ -309,11 +319,14 @@ imico_stream_write (void *stream, const void *bufp, size_t bufsz)
309
319
return -1 ;
310
320
// NOTE: reduce the size of first crypto frame to combine packets
311
321
int avail = lsquic_packet_out_avail (packet_out );
322
+ int coalescing = 0 ;
312
323
if (cryst -> mcs_enc_level == ENC_LEV_HSK
313
324
&& cryst -> mcs_write_off == 0
314
- && avail > conn -> imc_hello_pkt_remain - conn -> imc_long_header_sz )
325
+ && avail > ( int ) conn -> imc_hello_pkt_remain - conn -> imc_long_header_sz )
315
326
{
316
327
avail = conn -> imc_hello_pkt_remain - conn -> imc_long_header_sz ;
328
+ conn -> imc_hello_pkt_remain = 0 ;
329
+ coalescing = 1 ;
317
330
}
318
331
p = msg_ctx .buf ;
319
332
len = pf -> pf_gen_crypto_frame (packet_out -> po_data + packet_out -> po_data_sz ,
@@ -326,9 +339,15 @@ imico_stream_write (void *stream, const void *bufp, size_t bufsz)
326
339
packet_out -> po_data_sz += len ;
327
340
packet_out -> po_frame_types |= 1 << QUIC_FRAME_CRYPTO ;
328
341
packet_out -> po_flags |= PO_HELLO ;
342
+ if (coalescing && len < avail )
343
+ {
344
+ LSQ_DEBUG ("generated PADDING frame: %d bytes for packet %" PRIu64 ,
345
+ avail - len , packet_out -> po_packno );
346
+ imico_zero_pad (packet_out , avail - len );
347
+ }
329
348
cryst -> mcs_write_off += msg_ctx .buf - p ;
330
349
if (cryst -> mcs_enc_level == ENC_LEV_INIT )
331
- conn -> imc_hello_pkt_remain = avail - len ;
350
+ conn -> imc_hello_pkt_remain = lsquic_packet_out_avail ( packet_out ) ;
332
351
}
333
352
334
353
assert (msg_ctx .buf == msg_ctx .end );
@@ -795,19 +814,6 @@ imico_can_send (const struct ietf_mini_conn *conn, size_t size)
795
814
}
796
815
797
816
798
- // static void
799
- // imico_zero_pad (struct lsquic_packet_out *packet_out)
800
- // {
801
- // size_t pad_size;
802
- //
803
- // pad_size = lsquic_packet_out_avail(packet_out);
804
- // memset(packet_out->po_data + packet_out->po_data_sz, 0, pad_size);
805
- // packet_out->po_padding_sz = pad_size;
806
- // packet_out->po_data_sz += pad_size;
807
- // packet_out->po_frame_types |= QUIC_FTBIT_PADDING;
808
- // }
809
-
810
-
811
817
static lsquic_time_t
812
818
imico_rechist_largest_recv (void * rechist_ctx );
813
819
@@ -939,14 +945,19 @@ ietf_mini_conn_ci_next_packet_to_send (struct lsquic_conn *lconn,
939
945
"enough quota" , packet_out -> po_packno );
940
946
return NULL ;
941
947
}
942
- // if (!(packet_out->po_frame_types & (1 << QUIC_FRAME_PADDING))
943
- // && (packet_out->po_frame_types & IQUIC_FRAME_ACKABLE_MASK)
944
- // && lsquic_packet_out_avail(packet_out) > 0)
945
- // {
946
- // LSQ_DEBUG("generated PADDING frame: %hd bytes for packet %"PRIu64,
947
- // lsquic_packet_out_avail(packet_out), packet_out->po_packno);
948
- // imico_zero_pad(packet_out);
949
- // }
948
+ // NOTE: do not padd INIT packet only, here, instead pad the coalesced
949
+ // later, can save one packet, more efficient.
950
+ // if (!(packet_out->po_frame_types & (1 << QUIC_FRAME_PADDING))
951
+ // && (packet_out->po_frame_types & IQUIC_FRAME_ACKABLE_MASK)
952
+ // && IQUIC_MIN_INIT_PACKET_SZ > packet_out->po_data_sz)
953
+ // {
954
+ // size_t pad_size;
955
+ //
956
+ // pad_size = IQUIC_MIN_INIT_PACKET_SZ - packet_out->po_data_sz;
957
+ // LSQ_DEBUG("generated PADDING frame: %zd bytes for packet %"PRIu64,
958
+ // pad_size, packet_out->po_packno);
959
+ // imico_zero_pad(packet_out, pad_size);
960
+ // }
950
961
}
951
962
packet_size = lsquic_packet_out_total_sz (lconn , packet_out );
952
963
if (!(to_coal
0 commit comments