summaryrefslogtreecommitdiffhomepage
path: root/talpid_ipc/src/http_ipc
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-04-25 13:27:12 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-05-09 16:07:17 +0200
commitb866ee448d7f316214075f6412995054e7dfd4ee (patch)
treeffcea93fe8b48db9b0d72867bec62452663bef63 /talpid_ipc/src/http_ipc
parentf48586f6e55bbcf746a7bed922aad563fc57a525 (diff)
downloadmullvadvpn-b866ee448d7f316214075f6412995054e7dfd4ee.tar.xz
mullvadvpn-b866ee448d7f316214075f6412995054e7dfd4ee.zip
Update talpid_ipc to use ws and support sessions
Diffstat (limited to 'talpid_ipc/src/http_ipc')
-rw-r--r--talpid_ipc/src/http_ipc/mod.rs82
1 files changed, 0 insertions, 82 deletions
diff --git a/talpid_ipc/src/http_ipc/mod.rs b/talpid_ipc/src/http_ipc/mod.rs
deleted file mode 100644
index 16195ee69f..0000000000
--- a/talpid_ipc/src/http_ipc/mod.rs
+++ /dev/null
@@ -1,82 +0,0 @@
-extern crate jsonrpc_core;
-extern crate jsonrpc_http_server;
-
-use self::jsonrpc_http_server::{Server, ServerBuilder};
-use std::net::{IpAddr, Ipv4Addr, SocketAddr};
-use std::result::Result as StdResult;
-
-mod connection_info;
-
-error_chain! {
- errors {
- FailedToWriteConnectionInfo {
- description("Unable to write IPC connection info")
- }
- UnableToStartServer {
- description("Failed to start the server")
- }
- }
-}
-
-
-pub struct ServerHandle {
- address: String,
- server: Server,
-}
-
-impl ServerHandle {
- pub fn address(&self) -> &str {
- &self.address
- }
-
- pub fn stop(self) {
- self.server.close();
- }
-}
-
-pub fn start(build_router: fn() -> jsonrpc_core::IoHandler) -> Result<ServerHandle> {
- let server = start_server(build_router).chain_err(|| ErrorKind::UnableToStartServer)?;
- let write_result = connection_info::write(server.address()).chain_err(
- || {
- ErrorKind::FailedToWriteConnectionInfo
- },
- );
- if let Err(e) = write_result {
- error!("Could not write the connection info, killing the IPC server");
- server.stop();
- Err(e)
- } else {
- info!("Started Ipc server on: {}", server.address());
- Ok(server)
- }
-}
-
-fn start_server(build_router: fn() -> jsonrpc_core::IoHandler)
- -> StdResult<ServerHandle, jsonrpc_http_server::Error> {
- let mut last_error = None;
- for port in 5000..5010 {
- match start_server_on_port(port, build_router()) {
- Ok(server) => return Ok(server),
- Err(e) => last_error = Some(e),
- }
- }
- bail!(last_error.unwrap());
-}
-
-fn start_server_on_port(port: u16,
- router: jsonrpc_core::IoHandler)
- -> StdResult<ServerHandle, jsonrpc_http_server::Error> {
- let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
- let listen_addr = SocketAddr::new(ip, port);
- ServerBuilder::new(router)
- .allow_only_bind_host()
- .start_http(&listen_addr)
- .map(
- |server| {
- ServerHandle {
- address: format!("http://{}", listen_addr),
- server: server,
- }
- },
- )
-}