[PATCH 1/1] wireguard-rs: Update use of ip_constructors

Dan Robertson dan at dlrobertson.com
Fri Oct 19 17:47:26 CEST 2018


 - Update use of ip_constructors: The unspecified() function in libstd
   has been replaced with the UNSPECIFIED constants.
 - Implement Into<Vec<u8>> for CookieReply so that copying the
   underlying vector is not needed in cases where copying said vector
   is unnecessary.

Signed-off-by: Dan Robertson <dan at dlrobertson.com>
---
 src/interface/peer_server.rs | 2 +-
 src/lib.rs                   | 1 -
 src/message.rs               | 6 ++++++
 src/udp/mod.rs               | 4 ++--
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/interface/peer_server.rs b/src/interface/peer_server.rs
index a7c82cd..31dd78c 100644
--- a/src/interface/peer_server.rs
+++ b/src/interface/peer_server.rs
@@ -368,7 +368,7 @@ impl PeerServer {
             IpAddr::V6(ip) => self.cookie.generate_reply(index, mac1, &ip.octets())?,
         };
 

-        self.send_to_peer((addr, reply.to_vec())) // TODO: impl into() to avoid copies/allocs
+        self.send_to_peer((addr, reply.into()))
     }
 

     fn send_handshake_init(&mut self, peer_ref: &SharedPeer) -> Result<u32, Error> {
diff --git a/src/lib.rs b/src/lib.rs
index 99c8fa4..19c7646 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,7 +5,6 @@
 

 #![allow(unknown_lints)]
 #![warn(clippy)]
-#![feature(ip_constructors)]
 #![feature(try_trait)]
 #![feature(try_from)]
 #![feature(test)]
diff --git a/src/message.rs b/src/message.rs
index 12b2eb7..5777368 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -138,6 +138,12 @@ impl CookieReply {
     }
 }
 

+impl Into<Vec<u8>> for CookieReply {
+    fn into(self) -> Vec<u8> {
+        self.0
+    }
+}
+
 impl TryFrom<Vec<u8>> for CookieReply {
     type Error = Error;
 

diff --git a/src/udp/mod.rs b/src/udp/mod.rs
index 2a512cd..a519ad4 100644
--- a/src/udp/mod.rs
+++ b/src/udp/mod.rs
@@ -117,8 +117,8 @@ impl UdpSocket {
         setsockopt(socket4.as_raw_fd(), sockopt::Ipv4PacketInfo, &true);
         setsockopt(socket6.as_raw_fd(), sockopt::Ipv6RecvPacketInfo, &true);
 

-        socket4.bind(&SocketAddr::from((Ipv4Addr::unspecified(), port)).into())?;
-        socket6.bind(&SocketAddr::from((Ipv6Addr::unspecified(), port)).into())?;
+        socket4.bind(&SocketAddr::from((Ipv4Addr::UNSPECIFIED, port)).into())?;
+        socket6.bind(&SocketAddr::from((Ipv6Addr::UNSPECIFIED, port)).into())?;
 

         let socket4 = mio::net::UdpSocket::from_socket(socket4.into_udp_socket())?;
         let socket6 = mio::net::UdpSocket::from_socket(socket6.into_udp_socket())?;
-- 

2.19.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 855 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/wireguard/attachments/20181019/66a6c94f/attachment.asc>


More information about the WireGuard mailing list