summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--mullvad-jni/Cargo.toml2
-rw-r--r--mullvad-jni/src/daemon_interface.rs38
3 files changed, 41 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 60bfb33769..0744c310ca 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1165,7 +1165,9 @@ name = "mullvad-jni"
version = "0.1.0"
dependencies = [
"err-derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"jni 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "jsonrpc-client-core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log-panics 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/mullvad-jni/Cargo.toml b/mullvad-jni/Cargo.toml
index 9b87aa07a3..a9b8092d92 100644
--- a/mullvad-jni/Cargo.toml
+++ b/mullvad-jni/Cargo.toml
@@ -11,7 +11,9 @@ crate_type = ["cdylib"]
[dependencies]
err-derive = "0.1.5"
+futures = "0.1"
jni = "0.11"
+jsonrpc-client-core = "0.5"
lazy_static = "1"
log = "0.4"
log-panics = "2"
diff --git a/mullvad-jni/src/daemon_interface.rs b/mullvad-jni/src/daemon_interface.rs
index b682660edf..6b0e907eda 100644
--- a/mullvad-jni/src/daemon_interface.rs
+++ b/mullvad-jni/src/daemon_interface.rs
@@ -1,4 +1,23 @@
-use mullvad_daemon::DaemonCommandSender;
+use futures::{sync::oneshot, Future};
+use mullvad_daemon::{DaemonCommandSender, ManagementCommand};
+use mullvad_types::account::AccountData;
+
+#[derive(Debug, err_derive::Error)]
+pub enum Error {
+ #[error(display = "Can't send command to daemon because it is not running")]
+ NoDaemon(#[error(cause)] mullvad_daemon::Error),
+
+ #[error(display = "No response received from daemon")]
+ NoResponse,
+
+ #[error(display = "Attempt to use daemon command sender before it was configured")]
+ NoSender,
+
+ #[error(display = "Error performing RPC with the remote API")]
+ RpcError(#[error(cause)] jsonrpc_client_core::Error),
+}
+
+type Result<T> = std::result::Result<T, Error>;
pub struct DaemonInterface {
command_sender: Option<DaemonCommandSender>,
@@ -14,4 +33,21 @@ impl DaemonInterface {
pub fn set_command_sender(&mut self, sender: DaemonCommandSender) {
self.command_sender = Some(sender);
}
+
+ pub fn get_account_data(&self, account_token: String) -> Result<AccountData> {
+ let (tx, rx) = oneshot::channel();
+
+ self.send_command(ManagementCommand::GetAccountData(tx, account_token))?;
+
+ rx.wait()
+ .map_err(|_| Error::NoResponse)?
+ .wait()
+ .map_err(Error::RpcError)
+ }
+
+ fn send_command(&self, command: ManagementCommand) -> Result<()> {
+ let sender = self.command_sender.as_ref().ok_or(Error::NoSender)?;
+
+ sender.send(command).map_err(Error::NoDaemon)
+ }
}