Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix Domain Socket transport #55

Merged
merged 11 commits into from
Nov 23, 2020

Conversation

gabrik
Copy link
Contributor

@gabrik gabrik commented Nov 20, 2020

This PR contains the code to implement the Unix Domain Sockets as transport for Zenoh

Creating a draft to keep track of the work

  • Implement Unix Domain Socket Link, LinkManager
  • Update locator with unix/<domain socket path>
  • Add unix feature for this transport
  • Add conditional building to build only on UNIX systems
  • Add tests

@gabrik gabrik changed the title Unix Domain Socket transpor Unix Domain Socket transport Nov 20, 2020
@gabrik gabrik marked this pull request as ready for review November 20, 2020 12:47
@JEnoch
Copy link
Member

JEnoch commented Nov 20, 2020

I'm not sure "unix" is a good idea for the Cargo feature name as:

  • it's the same than the "unix" target name
  • on user's perspective, a "unix" feature doesn't sound clear on its purpose.
    Why not "unix-socket" feature ?

let _ = std::fs::remove_file("/tmp/socket.sock");
// Define the locator
let locators: Vec<Locator> = vec!["unix//tmp/socket.sock".parse().unwrap()];
// Define the reliability and congestgino control
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in congestion control.

fn channel_unix() {
let _ = std::fs::remove_file("/tmp/socket.sock");
// Define the locator
let locators: Vec<Locator> = vec!["unix//tmp/socket.sock".parse().unwrap()];
Copy link
Member

@Mallets Mallets Nov 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the file name to something more self-explanatory, e.g., zenoh-test-unix-socket.sock

@@ -63,19 +71,35 @@ pub enum Locator {
Tcp(SocketAddr),
#[cfg(feature = "udp")]
Udp(SocketAddr),
#[cfg(all(feature = "unix", target_family = "unix"))]
Unix(PathBuf),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to call the locator UnixDomainSocket and not simply Unix, alternatively we can use Uds.

@@ -17,6 +17,8 @@ use async_std::sync::Arc;
use crate::link::tcp::ManagerTcp;
#[cfg(feature = "udp")]
use crate::link::udp::ManagerUdp;
#[cfg(all(feature = "unix", target_family = "unix"))]
use crate::link::unix::ManagerUnix;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to call the ManagerUnixSocket instead of ManagerUnix

// Define the locator
let locators: Vec<Locator> = vec![
"tcp/127.0.0.1:7449".parse().unwrap(),
"unix//tmp/socket_1.sock".parse().unwrap(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the file name to something more self-explanatory, e.g., zenoh-test-unix-socket_1.sock

#[cfg(all(feature = "unix", target_family = "unix"))]
#[test]
fn channel_tcp_unix() {
let _ = std::fs::remove_file("/tmp/socket_1.sock");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although /tmp is available in the totality of the system, I believe that using the current directory for the unix socket path is a better approach:

It is guaranteed that the cargo test will have write permissions while executing the test
System files are not created outside the test directory
I also suggest to use a more explanatory name for the socket, e.g., zenoh-test-unix-socket_1.sock

Copy link
Member

@JEnoch JEnoch Nov 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another solution is use the tempfile crate that relies on std::env::temp_dir and performs automatic deletion of file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of using the tempfile crate. This should be added to the dev dependencies.

#[cfg(all(feature = "unix", target_family = "unix"))]
#[test]
fn channel_unix() {
let _ = std::fs::remove_file("/tmp/socket.sock");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although /tmp is available in the totality of the system, I believe that using the current directory for the unix socket path is a better approach:

It is guaranteed that the cargo test will have write permissions while executing the test
System files are not created outside the test directory
I also suggest to use a more explanatory name for the socket, e.g., zenoh-test-unix-socket.sock

#[cfg(all(feature = "unix", target_family = "unix"))]
#[test]
fn channel_udp_unix() {
let _ = std::fs::remove_file("/tmp/socket_2.sock");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the file name to something more self-explanatory, e.g., zenoh-test-unix-socket_2.sock

// Define the locator
let locators: Vec<Locator> = vec![
"udp/127.0.0.1:7449".parse().unwrap(),
"unix//tmp/socket_2.sock".parse().unwrap(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the file name to something more self-explanatory, e.g., zenoh-test-unix-socket_2.sock

@@ -36,13 +38,17 @@ pub const PORT_SEPARATOR: char = ':';
pub const STR_TCP: &str = "tcp";
#[cfg(feature = "udp")]
pub const STR_UDP: &str = "udp";
#[cfg(all(feature = "unix", target_family = "unix"))]
pub const STR_UNIX: &str = "unix";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My proposal for the locator protocol is to use "uds" from "unix domain socket". Other proposals are also accepted.

/*************************************/
/* LINK */
/*************************************/
pub struct Unix {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid ambiguity on the usage of term Unix here. I suggest either to use:

  • UnixDomainSocket
  • Uds

@Mallets
Copy link
Member

Mallets commented Nov 20, 2020

I'm not sure "unix" is a good idea for the Cargo feature name as:

  • it's the same than the "unix" target name
  • on user's perspective, a "unix" feature doesn't sound clear on its purpose.
    Why not "unix-socket" feature ?

I would be tempted to go even further and have a clearer approach in the whole zenoh. Any feature related to a transport technology should be trasport_*. I.e., existing tcp and udp features should be also renamed to transport_tcp and transport_udp. What do you think?

Signed-off-by: gabrik <[email protected]>
@gabrik gabrik requested a review from Mallets November 23, 2020 09:52
@Mallets Mallets merged commit beda767 into eclipse-zenoh:master Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants