summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls Piņķis <emils@mullvad.net>2018-08-27 14:59:56 +0100
committerEmīls Piņķis <emils@mullvad.net>2018-08-29 16:27:53 +0100
commitbc856deb0d0556ea938b75fa47ff6afa303922c4 (patch)
tree9f8ade7f99b9f6b93e0c01d17360d9e4c3a243bb
parent2acc24cc10e25b8d413316a518e8f36083d890cc (diff)
downloadmullvadvpn-bc856deb0d0556ea938b75fa47ff6afa303922c4.tar.xz
mullvadvpn-bc856deb0d0556ea938b75fa47ff6afa303922c4.zip
Use IPC instead of websockets in talpid-ipc
-rw-r--r--talpid-ipc/Cargo.toml4
-rw-r--r--talpid-ipc/src/lib.rs39
-rw-r--r--talpid-ipc/tests/ipc-client-server.rs10
3 files changed, 30 insertions, 23 deletions
diff --git a/talpid-ipc/Cargo.toml b/talpid-ipc/Cargo.toml
index 80b56f0b4f..45848b45ca 100644
--- a/talpid-ipc/Cargo.toml
+++ b/talpid-ipc/Cargo.toml
@@ -15,9 +15,6 @@ jsonrpc-pubsub = { git = "https://github.com/paritytech/jsonrpc", branch = "mast
jsonrpc-ipc-server = { git = "https://github.com/paritytech/jsonrpc", branch = "master" }
jsonrpc-client-core = { git = "https://github.com/mullvad/jsonrpc-client-rs" }
jsonrpc-client-ipc = { git = "https://github.com/mullvad/jsonrpc-client-rs" }
-tokio-core = "0.1"
-ws = { git = "https://github.com/tomusdrw/ws-rs" }
-url = "1.4"
[dev-dependencies]
assert_matches = "1.0"
@@ -25,3 +22,4 @@ env_logger = "0.5"
jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc", branch = "master" }
uuid = { version = "0.6", features = ["v4"] }
futures = "0.1.23"
+tokio-core = "0.1"
diff --git a/talpid-ipc/src/lib.rs b/talpid-ipc/src/lib.rs
index d775dfbcaa..6104a59848 100644
--- a/talpid-ipc/src/lib.rs
+++ b/talpid-ipc/src/lib.rs
@@ -10,28 +10,22 @@
#[macro_use]
extern crate error_chain;
-#[macro_use]
-extern crate log;
extern crate serde;
-#[macro_use]
extern crate serde_json;
extern crate jsonrpc_core;
extern crate jsonrpc_ipc_server;
extern crate jsonrpc_pubsub;
-#[macro_use]
+
extern crate jsonrpc_client_core;
extern crate jsonrpc_client_ipc;
-extern crate tokio_core;
-extern crate url;
-extern crate ws;
use jsonrpc_core::{MetaIoHandler, Metadata};
-use jsonrpc_ipc_server::{MetaExtractor, NoopExtractor, Server, ServerBuilder};
+use jsonrpc_ipc_server::{MetaExtractor, NoopExtractor, SecurityAttributes, Server, ServerBuilder};
-use std::fmt;
+use std::fmt;
/// An Id created by the Ipc server that the client can use to connect to it
pub type IpcServerId = String;
@@ -41,6 +35,10 @@ error_chain!{
IpcServerError {
description("Error in IPC server")
}
+
+ PermissionsError {
+ description("Unable to set permissions for IPC endpoint")
+ }
}
}
@@ -64,13 +62,25 @@ impl IpcServer {
M: Metadata + Default,
E: MetaExtractor<M>,
{
- ServerBuilder::new(handler)
- .session_meta_extractor(meta_extractor)
+ let security_attributes = SecurityAttributes::allow_everyone_create()
+ .chain_err(|| ErrorKind::PermissionsError)?;
+ let server = ServerBuilder::with_meta_extractor(handler, meta_extractor)
+ .set_security_attributes(security_attributes)
.start(&path)
+ .chain_err(|| ErrorKind::IpcServerError)
.map(|server| IpcServer {
path: path.to_owned(),
- server: server,
- }).chain_err(|| ErrorKind::IpcServerError)
+ server,
+ })?;
+
+ #[cfg(unix)]
+ {
+ use std::fs;
+ use std::os::unix::fs::PermissionsExt;
+ fs::set_permissions(&path, PermissionsExt::from_mode(0o766))
+ .chain_err(|| ErrorKind::PermissionsError)?;
+ }
+ Ok(server)
}
/// Returns the uds/named pipe path this `IpcServer` is listening on.
@@ -86,7 +96,7 @@ impl IpcServer {
/// Consumes the server and waits for it to finish. Get a `CloseHandle` before calling this
/// if you want to be able to shut the server down.
pub fn wait(self) {
- self.server.wait()
+ self.server.wait();
}
}
@@ -100,7 +110,6 @@ impl fmt::Debug for IpcServer {
}
}
-
#[derive(Clone)]
pub struct CloseHandle(jsonrpc_ipc_server::CloseHandle);
diff --git a/talpid-ipc/tests/ipc-client-server.rs b/talpid-ipc/tests/ipc-client-server.rs
index b7ae7c2f2f..dc5c8d9d17 100644
--- a/talpid-ipc/tests/ipc-client-server.rs
+++ b/talpid-ipc/tests/ipc-client-server.rs
@@ -16,7 +16,7 @@ use futures::sync::oneshot;
use futures::Future;
use tokio_core::reactor::Core;
-use jsonrpc_client_core::Error as ClientError;
+use jsonrpc_client_core::{Error as ClientError, Transport};
use jsonrpc_core::{Error, IoHandler};
use std::sync::{mpsc, Mutex};
use std::time::Duration;
@@ -47,7 +47,7 @@ fn can_call_rpcs_on_server() {
let (server, rx) = create_server();
let server_path = server.path().to_owned();
- let mut client = create_client(server_path);
+ let client = create_client(server_path);
let _result: () = client.call_method("foo", &[97]).wait().unwrap();
assert_eq!(Ok(97), rx.recv_timeout(Duration::from_millis(500)));
@@ -62,7 +62,7 @@ fn can_call_rpcs_on_server() {
#[test]
#[should_panic]
fn ipc_client_invalid_url() {
- create_client("INVALID ID".to_owned());
+ let _client = create_client("INVALID ID".to_owned());
}
fn create_server() -> (talpid_ipc::IpcServer, mpsc::Receiver<i64>) {
@@ -91,8 +91,8 @@ fn create_client(ipc_path: String) -> jsonrpc_client_core::ClientHandle {
jsonrpc_client_ipc::IpcTransport::new(&ipc_path, &core.handle())
.expect("failed to construct a transport")
.into_client();
- tx.send(client_handle);
- core.run(client);
+ tx.send(client_handle).unwrap();
+ core.run(client).unwrap();
});
let handle = rx.wait().expect("Failed to construct a valid client");