Skip to content

Commit

Permalink
refactor!: Remove QuicP2p
Browse files Browse the repository at this point in the history
Now that `Endpoint` has public constructors, there's no need for the
`QuicP2p` interface. This also removes a decent chunk of code from
`Endpoint` itself.

This leaves behind some redundant `Error` variants, but the intention is
to remove that whole type soon.

BREAKING CHANGE: The `QuicP2p` type has been removed. Use
`Endpoint::new` or `Endpoint::new_client` instead. The
`BootstrapFailure`, `EmptyBootstrapNodesList`, `Io`, `Endpoint`,
`NoEchoServerEndpointDefined`, `EchoServiceFailure`, `CannotAssignPort`,
`IncorrectPublicAddress`, and `UnresolvedPublicIp` `Error` variants have
been removed.
  • Loading branch information
Chris Connelly authored and connec committed Aug 27, 2021
1 parent c448df2 commit 44d964c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 478 deletions.
20 changes: 11 additions & 9 deletions examples/p2p_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use bytes::Bytes;
use color_eyre::eyre::Result;
use qp2p::{Config, ConnId, QuicP2p};
use qp2p::{Config, ConnId, Endpoint};
use std::{
env,
net::{Ipv4Addr, SocketAddr},
Expand All @@ -40,15 +40,17 @@ async fn main() -> Result<()> {
// collect cli args
let args: Vec<String> = env::args().collect();

// instantiate QuicP2p with custom config
let qp2p: QuicP2p<XId> = QuicP2p::with_config(Config {
idle_timeout: Duration::from_secs(60 * 60).into(), // 1 hour idle timeout.
..Default::default()
})?;

// create an endpoint for us to listen on and send from.
let (node, _incoming_conns, mut incoming_messages, _disconnections) =
qp2p.new_endpoint((Ipv4Addr::LOCALHOST, 0).into()).await?;
let (node, _incoming_conns, mut incoming_messages, _disconnections, _contact) =
Endpoint::<XId>::new(
SocketAddr::from((Ipv4Addr::LOCALHOST, 0)),
&[],
Config {
idle_timeout: Duration::from_secs(60 * 60).into(), // 1 hour idle timeout.
..Default::default()
},
)
.await?;

// if we received args then we parse them as SocketAddr and send a "marco" msg to each peer.
if args.len() > 1 {
Expand Down
210 changes: 0 additions & 210 deletions src/api.rs

This file was deleted.

9 changes: 3 additions & 6 deletions src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,19 +425,16 @@ async fn handle_endpoint_verification_req<I: ConnId>(

#[cfg(test)]
mod tests {
use crate::api::QuicP2p;
use crate::{config::Config, tests::local_addr, wire_msg::WireMsg};
use crate::{tests::new_endpoint, wire_msg::WireMsg};
use color_eyre::eyre::{eyre, Result};

#[tokio::test(flavor = "multi_thread")]
async fn echo_service() -> Result<()> {
let qp2p = QuicP2p::<[u8; 32]>::with_config(Config::default())?;

// Create Endpoint
let (peer1, mut peer1_connections, _, _) = qp2p.new_endpoint(local_addr()).await?;
let (peer1, mut peer1_connections, _, _, _) = new_endpoint().await?;
let peer1_addr = peer1.public_addr();

let (peer2, _, _, _) = qp2p.new_endpoint(local_addr()).await?;
let (peer2, _, _, _, _) = new_endpoint().await?;
let peer2_addr = peer2.public_addr();

let _ = peer2.get_or_connect_to(&peer1_addr).await?;
Expand Down
Loading

0 comments on commit 44d964c

Please sign in to comment.