summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-06-27 14:53:41 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-06-30 14:32:19 +0200
commitea4cf976d1d6510a2931fce037076087360b8193 (patch)
tree8b4e72e8d6aab8a5ea6e1ca0622748d00828354a
parent22cd558aae576bc3e4201311120f2b30bccead3c (diff)
downloadmullvadvpn-ea4cf976d1d6510a2931fce037076087360b8193.tar.xz
mullvadvpn-ea4cf976d1d6510a2931fce037076087360b8193.zip
Add Endpoint and protocol structs to net module
-rw-r--r--talpid_core/src/net.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/talpid_core/src/net.rs b/talpid_core/src/net.rs
index f5f40688a7..bc0becbfcd 100644
--- a/talpid_core/src/net.rs
+++ b/talpid_core/src/net.rs
@@ -19,6 +19,34 @@ error_chain! {
}
+/// Represents a network layer IP address together with the transport layer protocol and port.
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct Endpoint {
+ /// The address part of this endpoint, contains the IP and port.
+ pub address: RemoteAddr,
+ /// The protocol part of this endpoint.
+ pub protocol: TransportProtocol,
+}
+
+impl Endpoint {
+ /// Constructs a new `Endpoint` from the given parameters.
+ pub fn new(address: &str, port: u16, protocol: TransportProtocol) -> Self {
+ Endpoint {
+ address: RemoteAddr::new(address, port),
+ protocol: protocol,
+ }
+ }
+}
+
+/// Representation of a transport protocol, either UDP or TCP.
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum TransportProtocol {
+ /// Represents the UDP transport protocol.
+ Udp,
+ /// Represents the TCP transport protocol.
+ Tcp,
+}
+
/// Representation of a TCP or UDP endpoint. The IP level address is represented by either an IP
/// directly or a hostname/domain. The IP level address together with a port becomes a socket
/// address.