cuprated/txpool/dandelion/
diffuse_service.rs
1use std::{
2 future::{ready, Ready},
3 task::{Context, Poll},
4};
5
6use futures::FutureExt;
7use tower::Service;
8
9use cuprate_dandelion_tower::traits::DiffuseRequest;
10use cuprate_p2p::{BroadcastRequest, BroadcastSvc};
11use cuprate_p2p_core::ClearNet;
12
13use crate::txpool::dandelion::DandelionTx;
14
15pub struct DiffuseService {
17 pub clear_net_broadcast_service: BroadcastSvc<ClearNet>,
18}
19
20impl Service<DiffuseRequest<DandelionTx>> for DiffuseService {
21 type Response = ();
22 type Error = tower::BoxError;
23 type Future = Ready<Result<Self::Response, Self::Error>>;
24
25 fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
26 self.clear_net_broadcast_service
27 .poll_ready(cx)
28 .map_err(Into::into)
29 }
30
31 fn call(&mut self, req: DiffuseRequest<DandelionTx>) -> Self::Future {
32 let Ok(()) = self
34 .clear_net_broadcast_service
35 .call(BroadcastRequest::Transaction {
36 tx_bytes: req.0 .0,
37 direction: None,
38 received_from: None,
39 })
40 .into_inner();
41
42 ready(Ok(()))
43 }
44}