Browse Source

server: add key logging and explicit runtime

Justin Tracey 2 months ago
parent
commit
01b77d28b2
1 changed files with 22 additions and 4 deletions
  1. 22 4
      src/bin/mgen-server.rs

+ 22 - 4
src/bin/mgen-server.rs

@@ -9,7 +9,11 @@ use tokio::io::{split, AsyncWriteExt, ReadHalf, WriteHalf};
 use tokio::net::{TcpSocket, TcpStream};
 use tokio::sync::{mpsc, Notify, RwLock};
 use tokio::time::{timeout_at, Instant};
-use tokio_rustls::{rustls::PrivateKey, server::TlsStream, TlsAcceptor};
+use tokio_rustls::{
+    rustls::{KeyLogFile, PrivateKey},
+    server::TlsStream,
+    TlsAcceptor,
+};
 
 // FIXME: identifiers should be interned
 type ID = String;
@@ -18,8 +22,20 @@ type ReaderToSender = mpsc::UnboundedSender<Arc<SerializedMessage>>;
 type WriterDb = HashMap<Handshake, Updater<(WriteHalf<TlsStream<TcpStream>>, Arc<Notify>)>>;
 type SndDb = HashMap<ID, Arc<RwLock<HashMap<ID, ReaderToSender>>>>;
 
-#[tokio::main(flavor = "multi_thread", worker_threads = 10)]
-async fn main() -> Result<(), Box<dyn Error>> {
+fn main() -> Result<(), Box<dyn std::error::Error>> {
+    tokio::runtime::Builder::new_multi_thread()
+        .worker_threads(10)
+        .enable_all()
+        .disable_lifo_slot()
+        .build()
+        .unwrap()
+        .block_on(main_worker())
+}
+
+async fn main_worker() -> Result<(), Box<dyn Error>> {
+    #[cfg(feature = "tracing")]
+    console_subscriber::init();
+
     let mut args = std::env::args();
     let _arg0 = args.next().unwrap();
 
@@ -44,13 +60,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
         .collect();
     let key = load_private_key(&key_filename);
 
-    let config = tokio_rustls::rustls::ServerConfig::builder()
+    let key_log = Arc::new(KeyLogFile::new());
+    let mut config = tokio_rustls::rustls::ServerConfig::builder()
         .with_safe_default_cipher_suites()
         .with_safe_default_kx_groups()
         .with_safe_default_protocol_versions()
         .unwrap()
         .with_no_client_auth()
         .with_single_cert(certs, key)?;
+    config.key_log = key_log;
     let acceptor = TlsAcceptor::from(Arc::new(config));
 
     let addr = listen_addr.parse().unwrap();