2020-01-09 16:52:25 +00:00
|
|
|
/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */
|
2017-09-22 21:00:03 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2018-03-12 22:25:01 +00:00
|
|
|
#ifndef WIN32
|
2017-09-22 21:00:03 +00:00
|
|
|
#include <unistd.h>
|
2018-03-12 22:25:01 +00:00
|
|
|
#endif
|
2017-09-22 21:00:03 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <openssl/md5.h>
|
|
|
|
|
|
|
|
#include "lsquic.h"
|
|
|
|
|
|
|
|
#include "lsquic_int_types.h"
|
|
|
|
#include "lsquic_packet_common.h"
|
2019-09-11 15:27:58 +00:00
|
|
|
#include "lsquic_packet_gquic.h"
|
2017-09-22 21:00:03 +00:00
|
|
|
#include "lsquic_packet_out.h"
|
|
|
|
#include "lsquic_conn_flow.h"
|
|
|
|
#include "lsquic_sfcw.h"
|
2019-09-11 15:27:58 +00:00
|
|
|
#include "lsquic_varint.h"
|
|
|
|
#include "lsquic_hq.h"
|
|
|
|
#include "lsquic_hash.h"
|
2017-09-22 21:00:03 +00:00
|
|
|
#include "lsquic_stream.h"
|
|
|
|
#include "lsquic_types.h"
|
|
|
|
#include "lsquic_malo.h"
|
|
|
|
#include "lsquic_mm.h"
|
|
|
|
#include "lsquic_engine_public.h"
|
|
|
|
#include "lsquic_logger.h"
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
struct lsquic_engine_public enpub;
|
|
|
|
struct packet_out_srec_iter posi;
|
|
|
|
lsquic_packet_out_t *packet_out;
|
|
|
|
struct lsquic_stream streams[6];
|
|
|
|
struct stream_rec *srec;
|
|
|
|
|
|
|
|
memset(&enpub, 0, sizeof(enpub));
|
2018-02-26 21:01:16 +00:00
|
|
|
memset(&streams, 0, sizeof(streams));
|
2017-09-22 21:00:03 +00:00
|
|
|
lsquic_mm_init(&enpub.enp_mm);
|
2019-09-11 15:27:58 +00:00
|
|
|
packet_out = lsquic_mm_get_packet_out(&enpub.enp_mm, NULL, GQUIC_MAX_PAYLOAD_SZ);
|
2017-09-22 21:00:03 +00:00
|
|
|
|
Latest changes
- [API Change] Sendfile-like functionality is gone. The stream no
longer opens files and deals with file descriptors. (Among other
things, this makes the code more portable.) Three writing functions
are provided:
lsquic_stream_write
lsquic_stream_writev
lsquic_stream_writef (NEW)
lsquic_stream_writef() is given an abstract reader that has function
pointers for size() and read() functions which the user can implement.
This is the most flexible way. lsquic_stream_write() and
lsquic_stream_writev() are now both implemented as wrappers around
lsquic_stream_writef().
- [OPTIMIZATION] When writing to stream, be it within or without the
on_write() callback, place data directly into packet buffer,
bypassing auxiliary data structures. This reduces amount of memory
required, for the amount of data that can be written is limited
by the congestion window.
To support writes outside the on_write() callback, we keep N
outgoing packet buffers per connection which can be written to
by any stream. One half of these are reserved for the highest
priority stream(s), the other half for all other streams. This way,
low-priority streams cannot write instead of high-priority streams
and, on the other hand, low-priority streams get a chance to send
their packets out.
The algorithm is as follows:
- When user writes to stream outside of the callback:
- If this is the highest priority stream, place it onto the
reserved N/2 queue or fail.
(The actual size of this queue is dynamic -- MAX(N/2, CWND) --
rather than N/2, allowing high-priority streams to write as
much as can be sent.)
- If the stream is not the highest priority, try to place the
data onto the reserved N/2 queue or fail.
- When tick occurs *and* more packets can be scheduled:
- Transfer packets from the high N/2 queue to the scheduled
queue.
- If more scheduling is allowed:
- Call on_write callbacks for highest-priority streams,
placing resulting packets directly onto the scheduled queue.
- If more scheduling is allowed:
- Transfer packets from the low N/2 queue to the scheduled
queue.
- If more scheduling is allowed:
- Call on_write callbacks for non-highest-priority streams,
placing resulting packets directly onto the scheduled queue
The number N is currently 20, but it could be varied based on
resource usage.
- If stream is created due to incoming headers, make headers readable
from on_new.
- Outgoing packets are no longer marked non-writeable to prevent placing
more than one STREAM frame from the same stream into a single packet.
This property is maintained via code flow and an explicit check.
Packets for stream data are allocated using a special function.
- STREAM frame elision is cheaper, as we only perform it if a reset
stream has outgoing packets referencing it.
- lsquic_packet_out_t is smaller, as stream_rec elements are now
inside a union.
2017-10-31 13:35:58 +00:00
|
|
|
lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[0], QUIC_FRAME_STREAM, 7, 1);
|
|
|
|
lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[1], QUIC_FRAME_STREAM, 8, 1);
|
|
|
|
lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[2], QUIC_FRAME_STREAM, 9, 1);
|
|
|
|
lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[1], QUIC_FRAME_RST_STREAM, 10, 0);
|
|
|
|
lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[3], QUIC_FRAME_STREAM, 11, 1);
|
|
|
|
lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[4], QUIC_FRAME_STREAM, 12, 1);
|
|
|
|
lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[5], QUIC_FRAME_STREAM, 13, 1);
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2020-03-12 12:41:53 +00:00
|
|
|
srec = lsquic_posi_first(&posi, packet_out);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(srec->sr_stream == &streams[0]);
|
|
|
|
assert(srec->sr_off == 7);
|
2019-01-21 14:07:02 +00:00
|
|
|
assert(srec->sr_frame_type == QUIC_FRAME_STREAM);
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2020-03-12 12:41:53 +00:00
|
|
|
srec = lsquic_posi_next(&posi);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(srec->sr_stream == &streams[1]);
|
|
|
|
assert(srec->sr_off == 8);
|
2019-01-21 14:07:02 +00:00
|
|
|
assert(srec->sr_frame_type == QUIC_FRAME_STREAM);
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2020-03-12 12:41:53 +00:00
|
|
|
srec = lsquic_posi_next(&posi);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(srec->sr_stream == &streams[2]);
|
|
|
|
assert(srec->sr_off == 9);
|
2019-01-21 14:07:02 +00:00
|
|
|
assert(srec->sr_frame_type == QUIC_FRAME_STREAM);
|
|
|
|
|
2020-03-12 12:41:53 +00:00
|
|
|
srec = lsquic_posi_next(&posi);
|
2019-01-21 14:07:02 +00:00
|
|
|
assert(srec->sr_stream == &streams[1]);
|
|
|
|
assert(srec->sr_off == 10);
|
|
|
|
assert(srec->sr_frame_type == QUIC_FRAME_RST_STREAM);
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2020-03-12 12:41:53 +00:00
|
|
|
srec = lsquic_posi_next(&posi);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(srec->sr_stream == &streams[3]);
|
|
|
|
assert(srec->sr_off == 11);
|
2019-01-21 14:07:02 +00:00
|
|
|
assert(srec->sr_frame_type == QUIC_FRAME_STREAM);
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2020-03-12 12:41:53 +00:00
|
|
|
srec = lsquic_posi_next(&posi);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(srec->sr_stream == &streams[4]);
|
|
|
|
assert(srec->sr_off == 12);
|
2019-01-21 14:07:02 +00:00
|
|
|
assert(srec->sr_frame_type == QUIC_FRAME_STREAM);
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2020-03-12 12:41:53 +00:00
|
|
|
srec = lsquic_posi_next(&posi);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(srec->sr_stream == &streams[5]);
|
|
|
|
assert(srec->sr_off == 13);
|
2019-01-21 14:07:02 +00:00
|
|
|
assert(srec->sr_frame_type == QUIC_FRAME_STREAM);
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2020-03-12 12:41:53 +00:00
|
|
|
assert((void *) 0 == lsquic_posi_next(&posi));
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2018-10-16 13:03:33 +00:00
|
|
|
lsquic_packet_out_destroy(packet_out, &enpub, NULL);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(!lsquic_malo_first(enpub.enp_mm.malo.stream_rec_arr));
|
|
|
|
|
|
|
|
lsquic_mm_cleanup(&enpub.enp_mm);
|
|
|
|
return 0;
|
|
|
|
}
|