Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Dan Robertson <dan@dlrobertson.com>
To: "wireguard@lists.zx2c4.com" <wireguard@lists.zx2c4.com>
Subject: Re: [PATCH 1/1] wireguard-rs: Update use of ip_constructors
Date: Fri, 19 Oct 2018 15:49:31 +0000	[thread overview]
Message-ID: <w-83d7oQ6YtPLcG11zO3l2r5nngdCdltt4I50TSE3uDpfBmATXYbu-2E58CI3cnTWfpV5x-0Q0GFxyxDT5kSlF8j2bxUIclM_m0QDAK0kXg=@dlrobertson.com> (raw)


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

                 reply	other threads:[~2018-11-04 17:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='w-83d7oQ6YtPLcG11zO3l2r5nngdCdltt4I50TSE3uDpfBmATXYbu-2E58CI3cnTWfpV5x-0Q0GFxyxDT5kSlF8j2bxUIclM_m0QDAK0kXg=@dlrobertson.com' \
    --to=dan@dlrobertson.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).