Enable minimal datagram support (#2986)

This commit is contained in:
Lassi Immonen 2022-08-16 21:33:35 +03:00 коммит произвёл GitHub
Родитель 526836c96c
Коммит ce482de278
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 80 добавлений и 16 удалений

2
.github/workflows/cargo.yml поставляемый
Просмотреть файл

@ -16,7 +16,7 @@ jobs:
cargo:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
name: Cargo
steps:

3
.gitignore поставляемый
Просмотреть файл

@ -373,3 +373,6 @@ target/
# Cargo (Rust) lock file
Cargo.lock
# IntelliJ project files
.idea/

Просмотреть файл

@ -3,6 +3,7 @@
use cmake::Config;
use std::path::Path;
use std::env;
fn main() {
let path_extra = "lib";
@ -11,12 +12,26 @@ fn main() {
logging_enabled = "on";
}
let target = env::var("TARGET").unwrap();
// Builds the native MsQuic and installs it into $OUT_DIR.
let dst = Config::new(".")
.define("QUIC_ENABLE_LOGGING", logging_enabled)
.define("QUIC_TLS", "openssl")
.define("QUIC_OUTPUT_DIR", "../lib")
.build();
let mut config = Config::new(".");
config
.define("QUIC_ENABLE_LOGGING", logging_enabled)
.define("QUIC_TLS", "openssl")
.define("QUIC_OUTPUT_DIR", "../lib");
match target.as_str() {
"x86_64-apple-darwin" => config
.define("CMAKE_OSX_ARCHITECTURES", "x86_64")
.define("CMAKE_OSX_DEPLOYMENT_TARGET", "10.15"),
"aarch64-apple-darwin" => config
.define("CMAKE_OSX_ARCHITECTURES", "arm64")
.define("CMAKE_OSX_DEPLOYMENT_TARGET", "11.0"),
_ => &mut config
};
let dst = config.build();
let lib_path = Path::join(Path::new(&dst), Path::new(path_extra));
println!("cargo:rustc-link-search=native={}", lib_path.display());
}

Просмотреть файл

@ -832,6 +832,20 @@ pub struct ConnectionEventPeerStreamStarted {
pub flags: StreamOpenFlags,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventDatagramReceived {
pub buffer: *const Buffer,
pub flags: ReceiveFlags,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventDatagramSendStateChanged {
pub client_context: *const c_void,
pub state: DatagramSendState,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventResumptionTicketReceived {
@ -852,8 +866,8 @@ pub union ConnectionEventPayload {
//pub streams_available: ConnectionEventStreamsAvailable,
//pub ideal_processor_changed: ConnectionEventIdealProcessorChanged,
//pub datagram_state_changed: ConnectionEventDatagramStateChanged,
//pub datagram_received: ConnectionEventDatagramReceived,
//pub datagram_send_state_changed: ConnectionEventDatagramSendStateChanged,
pub datagram_received: ConnectionEventDatagramReceived,
pub datagram_send_state_changed: ConnectionEventDatagramSendStateChanged,
//pub resumed: ConnectionEventResumed,
pub resumption_ticket_received: ConnectionEventResumptionTicketReceived,
//pub peer_certificated_received: ConnectionEventPeerCertificateReceived,
@ -1207,6 +1221,11 @@ impl Settings {
self.idle_timeout_ms = value;
self
}
pub fn set_datagram_receive_enabled(&mut self, value: bool) -> &mut Settings {
self.is_set_flags |= 1 << 27;
self.other_flags |= (value as u8) << 3;
self
}
}
impl CredentialConfig {
@ -1310,7 +1329,7 @@ impl Drop for Registration {
impl Configuration {
pub fn new(
registration: &Registration,
alpn: &Buffer,
alpn: &[Buffer],
settings: *const Settings,
) -> Configuration {
let context: *const c_void = ptr::null();
@ -1322,8 +1341,8 @@ impl Configuration {
let status = unsafe {
((*registration.table).configuration_open)(
registration.handle,
*&alpn,
1,
alpn.as_ptr(),
alpn.len() as u32,
settings,
settings_size,
context,
@ -1390,7 +1409,7 @@ impl Connection {
self.handle,
configuration.handle,
0,
server_name_safe.as_ptr(),
server_name_safe.as_ptr() as *const i8,
server_port,
)
};
@ -1478,6 +1497,27 @@ impl Connection {
((*self.table).set_callback_handler)(stream_handle, handler as *const c_void, context)
};
}
pub fn datagram_send(
&self,
buffer: &Buffer,
buffer_count: u32,
flags: SendFlags,
client_send_context: *const c_void,
) {
let status = unsafe {
((*self.table).datagram_send)(
self.handle,
*&buffer,
buffer_count,
flags,
client_send_context,
)
};
if Status::failed(status) {
panic!("DatagramSend failure 0x{:x}", status);
}
}
}
impl Drop for Connection {
@ -1511,12 +1551,12 @@ impl Listener {
}
}
pub fn start(&self, alpn_buffers: &Buffer, alpn_buffer_count: u32, local_address: &Addr) {
pub fn start(&self, alpn: &[Buffer], local_address: &Addr) {
let status = unsafe {
((*self.table).listener_start)(
self.handle,
*&alpn_buffers,
alpn_buffer_count,
alpn.as_ptr(),
alpn.len() as u32,
*&local_address,
)
};
@ -1524,6 +1564,12 @@ impl Listener {
panic!("ListenerStart failed, {:x}!\n", status);
}
}
pub fn close(&self) {
unsafe {
((*self.table).listener_close)(self.handle);
}
}
}
impl Drop for Listener {
@ -1680,7 +1726,7 @@ fn test_module() {
let api = Api::new();
let registration = Registration::new(&api, ptr::null());
let alpn = Buffer::from("h3");
let alpn = [Buffer::from("h3")];
let configuration = Configuration::new(
&registration,
&alpn,