4 Revīzijas a22e534abe ... 09086a48cb

Autors SHA1 Ziņojums Datums
  Michael Buesch 09086a48cb Add support for UDP control port 1 nedēļu atpakaļ
  Michael Buesch ea41d587a6 Bump version 5 dienas atpakaļ
  Michael Buesch 0202e4bbc0 systemd: Add UDP support 5 dienas atpakaļ
  Michael Buesch a22e534abe Add support for UDP control port 1 nedēļu atpakaļ
5 mainītis faili ar 40 papildinājumiem un 26 dzēšanām
  1. 8 8
      Cargo.lock
  2. 6 6
      Cargo.toml
  3. 7 1
      letmein-proto/src/socket.rs
  4. 1 0
      letmeind/src/main.rs
  5. 18 11
      letmeind/src/server.rs

+ 8 - 8
Cargo.lock

@@ -534,7 +534,7 @@ dependencies = [
 
 [[package]]
 name = "letmein"
-version = "7.2.0"
+version = "8.0.0"
 dependencies = [
  "anyhow",
  "build-target",
@@ -548,7 +548,7 @@ dependencies = [
 
 [[package]]
 name = "letmein-conf"
-version = "7.2.0"
+version = "8.0.0"
 dependencies = [
  "anyhow",
  "letmein-proto",
@@ -556,7 +556,7 @@ dependencies = [
 
 [[package]]
 name = "letmein-fwproto"
-version = "7.2.0"
+version = "8.0.0"
 dependencies = [
  "anyhow",
  "tokio",
@@ -564,7 +564,7 @@ dependencies = [
 
 [[package]]
 name = "letmein-proto"
-version = "7.2.0"
+version = "8.0.0"
 dependencies = [
  "anyhow",
  "getrandom",
@@ -576,7 +576,7 @@ dependencies = [
 
 [[package]]
 name = "letmein-seccomp"
-version = "7.2.0"
+version = "8.0.0"
 dependencies = [
  "anyhow",
  "letmein-seccomp",
@@ -586,7 +586,7 @@ dependencies = [
 
 [[package]]
 name = "letmein-systemd"
-version = "7.2.0"
+version = "8.0.0"
 dependencies = [
  "anyhow",
  "libc",
@@ -595,7 +595,7 @@ dependencies = [
 
 [[package]]
 name = "letmeind"
-version = "7.2.0"
+version = "8.0.0"
 dependencies = [
  "anyhow",
  "build-target",
@@ -611,7 +611,7 @@ dependencies = [
 
 [[package]]
 name = "letmeinfwd"
-version = "7.2.0"
+version = "8.0.0"
 dependencies = [
  "anyhow",
  "build-target",

+ 6 - 6
Cargo.toml

@@ -14,7 +14,7 @@ members = [
 resolver = "2"
 
 [workspace.package]
-version = "7.2.0"
+version = "8.0.0"
 edition = "2021"
 rust-version = "1.75.0"
 license = "MIT OR Apache-2.0"
@@ -40,11 +40,11 @@ sha3 = "0.10"
 subtle = "2"
 tokio = "1"
 
-letmein-conf = { version = "7", path = "./letmein-conf" }
-letmein-fwproto = { version = "7", path = "./letmein-fwproto" }
-letmein-proto = { version = "7", path = "./letmein-proto" }
-letmein-seccomp = { version = "7", path = "./letmein-seccomp", default-features = false }
-letmein-systemd = { version = "7", path = "./letmein-systemd" }
+letmein-conf = { version = "8", path = "./letmein-conf" }
+letmein-fwproto = { version = "8", path = "./letmein-fwproto" }
+letmein-proto = { version = "8", path = "./letmein-proto" }
+letmein-seccomp = { version = "8", path = "./letmein-seccomp", default-features = false }
+letmein-systemd = { version = "8", path = "./letmein-systemd" }
 
 [profile.release]
 opt-level = "z"

+ 7 - 1
letmein-proto/src/socket.rs

@@ -209,6 +209,7 @@ impl<const MSG_SIZE: usize, const Q_SIZE: usize> NetSocket<MSG_SIZE, Q_SIZE> {
         } else {
             match self {
                 Self::Tcp(inner) => {
+                    // Send the message via TCP.
                     let mut count = 0;
                     loop {
                         inner
@@ -232,6 +233,7 @@ impl<const MSG_SIZE: usize, const Q_SIZE: usize> NetSocket<MSG_SIZE, Q_SIZE> {
                     }
                 }
                 Self::Udp(inner) => {
+                    // Send the message via UDP.
                     inner
                         .disp
                         .send_to(
@@ -252,6 +254,7 @@ impl<const MSG_SIZE: usize, const Q_SIZE: usize> NetSocket<MSG_SIZE, Q_SIZE> {
         } else {
             match self {
                 Self::Tcp(inner) => {
+                    // Receive a message via TCP.
                     let mut buf = [0; MSG_SIZE];
                     let mut count = 0;
                     loop {
@@ -278,7 +281,10 @@ impl<const MSG_SIZE: usize, const Q_SIZE: usize> NetSocket<MSG_SIZE, Q_SIZE> {
                         }
                     }
                 }
-                Self::Udp(inner) => inner.disp.recv_from(inner.peer_addr).await.map(Some),
+                Self::Udp(inner) => {
+                    // Receive a message via UDP.
+                    inner.disp.recv_from(inner.peer_addr).await.map(Some)
+                }
             }
         }
     }

+ 1 - 0
letmeind/src/main.rs

@@ -221,6 +221,7 @@ async fn async_main(opts: Arc<Opts>) -> ah::Result<()> {
                 match srv.accept().await {
                     Ok(conn) => {
                         // Socket connection handler.
+                        let conn = Arc::new(conn);
                         if let Ok(_permit) = conn_semaphore.acquire().await {
                             let conn = Arc::clone(&conn);
                             task::spawn(async move {

+ 18 - 11
letmeind/src/server.rs

@@ -10,7 +10,12 @@ use anyhow::{self as ah, format_err as err, Context as _};
 use letmein_conf::Config;
 use letmein_proto::{Message, MsgNetSocket, MsgUdpDispatcher};
 use letmein_systemd::{systemd_notify_ready, SystemdSocket};
-use std::{convert::Infallible, net::SocketAddr, sync::Arc, time::Duration};
+use std::{
+    convert::Infallible,
+    net::{Ipv6Addr, SocketAddr},
+    sync::Arc,
+    time::Duration,
+};
 use tokio::{
     net::{TcpListener, TcpStream, UdpSocket},
     task::{self, JoinHandle},
@@ -138,7 +143,7 @@ impl Server {
         // TCP bind.
         if conf.port().tcp {
             this.tcp = Arc::new(Some(
-                TcpListener::bind(("::0", conf.port().port))
+                TcpListener::bind((Ipv6Addr::UNSPECIFIED, conf.port().port))
                     .await
                     .context("Bind")?,
             ));
@@ -146,7 +151,7 @@ impl Server {
         // UDP bind.
         if conf.port().udp {
             this.udp = Arc::new(Some(Arc::new(MsgUdpDispatcher::new(
-                UdpSocket::bind(("::0", conf.port().port))
+                UdpSocket::bind((Ipv6Addr::UNSPECIFIED, conf.port().port))
                     .await
                     .context("Bind")?,
                 max_nr_udp_conn,
@@ -156,7 +161,8 @@ impl Server {
         Ok(this)
     }
 
-    pub async fn accept(&mut self) -> ah::Result<Arc<Connection>> {
+    pub async fn accept(&mut self) -> ah::Result<Connection> {
+        // Async task for accepting a new TCP connection.
         let join_tcp: JoinHandle<ah::Result<(TcpStream, SocketAddr)>> = task::spawn({
             let tcp = Arc::clone(&self.tcp);
             async move {
@@ -168,28 +174,29 @@ impl Server {
             }
         });
 
-        let join_udp: JoinHandle<ah::Result<SocketAddr>> = task::spawn({
+        // Async task for accepting a new UDP connection.
+        let join_udp: JoinHandle<ah::Result<(Arc<MsgUdpDispatcher>, SocketAddr)>> = task::spawn({
             let udp = Arc::clone(&self.udp);
             async move {
                 if let Some(udp) = udp.as_ref() {
-                    return udp.accept().await;
+                    return Ok((Arc::clone(udp), udp.accept().await?));
                 }
                 sleep_forever().await;
                 unreachable!();
             }
         });
 
+        // Await any one of the accept tasks.
         tokio::select! {
             result = join_tcp => {
                 let (stream, peer_addr) = result??;
                 let ns = MsgNetSocket::from_tcp(stream);
-                Ok(Arc::new(Connection::new(ns, peer_addr)?))
+                Ok(Connection::new(ns, peer_addr)?)
             }
             result = join_udp => {
-                let peer_addr = result??;
-                let udp_disp = (*self.udp).as_ref().unwrap();
-                let ns = MsgNetSocket::from_udp(Arc::clone(udp_disp), peer_addr);
-                Ok(Arc::new(Connection::new(ns, peer_addr)?))
+                let (udp_disp, peer_addr) = result??;
+                let ns = MsgNetSocket::from_udp(udp_disp, peer_addr);
+                Ok(Connection::new(ns, peer_addr)?)
             }
         }
     }