Changeset View
Changeset View
Standalone View
Standalone View
native/native_rust_library/src/lib.rs
use lazy_static::lazy_static; | use lazy_static::lazy_static; | ||||
use std::sync::Arc; | use std::sync::Arc; | ||||
use tokio::runtime::{Builder, Runtime}; | use tokio::runtime::{Builder, Runtime}; | ||||
use tonic::{transport::Channel, Status}; | use tonic::{transport::Channel, Status}; | ||||
use tracing::instrument; | use tracing::instrument; | ||||
use tunnelbroker::tunnelbroker_service_client::TunnelbrokerServiceClient; | use tunnelbroker::tunnelbroker_service_client::TunnelbrokerServiceClient; | ||||
mod crypto_tools; | mod crypto_tools; | ||||
mod identity_client; | mod identity_client; | ||||
mod identity { | mod identity { | ||||
tonic::include_proto!("identity"); | tonic::include_proto!("identity.keyserver"); | ||||
} | } | ||||
mod tunnelbroker { | mod tunnelbroker { | ||||
tonic::include_proto!("tunnelbroker"); | tonic::include_proto!("tunnelbroker"); | ||||
} | } | ||||
use crypto_tools::generate_device_id; | use crypto_tools::generate_device_id; | ||||
use identity::identity_service_client::IdentityServiceClient; | use identity::identity_keyserver_service_client::IdentityKeyserverServiceClient; | ||||
lazy_static! { | lazy_static! { | ||||
pub static ref RUNTIME: Arc<Runtime> = Arc::new( | pub static ref RUNTIME: Arc<Runtime> = Arc::new( | ||||
Builder::new_multi_thread() | Builder::new_multi_thread() | ||||
.worker_threads(1) | .worker_threads(1) | ||||
.max_blocking_threads(1) | .max_blocking_threads(1) | ||||
.enable_all() | .enable_all() | ||||
.build() | .build() | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | extern "Rust" { | ||||
// Crypto Tools | // Crypto Tools | ||||
fn generate_device_id(device_type: DeviceType) -> Result<String>; | fn generate_device_id(device_type: DeviceType) -> Result<String>; | ||||
} | } | ||||
} | } | ||||
#[derive(Debug)] | #[derive(Debug)] | ||||
pub struct IdentityClient { | pub struct IdentityClient { | ||||
identity_client: IdentityServiceClient<Channel>, | identity_client: IdentityKeyserverServiceClient<Channel>, | ||||
} | } | ||||
fn initialize_identity_client(addr: String) -> Box<IdentityClient> { | fn initialize_identity_client(addr: String) -> Box<IdentityClient> { | ||||
Box::new(IdentityClient { | Box::new(IdentityClient { | ||||
identity_client: RUNTIME | identity_client: RUNTIME | ||||
.block_on(IdentityServiceClient::connect(addr)) | .block_on(IdentityKeyserverServiceClient::connect(addr)) | ||||
.unwrap(), | .unwrap(), | ||||
}) | }) | ||||
} | } | ||||
#[instrument] | #[instrument] | ||||
fn identity_get_user_id_blocking( | fn identity_get_user_id_blocking( | ||||
client: Box<IdentityClient>, | client: Box<IdentityClient>, | ||||
auth_type: i32, | auth_type: i32, | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |