Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Adds nonce to ExternalRequest. Fixes #629. #640

Merged
merged 2 commits into from Aug 24, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/simple_key_value_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl Node {
from_authority : Authority,
response_token : Option<SignedToken>) {
match request {
ExternalRequest::Get(data_request) => {
ExternalRequest::Get(data_request, _) => {
self.handle_get_request(data_request,
our_authority,
from_authority,
Expand All @@ -163,10 +163,10 @@ impl Node {
}
}

fn handle_get_request(&mut self, data_request : DataRequest,
our_authority : Authority,
from_authority : Authority,
response_token : Option<SignedToken>) {
fn handle_get_request(&mut self, data_request: DataRequest,
our_authority: Authority,
from_authority: Authority,
response_token: Option<SignedToken>) {
let name = match data_request {
DataRequest::PlainData(name) => name,
_ => { println!("Node: Only serving plain data in this example"); return; }
Expand Down Expand Up @@ -356,7 +356,7 @@ impl Client {
};
}

fn send_get_request(&self, what: String) {
fn send_get_request(&mut self, what: String) {
let name = Client::calculate_key_name(&what);

self.routing_client.get_request(Authority::NaeManager(name.clone()),
Expand Down
2 changes: 1 addition & 1 deletion src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub fn our_authority(message: &RoutingMessage, routing_table: &RoutingTable) ->
let element = match message.content {
Content::ExternalRequest(ref request) => {
match *request {
ExternalRequest::Get(ref data_request) => Some(data_request.name().clone()),
ExternalRequest::Get(ref data_request, _) => Some(data_request.name().clone()),
ExternalRequest::Put(ref data) => Some(data.name()),
ExternalRequest::Post(ref data) => Some(data.name()),
ExternalRequest::Delete(ref data) => Some(data.name()),
Expand Down
2 changes: 1 addition & 1 deletion src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Debug for SignedToken {
/// These are the messageTypes routing provides
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug, RustcEncodable, RustcDecodable)]
pub enum ExternalRequest {
Get(DataRequest),
Get(DataRequest, u8),
Put(Data),
Post(Data),
Delete(Data),
Expand Down
2 changes: 1 addition & 1 deletion src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Routing {
data_request: DataRequest) {
let _ = self.action_sender.send(Action::SendContent(
our_authority, location,
Content::ExternalRequest(ExternalRequest::Get(data_request))));
Content::ExternalRequest(ExternalRequest::Get(data_request, 0u8))));
}

/// Add something to the network
Expand Down
15 changes: 8 additions & 7 deletions src/routing_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ use messages::{ExternalRequest, ExternalResponse, InternalRequest, Content};

type RoutingResult = Result<(), RoutingError>;

/// Routing provides an actionable interface to RoutingNode.
/// On constructing a new Routing object a RoutingNode will also be started.
/// Routing objects are clonable for multithreading, or a Routing object can be
/// cloned with a new set of keys while preserving a single RoutingNode.
/// Routing provides an actionable interface to RoutingNode. On constructing a new Routing object a
/// RoutingNode will also be started. Routing objects are clonable for multithreading, or a Routing
/// object can be cloned with a new set of keys while preserving a single RoutingNode.
#[derive(Clone)]
pub struct RoutingClient {
action_sender: mpsc::Sender<Action>,
get_counter: u8,
}

impl RoutingClient {
Expand All @@ -67,14 +67,15 @@ impl RoutingClient {
debug!("Routing node terminated running.");
});

RoutingClient { action_sender: action_sender }
RoutingClient { action_sender: action_sender, get_counter: 0u8 }
}

/// Send a Get message with a DataRequest to an Authority, signed with given keys.
pub fn get_request(&self, location: Authority, data_request: DataRequest) {
pub fn get_request(&mut self, location: Authority, data_request: DataRequest) {
let _ = self.action_sender.send(Action::ClientSendContent(
location,
Content::ExternalRequest(ExternalRequest::Get(data_request))));
Content::ExternalRequest(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will always give 1u8; you need to set get_counter

ExternalRequest::Get(data_request, self.get_counter.wrapping_add(1)))));
}

/// Add something to the network
Expand Down
4 changes: 2 additions & 2 deletions src/routing_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ impl RoutingNode {

fn handle_cache_get(&mut self, request: ExternalRequest) -> Option<Data> {
match request {
ExternalRequest::Get(data_request) => {
ExternalRequest::Get(data_request, _) => {
match data_request {
DataRequest::StructuredData(data_name, value) => {
match self.structured_data_cache.as_mut() {
Expand Down Expand Up @@ -1259,7 +1259,7 @@ mod test {
immutable.get_type_tag().clone());

let response = ExternalResponse::Get(immutable_data, data_request.clone(), Some(sign_token));
let request = ExternalRequest::Get(data_request);
let request = ExternalRequest::Get(data_request, 0u8);

assert!(node.handle_cache_get(request.clone()).is_none());
node.handle_cache_put(response);
Expand Down