Development discussion of WireGuard
 help / color / mirror / Atom feed
* Re: [PATCH 1/1] wireguard-rs: Update use of ip_constructors
@ 2018-10-19 15:49 Dan Robertson
  0 siblings, 0 replies; only message in thread
From: Dan Robertson @ 2018-10-19 15:49 UTC (permalink / raw)
  To: wireguard


[-- Attachment #1.1.1: Type: text/plain, Size: 2589 bytes --]

 - 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@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

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 855 bytes --]

[-- Attachment #2: Type: text/plain, Size: 148 bytes --]

_______________________________________________
WireGuard mailing list
WireGuard@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/wireguard

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-11-04 17:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-19 15:49 [PATCH 1/1] wireguard-rs: Update use of ip_constructors Dan Robertson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).