Skip to content

Commit 75c70eb

Browse files
committed
give the protocol handler access to the peer info
1 parent 88605b0 commit 75c70eb

File tree

8 files changed

+174
-78
lines changed

8 files changed

+174
-78
lines changed

Cargo.lock

Lines changed: 47 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ thread_local = { version = "1.1.8", default-features = false }
8181
tokio-util = { version = "0.7.12", default-features = false }
8282
tokio-stream = { version = "0.1.16", default-features = false }
8383
tokio = { version = "1.40.0", default-features = false }
84-
tower = { version = "0.4.13", default-features = false }
84+
tower = { git = "https://github.com/Boog900/tower.git", rev = "6c7faf0", default-features = false }
8585
tracing-subscriber = { version = "0.3.18", default-features = false }
8686
tracing = { version = "0.1.40", default-features = false }
8787

p2p/p2p-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tokio-util = { workspace = true, features = ["codec"] }
1919
tokio-stream = { workspace = true, features = ["sync"]}
2020
futures = { workspace = true, features = ["std"] }
2121
async-trait = { workspace = true }
22-
tower = { workspace = true, features = ["util", "tracing"] }
22+
tower = { workspace = true, features = ["util", "tracing", "make"] }
2323

2424
cfg-if = { workspace = true }
2525
thiserror = { workspace = true }

p2p/p2p-core/src/client/connector.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ use std::{
1212

1313
use futures::{FutureExt, Stream};
1414
use tokio::sync::OwnedSemaphorePermit;
15-
use tower::{Service, ServiceExt};
15+
use tower::{MakeService, Service, ServiceExt};
1616

17+
use crate::client::PeerInformation;
1718
use crate::{
1819
client::{handshaker::HandShaker, Client, DoHandshakeRequest, HandshakeError, InternalPeerID},
1920
AddressBook, BroadcastMessage, ConnectionDirection, CoreSyncSvc, NetworkZone, PeerSyncSvc,
20-
ProtocolRequestHandler,
21+
ProtocolRequest, ProtocolRequestHandler, ProtocolResponse,
2122
};
2223

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

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

39-
impl<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr>
40-
Connector<Z, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr>
40+
impl<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr>
41+
Connector<Z, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr>
4142
{
4243
/// Create a new connector from a handshaker.
4344
pub const fn new(
44-
handshaker: HandShaker<Z, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr>,
45+
handshaker: HandShaker<Z, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr>,
4546
) -> Self {
4647
Self { handshaker }
4748
}
4849
}
4950

50-
impl<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr, BrdcstStrm>
51-
Service<ConnectRequest<Z>> for Connector<Z, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr>
51+
impl<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr, BrdcstStrm>
52+
Service<ConnectRequest<Z>> for Connector<Z, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstStrmMkr>
5253
where
5354
AdrBook: AddressBook<Z> + Clone,
5455
CSync: CoreSyncSvc + Clone,
5556
PSync: PeerSyncSvc<Z> + Clone,
56-
ProtoHdlr: ProtocolRequestHandler + Clone,
57+
ProtoHdlrMkr: MakeService<
58+
PeerInformation<Z::Addr>,
59+
ProtocolRequest,
60+
MakeError = tower::BoxError,
61+
Service: ProtocolRequestHandler,
62+
Future: Send + 'static,
63+
> + Clone
64+
+ Send
65+
+ 'static,
5766
BrdcstStrm: Stream<Item = BroadcastMessage> + Send + 'static,
5867
BrdcstStrmMkr: Fn(InternalPeerID<Z::Addr>) -> BrdcstStrm + Clone + Send + 'static,
5968
{

0 commit comments

Comments
 (0)