From c19c59258635ecfae62ea1ef0a7a6fe3a93cd87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Thu, 20 May 2021 01:59:30 +0200 Subject: [PATCH] remove Protocol from Quic, cleanup code, fix some log spam --- client/src/lib.rs | 8 ++++-- network/src/channel.rs | 2 +- network/src/participant.rs | 38 +++++++++++++++----------- network/tests/helper.rs | 2 -- server/src/lib.rs | 8 ++++-- voxygen/src/menu/char_selection/mod.rs | 12 ++++---- 6 files changed, 40 insertions(+), 30 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 064d0b3a1d..d8b7b93856 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -220,9 +220,11 @@ impl Client { hostname, prefer_ipv6, } => { - let mut config = quinn::ClientConfigBuilder::default(); - config.protocols(&[b"VELOREN"]); - let config = config.build(); + warn!( + "QUIC is enabled. This is experimental and you won't be able to connect to \ + TCP servers unless deactivated" + ); + let config = quinn::ClientConfigBuilder::default().build(); addr::try_connect(&network, &hostname, prefer_ipv6, |a| { ConnectAddr::Quic(a, config.clone(), hostname.clone()) }) diff --git a/network/src/channel.rs b/network/src/channel.rs index aa5805800b..6395212e8d 100644 --- a/network/src/channel.rs +++ b/network/src/channel.rs @@ -548,7 +548,7 @@ impl UnreliableDrain for QuicDrain { QuicDataFormatStream::Unreliable => unimplemented!(), QuicDataFormatStream::Reliable(sid) => { use hashbrown::hash_map::Entry; - tracing::trace!(?sid, "Reliable"); + //tracing::trace!(?sid, "Reliable"); match self.reliables.entry(sid) { Entry::Occupied(mut occupied) => occupied.get_mut().write_all(&data.data).await, Entry::Vacant(vacant) => { diff --git a/network/src/participant.rs b/network/src/participant.rs index 3d669b6209..3ed8a49c4a 100644 --- a/network/src/participant.rs +++ b/network/src/participant.rs @@ -193,24 +193,30 @@ impl BParticipant { fn best_protocol(all: &SortedVec, promises: Promises) -> Option { // check for mpsc - for (cid, p) in all.data.iter() { - if matches!(p, SendProtocols::Mpsc(_)) { - return Some(*cid); + all.data.iter().find(|(_, p)| matches!(p, SendProtocols::Mpsc(_))).map(|(c, _)| *c).or_else( + || if network_protocol::TcpSendProtocol::::supported_promises() + .contains(promises) + { + // check for tcp + all.data.iter().find(|(_, p)| matches!(p, SendProtocols::Tcp(_))).map(|(c, _)| *c) + } else { + None } - } - // check for tcp - if network_protocol::TcpSendProtocol::::supported_promises() - .contains(promises) - { - for (cid, p) in all.data.iter() { - if matches!(p, SendProtocols::Tcp(_)) { - return Some(*cid); - } + ).or_else( + // check for quic, TODO: evaluate to order quic BEFORE tcp once its stable + || if network_protocol::QuicSendProtocol::::supported_promises() + .contains(promises) + { + all.data.iter().find(|(_, p)| matches!(p, SendProtocols::Quic(_))).map(|(c, _)| *c) + } else { + None } - } - - warn!("couldn't satisfy promises"); - all.data.first().map(|(c, _)| *c) + ).or_else( + || { + warn!("couldn't satisfy promises"); + all.data.first().map(|(c, _)| *c) + } + ) } //TODO: local stream_cid: HashMap to know the respective protocol diff --git a/network/tests/helper.rs b/network/tests/helper.rs index 9e78928f55..45abf32551 100644 --- a/network/tests/helper.rs +++ b/network/tests/helper.rs @@ -99,7 +99,6 @@ pub fn quic() -> (ListenAddr, ConnectAddr) { let mut server_config = quinn::ServerConfig::default(); server_config.transport = Arc::new(transport_config); let mut server_config = quinn::ServerConfigBuilder::new(server_config); - server_config.protocols(&[b"veloren"]); trace!("generating self-signed certificate"); let cert = rcgen::generate_simple_self_signed(vec![LOCALHOST.into()]).unwrap(); @@ -115,7 +114,6 @@ pub fn quic() -> (ListenAddr, ConnectAddr) { let server_config = server_config.build(); let mut client_config = quinn::ClientConfigBuilder::default(); - client_config.protocols(&[b"veloren"]); client_config .add_certificate_authority(cert) .expect("adding certificate failed"); diff --git a/server/src/lib.rs b/server/src/lib.rs index 84883e4d74..bc828d7b15 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -403,7 +403,6 @@ impl Server { match || -> Result<_, Box> { let mut server_config = quinn::ServerConfigBuilder::new(quinn::ServerConfig::default()); - server_config.protocols(&[b"VELOREN"]); let key = fs::read(&quic.key)?; let key = if quic.key.extension().map_or(false, |x| x == "der") { quinn::PrivateKey::from_der(&key)? @@ -422,12 +421,17 @@ impl Server { Ok(server_config.build()) }() { Ok(server_config) => { + warn!( + "QUIC is enabled. This is experimental and not recommended in production" + ); runtime.block_on( network .listen(ListenAddr::Quic(settings.gameserver_address, server_config)), )?; }, - Err(e) => error!(?e, "Failed to load Quic Certificate, run without Quic"), + Err(e) => { + error!(?e, ?settings.quic_files, "Failed to load Quic Certificate, run without Quic") + }, } } let connection_handler = ConnectionHandler::new(network, &runtime); diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index 007914cb4d..ae3f7c0a32 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -115,12 +115,12 @@ impl PlayState for CharSelectionState { self.client.borrow_mut().delete_character(character_id); }, ui::Event::Play(character_id) => { - self.client.borrow_mut().request_character(character_id); - //Send our ViewDistance - self.client - .borrow_mut() - .set_view_distance(global_state.settings.graphics.view_distance); - + { + let mut c = self.client.borrow_mut(); + c.request_character(character_id); + //Send our ViewDistance + c.set_view_distance(global_state.settings.graphics.view_distance); + } return PlayStateResult::Switch(Box::new(SessionState::new( global_state, Rc::clone(&self.client),