Skip to content

Commit 3f30ae3

Browse files
committed
add trait alias
1 parent 75c70eb commit 3f30ae3

File tree

7 files changed

+76
-105
lines changed

7 files changed

+76
-105
lines changed

Cargo.lock

Lines changed: 5 additions & 5 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 = { git = "https://github.com/Boog900/tower.git", rev = "6c7faf0", default-features = false }
84+
tower = { git = "https://github.com/Cuprate/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/src/client/connector.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ use futures::{FutureExt, Stream};
1414
use tokio::sync::OwnedSemaphorePermit;
1515
use tower::{MakeService, Service, ServiceExt};
1616

17-
use crate::client::PeerInformation;
1817
use crate::{
19-
client::{handshaker::HandShaker, Client, DoHandshakeRequest, HandshakeError, InternalPeerID},
18+
client::{
19+
handshaker::HandShaker, Client, DoHandshakeRequest, HandshakeError, InternalPeerID,
20+
PeerInformation,
21+
},
2022
AddressBook, BroadcastMessage, ConnectionDirection, CoreSyncSvc, NetworkZone, PeerSyncSvc,
21-
ProtocolRequest, ProtocolRequestHandler, ProtocolResponse,
23+
ProtocolRequest, ProtocolRequestHandler, ProtocolRequestHandlerMaker, ProtocolResponse,
2224
};
2325

2426
/// A request to connect to a peer.
@@ -54,15 +56,7 @@ where
5456
AdrBook: AddressBook<Z> + Clone,
5557
CSync: CoreSyncSvc + Clone,
5658
PSync: PeerSyncSvc<Z> + 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,
59+
ProtoHdlrMkr: ProtocolRequestHandlerMaker<Z> + Clone,
6660
BrdcstStrm: Stream<Item = BroadcastMessage> + Send + 'static,
6761
BrdcstStrmMkr: Fn(InternalPeerID<Z::Addr>) -> BrdcstStrm + Clone + Send + 'static,
6862
{

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tokio::{
1717
sync::{mpsc, OwnedSemaphorePermit, Semaphore},
1818
time::{error::Elapsed, timeout},
1919
};
20-
use tower::{MakeService, Service, ServiceExt};
20+
use tower::{Service, ServiceExt};
2121
use tracing::{info_span, Instrument, Span};
2222

2323
use cuprate_pruning::{PruningError, PruningSeed};
@@ -43,7 +43,7 @@ use crate::{
4343
services::PeerSyncRequest,
4444
AddressBook, AddressBookRequest, AddressBookResponse, BroadcastMessage, ConnectionDirection,
4545
CoreSyncDataRequest, CoreSyncDataResponse, CoreSyncSvc, NetZoneAddress, NetworkZone,
46-
PeerSyncSvc, ProtocolRequest, ProtocolRequestHandler, SharedError,
46+
PeerSyncSvc, ProtocolRequest, ProtocolRequestHandler, ProtocolRequestHandlerMaker, SharedError,
4747
};
4848

4949
pub mod builder;
@@ -142,15 +142,7 @@ where
142142
AdrBook: AddressBook<Z> + Clone,
143143
CSync: CoreSyncSvc + Clone,
144144
PSync: PeerSyncSvc<Z> + Clone,
145-
ProtoHdlrMkr: MakeService<
146-
PeerInformation<Z::Addr>,
147-
ProtocolRequest,
148-
MakeError = tower::BoxError,
149-
Service: ProtocolRequestHandler,
150-
Future: Send + 'static,
151-
> + Clone
152-
+ Send
153-
+ 'static,
145+
ProtoHdlrMkr: ProtocolRequestHandlerMaker<Z> + Clone,
154146
BrdcstStrm: Stream<Item = BroadcastMessage> + Send + 'static,
155147
BrdcstStrmMkr: Fn(InternalPeerID<Z::Addr>) -> BrdcstStrm + Clone + Send + 'static,
156148
{
@@ -254,16 +246,9 @@ async fn handshake<Z: NetworkZone, AdrBook, CSync, PSync, ProtoHdlrMkr, BrdcstSt
254246
) -> Result<Client<Z>, HandshakeError>
255247
where
256248
AdrBook: AddressBook<Z> + Clone,
257-
CSync: CoreSyncSvc + Clone,
258-
PSync: PeerSyncSvc<Z> + Clone,
259-
ProtoHdlrMkr: MakeService<
260-
PeerInformation<Z::Addr>,
261-
ProtocolRequest,
262-
MakeError = tower::BoxError,
263-
Service: ProtocolRequestHandler,
264-
Future: Send + 'static,
265-
> + Send
266-
+ 'static,
249+
CSync: CoreSyncSvc+ Clone,
250+
PSync: PeerSyncSvc<Z>+ Clone,
251+
ProtoHdlrMkr: ProtocolRequestHandlerMaker<Z>,
267252
BrdcstStrm: Stream<Item = BroadcastMessage> + Send + 'static,
268253
BrdcstStrmMkr: Fn(InternalPeerID<Z::Addr>) -> BrdcstStrm + Send + 'static,
269254
{

p2p/p2p-core/src/client/handshaker/builder.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use cuprate_wire::BasicNodeData;
99
use crate::{
1010
client::{handshaker::HandShaker, InternalPeerID, PeerInformation},
1111
AddressBook, BroadcastMessage, CoreSyncSvc, NetworkZone, PeerSyncSvc, ProtocolRequest,
12-
ProtocolRequestHandler,
12+
ProtocolRequestHandler, ProtocolRequestHandlerMaker,
1313
};
1414

1515
mod dummy;
@@ -203,15 +203,7 @@ impl<N: NetworkZone, AdrBook, CSync, PSync, ProtoHdlr, BrdcstStrmMkr>
203203
new_protocol_request_svc_maker: NProtoHdlrMkr,
204204
) -> HandshakerBuilder<N, AdrBook, CSync, PSync, NProtoHdlrMkr, BrdcstStrmMkr>
205205
where
206-
NProtoHdlrMkr: MakeService<
207-
PeerInformation<N::Addr>,
208-
ProtocolRequest,
209-
MakeError = tower::BoxError,
210-
Service: ProtocolRequestHandler,
211-
Future: Send + 'static,
212-
> + Clone
213-
+ Send
214-
+ 'static,
206+
NProtoHdlrMkr: ProtocolRequestHandlerMaker<N> + Clone,
215207
{
216208
let Self {
217209
address_book,

p2p/p2p-core/src/lib.rs

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -197,99 +197,109 @@ pub trait PeerSyncSvc<Z: NetworkZone>:
197197
PeerSyncRequest<Z>,
198198
Response = PeerSyncResponse<Z>,
199199
Error = tower::BoxError,
200-
Future = Self::Future2,
200+
Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
201201
> + Send
202202
+ 'static
203203
{
204-
// This allows us to put more restrictive bounds on the future without defining the future here
205-
// explicitly.
206-
type Future2: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static;
207204
}
208205

209-
impl<T, Z: NetworkZone> PeerSyncSvc<Z> for T
210-
where
211-
T: tower::Service<PeerSyncRequest<Z>, Response = PeerSyncResponse<Z>, Error = tower::BoxError>
212-
+ Send
213-
+ 'static,
214-
T::Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
206+
impl<T, Z: NetworkZone> PeerSyncSvc<Z> for T where
207+
T: tower::Service<
208+
PeerSyncRequest<Z>,
209+
Response = PeerSyncResponse<Z>,
210+
Error = tower::BoxError,
211+
Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
212+
> + Send
213+
+ 'static
215214
{
216-
type Future2 = T::Future;
217215
}
218216

219217
pub trait AddressBook<Z: NetworkZone>:
220218
tower::Service<
221219
AddressBookRequest<Z>,
222220
Response = AddressBookResponse<Z>,
223221
Error = tower::BoxError,
224-
Future = Self::Future2,
222+
Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
225223
> + Send
226224
+ 'static
227225
{
228-
// This allows us to put more restrictive bounds on the future without defining the future here
229-
// explicitly.
230-
type Future2: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static;
231226
}
232227

233-
impl<T, Z: NetworkZone> AddressBook<Z> for T
234-
where
228+
impl<T, Z: NetworkZone> AddressBook<Z> for T where
235229
T: tower::Service<
236230
AddressBookRequest<Z>,
237231
Response = AddressBookResponse<Z>,
238232
Error = tower::BoxError,
233+
Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
239234
> + Send
240-
+ 'static,
241-
T::Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
235+
+ 'static
242236
{
243-
type Future2 = T::Future;
244237
}
245238

246239
pub trait CoreSyncSvc:
247240
tower::Service<
248241
CoreSyncDataRequest,
249242
Response = CoreSyncDataResponse,
250243
Error = tower::BoxError,
251-
Future = Self::Future2,
244+
Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
252245
> + Send
253246
+ 'static
254247
{
255-
// This allows us to put more restrictive bounds on the future without defining the future here
256-
// explicitly.
257-
type Future2: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static;
258248
}
259249

260-
impl<T> CoreSyncSvc for T
261-
where
250+
impl<T> CoreSyncSvc for T where
262251
T: tower::Service<
263252
CoreSyncDataRequest,
264253
Response = CoreSyncDataResponse,
265254
Error = tower::BoxError,
255+
Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
266256
> + Send
267-
+ 'static,
268-
T::Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
257+
+ 'static
269258
{
270-
type Future2 = T::Future;
271259
}
272260

273261
pub trait ProtocolRequestHandler:
274262
tower::Service<
275263
ProtocolRequest,
276264
Response = ProtocolResponse,
277265
Error = tower::BoxError,
278-
Future = Self::Future2,
266+
Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
279267
> + Send
280268
+ 'static
281269
{
282-
// This allows us to put more restrictive bounds on the future without defining the future here
283-
// explicitly.
284-
type Future2: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static;
285270
}
286271

287-
impl<T> ProtocolRequestHandler for T
288-
where
289-
T: tower::Service<ProtocolRequest, Response = ProtocolResponse, Error = tower::BoxError>
290-
+ Send
291-
+ 'static,
292-
T::Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
272+
impl<T> ProtocolRequestHandler for T where
273+
T: tower::Service<
274+
ProtocolRequest,
275+
Response = ProtocolResponse,
276+
Error = tower::BoxError,
277+
Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
278+
> + Send
279+
+ 'static
280+
{
281+
}
282+
283+
pub trait ProtocolRequestHandlerMaker<Z: NetworkZone>:
284+
tower::MakeService<
285+
client::PeerInformation<Z::Addr>,
286+
ProtocolRequest,
287+
MakeError = tower::BoxError,
288+
Service: ProtocolRequestHandler,
289+
Future: Send + 'static,
290+
> + Send
291+
+ 'static
292+
{
293+
}
294+
295+
impl<T, Z: NetworkZone> ProtocolRequestHandlerMaker<Z> for T where
296+
T: tower::MakeService<
297+
client::PeerInformation<Z::Addr>,
298+
ProtocolRequest,
299+
MakeError = tower::BoxError,
300+
Service: ProtocolRequestHandler,
301+
Future: Send + 'static,
302+
> + Send
303+
+ 'static
293304
{
294-
type Future2 = T::Future;
295305
}

p2p/p2p/src/lib.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ use tower::{buffer::Buffer, util::BoxCloneService, MakeService, Service, Service
1414
use tracing::{instrument, Instrument, Span};
1515

1616
use cuprate_async_buffer::BufferStream;
17-
use cuprate_p2p_core::{
18-
client::Connector,
19-
client::InternalPeerID,
20-
services::{AddressBookRequest, AddressBookResponse, PeerSyncRequest},
21-
CoreSyncSvc, NetworkZone, ProtocolRequest, ProtocolRequestHandler,
22-
};
17+
use cuprate_p2p_core::{client::Connector, client::InternalPeerID, services::{AddressBookRequest, AddressBookResponse, PeerSyncRequest}, CoreSyncSvc, NetworkZone, ProtocolRequest, ProtocolRequestHandler, ProtocolRequestHandlerMaker};
2318

2419
mod block_downloader;
2520
mod broadcast;
@@ -54,15 +49,7 @@ pub async fn initialize_network<N, PR, CS>(
5449
where
5550
N: NetworkZone,
5651
N::Addr: borsh::BorshDeserialize + borsh::BorshSerialize,
57-
PR: MakeService<
58-
PeerInformation<N::Addr>,
59-
ProtocolRequest,
60-
MakeError = tower::BoxError,
61-
Service: ProtocolRequestHandler,
62-
Future: Send + 'static,
63-
> + Clone
64-
+ Send
65-
+ 'static,
52+
PR: ProtocolRequestHandlerMaker<N> + Clone,
6653
CS: CoreSyncSvc + Clone,
6754
{
6855
let address_book =
@@ -169,7 +156,10 @@ pub struct NetworkInterface<N: NetworkZone> {
169156
/// The address book service.
170157
address_book: BoxCloneService<AddressBookRequest<N>, AddressBookResponse<N>, tower::BoxError>,
171158
/// The peer's sync states service.
172-
sync_states_svc: Buffer<PeerSyncRequest<N>, <sync_states::PeerSyncSvc<N> as Service<PeerSyncRequest<N>>>::Future>,
159+
sync_states_svc: Buffer<
160+
PeerSyncRequest<N>,
161+
<sync_states::PeerSyncSvc<N> as Service<PeerSyncRequest<N>>>::Future,
162+
>,
173163
/// Background tasks that will be aborted when this interface is dropped.
174164
_background_tasks: Arc<JoinSet<()>>,
175165
}

0 commit comments

Comments
 (0)