mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
remove Protocol from Quic, cleanup code, fix some log spam
This commit is contained in:
parent
be56cd2a87
commit
c19c592586
@ -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())
|
||||
})
|
||||
|
@ -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) => {
|
||||
|
@ -193,24 +193,30 @@ impl BParticipant {
|
||||
|
||||
fn best_protocol(all: &SortedVec<Cid, SendProtocols>, promises: Promises) -> Option<Cid> {
|
||||
// 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::<crate::channel::TcpDrain>::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::<crate::channel::TcpDrain>::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::<crate::channel::QuicDrain>::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<Sid, Cid> to know the respective protocol
|
||||
|
@ -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");
|
||||
|
@ -403,7 +403,6 @@ impl Server {
|
||||
match || -> Result<_, Box<dyn std::error::Error>> {
|
||||
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);
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user