Skip to content
Merged
Changes from all commits
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
20 changes: 11 additions & 9 deletions crates/dkg/examples/bcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ use pluto_p2p::{
config::P2PConfig,
gater, k1,
p2p::{Node, NodeType},
p2p_context::P2PContext,
relay::{MutableRelayReservation, RelayRouter},
};
use pluto_tracing::TracingConfig;
Expand Down Expand Up @@ -578,23 +577,21 @@ async fn main() -> Result<()> {
disable_reuse_port: args.disable_reuse_port,
};

let p2p_context = P2PContext::new(known_peers.clone());
let (bcast_behaviour, component) =
bcast::Behaviour::new(cluster_peers.clone(), p2p_context.clone(), key.clone());
register_message(&component, local_node_number)
.await
.expect("Failed to register demo bcast message");

let mut component = None;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This handle approach is similar to what we have in parsigex: #291 (comment).

The design is very cumbersome to use so it requires some further work.

let mut node: Node<ExampleBehaviour> = Node::new(
p2p_config,
key,
key.clone(),
NodeType::QUIC,
args.filter_private_addrs,
known_peers,
|builder, keypair, relay_client| {
let p2p_context = builder.p2p_context();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can you try to remove this and use the outer p2p_context, that will be cleaner without having the mut component

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We can, I was just following the patterns that we already have in bootnode and parsigex:

let mut node: Node<ExampleBehaviour> = Node::new(
p2p_config,
pk,
NodeType::QUIC,
false,
known_peers.clone(),
|builder, keypair, relay_client| {
let p2p_context = builder.p2p_context();
let local_peer_id = keypair.public().to_peer_id();
// Create identify config
let identify_config =
identify::Config::new("/charon/1.0.0".to_string(), keypair.public());
builder.with_gater(conn_gater).with_inner(ExampleBehaviour {
relay: relay_client,
relay_reservation: MutableRelayReservation::new(relays.clone()),
relay_router: RelayRouter::new(relays.clone(), p2p_context, local_peer_id),
identify: identify::Behaviour::new(identify_config),
ping: ping::Behaviour::new(ping::Config::new()),
})
},
)?;

let mut parsigex_handle: Option<Handle> = None;
let mut node: Node<CombinedBehaviour> = Node::new(
p2p_config,
key,
NodeType::QUIC,
args.filter_private_addrs,
known_peers.clone(),
|builder, keypair, relay_client| {
let p2p_context = builder.p2p_context();
let local_peer_id = keypair.public().to_peer_id();
let config = parsigex::Config::new(
local_peer_id,
p2p_context.clone(),
verifier.clone(),
duty_gater.clone(),
)
.with_timeout(Duration::from_secs(10));
let (parsigex, handle) = parsigex::Behaviour::new(config);
parsigex_handle = Some(handle);
builder
.with_gater(conn_gater)
.with_inner(CombinedBehaviour {
parsigex,
relay: relay_client,
relay_reservation: MutableRelayReservation::new(relays.clone()),
relay_router: RelayRouter::new(relays.clone(), p2p_context, local_peer_id),
})
},
)?;
let parsigex_handle =
parsigex_handle.ok_or_else(|| anyhow!("parsigex handle should be created"))?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we will revisit these examples to see if we can have a cleaner approach. LGTM now

let local_peer_id = keypair.public().to_peer_id();

let (bcast_behaviour, c) =
bcast::Behaviour::new(cluster_peers.clone(), p2p_context.clone(), key.clone());
component = Some(c);

builder
.with_p2p_context(p2p_context.clone())
.with_gater(conn_gater)
Expand All @@ -607,6 +604,11 @@ async fn main() -> Result<()> {
},
)?;

let component = component.expect("BCast component was not initialized");
register_message(&component, local_node_number)
.await
.expect("Failed to register demo bcast message");

info!(
local_peer_id = %local_peer_id,
local_node = local_node_number,
Expand Down
Loading