WireGuard Archive on lore.kernel.org
 help / Atom feed
* Re: [PATCH 1/1] wireguard-rs: Update use of ip_constructors
@ 2018-10-19 15:49 Dan Robertson
  0 siblings, 0 replies; 1+ messages 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] 1+ messages in thread

only message in thread, back to index

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

WireGuard Archive on lore.kernel.org

Archives are clonable: git clone --mirror https://lore.kernel.org/wireguard/0 wireguard/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 wireguard wireguard/ https://lore.kernel.org/wireguard \
		wireguard@lists.zx2c4.com zx2c4-wireguard@archiver.kernel.org
	public-inbox-index wireguard


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/com.zx2c4.lists.wireguard


AGPL code for this site: git clone https://public-inbox.org/ public-inbox