Skip to content

Commit

Permalink
Update cbindgen.toml and generated header file (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
iyangsj authored Jul 9, 2024
1 parent 410372d commit 6e35e18
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 129 deletions.
5 changes: 3 additions & 2 deletions cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ documentation = true

# A list of headers to #include (with quotes)
sys_includes = ["sys/socket.h", "sys/types.h"]
includes = ["openssl/ssl.h"]
includes = ["openssl/ssl.h", "tquic_def.h"]

[export]
exclude = ["MAX_CID_LEN", "MIN_CLIENT_INITIAL_LEN"]
exclude = ["MAX_CID_LEN", "MIN_CLIENT_INITIAL_LEN", "VINT_MAX"]

[export.rename]
"Config" = "quic_config_t"
Expand All @@ -42,6 +42,7 @@ exclude = ["MAX_CID_LEN", "MIN_CLIENT_INITIAL_LEN"]
"TlsConfigSelectMethods" = "quic_tls_config_select_methods_t"
"TlsConfigSelectorContext" = "quic_tls_config_select_context_t"
"CongestionControlAlgorithm" = "quic_congestion_control_algorithm"
"MultipathAlgorithm" = "quic_multipath_algorithm"
"LevelFilter" = "quic_log_level"
"Http3Connection" = "http3_conn_t"
"Http3Config" = "http3_config_t"
Expand Down
144 changes: 19 additions & 125 deletions include/tquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <sys/socket.h>
#include <sys/types.h>
#include "openssl/ssl.h"
#include "tquic_def.h"

/**
* The current QUIC wire version.
Expand All @@ -22,13 +23,13 @@
#define QUIC_VERSION_V1 1

/**
* Available congestion control algorithm
* Available congestion control algorithms.
*/
typedef enum quic_congestion_control_algorithm {
/**
* CUBIC uses a cubic function instead of a linear window increase function
* of the current TCP standards to improve scalability and stability under
* fast and long-distance networks..
* fast and long-distance networks.
*/
QUIC_CONGESTION_CONTROL_ALGORITHM_CUBIC,
/**
Expand All @@ -52,6 +53,11 @@ typedef enum quic_congestion_control_algorithm {
* (Experimental)
*/
QUIC_CONGESTION_CONTROL_ALGORITHM_COPA,
/**
* Dummy is a simple congestion controller with a static congestion window.
* It is intended to be used for testing and experiments.
*/
QUIC_CONGESTION_CONTROL_ALGORITHM_DUMMY,
} quic_congestion_control_algorithm;

/**
Expand All @@ -64,7 +70,7 @@ typedef enum quic_multipath_algorithm {
* load balancing, making it particularly advantageous for bulk transfer
* applications in heterogeneous networks.
*/
MULTIPATH_ALGORITHM_MIN_RTT,
QUIC_MULTIPATH_ALGORITHM_MIN_RTT,
/**
* The scheduler sends all packets redundantly on all available paths. It
* utilizes additional bandwidth to minimize latency, thereby reducing the
Expand All @@ -74,14 +80,14 @@ typedef enum quic_multipath_algorithm {
* present, it ensures a goodput at least equivalent to the best single
* path.
*/
MULTIPATH_ALGORITHM_REDUNDANT,
QUIC_MULTIPATH_ALGORITHM_REDUNDANT,
/**
* The scheduler sends packets over available paths in a round robin
* manner. It aims to fully utilize the capacity of each path as the
* distribution across all path is equal. It is only used for testing
* purposes.
*/
MULTIPATH_ALGORITHM_ROUND_ROBIN,
QUIC_MULTIPATH_ALGORITHM_ROUND_ROBIN,
} quic_multipath_algorithm;

/**
Expand Down Expand Up @@ -358,7 +364,6 @@ void enable_dplpmtud(struct quic_config_t *config, bool v);
/**
* Set the maximum outgoing UDP payload size in bytes.
* It corresponds to the maximum datagram size that DPLPMTUD tries to discovery.
*
* The default value is `1200` which means let DPLPMTUD choose a value.
*/
void quic_config_set_send_udp_payload_size(struct quic_config_t *config, uintptr_t v);
Expand Down Expand Up @@ -1156,6 +1161,13 @@ int64_t http3_stream_new_with_priority(struct http3_conn_t *conn,
struct quic_conn_t *quic_conn,
const struct http3_priority_t *priority);

/**
* Close the given HTTP/3 stream.
*/
int http3_stream_close(struct http3_conn_t *conn,
struct quic_conn_t *quic_conn,
uint64_t stream_id);

/**
* Set priority for an HTTP/3 stream.
*/
Expand All @@ -1164,13 +1176,6 @@ int http3_stream_set_priority(struct http3_conn_t *conn,
uint64_t stream_id,
const struct http3_priority_t *priority);

/**
* Close the given HTTP/3 stream.
*/
int http3_stream_close(struct http3_conn_t *conn,
struct quic_conn_t *quic_conn,
uint64_t stream_id);

/**
* Send HTTP/3 request or response headers on the given stream.
*/
Expand Down Expand Up @@ -1226,128 +1231,17 @@ int http3_take_priority_update(struct http3_conn_t *conn,
void *argp),
void *argp);

/**
* An enum representing the available verbosity level filters of the logger.
*/
typedef enum quic_log_level {
/**
* A level lower than all log levels.
*/
QUIC_LOG_LEVEL_OFF,
/**
* Corresponds to the `Error` log level.
*/
QUIC_LOG_LEVEL_ERROR,
/**
* Corresponds to the `Warn` log level.
*/
QUIC_LOG_LEVEL_WARN,
/**
* Corresponds to the `Info` log level.
*/
QUIC_LOG_LEVEL_INFO,
/**
* Corresponds to the `Debug` log level.
*/
QUIC_LOG_LEVEL_DEBUG,
/**
* Corresponds to the `Trace` log level.
*/
QUIC_LOG_LEVEL_TRACE,
} quic_log_level;

/**
* Set logger.
* `cb` is a callback function that will be called for each log message.
* `line` is a null-terminated log message and `argp` is user-defined data that will be passed to
* `data` is a '\n' terminated log message and `argp` is user-defined data that will be passed to
* the callback.
* `level` represents the log level.
*/
void quic_set_logger(void (*cb)(const uint8_t *data, size_t data_len, void *argp),
void *argp,
quic_log_level level);

typedef enum http3_error {
HTTP3_NO_ERROR = 0,

// There is no error or no work to do
HTTP3_ERR_DONE = -1,

// The endpoint detected an error in the protocol
HTTP3_ERR_GENERAL_PROTOCOL_ERROR = -2,

// The endpoint encountered an internal error and cannot continue with the
// connection
HTTP3_ERR_INTERNAL_ERROR = -3,

// The endpoint detected that its peer created a stream that it will not
// accept
HTTP3_ERR_STREAM_CREATION_ERROR = -4,

// A stream required by the connection was closed or reset
HTTP3_ERR_CLOSED_CRITICAL_STREAM = -5,

// A frame was received which is not permitted in the current state or on
// the current stream
HTTP3_ERR_FRAME_UNEXPECTED = -6,

// A frame that fails to satisfy layout requirements or with an invalid
// size was received
HTTP3_ERR_FRAME_ERROR = -7,

// The endpoint detected that its peer is exhibiting a behavior that might
// be generating excessive load
HTTP3_ERR_EXCESSIVE_LOAD = -8,

// A stream ID or push ID was used incorrectly, such as exceeding a limit,
// reducing a limit, or being reused
HTTP3_ERR_ID_ERROR = -9,

// An endpoint detected an error in the payload of a SETTINGS frame
HTTP3_ERR_SETTINGS_ERROR = -10,

// No SETTINGS frame was received at the beginning of the control stream
HTTP3_ERR_MISSING_SETTINGS = -11,

// -12 reserved

// The stream is blocked
HTTP3_ERR_STREAM_BLOCKED = -13,

// The server rejected the request without performing any application
// processing
HTTP3_ERR_REQUEST_REJECTED = -14,

// The request or its response (including pushed response) is cancelled
HTTP3_ERR_REQUEST_CANCELLED = -15,

// The client's stream terminated without containing a fully-formed request
HTTP3_ERR_REQUEST_INCOMPLETE = -16,

// An HTTP message was malformed and cannot be processed
HTTP3_ERR_MESSAGE_ERROR = -17,

// The TCP connection established in response to a CONNECT request was
// reset or abnormally closed
HTTP3_ERR_CONNECT_ERROR = -18,

// The requested operation cannot be served over HTTP/3. The peer should
// retry over HTTP/1.1
HTTP3_ERR_VERSION_FALLBACK = -19,

// The decoder failed to interpret an encoded field section and is not
// able to continue decoding that field section
HTTP3_ERR_QPACK_DECOMPRESSION_FAILED = -20,

// The decoder failed to interpret an encoder instruction received on the
// encoder stream
HTTP3_ERR_QPACK_ENCODER_STREAM_ERROR = -21,

// The encoder failed to interpret a decoder instruction received on the
// decoder stream
HTTP3_ERR_QPACK_DECODER_STREAM_ERROR = -22,
} http3_error;

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
Expand Down
116 changes: 116 additions & 0 deletions include/tquic_def.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#ifndef _TQUIC_DEF_H_
#define _TQUIC_DEF_H_

/**
* An enum representing the available verbosity level filters of the logger.
*/
typedef enum quic_log_level {
/**
* A level lower than all log levels.
*/
QUIC_LOG_LEVEL_OFF,
/**
* Corresponds to the `Error` log level.
*/
QUIC_LOG_LEVEL_ERROR,
/**
* Corresponds to the `Warn` log level.
*/
QUIC_LOG_LEVEL_WARN,
/**
* Corresponds to the `Info` log level.
*/
QUIC_LOG_LEVEL_INFO,
/**
* Corresponds to the `Debug` log level.
*/
QUIC_LOG_LEVEL_DEBUG,
/**
* Corresponds to the `Trace` log level.
*/
QUIC_LOG_LEVEL_TRACE,
} quic_log_level;


typedef enum http3_error {
HTTP3_NO_ERROR = 0,

// There is no error or no work to do
HTTP3_ERR_DONE = -1,

// The endpoint detected an error in the protocol
HTTP3_ERR_GENERAL_PROTOCOL_ERROR = -2,

// The endpoint encountered an internal error and cannot continue with the
// connection
HTTP3_ERR_INTERNAL_ERROR = -3,

// The endpoint detected that its peer created a stream that it will not
// accept
HTTP3_ERR_STREAM_CREATION_ERROR = -4,

// A stream required by the connection was closed or reset
HTTP3_ERR_CLOSED_CRITICAL_STREAM = -5,

// A frame was received which is not permitted in the current state or on
// the current stream
HTTP3_ERR_FRAME_UNEXPECTED = -6,

// A frame that fails to satisfy layout requirements or with an invalid
// size was received
HTTP3_ERR_FRAME_ERROR = -7,

// The endpoint detected that its peer is exhibiting a behavior that might
// be generating excessive load
HTTP3_ERR_EXCESSIVE_LOAD = -8,

// A stream ID or push ID was used incorrectly, such as exceeding a limit,
// reducing a limit, or being reused
HTTP3_ERR_ID_ERROR = -9,

// An endpoint detected an error in the payload of a SETTINGS frame
HTTP3_ERR_SETTINGS_ERROR = -10,

// No SETTINGS frame was received at the beginning of the control stream
HTTP3_ERR_MISSING_SETTINGS = -11,

// -12 reserved

// The stream is blocked
HTTP3_ERR_STREAM_BLOCKED = -13,

// The server rejected the request without performing any application
// processing
HTTP3_ERR_REQUEST_REJECTED = -14,

// The request or its response (including pushed response) is cancelled
HTTP3_ERR_REQUEST_CANCELLED = -15,

// The client's stream terminated without containing a fully-formed request
HTTP3_ERR_REQUEST_INCOMPLETE = -16,

// An HTTP message was malformed and cannot be processed
HTTP3_ERR_MESSAGE_ERROR = -17,

// The TCP connection established in response to a CONNECT request was
// reset or abnormally closed
HTTP3_ERR_CONNECT_ERROR = -18,

// The requested operation cannot be served over HTTP/3. The peer should
// retry over HTTP/1.1
HTTP3_ERR_VERSION_FALLBACK = -19,

// The decoder failed to interpret an encoded field section and is not
// able to continue decoding that field section
HTTP3_ERR_QPACK_DECOMPRESSION_FAILED = -20,

// The decoder failed to interpret an encoder instruction received on the
// encoder stream
HTTP3_ERR_QPACK_ENCODER_STREAM_ERROR = -21,

// The encoder failed to interpret a decoder instruction received on the
// decoder stream
HTTP3_ERR_QPACK_DECODER_STREAM_ERROR = -22,
} http3_error;

#endif /* _TQUIC_DEF_H_ */
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use crate::trans_param::TransportParams;
pub const QUIC_VERSION: u32 = QUIC_VERSION_V1;

/// The QUIC Version 1
const QUIC_VERSION_V1: u32 = 0x0000_0001;
pub const QUIC_VERSION_V1: u32 = 0x0000_0001;

/// The Connection ID MUST NOT exceed 20 bytes in QUIC version 1.
/// See RFC 9000 Section 17.2
Expand Down Expand Up @@ -1182,6 +1182,12 @@ mod qlog;
#[cfg(feature = "ffi")]
mod ffi;

// Note: Workaround for the module path issue in cbindgen.
// DON'T enable this feature when building with cargo.
#[cfg(feature = "cbindgen")]
#[path = "h3/connection.rs"]
mod h3_connection;

mod codec;
pub mod endpoint;
pub mod error;
Expand Down
1 change: 0 additions & 1 deletion src/tls/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ where
}
}

#[repr(C)]
pub struct TlsConfig {
/// Boringssl SSL context.
tls_ctx: boringssl::tls::Context,
Expand Down

0 comments on commit 6e35e18

Please sign in to comment.