From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 385A9652BF for ; Tue, 1 Feb 2022 13:02:46 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2E4122E3F7 for ; Tue, 1 Feb 2022 13:02:46 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 9221E2E3EB for ; Tue, 1 Feb 2022 13:02:45 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6266743C52 for ; Tue, 1 Feb 2022 13:02:45 +0100 (CET) Message-ID: Date: Tue, 1 Feb 2022 13:02:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:97.0) Gecko/20100101 Thunderbird/97.0 Content-Language: en-US To: Proxmox Backup Server development discussion , Dominik Csapak References: <20220117104825.2409598-1-d.csapak@proxmox.com> <20220117104825.2409598-4-d.csapak@proxmox.com> From: Thomas Lamprecht In-Reply-To: <20220117104825.2409598-4-d.csapak@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.061 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs] Subject: Re: [pbs-devel] [PATCH proxmox v4 3/4] proxmox-async: add connect_to_udp helper X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2022 12:02:46 -0000 A overly "sensitive" review due to getting a new public method, which is always more work to change. On 17.01.22 11:48, Dominik Csapak wrote: > so that we do not have to always check the target ipaddr family manually nit: above is slightly to long for our commit message style guide > index 9a6d8a6..2dd49d4 100644 > --- a/proxmox-async/src/io/mod.rs > +++ b/proxmox-async/src/io/mod.rs > @@ -2,3 +2,6 @@ > > mod async_channel_writer; > pub use async_channel_writer::AsyncChannelWriter; > + > +mod udp_connect; nit: why not just udp? I mean, it's private so we can change any time without breaking much, but feel still a bit to narrow/specialized - not really hard feelings though. > +pub use udp_connect::connect_to_udp; > diff --git a/proxmox-async/src/io/udp_connect.rs b/proxmox-async/src/io/udp_connect.rs > new file mode 100644 > index 0000000..878b150 > --- /dev/null > +++ b/proxmox-async/src/io/udp_connect.rs > @@ -0,0 +1,18 @@ > +use std::io; > +use std::net::SocketAddr; > + > +use tokio::net::{ToSocketAddrs, UdpSocket}; > + > +/// Helper to connect to UDP addresses without having to manually bind to the correct ip address > +pub async fn connect_to_udp( name is a bit weird, as one cannot connect to a UDP, maybe dropping the `to`, i.e., `udp_connect`, would be already fine? One alternative could be to make this module `pub mod udp` and name the helper either just `connect` or `connect_to`, just throwing out the idea here, not much preference. > + addr: A, > +) -> io::Result { > + let socket = match tokio::net::lookup_host(&addr).await?.next() {> + Some(SocketAddr::V4(_)) => UdpSocket::bind("0.0.0.0:0").await?, > + Some(SocketAddr::V6(_)) => UdpSocket::bind("[::]:0").await?, > + None => proxmox_sys::io_bail!("could not resolve address family {}", addr), would it have some merit to use {:?} to loose the Display trait bound? Probably not to relevant though.