rapido
Data Structures | Macros | Typedefs | Functions
rapido.h File Reference
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/socket.h>
#include "picotls.h"

Go to the source code of this file.

Data Structures

struct  rapido_set_t
 
struct  rapido_array_t
 A growing array allocating capacity * item_size bytes. More...
 
struct  rapido_queue_t
 A growing and cycling queue allocating capacity * item_size bytes. More...
 
struct  rapido_buffer_t
 A growing and cycling byte buffer. More...
 
struct  rapido_range_list_t
 A uin64_t interval list, sorted by ascending order. More...
 
struct  rapido_range_list_t::rapido_range_item
 
struct  rapido_range_buffer_t
 A growing and cycling buffer, also tracking the ranges of bytes present in the buffer following a global read_offset. More...
 
struct  rapido_record_metadata_t
 
struct  rapido_server_t
 
struct  rapido_session_t
 
struct  rapido_connection_t
 
struct  rapido_connection_info_t
 
struct  rapido_pending_connection_t
 
struct  rapido_stream_write_cb_t
 
struct  rapido_stream_t
 
struct  rapido_application_notification_t
 

Macros

#define CLIENT_STREAM(sid)   (((sid)&0x1) == 0)
 
#define SERVER_STREAM(sid)   (((sid)&0x1) == 1)
 
#define TLS_SESSION_ID_LEN   32
 
#define SET_LEN   64ull
 
#define SET_HAS(bs, e)   (bs & (1ull << ((uint64_t)(e))))
 
#define SET_ADD(bs, e)   bs = (bs | (1ull << ((uint64_t)(e))))
 
#define SET_REMOVE(bs, e)   bs = (bs & (~(1ull << ((uint64_t)e))))
 
#define rapido_set_iter(set, i, v, bl)
 
#define rapido_array_iter(a, i, e, bl)
 
#define RANGES_LEN   64
 
#define rapido_queue_drain(q, e, bl)
 
#define rapido_time_to_send(conn_info, bytes_len)   ((((((uint64_t) bytes_len) * 1000000ul) / (conn_info).congestion_window) * (conn_info).smoothed_rtt) / 1000000ul)
 
#define rapido_time_to_drain(conn_info)   (rapido_time_to_send(conn_info, (conn_info).bytes_queued_for_sending))
 
#define rapido_time_to_transfer(conn_info, bytes_len)   (rapido_time_to_drain(conn_info) + rapido_time_to_send(conn_info, bytes_len) + (conn_info).smoothed_rtt)
 

Typedefs

typedef uint32_t rapido_connection_id_t
 
typedef uint32_t rapido_stream_id_t
 
typedef uint8_t rapido_address_id_t
 
typedef uint8_t *(* rapido_stream_producer_t) (rapido_session_t *, rapido_stream_id_t, void *, uint64_t, size_t *)
 

Functions

void rapido_set_add (rapido_set_t *set, uint32_t value)
 Adds the given value to the set when it can contains, otherwise fails.
 
bool rapido_set_has (rapido_set_t *set, uint32_t value)
 Returns whether the set contains the given value.
 
void rapido_set_remove (rapido_set_t *set, uint32_t value)
 Removes the given value from the set.
 
size_t rapido_set_size (rapido_set_t *set)
 Returns the number of element in the set.
 
void * rapido_queue_pop (rapido_queue_t *queue)
 Returns a pointer to an element poped from the front of the queue. More...
 
rapido_server_trapido_new_server (ptls_context_t *tls_ctx, const char *server_name, FILE *qlog_out)
 Creates a new rapido server.
 
rapido_address_id_t rapido_add_server_address (rapido_server_t *server, struct sockaddr *addr, socklen_t addr_len, bool add_listen_socket)
 Adds a local address to the server, and creates a listen socket bound to the address when required.
 
int rapido_remove_server_address (rapido_session_t *session, rapido_address_id_t local_address_id)
 Removes a local address from the server.
 
int rapido_run_server_network (rapido_server_t *server, int timeout)
 Runs the server for some time.
 
rapido_application_notification_trapido_next_server_notification (rapido_server_t *server, size_t *session_index)
 Pops the next notification and gets the index of the corresponding session.
 
rapido_session_trapido_new_session (ptls_context_t *tls_ctx, bool is_server, const char *server_name, FILE *qlog_out)
 Creates a new rapido session.
 
rapido_address_id_t rapido_add_address (rapido_session_t *session, struct sockaddr *addr, socklen_t addr_len)
 Adds a local address to the session.
 
rapido_address_id_t rapido_add_remote_address (rapido_session_t *session, struct sockaddr *addr, socklen_t addr_len)
 Adds a remote address to the session.
 
int rapido_remove_address (rapido_session_t *session, rapido_address_id_t local_address_id)
 Removes a local address from the session.
 
rapido_connection_id_t rapido_create_connection (rapido_session_t *session, uint8_t local_address_id, uint8_t remote_address_id)
 Creates a new connection for the session with the given local and remote addresses.
 
rapido_connection_id_t rapido_client_add_connection (rapido_session_t *session, int fd, uint8_t local_address_id, uint8_t remote_address_id)
 Adds the given file descriptor to the session as a new connection with the given local and remote addresses.
 
int rapido_run_network (rapido_session_t *session, int timeout)
 Runs the session for some time.
 
int rapido_retransmit_connection (rapido_session_t *session, rapido_connection_id_t connection_id, rapido_set_t connections)
 Marks the given set of connections as eligible for retransmitting the content of the given connection.
 
int rapido_close_connection (rapido_session_t *session, rapido_connection_id_t connection_id)
 Gracefully closes the connection.
 
int rapido_close_session (rapido_session_t *session, rapido_connection_id_t connection_id)
 Gracefully closes the session and send the TLS alert on the given connection.
 
rapido_stream_id_t rapido_open_stream (rapido_session_t *session)
 Add a new stream to the session.
 
int rapido_attach_stream (rapido_session_t *session, rapido_stream_id_t stream_id, rapido_connection_id_t connection_id)
 Marks the connection as eligible to send content of this stream.
 
int rapido_detach_stream (rapido_session_t *session, rapido_stream_id_t stream_id, rapido_connection_id_t connection_id)
 Removes the mark of elibility of this connection for sending the content of this stream.
 
int rapido_add_to_stream (rapido_session_t *session, rapido_stream_id_t stream_id, void *data, size_t len)
 Adds the given data to the end of the stream.
 
int rapido_add_to_stream_notify (rapido_session_t *session, rapido_stream_id_t stream_id, void *data, size_t len, void *app_ctx)
 Adds the given data to the end of the stream and registers a notification containing the given application context when the data has been written in frames.
 
int rapido_set_stream_producer (rapido_session_t *session, rapido_stream_id_t stream_id, rapido_stream_producer_t producer, void *producer_ctx)
 Sets the given function and associated context as a data producer for this stream.
 
void * rapido_read_stream (rapido_session_t *session, rapido_stream_id_t stream_id, size_t *len)
 Returns a pointer to read at most the *len following bytes from this stream.
 
int rapido_close_stream (rapido_session_t *session, rapido_stream_id_t stream_id)
 Marks the end of this stream.
 
int rapido_session_accept_new_connection (rapido_session_t *session, int accept_fd, rapido_address_id_t local_address_id)
 Adds a given file descriptor as a new connection to a session.
 
int rapido_server_accept_new_connection (rapido_server_t *server, int accept_fd, rapido_address_id_t local_address_id)
 Accepts from a given file descriptor and adds the new connection to the server.
 
size_t rapido_server_add_new_connection (rapido_array_t *pending_connections, ptls_context_t *tls_ctx, ptls_t *tls, const char *server_name, int conn_fd, rapido_address_id_t local_address_id)
 Adds the new connection to pending connections and returns its index within the latter array.
 
int rapido_client_process_handshake (rapido_session_t *session, rapido_connection_id_t connection_id, uint8_t *buffer, size_t *len)
 Processes data received by a client during the handshake and returns whether the handshake is complete.
 
int rapido_server_process_handshake (rapido_server_t *server, rapido_session_t *session, rapido_array_t *pending_connections, size_t pending_connection_index, uint8_t *buffer, size_t *len, ptls_buffer_t *handshake_buffer, rapido_session_t **created_session, rapido_connection_t **created_connection)
 Processes data received by a server during the handshake. More...
 
void rapido_process_incoming_data (rapido_session_t *session, rapido_connection_id_t connection_id, uint64_t current_time, uint8_t *buffer, size_t *len)
 Processes incoming data received after the handshake.
 
int rapido_connection_wants_to_send (rapido_session_t *session, rapido_connection_t *connection, uint64_t current_time, bool *is_blocked)
 Returns whether the given connection wants to send data.
 
void rapido_prepare_data (rapido_session_t *session, rapido_connection_id_t connection_id, uint64_t current_time, uint8_t *buffer, size_t *len)
 Prepares data to send.
 
void rapido_connection_set_app_ptr (rapido_session_t *session, rapido_connection_id_t connection_id, void *app_ptr)
 Sets an application pointer associated with the given connection.
 
void * rapido_connection_get_app_ptr (rapido_session_t *session, rapido_connection_id_t connection_id)
 Gets an application pointer associated with the given connection.
 
void rapido_connection_get_info (rapido_session_t *session, rapido_connection_id_t connection_id, rapido_connection_info_t *info)
 Returns TCP-level information on the given connection.
 
int rapido_session_free (rapido_session_t *session)
 Deallocates the memory zones referenced in this session structure.
 
int rapido_server_free (rapido_server_t *server)
 Deallocates the memory zones referenced in this server structure.
 

Macro Definition Documentation

◆ rapido_array_iter

#define rapido_array_iter (   a,
  i,
  e,
  bl 
)
Value:
do { \
for (int i = 0; i < (a)->capacity; i++) { \
size_t offset = (1 + (a)->item_size) * i; \
if ((a)->data[offset] == true) { \
e = (void *)(a)->data + offset + 1; \
bl \
} \
} \
} while (0)

◆ rapido_queue_drain

#define rapido_queue_drain (   q,
  e,
  bl 
)
Value:
do { \
while ((q)->size) { \
e = rapido_queue_pop(q); \
bl \
} \
} while (0)
void * rapido_queue_pop(rapido_queue_t *queue)
Returns a pointer to an element poped from the front of the queue.
Definition: rapido.c:387

◆ rapido_set_iter

#define rapido_set_iter (   set,
  i,
  v,
  bl 
)
Value:
do { \
if ((set)->bs == 0) break; \
for (int i = 0; i < SET_LEN; i++) { \
if (SET_HAS((set)->bs, i)) { \
v = (set)->start + i; \
bl \
} \
} \
} while (0)

Function Documentation

◆ rapido_queue_pop()

void * rapido_queue_pop ( rapido_queue_t queue)

Returns a pointer to an element poped from the front of the queue.

Note: Pushing on the queue can overwrite the memory zone returned.

◆ rapido_server_process_handshake()

int rapido_server_process_handshake ( rapido_server_t server,
rapido_session_t session,
rapido_array_t pending_connections,
size_t  pending_connection_index,
uint8_t *  buffer,
size_t *  len,
ptls_buffer_t *  handshake_buffer,
rapido_session_t **  created_session,
rapido_connection_t **  created_connection 
)

Processes data received by a server during the handshake.

Returns PTLS_ERROR_IN_PROGRESS when the handshake is still progressing, -1 when TCPLS could not be used and 0 when the handshake completed.