Skip to content

Commit

Permalink
give the protocol handler access to the peer info
Browse files Browse the repository at this point in the history
  • Loading branch information
Boog900 committed Sep 27, 2024
1 parent 88605b0 commit 75c70eb
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 78 deletions.
69 changes: 47 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ thread_local = { version = "1.1.8", default-features = false }
tokio-util = { version = "0.7.12", default-features = false }
tokio-stream = { version = "0.1.16", default-features = false }
tokio = { version = "1.40.0", default-features = false }
tower = { version = "0.4.13", default-features = false }
tower = { git = "https://github.com/Boog900/tower.git", rev = "6c7faf0", default-features = false }
tracing-subscriber = { version = "0.3.18", default-features = false }
tracing = { version = "0.1.40", default-features = false }

Expand Down
2 changes: 1 addition & 1 deletion p2p/p2p-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tokio-util = { workspace = true, features = ["codec"] }
tokio-stream = { workspace = true, features = ["sync"]}
futures = { workspace = true, features = ["std"] }
async-trait = { workspace = true }
tower = { workspace = true, features = ["util", "tracing"] }
tower = { workspace = true, features = ["util", "tracing", "make"] }

cfg-if = { workspace = true }
thiserror = { workspace = true }
Expand Down
29 changes: 19 additions & 10 deletions p2p/p2p-core/src/client/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ use std::{

use futures::{FutureExt, Stream};
use tokio::sync::OwnedSemaphorePermit;
use tower::{Service, ServiceExt};
use tower::{MakeService, Service, ServiceExt};

use crate::client::PeerInformation;
use crate::{
client::{handshaker::HandShaker, Client, DoHandshakeRequest, HandshakeError, InternalPeerID},
AddressBook, BroadcastMessage, ConnectionDirection, CoreSyncSvc, NetworkZone, PeerSyncSvc,
ProtocolRequestHandler,
ProtocolRequest, ProtocolRequestHandler, ProtocolResponse,
};

/// A request to connect to a peer.
Expand All @@ -32,28 +33,36 @@ pub struct ConnectRequest<Z: NetworkZone> {
}

/// The connector service, this service connects to peer and returns the [`Client`].
pub struct Connector<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr> {
handshaker: HandShaker<Z, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr>,
pub struct Connector<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr> {
handshaker: HandShaker<Z, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr>,
}

impl<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr>
Connector<Z, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr>
impl<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr>
Connector<Z, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr>
{
/// Create a new connector from a handshaker.
pub const fn new(
handshaker: HandShaker<Z, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr>,
handshaker: HandShaker<Z, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr>,
) -> Self {
Self { handshaker }
}
}

impl<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr, BrdcstStrm>
Service<ConnectRequest<Z>> for Connector<Z, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr>
impl<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr, BrdcstStrm>
Service<ConnectRequest<Z>> for Connector<Z, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr>
where
AdrBook: AddressBook<Z> + Clone,
CSync: CoreSyncSvc + Clone,
PSync: PeerSyncSvc<Z> + Clone,
ProtoHdlr: ProtocolRequestHandler + Clone,
ProtoHdlrMkr: MakeService<
PeerInformation<Z::Addr>,
ProtocolRequest,
MakeError = tower::BoxError,
Service: ProtocolRequestHandler,
Future: Send + 'static,
> + Clone
+ Send
+ 'static,
BrdcstStrm: Stream<Item = BroadcastMessage> + Send + 'static,
BrdcstStrmMkr: Fn(InternalPeerID<Z::Addr>) -> BrdcstStrm + Clone + Send + 'static,
{
Expand Down
Loading

0 comments on commit 75c70eb

Please sign in to comment.