Skip to content
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
Prev Previous commit
Merge branch 'refactor' into refactor
  • Loading branch information
ong-jonas authored Oct 12, 2023
commit 309a0d68420fa344a0006bcbff4bb5660df6289c
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ pub struct Config {

/// Interval in seconds for querying the network to discover peers
pub peer_discovery_interval: u64,

/// Protocol name to communicate with other Kademlia nodes
pub protocol_name: String,
}

// Returns a complete list of accepted topics in pchain-network
pub(crate) fn fullnode_topics(public_address: PublicAddress) -> Vec<Topic> {
vec![Topic::HotStuffRsBroadcast, Topic::HotStuffRsSend(public_address).into(), Topic::Mempool, Topic::DroppedTxns]
}
8 changes: 4 additions & 4 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ use std::net::Ipv4Addr;
use std::time::Duration;

use crate::{
behaviour::{Behaviour, PeerNetworkEvent},
config,
conversions,
behaviour::{Behaviour, NetworkEvent},
messages::{DroppedTxMessage, Envelope, Topic, Message},
messages::Topic::{DroppedTxns, HotStuffRsBroadcast, HotStuffRsSend, Mempool},
peer::{EngineCommand, PeerBuilder, Peer},
peer::{EngineCommand, PeerBuilder, Peer}, conversions, config,
};

/// [start] p2p networking peer and return the handle [NetworkHandle] of this process.
Expand Down Expand Up @@ -164,11 +164,11 @@ pub(crate) async fn start(
// So we need to convert Vec<u8> to pchain_network::Message. Instead of implementing
// TryFrom trait for Vec<u8> to Message, implement a function that takes in the Message Topic to help
// converting Vec<u8> to Message. You can refer to fullnode/mempool messagegate to see how to

// deserialise each Message type.
let topic = config::fullnode_topics(local_public_address)
.into_iter()
.find(|t| t.clone().hash() == message.topic);


if let Some(topic) = topic {
let pchain_message = match topic {
Expand All @@ -190,7 +190,7 @@ pub(crate) async fn start(
}
};
}

} else {
log::debug!("Receive unknown gossip message");
}
Expand Down
11 changes: 11 additions & 0 deletions src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ use pchain_types::{blockchain::TransactionV1, cryptography::{Sha256Hash, PublicA
/// Hash of the message topic.
pub type MessageTopicHash = libp2p::gossipsub::TopicHash;

/// [Envelope] encapsulates the message received from the p2p network with it's sender address.
#[derive(Clone)]
pub struct Envelope {
/// The origin of the message
pub origin: PublicAddress,

/// The message encapsulated
pub message: Message,
}

/// [Topic] defines the topics of the messages in pchain-network.
#[derive(PartialEq, Debug, Clone)]
pub enum Topic {
HotStuffRsBroadcast,
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.