Compare commits
2 Commits
b0e2763521
...
f5382ffaf0
Author | SHA1 | Date |
---|---|---|
copygirl | f5382ffaf0 | 3 weeks ago |
copygirl | 3a59fd8263 | 3 weeks ago |
7 changed files with 2507 additions and 519 deletions
File diff suppressed because it is too large
Load Diff
@ -1,14 +1 @@ |
||||
pub fn add(left: u64, right: u64) -> u64 { |
||||
left + right |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn it_works() { |
||||
let result = add(2, 2); |
||||
assert_eq!(result, 4); |
||||
} |
||||
} |
||||
pub const WEB_TRANSPORT_PORT: u16 = 25565; |
||||
|
@ -1,12 +1,96 @@ |
||||
use bevy::{log::LogPlugin, prelude::*}; |
||||
use { |
||||
aeronet::io::{ |
||||
connection::{DisconnectReason, Disconnected, LocalAddr}, |
||||
server::Server, |
||||
Session, |
||||
}, |
||||
aeronet_webtransport::{ |
||||
cert, |
||||
server::{SessionRequest, SessionResponse, WebTransportServer, WebTransportServerPlugin}, |
||||
wtransport::{Identity, ServerConfig}, |
||||
}, |
||||
bevy::{log::LogPlugin, prelude::*}, |
||||
std::time::Duration, |
||||
}; |
||||
|
||||
fn main() -> AppExit { |
||||
App::new() |
||||
.add_plugins((LogPlugin::default(), MinimalPlugins)) |
||||
.add_systems(Startup, setup) |
||||
.add_plugins(( |
||||
LogPlugin::default(), |
||||
MinimalPlugins, |
||||
WebTransportServerPlugin, |
||||
)) |
||||
.add_systems(Startup, (setup, open_web_transport_server)) |
||||
.add_observer(on_server_opened) |
||||
.add_observer(on_client_session_request) |
||||
.add_observer(on_client_connected) |
||||
.add_observer(on_client_disconnected) |
||||
.run() |
||||
} |
||||
|
||||
fn setup() { |
||||
info!("Hello from gæmstone server!"); |
||||
} |
||||
|
||||
fn open_web_transport_server(mut commands: Commands) { |
||||
let identity = Identity::self_signed(["localhost", "127.0.0.1", "::1"]).unwrap(); |
||||
let cert = &identity.certificate_chain().as_slice()[0]; |
||||
let spki_fingerprint = cert::spki_fingerprint_b64(cert).unwrap(); |
||||
let cert_hash = cert::hash_to_b64(cert.hash()); |
||||
info!("************************"); |
||||
info!("SPKI FINGERPRINT"); |
||||
info!(" {spki_fingerprint}"); |
||||
info!("CERTIFICATE HASH"); |
||||
info!(" {cert_hash}"); |
||||
info!("************************"); |
||||
|
||||
let config = ServerConfig::builder() |
||||
.with_bind_default(common::WEB_TRANSPORT_PORT) |
||||
.with_identity(&identity) |
||||
.keep_alive_interval(Some(Duration::from_secs(1))) |
||||
.max_idle_timeout(Some(Duration::from_secs(5))) |
||||
.unwrap() |
||||
.build(); |
||||
|
||||
commands |
||||
.spawn_empty() |
||||
.queue(WebTransportServer::open(config)); |
||||
info!("Starting WebTransport server ..."); |
||||
} |
||||
|
||||
fn on_server_opened(trigger: Trigger<OnAdd, Server>, servers: Query<&LocalAddr>) { |
||||
let server = trigger.entity(); |
||||
let local_addr = servers.get(server).unwrap(); |
||||
info!("Server listening on {}", **local_addr); |
||||
} |
||||
|
||||
fn on_client_session_request(mut trigger: Trigger<SessionRequest>) { |
||||
let client = trigger.entity(); |
||||
let request = trigger.event_mut(); |
||||
request.respond(SessionResponse::Accepted); |
||||
|
||||
info!("{client} connecting with headers:"); |
||||
for (header_key, header_value) in &request.headers { |
||||
info!(" {header_key}: {header_value}"); |
||||
} |
||||
} |
||||
|
||||
fn on_client_connected(trigger: Trigger<OnAdd, Session>) { |
||||
let client = trigger.entity(); |
||||
info!("{client} connected"); |
||||
} |
||||
|
||||
fn on_client_disconnected(trigger: Trigger<Disconnected>) { |
||||
let client = trigger.entity(); |
||||
match &trigger.event().reason { |
||||
DisconnectReason::User(reason) => { |
||||
info!("{client} disconnected (server): {reason}"); |
||||
} |
||||
DisconnectReason::Peer(reason) => { |
||||
info!("{client} disconnected (client): {reason}"); |
||||
} |
||||
DisconnectReason::Error(err) => { |
||||
warn!("{client} disconnected (error): {err:#}"); |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue