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

Commit

Permalink
Merge pull request #64 from ustulation/with_new_routing
Browse files Browse the repository at this point in the history
all tests compile and pass
  • Loading branch information
Viv Rajkumar committed Dec 21, 2015
2 parents e4552db + 67eaf46 commit 003f4ec
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 97 deletions.
36 changes: 17 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
[package]
name = "safe_dns"
version = "0.3.1"
authors = ["MaidSafe Developers <dev@maidsafe.net>"]
description = "SAFE DNS API library"
authors = ["MaidSafe Developers <dev@maidsafe.net>"]
description = "SAFE DNS API library"
documentation = "http://maidsafe.net/safe_dns/latest"
repository = "https://github.com/maidsafe/safe_dns"
readme = "README.md"
license = "GPL-3.0"
homepage = "http://maidsafe.net"
homepage = "http://maidsafe.net"
license = "GPL-3.0"
name = "safe_dns"
readme = "README.md"
repository = "https://github.com/maidsafe/safe_dns"
version = "0.3.1"

[dependencies]
# ---- Maidsafe ----
routing = "~0.4.2"
safe_nfs = "~0.3.1"
safe_core = "~0.3.1"

# ---- Others ----
log = "~0.3.3"
sodiumoxide = "~0.0.9"
log = "~0.3.4"
maidsafe_utilities = "~0.1.5"
routing = "~0.5.2"
rustc-serialize = "~0.3.16"
safe_core = "~0.4.0"
safe_nfs = "~0.4.0"
sodiumoxide = "~0.0.9"
xor_name = "~0.0.1"

[dev-dependencies]
regex = "~0.1.41"
regex = "~0.1.44"

[features]
use-mock-routing = ["safe_core/use-mock-routing",
"safe_nfs/use-mock-routing"]
use-mock-routing = ["safe_core/use-mock-routing", "safe_nfs/use-mock-routing"]
22 changes: 13 additions & 9 deletions examples/simulate_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
extern crate regex;
extern crate routing;
extern crate safe_dns;
extern crate safe_core;
extern crate safe_nfs;
extern crate sodiumoxide;
#[macro_use] extern crate safe_core;
#[macro_use] extern crate maidsafe_utilities;

use routing::Data;

const DEFAULT_SERVICE: &'static str = "www";
const HOME_PAGE_FILE_NAME: &'static str = "index.html";
Expand Down Expand Up @@ -52,7 +55,7 @@ fn handle_login() -> std::sync::Arc<std::sync::Mutex<safe_core::client::Client>>
// Account Creation
{
println!("\nTrying to create an account ...");
let _ = eval_result!(safe_core::client::Client::create_account(keyword.clone(), pin.clone(), password.clone()));
let _ = unwrap_result!(safe_core::client::Client::create_account(keyword.clone(), pin.clone(), password.clone()));
println!("Account Creation Successful !!");
}

Expand All @@ -61,7 +64,7 @@ fn handle_login() -> std::sync::Arc<std::sync::Mutex<safe_core::client::Client>>

// Log into the created account
println!("\nTrying to log into the created account using supplied credentials ...");
std::sync::Arc::new(std::sync::Mutex::new(eval_result!(safe_core::client::Client::log_in(keyword, pin, password))))
std::sync::Arc::new(std::sync::Mutex::new(unwrap_result!(safe_core::client::Client::log_in(keyword, pin, password))))
}

fn create_dns_record(client : std::sync::Arc<std::sync::Mutex<safe_core::client::Client>>,
Expand All @@ -87,7 +90,7 @@ fn create_dns_record(client : std::sync::Arc<std::sync::Mutex<safe_core::
owners,
&secret_signing_key,
None));
Ok(try!(eval_result!(client.lock()).put(routing::data::Data::StructuredData(dns_struct_data), None)))
Ok(try!(unwrap_result!(client.lock()).put(Data::StructuredData(dns_struct_data), None)))
}

fn delete_dns_record(client : std::sync::Arc<std::sync::Mutex<safe_core::client::Client>>,
Expand All @@ -104,7 +107,7 @@ fn delete_dns_record(client : std::sync::Arc<std::sync::Mutex<safe_core::
println!("Deleting Dns...");

let dns_struct_data = try!(dns_operations.delete_dns(&long_name, &secret_signing_key));
Ok(try!(eval_result!(client.lock()).delete(routing::data::Data::StructuredData(dns_struct_data), None)))
Ok(try!(unwrap_result!(client.lock()).delete(Data::StructuredData(dns_struct_data), None)))
}

fn display_dns_records(dns_operations: &safe_dns::dns_operations::DnsOperations) -> Result<(), safe_dns::errors::DnsError> {
Expand Down Expand Up @@ -164,7 +167,8 @@ fn add_service(client : std::sync::Arc<std::sync::Mutex<safe_core::client
(service_name, dir_key.clone()),
&secret_signing_key,
None));
Ok(client.lock().unwrap().post(routing::data::Data::StructuredData(struct_data), None))

Ok(try!(client.lock().unwrap().post(Data::StructuredData(struct_data), None)))
}

fn remove_service(client : std::sync::Arc<std::sync::Mutex<safe_core::client::Client>>,
Expand All @@ -185,7 +189,7 @@ fn remove_service(client : std::sync::Arc<std::sync::Mutex<safe_core::cli

let secret_signing_key = try!(client.lock().unwrap().get_secret_signing_key()).clone();
let struct_data = try!(dns_operations.remove_service(&long_name, service_name, &secret_signing_key, None));
Ok(client.lock().unwrap().post(routing::data::Data::StructuredData(struct_data), None))
Ok(try!(client.lock().unwrap().post(Data::StructuredData(struct_data), None)))
}

fn display_services(dns_operations: &safe_dns::dns_operations::DnsOperations) -> Result<(), safe_dns::errors::DnsError> {
Expand Down Expand Up @@ -259,14 +263,14 @@ fn parse_url_and_get_home_page(client : std::sync::Arc<std::sync::Mutex<s

fn main() {
let client = handle_login();
let unregistered_client = ::std::sync::Arc::new(::std::sync::Mutex::new(eval_result!(::safe_core
let unregistered_client = ::std::sync::Arc::new(::std::sync::Mutex::new(unwrap_result!(::safe_core
::client
::Client
::create_unregistered_client())));
println!("Account Login Successful !!");

println!("Initialising Dns...");
let dns_operations = eval_result!(safe_dns::dns_operations::DnsOperations::new(client.clone()));
let dns_operations = unwrap_result!(safe_dns::dns_operations::DnsOperations::new(client.clone()));
let dns_operations_unregistered = safe_dns::dns_operations::DnsOperations::new_unregistered(unregistered_client.clone());

let mut user_option = String::new();
Expand Down
26 changes: 14 additions & 12 deletions src/dns_operations/dns_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// Please review the Licences for the specific language governing permissions and limitations
// relating to use of the SAFE Network Software.

use maidsafe_utilities::serialisation::{serialise, deserialise};

const DNS_CONFIG_DIR_NAME: &'static str = "DnsReservedDirectory";
const DNS_CONFIG_FILE_NAME: &'static str = "DnsConfigurationFile";

Expand Down Expand Up @@ -49,7 +51,7 @@ pub fn get_dns_configuaration_data(client: ::std::sync::Arc<::std::sync::Mutex<:
let mut reader = file_helper.read(file);
let size = reader.size();
if size != 0 {
Ok(try!(::safe_core::utility::deserialise(&try!(reader.read(0, size)))))
Ok(try!(deserialise(&try!(reader.read(0, size)))))
} else {
Ok(vec![])
}
Expand All @@ -63,7 +65,7 @@ pub fn write_dns_configuaration_data(client: ::std::sync::Arc<::std::sync::Mutex
let file_helper = ::safe_nfs::helper::file_helper::FileHelper::new(client.clone());
let mut writer = try!(file_helper.update_content(file, ::safe_nfs::helper::writer::Mode::Overwrite, dir_listing));
debug!("Writing dns configuration data ...");
writer.write(&try!(::safe_core::utility::serialise(&config)), 0);
writer.write(&try!(serialise(&config)), 0);
let _ = try!(writer.close());
Ok(())
}
Expand All @@ -74,16 +76,16 @@ mod test {

#[test]
fn read_write_dns_configuration_file() {
let client = ::std::sync::Arc::new(::std::sync::Mutex::new(eval_result!(::safe_core::utility::test_utils::get_client())));
let client = ::std::sync::Arc::new(::std::sync::Mutex::new(unwrap_result!(::safe_core::utility::test_utils::get_client())));

// Initialise Dns Configuration File
eval_result!(initialise_dns_configuaration(client.clone()));
unwrap_result!(initialise_dns_configuaration(client.clone()));

// Get the Stored Configurations
let mut config_vec = eval_result!(get_dns_configuaration_data(client.clone()));
let mut config_vec = unwrap_result!(get_dns_configuaration_data(client.clone()));
assert_eq!(config_vec.len(), 0);

let long_name = eval_result!(::safe_core::utility::generate_random_string(10));
let long_name = unwrap_result!(::safe_core::utility::generate_random_string(10));

// Put in the 1st record
let mut keypair = ::sodiumoxide::crypto::box_::gen_keypair();
Expand All @@ -93,10 +95,10 @@ mod test {
};

config_vec.push(config_0.clone());
eval_result!(write_dns_configuaration_data(client.clone(), &config_vec));
unwrap_result!(write_dns_configuaration_data(client.clone(), &config_vec));

// Get the Stored Configurations
config_vec = eval_result!(get_dns_configuaration_data(client.clone()));
config_vec = unwrap_result!(get_dns_configuaration_data(client.clone()));
assert_eq!(config_vec.len(), 1);

assert_eq!(config_vec[0], config_0);
Expand All @@ -109,21 +111,21 @@ mod test {
};

config_vec[0] = config_1.clone();
eval_result!(write_dns_configuaration_data(client.clone(), &config_vec));
unwrap_result!(write_dns_configuaration_data(client.clone(), &config_vec));

// Get the Stored Configurations
config_vec = eval_result!(get_dns_configuaration_data(client.clone()));
config_vec = unwrap_result!(get_dns_configuaration_data(client.clone()));
assert_eq!(config_vec.len(), 1);

assert!(config_vec[0] != config_0);
assert_eq!(config_vec[0], config_1);

// Delete Record
config_vec.clear();
eval_result!(write_dns_configuaration_data(client.clone(), &config_vec));
unwrap_result!(write_dns_configuaration_data(client.clone(), &config_vec));

// Get the Stored Configurations
config_vec = eval_result!(get_dns_configuaration_data(client.clone()));
config_vec = unwrap_result!(get_dns_configuaration_data(client.clone()));
assert_eq!(config_vec.len(), 0);
}
}

0 comments on commit 003f4ec

Please sign in to comment.