Skip to content
This repository has been archived by the owner on Jan 6, 2020. It is now read-only.

Commit

Permalink
rustfmt again
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Jan 20, 2016
1 parent 3e08846 commit 55034b5
Show file tree
Hide file tree
Showing 20 changed files with 180 additions and 213 deletions.
5 changes: 2 additions & 3 deletions src/ffi/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

use libc::c_char;

use ::std::ffi::CStr;
use std::ffi::CStr;

use ffi::errors::FfiError;

/// Converts c character pointer into Rust String
#[allow(unsafe_code)]
pub fn c_char_ptr_to_string(c_char_ptr: *const c_char)
-> Result<String, FfiError> {
pub fn c_char_ptr_to_string(c_char_ptr: *const c_char) -> Result<String, FfiError> {
use std::error::Error;

let cstr = unsafe { CStr::from_ptr(c_char_ptr) };
Expand Down
6 changes: 2 additions & 4 deletions src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ mod test {
use safe_core::utility;

fn generate_random_cstring(len: usize) -> Result<CString, FfiError> {
let mut cstring_vec =
unwrap_result!(utility::generate_random_vector::<u8>(len));
let mut cstring_vec = unwrap_result!(utility::generate_random_vector::<u8>(len));
// Avoid internal nulls and ensure valid ASCII (thus valid utf8)
for it in cstring_vec.iter_mut() {
*it %= 128;
Expand All @@ -121,8 +120,7 @@ mod test {
}
}

CString::new(cstring_vec)
.map_err(|error| FfiError::from(error.description()))
CString::new(cstring_vec).map_err(|error| FfiError::from(error.description()))
}

#[test]
Expand Down
6 changes: 2 additions & 4 deletions src/launcher/app_handler/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ pub struct LauncherConfiguration {
// (Spandan)
// This is a hack because presently cbor isn't able to decode/encode HashMap<NameType, String>
// properly
pub fn convert_hashmap_to_vec(hashmap: &HashMap<XorName, String>)
-> Vec<(XorName, String)> {
pub fn convert_hashmap_to_vec(hashmap: &HashMap<XorName, String>) -> Vec<(XorName, String)> {
hashmap.iter().map(|a| (a.0.clone(), a.1.clone())).collect()
}

// (Spandan)
// This is a hack because presently cbor isn't able to decode/encode HashMap<NameType, String>
// properly
pub fn convert_vec_to_hashmap(vec: Vec<(XorName, String)>)
-> HashMap<XorName, String> {
pub fn convert_vec_to_hashmap(vec: Vec<(XorName, String)>) -> HashMap<XorName, String> {
vec.into_iter().collect()
}

Expand Down
89 changes: 43 additions & 46 deletions src/launcher/app_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use xor_name::XorName;
use maidsafe_utilities::thread::RaiiThreadJoiner;
use maidsafe_utilities::serialisation::{serialise, deserialise};

use config::{LAUNCHER_GLOBAL_CONFIG_FILE_NAME,
LAUNCHER_GLOBAL_DIRECTORY_NAME,
use config::{LAUNCHER_GLOBAL_CONFIG_FILE_NAME, LAUNCHER_GLOBAL_DIRECTORY_NAME,
LAUNCHER_NONCE_LENGTH};
use errors::LauncherError;
use launcher::ipc_server::EventSenderToServer;
Expand All @@ -47,20 +46,20 @@ mod misc;
const APP_HANDLER_THREAD_NAME: &'static str = "AppHandlerThread";

pub struct AppHandler {
client : Arc<Mutex<Client>>,
launcher_endpoint : String,
local_config_data : HashMap<XorName, String>,
app_add_observers : Vec<AppHandlerObserver>,
app_remove_observers : Vec<AppHandlerObserver>,
app_modify_observers : Vec<AppHandlerObserver>,
app_activate_observers : Vec<AppHandlerObserver>,
client: Arc<Mutex<Client>>,
launcher_endpoint: String,
local_config_data: HashMap<XorName, String>,
app_add_observers: Vec<AppHandlerObserver>,
app_remove_observers: Vec<AppHandlerObserver>,
app_modify_observers: Vec<AppHandlerObserver>,
app_activate_observers: Vec<AppHandlerObserver>,
ipc_server_event_sender: EventSenderToServer<ExternalEvent>,
}

impl AppHandler {
pub fn new(client : Arc<Mutex<Client>>,
pub fn new(client: Arc<Mutex<Client>>,
event_sender: EventSenderToServer<ExternalEvent>)
-> (RaiiThreadJoiner, mpsc::Sender<events::AppHandlerEvent>) {
-> (RaiiThreadJoiner, mpsc::Sender<events::AppHandlerEvent>) {
let (event_tx, event_rx) = mpsc::channel();

let joiner = thread!(APP_HANDLER_THREAD_NAME, move || {
Expand All @@ -84,24 +83,24 @@ impl AppHandler {
if event_sender.send(ExternalEvent::GetListenerEndpoint(tx)).is_ok() {
if let Ok(launcher_endpoint) = rx.recv() {
let mut app_handler = AppHandler {
client : client,
launcher_endpoint : launcher_endpoint,
local_config_data : local_config_data,
app_add_observers : Vec::with_capacity(2),
app_remove_observers : Vec::with_capacity(2),
app_modify_observers : Vec::with_capacity(2),
app_activate_observers : Vec::with_capacity(2),
client: client,
launcher_endpoint: launcher_endpoint,
local_config_data: local_config_data,
app_add_observers: Vec::with_capacity(2),
app_remove_observers: Vec::with_capacity(2),
app_modify_observers: Vec::with_capacity(2),
app_activate_observers: Vec::with_capacity(2),
ipc_server_event_sender: event_sender,
};

app_handler.run(event_rx);
} else {
debug!("AppHandler <-> IPC-Server Communication failed - \
Probably Launcher was closed too soon.");
debug!("AppHandler <-> IPC-Server Communication failed - Probably Launcher \
was closed too soon.");
}
} else {
debug!("AppHandler <-> IPC-Server Communication failed - \
Probably Launcher was closed too soon.");
debug!("AppHandler <-> IPC-Server Communication failed - Probably Launcher was \
closed too soon.");
}

debug!("Exiting thread {:?}", APP_HANDLER_THREAD_NAME);
Expand Down Expand Up @@ -258,9 +257,8 @@ impl AppHandler {
.arg("--launcher")
.arg(command_line_arg)
.spawn() {
if let Err(err) =
self.ipc_server_event_sender
.send(ExternalEvent::EndSession(app_id)) {
if let Err(err) = self.ipc_server_event_sender
.send(ExternalEvent::EndSession(app_id)) {
debug!("{:?} Error sending end-session signal to IPC Server.", err);
}

Expand All @@ -273,9 +271,8 @@ impl AppHandler {
fn on_remove_app(&mut self, app_id: XorName) {
let reply = match self.on_remove_app_impl(app_id) {
Ok(data) => {
if let Err(err) =
self.ipc_server_event_sender
.send(ExternalEvent::EndSession(app_id)) {
if let Err(err) = self.ipc_server_event_sender
.send(ExternalEvent::EndSession(app_id)) {
debug!("{:?} Error sending end-session signal to IPC Server.", err);
}

Expand All @@ -300,15 +297,15 @@ impl AppHandler {
try!(self.get_launcher_global_config_and_dir());

let position = try!(launcher_configurations.iter()
.position(|config| config.app_id == app_id)
.ok_or(LauncherError::AppNotRegistered));
.position(|config| config.app_id == app_id)
.ok_or(LauncherError::AppNotRegistered));
let reference_count = launcher_configurations[position].reference_count;

if reference_count == 1 {
let _ = launcher_configurations.remove(position);
} else {
let config = try!(launcher_configurations.get_mut(position)
.ok_or(LauncherError::AppNotRegistered));
.ok_or(LauncherError::AppNotRegistered));
config.reference_count -= 1;
}

Expand Down Expand Up @@ -344,10 +341,9 @@ impl AppHandler {
group_send!(reply, &mut self.app_modify_observers);
}

fn on_modify_app_settings_impl
(&mut self,
data: events::event_data::ModifyAppSettings)
-> Result<AppModification, LauncherError> {
fn on_modify_app_settings_impl(&mut self,
data: events::event_data::ModifyAppSettings)
-> Result<AppModification, LauncherError> {
let (mut global_configs, config_dir) = try!(self.get_launcher_global_config_and_dir());

let mut global_config_modified = false;
Expand All @@ -367,8 +363,9 @@ impl AppHandler {
app_info.safe_drive_access = safe_drive_access;
global_config_modified = true;

if self.ipc_server_event_sender.send(ExternalEvent
::ChangeSafeDriveAccess(data.id, safe_drive_access)).is_err() {
if self.ipc_server_event_sender
.send(ExternalEvent::ChangeSafeDriveAccess(data.id, safe_drive_access))
.is_err() {
debug!("Error asking IPC Server to change \"SAFEDrive\" permission for an app");
}

Expand Down Expand Up @@ -425,8 +422,9 @@ impl AppHandler {
self.app_modify_observers.push(observer);
}

fn on_get_all_managed_apps(&self, observer: mpsc::Sender<
Result<Vec<events::event_data::ManagedApp>, LauncherError>>) {
fn on_get_all_managed_apps(&self,
observer: mpsc::Sender<Result<Vec<events::event_data::ManagedApp>,
LauncherError>>) {
let global_configs = eval_send_one!(self.get_launcher_global_config(), &observer);
let mut managed_apps = Vec::with_capacity(global_configs.len());
for it in global_configs.iter() {
Expand Down Expand Up @@ -477,9 +475,8 @@ impl AppHandler {
dir_name
}

fn get_launcher_global_config
(&self)
-> Result<Vec<misc::LauncherConfiguration>, LauncherError> {
fn get_launcher_global_config(&self)
-> Result<Vec<misc::LauncherConfiguration>, LauncherError> {
Ok(try!(self.get_launcher_global_config_and_dir()).0)
}

Expand All @@ -506,8 +503,7 @@ impl AppHandler {
let file = unwrap_option!(dir_listing.get_files()
.iter()
.find(|file| {
file.get_name() ==
LAUNCHER_GLOBAL_CONFIG_FILE_NAME
file.get_name() == LAUNCHER_GLOBAL_CONFIG_FILE_NAME
}),
"Logic Error - Launcher start-up should ensure the file must \
be present at this stage - Report bug.")
Expand All @@ -521,8 +517,9 @@ impl AppHandler {
Ok(())
}

fn get_launcher_global_config_and_dir(&self) -> Result<(Vec<misc::LauncherConfiguration>,
DirectoryListing), LauncherError> {
fn get_launcher_global_config_and_dir
(&self)
-> Result<(Vec<misc::LauncherConfiguration>, DirectoryListing), LauncherError> {
let dir_helper = DirectoryHelper::new(self.client.clone());
let dir_listing = try!(dir_helper.get_configuration_directory_listing(
LAUNCHER_GLOBAL_DIRECTORY_NAME.to_string()));
Expand Down
35 changes: 17 additions & 18 deletions src/launcher/ipc_server/ipc_session/authenticate_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ pub fn verify_launcher_nonce(
let payload_as_str = eval_send_one!(parse_result!(String::from_utf8(payload),
"Invalid UTF-8"),
&event_sender);
let handshake_request: HandshakeRequest =
eval_send_one!(json::decode(&payload_as_str), &event_sender);
let handshake_request: HandshakeRequest = eval_send_one!(json::decode(&payload_as_str),
&event_sender);

if handshake_request.endpoint != APP_AUTHENTICATION_ENDPOINT {
eval_send_one!(Err(LauncherError::SpecificParseError("Invalid endpoint \
for app-auhtentication"
.to_string())),
eval_send_one!(Err(LauncherError::SpecificParseError("Invalid endpoint for \
app-auhtentication"
.to_string())),
&event_sender);
}

Expand All @@ -53,9 +53,9 @@ pub fn verify_launcher_nonce(
"Nonce -> Base64"),
&event_sender);
if vec_nonce.len() != box_::NONCEBYTES {
eval_send_one!(Err(LauncherError::SpecificParseError("Invalid asymmetric \
nonce length."
.to_string())),
eval_send_one!(Err(LauncherError::SpecificParseError("Invalid asymmetric nonce \
length."
.to_string())),
&event_sender);
}

Expand All @@ -65,9 +65,9 @@ pub fn verify_launcher_nonce(
"PublicKey -> Base64"),
&event_sender);
if vec_pub_key.len() != box_::PUBLICKEYBYTES {
eval_send_one!(Err(LauncherError::SpecificParseError("Invalid asymmetric \
public key length."
.to_string())),
eval_send_one!(Err(LauncherError::SpecificParseError("Invalid asymmetric public \
key length."
.to_string())),
&event_sender);
}

Expand All @@ -81,13 +81,12 @@ pub fn verify_launcher_nonce(
asymm_pub_key.0[it.0] = it.1;
}

if let Err(err) =
send_one!(Ok(AuthData {
str_nonce: handshake_request.data.launcher_string,
asymm_nonce: asymm_nonce,
asymm_pub_key: asymm_pub_key,
}),
&event_sender) {
if let Err(err) = send_one!(Ok(AuthData {
str_nonce: handshake_request.data.launcher_string,
asymm_nonce: asymm_nonce,
asymm_pub_key: asymm_pub_key,
}),
&event_sender) {
debug!("{:?} Error sending authentication data to IPCSession.", err);
}

Expand Down
6 changes: 3 additions & 3 deletions src/launcher/ipc_server/ipc_session/ecdh_key_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use sodiumoxide::crypto::{box_, secretbox};
use errors::LauncherError;
use launcher::ipc_server::ipc_session::stream::IpcStream;

pub fn perform_ecdh_exchange(ipc_stream : &mut IpcStream,
app_nonce : box_::Nonce,
pub fn perform_ecdh_exchange(ipc_stream: &mut IpcStream,
app_nonce: box_::Nonce,
app_pub_key: box_::PublicKey)
-> Result<(secretbox::Nonce, secretbox::Key), LauncherError> {
-> Result<(secretbox::Nonce, secretbox::Key), LauncherError> {
use rustc_serialize::base64::ToBase64;
use rustc_serialize::json;

Expand Down
Loading

0 comments on commit 55034b5

Please sign in to comment.