Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #875 from holochain/net-protocol
Browse files Browse the repository at this point in the history
holochain_net: protocol update - HandleGetDht Data & Meta + renames
  • Loading branch information
ddd-mtl authored Jan 18, 2019
2 parents a697d28 + 86cb01e commit 34609fa
Show file tree
Hide file tree
Showing 24 changed files with 444 additions and 427 deletions.
4 changes: 1 addition & 3 deletions core/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ use holochain_core_types::{
link::Link,
validation::ValidationPackage,
};
use holochain_net_connection::protocol_wrapper::{
DhtData, DhtMetaData, GetDhtData, GetDhtMetaData,
};
use holochain_net_connection::json_protocol::{DhtData, DhtMetaData, GetDhtData, GetDhtMetaData};
use snowflake;
use std::{
hash::{Hash, Hasher},
Expand Down
4 changes: 1 addition & 3 deletions core/src/network/handler/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use crate::{
nucleus,
};
use holochain_core_types::cas::content::Address;
use holochain_net_connection::protocol_wrapper::{
DhtData, DhtMetaData, GetDhtData, GetDhtMetaData,
};
use holochain_net_connection::json_protocol::{DhtData, DhtMetaData, GetDhtData, GetDhtMetaData};
use regex::Regex;
use std::{collections::HashSet, sync::Arc};

Expand Down
28 changes: 14 additions & 14 deletions core/src/network/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use holochain_core_types::{
cas::content::{Address, AddressableContent},
hash::HashString,
};
use holochain_net_connection::{net_connection::NetHandler, protocol_wrapper::ProtocolWrapper};
use holochain_net_connection::{json_protocol::JsonProtocol, net_connection::NetHandler};
use std::{convert::TryFrom, sync::Arc};

// FIXME: Temporary hack to ignore messages incorrectly sent to us by the networking
Expand Down Expand Up @@ -51,46 +51,46 @@ pub fn create_handler(c: &Arc<Context>) -> NetHandler {
Box::new(move |message| {
let message = message.unwrap();
//context.log(format!("debug/net/handle: {:?}", message));
let protocol_wrapper = ProtocolWrapper::try_from(message);
match protocol_wrapper {
Ok(ProtocolWrapper::StoreDht(dht_data)) => {
let json_msg = JsonProtocol::try_from(message);
match json_msg {
Ok(JsonProtocol::HandleStoreDhtData(dht_data)) => {
// NOTE data in message doesn't allow us to confirm agent!
if !is_me(&context, &dht_data.dna_address, "") {
return Ok(());
}
context.log(format!("debug/net/handle: StoreDht: {:?}", dht_data));
handle_store_dht(dht_data, context.clone())
}
Ok(ProtocolWrapper::StoreDhtMeta(dht_meta_data)) => {
Ok(JsonProtocol::HandleStoreDhtMeta(dht_meta_data)) => {
context.log(format!(
"debug/net/handle: StoreDhtMeta: {:?}",
"debug/net/handle: HandleStoreDhtMeta: {:?}",
dht_meta_data
));
if !is_me(&context, &dht_meta_data.dna_address, "") {
context.log(format!(
"debug/net/handle: StoreDhtMeta: ignoring, not for me. {:?}",
"debug/net/handle: HandleStoreDhtMeta: ignoring, not for me. {:?}",
dht_meta_data
));
return Ok(());
}
handle_store_dht_meta(dht_meta_data, context.clone())
}
Ok(ProtocolWrapper::GetDht(get_dht_data)) => {
Ok(JsonProtocol::HandleGetDhtData(get_dht_data)) => {
// NOTE data in message doesn't allow us to confirm agent!
if !is_me(&context, &get_dht_data.dna_address, "") {
return Ok(());
}
context.log(format!("debug/net/handle: GetDht: {:?}", get_dht_data));
handle_get_dht(get_dht_data, context.clone())
}
Ok(ProtocolWrapper::GetDhtResult(dht_data)) => {
Ok(JsonProtocol::GetDhtDataResult(dht_data)) => {
if !is_me(&context, &dht_data.dna_address, &dht_data.agent_id) {
return Ok(());
}
context.log(format!("debug/net/handle: GetDhtResult: {:?}", dht_data));
handle_get_dht_result(dht_data, context.clone())
}
Ok(ProtocolWrapper::GetDhtMeta(get_dht_meta_data)) => {
Ok(JsonProtocol::HandleGetDhtMeta(get_dht_meta_data)) => {
if is_me(&context, &get_dht_meta_data.dna_address, "") {
context.log(format!(
"debug/net/handle: GetDhtMeta: {:?}",
Expand All @@ -99,7 +99,7 @@ pub fn create_handler(c: &Arc<Context>) -> NetHandler {
handle_get_dht_meta(get_dht_meta_data, context.clone())
}
}
Ok(ProtocolWrapper::GetDhtMetaResult(get_dht_meta_data)) => {
Ok(JsonProtocol::GetDhtMetaResult(get_dht_meta_data)) => {
if is_me(&context, &get_dht_meta_data.dna_address, "") {
// TODO: Find a proper solution for selecting DHT meta responses.
// Current network implementation broadcasts messages to all nodes which means
Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn create_handler(c: &Arc<Context>) -> NetHandler {
//}
}
}
Ok(ProtocolWrapper::HandleSend(message_data)) => {
Ok(JsonProtocol::HandleSendMessage(message_data)) => {
if !is_me(
&context,
&message_data.dna_address,
Expand All @@ -138,7 +138,7 @@ pub fn create_handler(c: &Arc<Context>) -> NetHandler {
}
handle_send(message_data, context.clone())
}
Ok(ProtocolWrapper::SendResult(message_data)) => {
Ok(JsonProtocol::SendMessageResult(message_data)) => {
if !is_me(
&context,
&message_data.dna_address,
Expand All @@ -148,7 +148,7 @@ pub fn create_handler(c: &Arc<Context>) -> NetHandler {
}
handle_send_result(message_data, context.clone())
}
Ok(ProtocolWrapper::PeerConnected(peer_data)) => {
Ok(JsonProtocol::PeerConnected(peer_data)) => {
// if is not my DNA ignore
if !is_me(&context, &peer_data.dna_address, "") {
return Ok(());
Expand Down
2 changes: 1 addition & 1 deletion core/src/network/handler/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use futures::executor::block_on;
use holochain_core_types::cas::content::Address;
use std::{sync::Arc, thread};

use holochain_net_connection::protocol_wrapper::MessageData;
use holochain_net_connection::json_protocol::MessageData;

/// We got a ProtocolWrapper::SendMessage, this means somebody initiates message roundtrip
/// -> we are being called
Expand Down
8 changes: 4 additions & 4 deletions core/src/network/handler/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use holochain_core_types::{
cas::content::Address,
crud_status::{CrudStatus, LINK_NAME, STATUS_NAME},
};
use holochain_net_connection::protocol_wrapper::{DhtData, DhtMetaData};
use holochain_net_connection::json_protocol::{DhtData, DhtMetaData};
use std::{sync::Arc, thread};

/// The network requests us to store (i.e. hold) the given entry.
Expand All @@ -28,7 +28,7 @@ pub fn handle_store_dht(dht_data: DhtData, context: Arc<Context>) {
pub fn handle_store_dht_meta(dht_meta_data: DhtMetaData, context: Arc<Context>) {
match dht_meta_data.attribute.as_ref() {
"link" => {
context.log("debug/net/handle: StoreDhtMeta: got LINK. processing...");
context.log("debug/net/handle: HandleStoreDhtMeta: got LINK. processing...");
let entry_with_header: EntryWithHeader = serde_json::from_str(
&serde_json::to_string(&dht_meta_data.content)
.expect("dht_meta_data should be EntryWithHader"),
Expand All @@ -42,7 +42,7 @@ pub fn handle_store_dht_meta(dht_meta_data: DhtMetaData, context: Arc<Context>)
});
}
STATUS_NAME => {
context.log("debug/net/handle: StoreDhtMeta: got CRUD status. processing...");
context.log("debug/net/handle: HandleStoreDhtMeta: got CRUD status. processing...");
let _crud_status: CrudStatus = serde_json::from_str(
&serde_json::to_string(&dht_meta_data.content)
.expect("dht_meta_data should be crud_status"),
Expand All @@ -51,7 +51,7 @@ pub fn handle_store_dht_meta(dht_meta_data: DhtMetaData, context: Arc<Context>)
// FIXME: block_on hold crud_status metadata in DHT?
}
LINK_NAME => {
context.log("debug/net/handle: StoreDhtMeta: got CRUD LINK. processing...");
context.log("debug/net/handle: HandleStoreDhtMeta: got CRUD LINK. processing...");
let _crud_link: Address = serde_json::from_str(
&serde_json::to_string(&dht_meta_data.content)
.expect("dht_meta_data should be crud_link"),
Expand Down
4 changes: 2 additions & 2 deletions core/src/network/reducers/get_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use crate::{
network::{reducers::send, state::NetworkState},
};
use holochain_core_types::error::HolochainError;
use holochain_net_connection::protocol_wrapper::{GetDhtData, ProtocolWrapper};
use holochain_net_connection::json_protocol::{GetDhtData, JsonProtocol};
use std::sync::Arc;

fn inner(network_state: &mut NetworkState, key: &GetEntryKey) -> Result<(), HolochainError> {
network_state.initialized()?;

send(
network_state,
ProtocolWrapper::GetDht(GetDhtData {
JsonProtocol::GetDhtData(GetDhtData {
msg_id: key.id.clone(),
dna_address: network_state.dna_address.clone().unwrap(),
from_agent_id: network_state.agent_id.clone().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions core/src/network/reducers/get_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use crate::{
network::{reducers::send, state::NetworkState},
};
use holochain_core_types::error::HolochainError;
use holochain_net_connection::protocol_wrapper::{GetDhtMetaData, ProtocolWrapper};
use holochain_net_connection::json_protocol::{GetDhtMetaData, JsonProtocol};
use std::sync::Arc;

fn inner(network_state: &mut NetworkState, key: &GetLinksKey) -> Result<(), HolochainError> {
network_state.initialized()?;

send(
network_state,
ProtocolWrapper::GetDhtMeta(GetDhtMetaData {
JsonProtocol::GetDhtMeta(GetDhtMetaData {
msg_id: key.id.clone(),
dna_address: network_state.dna_address.clone().unwrap(),
from_agent_id: network_state.agent_id.clone().unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion core/src/network/reducers/handle_get_links_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
network::state::NetworkState,
};
use holochain_core_types::{cas::content::Address, error::HolochainError};
use holochain_net_connection::protocol_wrapper::DhtMetaData;
use holochain_net_connection::json_protocol::DhtMetaData;
use std::sync::Arc;

fn inner(
Expand Down
2 changes: 1 addition & 1 deletion core/src/network/reducers/handle_get_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
network::state::NetworkState,
};
use holochain_core_types::{cas::content::Address, entry::EntryWithMeta, error::HolochainError};
use holochain_net_connection::protocol_wrapper::DhtData;
use holochain_net_connection::json_protocol::DhtData;
use std::sync::Arc;

fn inner(
Expand Down
4 changes: 2 additions & 2 deletions core/src/network/reducers/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
};
use holochain_net::{p2p_config::P2pConfig, p2p_network::P2pNetwork};
use holochain_net_connection::{
json_protocol::{JsonProtocol, TrackDnaData},
net_connection::NetSend,
protocol_wrapper::{ProtocolWrapper, TrackAppData},
};
use std::{
str::FromStr,
Expand All @@ -26,7 +26,7 @@ pub fn reduce_init(

let _ = network
.send(
ProtocolWrapper::TrackApp(TrackAppData {
JsonProtocol::TrackDna(TrackDnaData {
dna_address: network_settings.dna_address.clone(),
agent_id: network_settings.agent_id.clone(),
})
Expand Down
8 changes: 4 additions & 4 deletions core/src/network/reducers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ use crate::{
};
use holochain_core_types::{cas::content::Address, error::HolochainError};
use holochain_net_connection::{
json_protocol::{JsonProtocol, MessageData},
net_connection::NetSend,
protocol_wrapper::{MessageData, ProtocolWrapper},
};
use snowflake::ProcessUniqueId;
use std::sync::Arc;
Expand Down Expand Up @@ -86,7 +86,7 @@ pub fn reduce(
/// that lives in the NetworkState.
pub fn send(
network_state: &mut NetworkState,
protocol_wrapper: ProtocolWrapper,
json_message: JsonProtocol,
) -> Result<(), HolochainError> {
network_state
.network
Expand All @@ -95,7 +95,7 @@ pub fn send(
network
.lock()
.unwrap()
.send(protocol_wrapper.into())
.send(json_message.into())
.map_err(|error| HolochainError::IoError(error.to_string()))
})
.ok_or(HolochainError::ErrorGeneric(
Expand All @@ -122,7 +122,7 @@ pub fn send_message(
data: serde_json::from_str(&serde_json::to_string(&message).unwrap()).unwrap(),
};

let _ = send(network_state, ProtocolWrapper::SendMessage(data))?;
let _ = send(network_state, JsonProtocol::SendMessage(data))?;

network_state.direct_message_connections.insert(id, message);

Expand Down
10 changes: 5 additions & 5 deletions core/src/network/reducers/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use holochain_core_types::{
entry::{entry_type::EntryType, Entry},
error::HolochainError,
};
use holochain_net_connection::protocol_wrapper::{DhtData, DhtMetaData, ProtocolWrapper};
use holochain_net_connection::json_protocol::{DhtData, DhtMetaData, JsonProtocol};
use std::sync::Arc;

fn publish_entry(
Expand All @@ -26,7 +26,7 @@ fn publish_entry(

send(
network_state,
ProtocolWrapper::PublishDht(DhtData {
JsonProtocol::PublishDhtData(DhtData {
msg_id: "?".to_string(),
dna_address: network_state.dna_address.clone().unwrap(),
agent_id: network_state.agent_id.clone().unwrap(),
Expand All @@ -46,7 +46,7 @@ fn publish_crud_meta(
// publish crud-status
send(
network_state,
ProtocolWrapper::PublishDhtMeta(DhtMetaData {
JsonProtocol::PublishDhtMeta(DhtMetaData {
msg_id: "?".to_string(),
dna_address: network_state.dna_address.clone().unwrap(),
agent_id: network_state.agent_id.clone().unwrap(),
Expand All @@ -63,7 +63,7 @@ fn publish_crud_meta(
}
send(
network_state,
ProtocolWrapper::PublishDhtMeta(DhtMetaData {
JsonProtocol::PublishDhtMeta(DhtMetaData {
msg_id: "?".to_string(),
dna_address: network_state.dna_address.clone().unwrap(),
agent_id: network_state.agent_id.clone().unwrap(),
Expand Down Expand Up @@ -100,7 +100,7 @@ fn publish_link_meta(

send(
network_state,
ProtocolWrapper::PublishDhtMeta(DhtMetaData {
JsonProtocol::PublishDhtMeta(DhtMetaData {
msg_id: "?".to_string(),
dna_address: network_state.dna_address.clone().unwrap(),
agent_id: network_state.agent_id.clone().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions core/src/network/reducers/respond_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
network::{actions::ActionResponse, reducers::send, state::NetworkState},
};
use holochain_core_types::{entry::EntryWithMeta, error::HolochainError};
use holochain_net_connection::protocol_wrapper::{DhtData, GetDhtData, ProtocolWrapper};
use holochain_net_connection::json_protocol::{DhtData, GetDhtData, JsonProtocol};
use std::sync::Arc;

fn reduce_respond_get_inner(
Expand All @@ -16,7 +16,7 @@ fn reduce_respond_get_inner(

send(
network_state,
ProtocolWrapper::GetDhtResult(DhtData {
JsonProtocol::HandleGetDhtDataResult(DhtData {
msg_id: get_dht_data.msg_id.clone(),
dna_address: network_state.dna_address.clone().unwrap(),
agent_id: get_dht_data.from_agent_id.clone(),
Expand Down
4 changes: 2 additions & 2 deletions core/src/network/reducers/respond_get_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
network::{actions::ActionResponse, reducers::send, state::NetworkState},
};
use holochain_core_types::{cas::content::Address, error::HolochainError};
use holochain_net_connection::protocol_wrapper::{DhtMetaData, GetDhtMetaData, ProtocolWrapper};
use holochain_net_connection::json_protocol::{DhtMetaData, GetDhtMetaData, JsonProtocol};
use std::sync::Arc;

fn reduce_respond_get_links_inner(
Expand All @@ -16,7 +16,7 @@ fn reduce_respond_get_links_inner(

send(
network_state,
ProtocolWrapper::GetDhtMetaResult(DhtMetaData {
JsonProtocol::HandleGetDhtMetaResult(DhtMetaData {
msg_id: get_dht_meta_data.msg_id.clone(),
dna_address: network_state.dna_address.clone().unwrap(),
agent_id: get_dht_meta_data.from_agent_id.clone(),
Expand Down
6 changes: 3 additions & 3 deletions core/src/network/reducers/send_direct_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
network::{reducers::send, state::NetworkState},
};
use holochain_core_types::error::HolochainError;
use holochain_net_connection::protocol_wrapper::{MessageData, ProtocolWrapper};
use holochain_net_connection::json_protocol::{JsonProtocol, MessageData};
use std::sync::Arc;

fn inner(
Expand All @@ -23,12 +23,12 @@ fn inner(
};

let protocol_object = if direct_message_data.is_response {
ProtocolWrapper::HandleSendResult(data)
JsonProtocol::HandleSendMessageResult(data)
} else {
network_state
.direct_message_connections
.insert(data.msg_id.clone(), direct_message_data.message.clone());
ProtocolWrapper::SendMessage(data)
JsonProtocol::SendMessage(data)
};

send(network_state, protocol_object)
Expand Down
Loading

0 comments on commit 34609fa

Please sign in to comment.