initial commit

This commit is contained in:
Christian Ulrich 2020-11-02 00:52:13 +01:00
parent f8dcc23275
commit 932dd80499
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
16 changed files with 775 additions and 0 deletions

39
picotls/openssl.nim Normal file
View File

@ -0,0 +1,39 @@
from std/openssl import
EVP_PKEY,
PEVP_MD,
PX509_STORE
from picotls import
ptls_cipher_suite_t,
ptls_key_exchange_algorithm_t,
ptls_sign_certificate_t,
ptls_verify_certificate_t
type
ptls_openssl_signature_scheme_t {.importc, header: "picotls/openssl.h", bycopy.} = object
scheme_id*: uint16
scheme_md*: PEVP_MD
ptls_openssl_sign_certificate_t {.importc, header: "picotls/openssl.h", bycopy.} = object
super*: ptls_sign_certificate_t
key*: EVP_PKEY
schemes*: array[4, ptls_openssl_signature_scheme_t]
ptls_openssl_verify_certificate_t {.importc, header: "picotls/openssl.h", bycopy.} = object
super*: ptls_verify_certificate_t
cert_store*: PX509_STORE
proc ptls_openssl_random_bytes*(buf: pointer, len: csize_t) {.cdecl, importc,
header: "picotls/openssl.h".}
proc ptls_openssl_init_verifiy_certificate*(self: ptr ptls_openssl_verify_certificate_t,
store: PX509_STORE): cint {.cdecl,
importc, header: "picotls/openssl.h".}
proc ptls_openssl_init_sign_certificate*(self: ptr ptls_openssl_sign_certificate_t,
key: EVP_PKEY): cint {.cdecl, importc,
header: "picotls/openssl.h".}
var ptls_openssl_cipher_suites* {.importc, header: "picotls/openssl.h".}: ptr ptr ptls_cipher_suite_t
var ptls_openssl_key_exchanges* {.importc, header: "picotls/openssl.h".}: ptr ptr ptls_key_exchange_algorithm_t

280
picotls/picotls.nim Normal file
View File

@ -0,0 +1,280 @@
const PTLS_MAX_DIGEST_SIZE = 64
type
List*[T] = object
list*: ptr T
count*: csize_t
ptls_cipher_algorithm_t* {.importc, header: "picotls.h", bycopy.} = object
name*: cstring
key_size*: csize_t
block_size*: csize_t
iv_size*: csize_t
context_size*: csize_t
setup_crypto*: proc(ctx: ptr ptls_cipher_context_t, is_enc: cint,
key: pointer): cint {.cdecl.}
ptls_aead_algorithm_t* {.importc, header: "picotls.h", bycopy.} = object
name*: cstring
confidentiality_limit*: uint64
integrity_limit*: uint64
ctr_cipher*: ptr ptls_cipher_algorithm_t
ecb_cipher*: ptr ptls_cipher_algorithm_t
key_size*: csize_t
iv_size*: csize_t
tag_size*: csize_t
context_size*: csize_t
setup_crypto*: proc(ctx: ptr ptls_aead_context_t, is_enc: cint,
key: pointer, iv: pointer): cint {.cdecl.}
ptls_hash_final_mode_t* {.importc, header: "picotls.h".} = enum
PTLS_HASH_FINAL_MODE_FREE = 0,
PTLS_HASH_FINAL_MODE_RESET = 1,
PTLS_HASH_FINAL_MODE_SNAPSHOT = 2
ptls_hash_context_t* {.importc, header: "picotls.h", bycopy.} = object
update*: proc(ctx: ptr ptls_hash_context_t, src: pointer, len: csize_t)
{.cdecl.}
final*: proc(ctx: ptr ptls_hash_context_t, md: pointer,
mode: ptls_hash_final_mode_t) {.cdecl.}
clone*: proc(src: ptr ptls_hash_context_t): ptr ptls_hash_context_t
{.cdecl.}
ptls_hash_algorithm_t* {.importc, header: "picotls.h", bycopy.} = object
block_size*: csize_t
digest_size*: csize_t
create*: proc(): ptr ptls_hash_context_t {.cdecl.}
empty_digest*: array[PTLS_MAX_DIGEST_SIZE, uint8]
ptls_cipher_suite_t* {.importc, header: "picotls.h", bycopy.} = object
id*: uint16
aead*: ptr ptls_aead_algorithm_t
hash*: ptr ptls_hash_algorithm_t
CipherSuiteListElem* = object
cipher_suite*: ptr ptls_cipher_suite_t
record_digest*: array[PTLS_MAX_DIGEST_SIZE, uint8]
VerifySignCb* = proc(verify_ctx: pointer, data: ptls_iovec_t,
sign: ptls_iovec_t): cint {.cdecl.}
ptls_t* {.importc, header: "picotls.h", bycopy.} = object
ptls_key_exchange_algorithm_t* {.importc, header: "picotls.h", bycopy.} = object
id*: uint16
create*: proc(algo: ptr ptls_key_exchange_algorithm_t,
ctx: ptr ptr ptls_key_exchange_context_t): cint {.cdecl.}
exchange*: proc(algo: ptr ptls_key_exchange_algorithm_t,
pubkey: ptr ptls_iovec_t, secret: ptr ptls_iovec_t): cint
{.cdecl.}
data*: pointer
ptls_key_exchange_context_t* {.importc, header: "picotls.h", bycopy.} = object
algo*: ptr ptls_key_exchange_algorithm_t
pubkey*: ptls_iovec_t
on_exchange*: proc(keyex: ptr ptr ptls_key_exchange_context_t, release: cint,
secret: ptr ptls_iovec_t, peerkey: ptls_iovec_t): cint
{.cdecl.}
ptls_esni_context_t* {.importc, header: "picotls.h", bycopy.} = object
key_exchanges*: ptr ptr ptls_key_exchange_context_t
cipher_suites*: ptr CipherSuiteListElem
padded_length*: uint16
not_before*: uint64
not_after*: uint64
version*: uint16
ptls_iovec_t* {.importc, header: "picotls.h", bycopy.} = object
base*: uint8
len*: csize_t
ptls_on_client_hello_parameters_t* {.importc, header: "picotls.h", bycopy.} = object
server_name*: ptls_iovec_t
raw_message*: ptls_iovec_t
negotiated_protocols*: List[ptls_iovec_t]
signature_algorithms*: List[uint16]
certificate_compression_algorithms*: List[uint16]
cipher_suites*: List[uint16]
esni* {.bitsize: 1.}: cuint
incompatible_version* {.bitsize: 1.}: cuint
ptls_traffic_protection_t* {.importc, header: "picotls.h", incompleteStruct.} = object
ptls_message_emitter_t* {.importc, header: "picotls.h", bycopy.} = object
buf*: ptr ptls_buffer_t
enc*: ptr ptls_traffic_protection_t
record_header_length*: csize_t
begin_message*: proc (self: ptr ptls_message_emitter_t): cint {.cdecl.}
commit_message*: proc (self: ptr ptls_message_emitter_t): cint {.cdecl.}
ptls_key_schedule_t* {.importc, header: "picotls.h", bycopy.} = object
ptls_buffer_t* {.importc, header: "picotls.h", bycopy.} = object
base*: uint8
capacity*: csize_t
off*: csize_t
is_allocated*: cint
ptls_get_time_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_get_time_t): uint64 {.cdecl.}
ptls_on_client_hello_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_on_client_hello_t, tls: ptr ptls_t,
params: ptr ptls_on_client_hello_parameters_t): cint {.cdecl.}
ptls_emit_certificate_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_emit_certificate_t, tls: ptr ptls_t,
emitter: ptr ptls_message_emitter_t,
key_sched: ptr ptls_key_schedule_t, context: ptls_iovec_t,
push_status_request: cint, compress_algos: uint16,
num_compress_algos: csize_t): cint {.cdecl.}
ptls_sign_certificate_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_sign_certificate_t, tls: ptr ptls_t,
selected_algorithm: uint16, output: ptr ptls_buffer_t,
input: ptls_iovec_t, algorithms: uint16,
num_algorithms: csize_t): cint {.cdecl.}
ptls_verify_certificate_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_verify_certificate_t, tls: ptr ptls_t,
verify_sign: ptr VerifySignCb, verify_data: ptr pointer,
certs: ptls_iovec_t, numCerts: csize_t): cint {.cdecl.}
ptls_encrypt_ticket_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_encrypt_ticket_t, tls: ptr ptls_t, is_encrypt: cint,
dst: ptr ptls_buffer_t, src: ptls_iovec_t): cint {.cdecl.}
ptls_save_ticket_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_save_ticket_t, tls: ptr ptls_t, input: ptls_iovec_t):
cint {.cdecl.}
ptls_log_event_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_log_event_t, tls: ptr ptls_t, `type`: cstring,
fmt: cstring) {.cdecl, varargs.}
ptls_update_open_count_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_update_open_count_t, delta: BiggestInt) {.cdecl.}
ptls_update_traffic_key_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_update_traffic_key_t, tls: ptr ptls_t, is_enc: cint,
epoch: csize_t, secret: pointer): cint {.cdecl.}
ptls_decompress_certificate_t* {.importc, header: "picotls.h", bycopy.} = object
supported_algorithms*: uint16
cb: proc(self: ptr ptls_decompress_certificate_t, tls: ptr ptls_t,
algorithm: uint16, output: ptls_iovec_t, input: ptls_iovec_t): cint
{.cdecl.}
ptls_update_esni_key_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_update_esni_key_t, tls: ptr ptls_t, secret: ptls_iovec_t,
hash: ptls_hash_algorithm_t, hashed_esni_contents: pointer): cint
{.cdecl.}
ptls_on_extension_t* {.importc, header: "picotls.h", bycopy.} = object
cb: proc(self: ptr ptls_on_extension_t, tls: ptr ptls_t, hstype: uint8,
exttype: uint16, extdata: ptls_iovec_t): cint {.cdecl.}
ptls_context_t* {.importc, header: "picotls.h", bycopy.} = object
random_bytes*: proc (buf: pointer, len: csize_t) {.cdecl.}
get_time*: ptr ptls_get_time_t
key_exchanges*: ptr ptr ptls_key_exchange_algorithm_t
cipher_suites*: ptr ptr ptls_cipher_suite_t
certificates*: List[ptls_iovec_t]
esni*: ptr ptr ptls_esni_context_t
on_client_hello*: ptr ptls_on_client_hello_t
emit_certificate*: ptr ptls_emit_certificate_t
sign_certificate*: ptr ptls_sign_certificate_t
verify_certificate*: ptr ptls_verify_certificate_t
ticket_lifetime*: uint32
max_early_data_size*: uint32
max_buffer_size*: csize_t
hkdf_label_prefix_obsolete: cstring
require_dhe_on_psk* {.bitsize: 1.}: cuint
use_exporter* {.bitsize: 1.}: cuint
send_change_cipher_spec* {.bitsize: 1.}: cuint
require_client_authentication* {.bitsize: 1.}: cuint
omit_end_of_early_data* {.bitsize: 1.}: cuint
encrypt_ticket*: ptr ptls_encrypt_ticket_t
save_ticket*: ptr ptls_save_ticket_t
log_event*: ptr ptls_log_event_t
update_open_count*: ptr ptls_update_open_count_t
update_traffic_key*: ptr ptls_update_traffic_key_t
decompress_certificate*: ptr ptls_decompress_certificate_t
update_esni_key*: ptr ptls_update_esni_key_t
on_extension*: ptr ptls_on_extension_t
ptls_cipher_context_t* {.importc, header: "picotls.h", bycopy.} = object
algo*: ptr ptls_cipher_algorithm_t
do_dispose*: proc(ctx: ptr ptls_cipher_context_t) {.cdecl.}
do_init*: proc(ctx: ptr ptls_cipher_context_t, iv: pointer) {.cdecl.}
do_transform*: proc(ctx: ptr ptls_cipher_context_t, output: pointer,
input: pointer, len: csize_t) {.cdecl.}
ptls_aead_supplementary_encryption_t* {.importc, header: "picotls.h", bycopy.} = object
ctx*: ptr ptls_cipher_context_t
input*: pointer
output*: array[16, uint8]
ptls_aead_context_t* {.importc, header: "picotls.h", bycopy.} = object
algo*: ptr ptls_aead_algorithm_t
dispose_crypto*: proc(ctx: ptr ptls_aead_context_t) {.cdecl.}
do_encrypt_init*: proc(ctx: ptr ptls_aead_context_t, seq: uint64,
aad: pointer, aadlen: csize_t) {.cdecl.}
do_encrypt_update*: proc(ctx: ptr ptls_aead_context_t, output: pointer,
input: pointer, inlen: csize_t): csize_t {.cdecl.}
do_encrypt_final*: proc(ctx: ptr ptls_aead_context_t, output: pointer):
csize_t {.cdecl.}
do_encrypt*: proc(ctx: ptr ptls_aead_context_t, output: pointer,
input: pointer, inlen: csize_t, seq: uint64, aad: pointer,
aadlen: csize_t,
supp: ptr ptls_aead_supplementary_encryption_t) {.cdecl.}
ClientProperties* {.bycopy.} = object
negotiated_protocols*: List[ptls_iovec_t]
session_ticket*: ptls_iovec_t
max_early_data_size*: ptr csize_t
early_data_acceptance*: ptls_early_data_acceptance_t
negotiate_before_key_exchange* {.bitsize: 1.}: cuint
esni_keys*: ptls_iovec_t
PskBinder* {.bycopy.} = object
base*: array[64, uint8]
len*: csize_t
Cookie* {.bycopy.} = object
key*: pointer
additional_data*: ptls_iovec_t
ServerProperties* {.bycopy.} = object
selected_psk_binder*: PskBinder
cookie*: Cookie
enforce_retry* {.bitsize: 1.}: cuint
retry_uses_cookie* {.bitsize: 1.}: cuint
ClientOrServer* {.union, bycopy.} = object
client*: ClientProperties
server*: ServerProperties
ptls_raw_extension_t* {.importc, header: "picotls.h", bycopy.} = object
`type`*: uint16
data*: ptls_iovec_t
ptls_early_data_acceptance_t* {.importc, header: "picotls.h".} = enum
PTLS_EARLY_DATA_ACCEPTANCE_UNKNOWN = 0,
PTLS_EARLY_DATA_REJECTED,
PTLS_EARLY_DATA_ACCEPTED
ptls_handshake_properties_t* {.importc, header: "picotls.h", bycopy.} = object
properties*: ClientOrServer
additional_extensions*: ptr ptls_raw_extension_t
collect_extension*: proc (tls: ptr ptls_t;
properties: ptr ptls_handshake_properties_t;
`type`: uint16): cint {.cdecl.}
collected_extensions*: proc (tls: ptr ptls_t;
properties: ptr ptls_handshake_properties_t;
extensions: ptr ptls_raw_extension_t): cint {.cdecl.}
var ptls_get_time* {.importc, header: "picotls.h".}: ptls_get_time_t
proc ptls_load_certificates*(ctx: ptls_context_t, cert_pem_file: cstring) {.cdecl,
importc, header: "picotls.h".}

BIN
quicly/.quicly.nim.swp Normal file

Binary file not shown.

5
quicly/cc.nim Normal file
View File

@ -0,0 +1,5 @@
type
quicly_cc_t* {.importc, header: "quicly/cc.h", bycopy.} = enum
CC_RENO_MODIFIED,
#CUBIC (RFC 8312)
CC_CUBIC

22
quicly/cid.nim Normal file
View File

@ -0,0 +1,22 @@
type
quicly_cid_t* {.importc, header: "quicly/cid.h", bycopy.} = object
cid*: array[20, uint8]
len*: uint8
quicly_cid_plaintext_t* {.importc, header: "quicly/cid.h", bycopy.} = object
master_id*: uint32
path_id* {.bitsize: 8.}: uint32
thread_id* {.bitsize: 24.}: uint32
node_id*: uint64
quicly_cid_encryptor_t* {.importc, header: "quicly/cid.h", bycopy.} = object
encrypt_cid*: proc (self: ptr quicly_cid_encryptor_t;
encrypted: ptr quicly_cid_t; stateless_reset_token: pointer;
plaintext: ptr quicly_cid_plaintext_t) {.cdecl.}
decrypt_cid*: proc (self: ptr quicly_cid_encryptor_t;
plaintext: ptr quicly_cid_plaintext_t; encrypted: pointer;
len: csize_t): csize_t {.cdecl.}
generate_stateless_reset_token*: proc (self: ptr quicly_cid_encryptor_t;
token: pointer; cid: pointer): cint {.cdecl.}

62
quicly/constants.nim Normal file
View File

@ -0,0 +1,62 @@
from linklist import quicly_linklist_t
from maxsender import quicly_maxsender_t
from recvstate import
quicly_recvstate_t,
quicly_recvstate_transfer_complete
from sendstate import
quicly_sendstate_t,
quicly_sendstate_is_open
type
quicly_stream_id_t* {.importc, header: "quicly/constants.h", bycopy.} = int64
quicly_conn_t* {.importc, header: "quicly/constants.h", incompleteStruct.} = object
quicly_stream_callbacks_t* {.importc, header: "quicly.h", bycopy.} = object
on_destroy*: proc(stream: ptr quicly_stream_t, err: cint) {.cdecl.}
on_send_shift*: proc(stream: ptr quicly_stream_t, delta: csize_t) {.cdecl.}
on_send_emit*: proc(stream: ptr quicly_stream_t, off: csize_t, dst: pointer,
len: csize_t, wrote_all: cint) {.cdecl.}
on_send_stop*: proc(stream: ptr quicly_stream_t, err: cint) {.cdecl.}
on_receive*: proc(stream: ptr quicly_stream_t, off: csize_t, src: pointer,
len: csize_t) {.cdecl.}
on_receive_reset*: proc(stream: ptr quicly_stream_t, err: cint) {.cdecl.}
quicly_sender_state_t* {.importc, header: "quicly.h".} = enum
QUICLY_SENDER_STATE_NONE,
QUICLY_SENDER_STATE_SEND,
QUICLY_SENDER_STATE_UNACKED,
QUICLY_SENDER_STATE_ACKED,
StreamSendError* {.bycopy.} = object
sender_state*: quicly_sender_state_t
error_code: uint16
StreamSendPendingLink* {.bycopy.} = object
control*: quicly_linklist_t
default_scheduler*: quicly_linklist_t
StreamSendAux* {.bycopy.} = object
max_stream_data*: uint64
stop_sending*: StreamSendError
reset_stream*: StreamSendError
max_stream_data_sender*: quicly_maxsender_t
blocked*: quicly_sender_state_t
pending_link*: StreamSendPendingLink
StreamRecvAux* {.bycopy.} = object
window*: uint32
max_ranges*: uint32
quicly_stream_t* {.importc, header: "quicly.h", bycopy.} = object
conn*: ptr quicly_conn_t
stream_id*: quicly_stream_id_t
callbacks*: ptr quicly_stream_callbacks_t
sendstate*: quicly_sendstate_t
recvstate*: quicly_recvstate_t
data*: pointer
streams_blocked* {.bitsize: 1.}: cuint
send_aux*: StreamSendAux
recv_aux*: StreamRecvAux

5
quicly/defaults.nim Normal file
View File

@ -0,0 +1,5 @@
from quicly import quicly_context_t
var quicly_spec_context* {.importc, header: "quicly/defaults.h".}: quicly_context_t
var quicly_performant_context* {.importc, header: "quicly/defaults.h".}: quicly_context_t

4
quicly/linklist.nim Normal file
View File

@ -0,0 +1,4 @@
type
quicly_linklist_t* {.importc, header: "quicly/linklist.h", bycopy.} = object
prev*: ptr quicly_linklist_t
next*: ptr quicly_linklist_t

6
quicly/loss.nim Normal file
View File

@ -0,0 +1,6 @@
type
quicly_loss_conf_t* {.importc, header: "quicly/loss.h", bycopy.} = object
time_reordering_percentile*: cuint
min_pto*: uint32
default_initial_rtt*: uint32
num_speculative_ptos*: uint8

10
quicly/maxsender.nim Normal file
View File

@ -0,0 +1,10 @@
type
quicly_maxsender_t* {.importc, header: "quicly/maxsender.h", bycopy.} = object
max_committed*: int64
max_acked*: int64
num_inflight*: csize_t
force_send* {.bitsize: 1.}: cuint
quicly_maxsender_sent_t* {.importc, header: "quicly/maxsender.h", bycopy.} = object
inflight* {.bitsize: 1.}: uint64
value* {.bitsize: 63.}: uint64

222
quicly/quicly.nim Normal file
View File

@ -0,0 +1,222 @@
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 nativesockets import SockAddr, Sockaddr_in, Sockaddr_in6, SockLen
from constants import
quicly_conn_t,
quicly_stream_id_t,
quicly_stream_t
from ../picotls/picotls import
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
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* {.bycopy.} = object
encrypted*: ptls_iovec_t
plaintext*: quicly_cid_plaintext_t
might_be_client_generated* {.bitsize: 1.}: cuint
Cid* {.bycopy.} = object
dest: CidDest
src: ptls_iovec_t
Decrypted* {.bycopy.} = object
pn: uint64
key_phase: uint64
IsStatelessReset* = 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 {.cdecl, importc, header: "quicly.h".}
proc quicly_close*(conn: ptr quicly_conn_t, err: cint, reason_phrase: cstring):
cint {.cdecl, importc, header: "quicly.h".}
proc quicly_free*(conn: ptr quicly_conn_t): cint {.cdecl, importc, header: "quicly.h".}
proc quicly_decode_packet*(ctx: ptr quicly_context_t,
packet: ptr quicly_decoded_packet_t,
datagram: ptr uint8, datagram_size: csize_t,
off: csize_t): csize_t
{.cdecl, importc, header: "quicly.h".}
proc quicly_is_destination*(conn: ptr quicly_conn_t, dest_addr: ptr SockAddr,
src_addr: ptr SockAddr,
decoded: ptr quicly_decoded_packet_t): cint
{.cdecl, importc, header: "quicly.h".}
proc quicly_receive*(conn: ptr quicly_conn_t, dest_addr: ptr SockAddr,
src_addr: ptr SockAddr,
packet: ptr quicly_decoded_packet_t): cint
{.cdecl, importc, header: "quicly.h".}
proc quicly_accept*(conn: ptr ptr quicly_conn_t, ctx: ptr quicly_context_t,
dest_addr: ptr SockAddr, src_addr: ptr SockAddr,
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
{.cdecl, importc, header: "quicly.h".}
proc quicly_connect*(conn: ptr ptr quicly_conn_t, server_name: cstring,
dest_addr: ptr SockAddr, src_addr: ptr SockAddr,
new_cid: ptr quicly_cid_plaintext_t,
address_token: ptr quicly_address_token_plaintext_t,
handshake_properties: ptr ptls_handshake_properties_t,
resumed_transport_params: ptr quicly_transport_parameters_t):
cint {.cdecl, importc, header: "quicly.h".}
proc quicly_get_socklen*(sa: ptr SockAddr): SockLen
{.cdecl, importc, header: "quicly.h".}
proc quicly_get_fist_timeout*(conn: ptr quicly_conn_t): int64
{.cdecl, importc, header: "quicly.h".}

10
quicly/ranges.nim Normal file
View File

@ -0,0 +1,10 @@
type
quicly_range_t* {.importc, header: "quicly/ranges.h", bycopy.} = object
start*: uint64
`end`*: uint64
quicly_ranges_t* {.importc, header: "quicly/ranges.h", bycopy.} = object
ranges*: ptr quicly_range_t
num_ranges*: csize_t
capacity*: csize_t
initial*: quicly_range_t

10
quicly/recvstate.nim Normal file
View File

@ -0,0 +1,10 @@
from ranges import quicly_ranges_t
type
quicly_recvstate_t* {.importc, header: "quicly/recvstate.h", bycopy.} = object
received*: quicly_ranges_t
data_off*: uint64
eos*: uint64
proc quicly_recvstate_transfer_complete*(state: ptr quicly_recvstate_t): cint
{.cdecl, importc, header: "quicly/recvstate.h".}

15
quicly/sendstate.nim Normal file
View File

@ -0,0 +1,15 @@
from ranges import quicly_ranges_t
type
quicly_sendstate_t* {.importc, header: "quicly/sendstate.h", bycopy.} = object
acked*: quicly_ranges_t
pending*: quicly_ranges_t
size_inflight*: uint64
final_size*: uint64
quicly_sendstate_sent_t* {.importc, header: "quicly/sendstate.h", bycopy.} = object
start*: uint64
`end`*: uint64
proc quicly_sendstate_is_open*(state: ptr quicly_sendstate_t): cint
{.cdecl, importc, header: "quicly/sendstate.h".}

59
quicly/streambuf.nim Normal file
View File

@ -0,0 +1,59 @@
from ../picotls/picotls import ptls_buffer_t, ptls_iovec_t
from constants import quicly_stream_t
type
quicly_streambuf_sendvec_callbacks_t* {.importc, header: "quicly/streambuf.h", bycopy.} = object
flatten_vec*: proc(vec: ptr quicly_sendbuf_vec_t, dst: pointer, off: csize_t,
len: csize_t): cint {.cdecl.}
discard_vec*: proc(vec: ptr quicly_sendbuf_vec_t) {.cdecl.}
quicly_sendbuf_vec_t* {.importc, header: "quicly/streambuf.h", bycopy.} = object
cb*: ptr quicly_streambuf_sendvec_callbacks_t
`len`*: csize_t
cbdata*: pointer
VecList* {.bycopy.} = object
entries*: ptr quicly_sendbuf_vec_t
size*: csize_t
capacity*: csize_t
quicly_sendbuf_t* {.importc, header: "quicly/streambuf.h", bycopy.} = object
vecs*: VecList
off_in_first_vec*: csize_t
bytes_written*: uint64
quicly_streambuf_t* {.importc, header: "quicly/streambuf.h", bycopy.} = object
egress*: quicly_sendbuf_t
ingress: ptls_buffer_t
proc quicly_streambuf_create*(stream: ptr quicly_stream_t, sz: csize_t): cint
{.cdecl, importc, header: "quicly/streambuf.h".}
proc quicly_streambuf_destroy*(stream: ptr quicly_stream_t, err: cint)
{.cdecl, importc, header: "quicly/streambuf.h".}
proc quicly_streambuf_egress_shutdown*(stream: ptr quicly_stream_t): cint
{.cdecl, importc, header: "quicly/streambuf.h".}
proc quicly_streambuf_egress_write*(stream: ptr quicly_stream_t, src: pointer,
len: csize_t): cint
{.cdecl, importc, header: "quicly/streambuf.h".}
proc quicly_streambuf_egress_emit*(stream: ptr quicly_stream_t, off: csize_t,
dst: pointer, len: csize_t, wrote_all: cint)
{.cdecl, importc, header: "quicly/streambuf.h".}
proc quicly_streambuf_egress_shift*(stream: ptr quicly_stream_t, delta: csize_t)
{.cdecl, importc, header: "quicly/streambuf.h".}
proc quicly_streambuf_ingress_receive*(stream: ptr quicly_stream_t,
off: csize_t, src: pointer,
len: csize_t): cint
{.cdecl, importc, header: "quicly/streambuf.h".}
proc quicly_streambuf_ingress_get*(stream: ptr quicly_stream_t): ptls_iovec_t
{.cdecl, importc, header: "quicly/streambuf.h".}
proc quicly_streambuf_ingress_shift*(stream: ptr quicly_stream_t,
delta: csize_t)
{.cdecl, importc, header: "quicly/streambuf.h".}

26
quicp2p.nim Normal file
View File

@ -0,0 +1,26 @@
{.passL: "-l quicly -l picotls-core -l picotls-openssl".}
import quicly/quicly
import picotls/picotls
import picotls/openssl
proc main() =
echo "hello world"
#type
# PtlsGetTime {.pure, final.} = pointer
#
# PtlsContext {.importc: "struct ptls_context_t", pure, final,
# header: "picotls.h".} = object
# random_bytes: proc(buf: pointer, len: csize_t) {.cdecl.}
# get_time: ptr PtlsGetTime
# key_exchanges: ptr ptr PtlsKeyExchangeAlgorithm
# cipher_suites: ptr ptr PtlsCipherSuite
# certificates:
#
#
# proc
#
#
#proc main() =
# ptlsContext =