quicp2p/quicly/quicly.nim

256 lines
10 KiB
Nim

from cc import quicly_cc_t
from cid import quicly_cid_t, quicly_cid_encryptor_t, quicly_cid_plaintext_t
from loss import quicly_loss_conf_t
from posix import IOVec
from nativesockets import
SockAddr,
Sockaddr_storage,
Sockaddr_in,
Sockaddr_in6,
SockLen
from constants import
quicly_conn_t,
quicly_stream_id_t,
quicly_stream_t
from ../picotls/picotls import
ptls_t,
ptls_aead_algorithm_t,
ptls_aead_context_t,
ptls_buffer_t,
ptls_cipher_context_t,
ptls_context_t,
ptls_handshake_properties_t,
ptls_hash_algorithm_t,
ptls_iovec_t
export
quicly_conn_t,
quicly_stream_t,
quicly_stream_id_t
type
quicly_address_t* {.importc, header: "quicly.h", bycopy.} = object
sa*: SockAddr
sin*: Sockaddr_in
sin6*: Sockaddr_in6
Retry* {.bycopy.} = object
original_dcid*: quicly_cid_t
client_cid*: quicly_cid_t
server_cid*: quicly_cid_t
Resumption* {.bycopy.} = object
bytes*: array[256, uint8]
len*: csize_t
RetryOrResumption* {.union, bycopy.} = object
retry*: Retry
resumption*: Resumption
AppData* {.bycopy.} = object
bytes*: array[256, uint8]
len*: csize_t
AddressTokenType* {.bycopy.} = enum
QUICLY_ADDRESS_TOKEN_TYPE_RETRY
QUICLY_ADDRESS_TOKEN_TYPE_RESUMPTION
quicly_address_token_plaintext_t* {.importc, header: "quicly.h", bycopy.} = object
`type`: AddressTokenType
issued_at*: uint64
local*: quicly_address_t
remote*: quicly_address_t
type_specific*: RetryOrResumption
appdata*: AppData
quicly_stream_open_t* {.importc, header: "quicly.h", bycopy.} = object
cb*: proc(self: ptr quicly_stream_open_t, stream: ptr quicly_stream_t): cint
{.cdecl.}
quicly_receive_datagram_frame_t* {.importc, header: "quicly.h", bycopy.} = object
cb*: proc(self: ptr quicly_receive_datagram_frame_t, conn: ptr quicly_conn_t,
payload: ptls_iovec_t) {.cdecl.}
quicly_closed_by_remote_t* {.importc, header: "quicly.h", bycopy.} = object
cb*: proc(self: ptr quicly_closed_by_remote_t, conn: ptr quicly_conn_t,
err: cint, frame_type: uint64, reason: cstring,
reason_len: csize_t) {.cdecl.}
quicly_now_t* {.importc, header: "quicly.h", bycopy.} = object
cb*: proc(self: ptr quicly_now_t): int64 {.cdecl.}
quicly_save_resumption_token_t* {.importc, header: "quicly.h", bycopy.} = object
cb*: proc(self: ptr quicly_save_resumption_token_t, conn: ptr quicly_conn_t,
token: ptls_iovec_t): cint {.cdecl.}
quicly_generate_resumption_token_t* {.importc, header: "quicly.h", bycopy.} = object
cb*: proc(self: ptr quicly_generate_resumption_token_t,
conn: ptr quicly_conn_t, buf: ptr ptls_buffer_t,
token: ptr quicly_address_token_plaintext_t): cint {.cdecl.}
quicly_init_cc_t* {.importc, header: "quicly.h", bycopy.} = object
cb*: proc(self: ptr quicly_init_cc_t, cc: ptr quicly_cc_t, initcwnd: uint32,
now: int64) {.cdecl.}
quicly_max_stream_data_t* {.importc, header: "quicly.h", bycopy.} = object
bidi_local*: uint64
bidi_remote*: uint64
uni*: uint64
quicly_transport_parameters_t* {.importc, header: "quicly.h", bycopy.} = object
max_stream_data*: quicly_max_stream_data_t
max_data*: uint64
max_idle_timeout*: uint64
max_streams_bidi*: uint64
max_streams_uni*: uint64
max_udp_payload_size*: uint64
ack_delay_exponent*: uint8
max_ack_delay*: uint8
min_ack_delay_usec*: uint64
disable_active_migration* {.bitsize: 1.}: uint8
active_connection_id_limit*: uint64
max_datagram_frame_size*: uint16
quicly_stream_scheduler_t* {.importc, header: "quicly.h", bycopy.} = object
can_send*: proc(sched: ptr quicly_stream_scheduler_t,
conn: ptr quicly_conn_t, conn_is_saturated: cint): cint
{.cdecl.}
do_send*: proc(sched: ptr quicly_stream_scheduler_t,
stream: ptr quicly_stream_t): cint {.cdecl.}
update_state*: proc(sched: ptr quicly_stream_scheduler_t,
stream: ptr quicly_stream_t): cint {.cdecl.}
quicly_crypto_engine_t* {.importc, header: "quicly.h", bycopy.} = object
setup_cipher*: proc(engine: ptr quicly_crypto_engine_t,
conn: ptr quicly_conn_t, epoch: csize_t, is_enc: cint,
header_protect_ctx: ptr ptr ptls_cipher_context_t,
packet_protect_ctx: ptr ptr ptls_aead_context_t,
aead: ptr ptls_aead_algorithm_t,
hash: ptr ptls_hash_algorithm_t, secret: pointer): cint
{.cdecl.}
encrypt_packet: proc(engine: ptr quicly_crypto_engine_t,
conn: ptr quicly_conn_t,
header_protect_ctx: ptr ptls_cipher_context_t,
packet_protect_ctx: ptr ptls_aead_context_t,
datagram: ptls_iovec_t, first_byte_at: csize_t)
{.cdecl.}
quicly_context_t* {.importc, header: "quicly.h", bycopy.} = object
tls*: ptr ptls_context_t
initial_egress_max_udp_payload_size*: uint16
loss*: quicly_loss_conf_t
transport_params*: quicly_transport_parameters_t
max_packets_per_key*: uint64
max_crypto_bytes*: uint64
initial_version*: uint32
pre_validation_amplification_limit*: uint16
is_clustered* {.bitsize: 1.}: cuint
expand_client_hello* {.bitsize: 1.}: cuint
cid_encryptor*: ptr quicly_cid_encryptor_t
stream_open*: ptr quicly_stream_open_t
stream_scheduler*: ptr quicly_stream_scheduler_t
receive_datagram_frame*: ptr quicly_receive_datagram_frame_t
closed_by_remote*: ptr quicly_closed_by_remote_t
now*: ptr quicly_now_t
save_resumption_token*: ptr quicly_save_resumption_token_t
generate_resumption_token*: ptr quicly_generate_resumption_token_t
crypto_engine*: ptr quicly_crypto_engine_t
init_cc*: ptr quicly_init_cc_t
CidDest* {.importc, header: "quicly.h", bycopy.} = object
encrypted*: ptls_iovec_t
plaintext*: quicly_cid_plaintext_t
might_be_client_generated* {.bitsize: 1.}: cuint
Cid* {.importc, header: "quicly.h", bycopy.} = object
dest: CidDest
src: ptls_iovec_t
Decrypted* {.importc, header: "quicly.h", bycopy.} = object
pn: uint64
key_phase: uint64
IsStatelessReset* {.importc, header: "quicly.h", bycopy.} = enum
QUICLY_DECODED_PACKET_CACHED_MAYBE_STATELESS_RESET = 0,
QUICLY_DECODED_PACKET_CACHED_IS_STATELESS_RESET,
QUICLY_DECODED_PACKET_CACHED_NOT_STATELESS_RESET
quicly_decoded_packet_t* {.importc, header: "quicly.h", bycopy.} = object
octets*: ptls_iovec_t
cid*: Cid
version*: uint32
token*: ptls_iovec_t
encrypted_off*: csize_t
datagram_size*: csize_t
decrypted*: Decrypted
is_stateless_reset_cached: IsStatelessReset
proc quicly_get_stream*(conn: ptr quicly_conn_t, stream_id: quicly_stream_id_t):
ptr quicly_stream_t {.importc, header: "quicly.h", cdecl.}
proc quicly_close*(conn: ptr quicly_conn_t, err: cint, reason_phrase: cstring):
cint {.importc, header: "quicly.h", cdecl.}
proc quicly_free*(conn: ptr quicly_conn_t) {.importc, header: "quicly.h", cdecl.}
proc quicly_decode_packet*(ctx: ptr quicly_context_t,
packet: ptr quicly_decoded_packet_t,
datagram: ptr uint8, datagram_size: csize_t,
off: ptr csize_t): csize_t
{.importc, header: "quicly.h", cdecl.}
proc quicly_is_destination*(conn: ptr quicly_conn_t,
dest_addr: ptr SockAddr | ptr Sockaddr_storage,
src_addr: ptr SockAddr | ptr Sockaddr_storage,
decoded: ptr quicly_decoded_packet_t): cint
{.importc, header: "quicly.h", cdecl.}
proc quicly_receive*(conn: ptr quicly_conn_t,
dest_addr: ptr SockAddr | ptr Sockaddr_storage,
src_addr: ptr SockAddr | ptr Sockaddr_storage,
packet: ptr quicly_decoded_packet_t): cint
{.importc, header: "quicly.h", cdecl.}
proc quicly_send*(conn: ptr quicly_conn_t, dest: ptr quicly_address_t,
src: ptr quicly_address_t, datagrams: ptr IOVec,
num_diagrams: ptr csize_t, buf: pointer, bufsize: csize_t):
cint {.importc, header: "quicly.h", cdecl.}
proc quicly_accept*(conn: ptr ptr quicly_conn_t, ctx: ptr quicly_context_t,
dest_addr: ptr SockAddr | ptr Sockaddr_storage,
src_addr: ptr SockAddr | ptr Sockaddr_storage,
packet: ptr quicly_decoded_packet_t,
address_token: ptr quicly_address_token_plaintext_t,
new_cid: ptr quicly_cid_plaintext_t,
handshake_properties: ptr ptls_handshake_properties_t): cint
{.importc, header: "quicly.h", cdecl.}
proc quicly_connect*(conn: ptr ptr quicly_conn_t, ctx: ptr quicly_context_t,
server_name: cstring,
dest_addr: ptr SockAddr | ptr Sockaddr_storage,
src_addr: ptr SockAddr | ptr Sockaddr_storage,
new_cid: ptr quicly_cid_plaintext_t,
address_token: ptls_iovec_t,
handshake_properties: ptr ptls_handshake_properties_t,
resumed_transport_params: ptr quicly_transport_parameters_t):
cint {.importc, header: "quicly.h", cdecl.}
proc quicly_open_stream*(conn: ptr quicly_conn_t,
stream: ptr ptr quicly_stream_t, unidirectional: cint):
cint {.importc, header: "quicly.h", cdecl.}
proc quicly_amend_ptls_context*(ptls: ptr ptls_context_t)
{.importc, header: "quicly.h", cdecl.}
proc quicly_get_socklen*(sa: ptr SockAddr | ptr Sockaddr_storage): SockLen
{.importc, header: "quicly.h", cdecl.}
proc quicly_get_first_timeout*(conn: ptr quicly_conn_t): int64
{.importc, header: "quicly.h", cdecl.}
proc quicly_get_data*(conn: ptr quicly_conn_t): ptr pointer
{.importc, header: "quicly.h", cdecl.}