Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
895b3a2
new pchain_network structure according to pull request comments
Oct 10, 2023
47046ea
network subscribes to fullnode topics declared in config
ong-jonas Oct 10, 2023
8e13e7b
Added handlers field in PeerBuilder, change visibility of constants
Oct 10, 2023
8359198
filter types of messages to pass into handlers
ong-jonas Oct 10, 2023
929e2c2
Replace libp2p::identity::Keypair with libp2p::identity::ed25519::Key…
Oct 10, 2023
89af337
removed constant inputs that were redundantly passed into functions
ong-jonas Oct 10, 2023
632e0cc
Use libp2p::identity::PeerId, instead of libp2p::PeerId
Oct 11, 2023
7632917
Implemented Drop trait for Peer, fixed errors in engine.rs
Oct 11, 2023
06d7fd1
changed method of identifying message topics, updated protocol name a…
ong-jonas Oct 11, 2023
61caf60
Updated comments and docs
Oct 11, 2023
34dd150
improve deserialization of messages
ong-jonas Oct 12, 2023
309a0d6
Merge branch 'refactor' into refactor
ong-jonas Oct 12, 2023
e4e4b1b
Merge pull request #15 from ong-jonas/refactor
manngayin612 Oct 12, 2023
b6c155e
Resolved conflicts from pull request, added helper function to for me…
Oct 12, 2023
8bf6953
update comments, removed Envelope from message.rs
Oct 12, 2023
8916714
DOC: updated comments in message.rs
Oct 12, 2023
1777c61
fixed network tests
ong-jonas Oct 13, 2023
b0a5f6e
Moved configuration of PeerBuilder as argument of PeerBuilder::new(),…
Oct 13, 2023
2a699f2
Merge branch 'refactor' into tests/refactor
ong-jonas Oct 16, 2023
9e3082b
updated lib.rs example usage
ong-jonas Oct 16, 2023
52de07b
updated behaviour.rs test to check if the specific peer has been added
ong-jonas Oct 16, 2023
71e8b0a
updated config boot_nodes type to Vec<(PublicAddress, Ipv4Addr, u16)>
ong-jonas Oct 16, 2023
51e58a9
updated variable names and comments, removed explicit declaration of …
ong-jonas Oct 16, 2023
cdabd42
Update comments
Oct 16, 2023
f29a849
Updated comments in lib.rs
Oct 16, 2023
24c83d9
Merge pull request #16 from parallelchain-io/tests/refactor
manngayin612 Oct 16, 2023
cea24db
updated documentation and comments
ong-jonas Oct 17, 2023
cf2ab28
implement tryfrom gossip_message to pchain_message and moved definiti…
ong-jonas Oct 19, 2023
862a280
EngineStartError moved to mod engine
ong-jonas Oct 19, 2023
d4403a1
remove PeerBuilder and create Peer through Peer::start, engine::start…
ong-jonas Oct 19, 2023
aca23b8
convert gossipsub message to message using identify topics
ong-jonas Oct 20, 2023
4ab7543
renamed variables
ong-jonas Oct 20, 2023
20ecbbf
remove engine and replace functionality with peer
ong-jonas Oct 20, 2023
311ae56
decompose engine start into 3 separate functions
ong-jonas Oct 23, 2023
e69a8df
renamed MessageError to MessageConversionError
ong-jonas Oct 23, 2023
c9cbc37
renamed InvalidTopic to InvalidTopicError
ong-jonas Oct 23, 2023
d2f1d72
updated conversion errors
ong-jonas Oct 23, 2023
fed8fe6
removed identity topics
ong-jonas Oct 23, 2023
0e2ee29
removed impl From for PeerStartError and mapped errors in Peer::start()
ong-jonas Oct 23, 2023
6c7d3f1
removed start_listening function
ong-jonas Oct 24, 2023
a739d94
peers publish messages to themselves if they are subscribed
ong-jonas Oct 24, 2023
e51f6db
documentation and tests update
ong-jonas Oct 26, 2023
c228d2f
moved conversion of gossipsub::message to conversion.rs
ong-jonas Oct 27, 2023
702dfe2
Merge pull request #18 from parallelchain-io/message/refactor
manngayin612 Oct 27, 2023
a802936
Removed redundant incoming _msgs_buffer_capacity
Oct 27, 2023
7e37505
Renamed variable. Updated docs
Oct 27, 2023
434be9a
separated broadcast and send to self test cases
ong-jonas Oct 27, 2023
d0d1c41
Merge branch 'refactor' of https://github.com/parallelchain-io/pchain…
ong-jonas Oct 27, 2023
2448e97
updated network tests and hotstuff dependency to 0.3
ong-jonas Oct 30, 2023
0c21c1b
added conversion between pchain types Keypair and libp2p Keypair
ong-jonas Oct 31, 2023
18362f4
removed keypair conversions
ong-jonas Oct 31, 2023
2db4d17
updated documentation
ong-jonas Oct 31, 2023
5abd30b
added helper function in network tests
ong-jonas Oct 31, 2023
4904909
Updated lib.rs
Oct 31, 2023
c0f3fe0
Updated lib.rs
Nov 1, 2023
fa28fcd
Update libp2p::Kademlia deprecated packages, set allow_self_origin to…
Nov 6, 2023
710ecff
Update message handlers to be type of FnMut
Nov 9, 2023
156bb47
Fix: disambiguate serialization used for DroppedTxsStatusCode
Nov 10, 2023
03f1c78
FIX: removed deprecated dependencies
ong-jonas Nov 16, 2023
02de232
REFACTOR: removed with_dns, added nodelay(true)
ong-jonas Nov 16, 2023
74551df
REFACTOR: try_from to filter_gossipsub_messages, Vec<msg_handlers> to…
ong-jonas Nov 21, 2023
5900f43
deps: update dependency to hotstuff_rs
ong-jonas Nov 30, 2023
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
Next Next commit
Implemented Drop trait for Peer, fixed errors in engine.rs
  • Loading branch information
syrettaman committed Oct 11, 2023
commit 763291736044b8593900b6104b84387878b90c4f
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use pchain_types::cryptography::PublicAddress;

use crate::messages::Topic;

pub(crate) struct Config {
pub struct Config {
/// Keypair used for identifying the peer
pub keypair: Keypair,

Expand Down
22 changes: 9 additions & 13 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use std::time::Duration;
use crate::{
behaviour::{Behaviour, PeerNetworkEvent},
messages::{Envelope, Topic},
peer::{EngineCommand, PeerBuilder, Peer}, conversions,
peer::{EngineCommand, PeerBuilder, Peer}, conversions, config,
};

/// [start] p2p networking peer and return the handle [NetworkHandle] of this process.
Expand All @@ -50,11 +50,11 @@ pub(crate) async fn start(
) -> Result<Peer, Box<dyn Error>> {

let config = peer.config.unwrap();
let local_keypair = config.keypair;

let local_public_address: PublicAddress = config.keypair.public().to_bytes();
let local_public_address: PublicAddress = local_keypair.public().to_bytes();

let local_peer_id = identity::Keypair::from(config.keypair).public().to_peer_id();
let local_keypair = config.keypair;
let local_peer_id = identity::Keypair::from(local_keypair.clone()).public().to_peer_id();
log::info!(
"Local peer id: {:?} {:?}",
local_peer_id,
Expand All @@ -78,14 +78,14 @@ pub(crate) async fn start(
config.boot_nodes.iter().for_each(|peer_info| {
swarm.behaviour_mut().add_address(
&peer_info.0,
peer_info.1,
peer_info.1.clone(),
);
});
}

// 3. Subscribe to Topic
//TODO jonas
swarm.behaviour_mut().subscribe()?;
swarm.behaviour_mut().subscribe(config::fullnode_topics(local_public_address))?;

// 4. Start p2p networking
let (sender, mut receiver) =
Expand Down Expand Up @@ -123,20 +123,16 @@ pub(crate) async fn start(
// send to myself
let envelope = Envelope {
origin: local_public_address,
message: message.into(),
message: message.clone().into(),
};
peer.handlers.into_iter().map(|handler| handler(local_public_address, message));
// TODO
// message_gates
// .message_in(&Topic::HotStuffRsSend(local_public_address).hash(), envelope)
// .await;
let _ = peer.handlers.iter().map(|handler| handler(local_public_address, message.clone()));
} else if let Err(e) = swarm.behaviour_mut().publish(topic.into(), message) {
log::debug!("{:?}", e);
}
}

EngineCommand::Shutdown => {
log::info!("Exiting out of Engine thread");
log::info!("Shutting down the engine...");
break
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::messages::{Topic, Message, DroppedTxMessage};
use crate::config::Config;

pub struct PeerBuilder {
pub(crate) config: Option<Config>,
pub(crate) handlers: Option<Box<dyn Fn(PublicAddress, Message)>>,
pub config: Option<Config>,
pub handlers: Option<Box<dyn Fn(PublicAddress, Message) + Send>>,
}

impl PeerBuilder {
Expand All @@ -30,12 +30,11 @@ impl PeerBuilder {
self
}

fn on_receive_msg(&mut self, handlers: impl Fn(PublicAddress, Message)) -> &mut Self {
pub fn on_receive_msg(&mut self, handlers: impl Fn(PublicAddress, Message) + Send + 'static) -> &mut Self {
self.handlers = Some(Box::new(handlers));
self
}


pub async fn start(self) -> Peer {
crate::engine::start(self).await.unwrap()
}
Expand Down Expand Up @@ -76,6 +75,12 @@ impl Peer {
}
}

impl Drop for Peer {
fn drop(&mut self) {
let _ = self.to_engine.try_send(EngineCommand::Shutdown);
}
}

pub(crate) enum EngineCommand {
Publish(Topic, Message),
Shutdown,
Expand Down