Skip to content

Commit dbceffd

Browse files
authored
refactor(ipc): simplify RpcServiceCfg from enum to struct (#19180)
1 parent 936baf1 commit dbceffd

File tree

2 files changed

+11
-34
lines changed

2 files changed

+11
-34
lines changed

crates/rpc/ipc/src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ where
391391
fn call(&mut self, request: String) -> Self::Future {
392392
trace!("{:?}", request);
393393

394-
let cfg = RpcServiceCfg::CallsAndSubscriptions {
394+
let cfg = RpcServiceCfg {
395395
bounded_subscriptions: BoundedSubscriptions::new(
396396
self.inner.server_cfg.max_subscriptions_per_connection,
397397
),

crates/rpc/ipc/src/server/rpc_service.rs

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,11 @@ pub struct RpcService {
2525
}
2626

2727
/// Configuration of the `RpcService`.
28-
#[allow(dead_code)]
2928
#[derive(Clone, Debug)]
30-
pub(crate) enum RpcServiceCfg {
31-
/// The server supports only calls.
32-
OnlyCalls,
33-
/// The server supports both method calls and subscriptions.
34-
CallsAndSubscriptions {
35-
bounded_subscriptions: BoundedSubscriptions,
36-
sink: MethodSink,
37-
id_provider: Arc<dyn IdProvider>,
38-
},
29+
pub(crate) struct RpcServiceCfg {
30+
pub(crate) bounded_subscriptions: BoundedSubscriptions,
31+
pub(crate) sink: MethodSink,
32+
pub(crate) id_provider: Arc<dyn IdProvider>,
3933
}
4034

4135
impl RpcService {
@@ -82,30 +76,20 @@ impl RpcServiceT for RpcService {
8276
ResponseFuture::future(fut)
8377
}
8478
MethodCallback::Subscription(callback) => {
85-
let RpcServiceCfg::CallsAndSubscriptions {
86-
bounded_subscriptions,
87-
sink,
88-
id_provider,
89-
} = &self.cfg
90-
else {
91-
tracing::warn!(id = ?id, method = %name, "Attempted subscription on a service not configured for subscriptions.");
92-
let rp =
93-
MethodResponse::error(id, ErrorObject::from(ErrorCode::InternalError));
94-
return ResponseFuture::ready(rp);
95-
};
96-
97-
if let Some(p) = bounded_subscriptions.acquire() {
79+
let cfg = &self.cfg;
80+
81+
if let Some(p) = cfg.bounded_subscriptions.acquire() {
9882
let conn_state = SubscriptionState {
9983
conn_id,
100-
id_provider: &**id_provider,
84+
id_provider: &*cfg.id_provider,
10185
subscription_permit: p,
10286
};
10387

10488
let fut =
105-
callback(id.clone(), params, sink.clone(), conn_state, extensions);
89+
callback(id.clone(), params, cfg.sink.clone(), conn_state, extensions);
10690
ResponseFuture::future(fut)
10791
} else {
108-
let max = bounded_subscriptions.max();
92+
let max = cfg.bounded_subscriptions.max();
10993
let rp = MethodResponse::error(id, reject_too_many_subscriptions(max));
11094
ResponseFuture::ready(rp)
11195
}
@@ -114,13 +98,6 @@ impl RpcServiceT for RpcService {
11498
// Don't adhere to any resource or subscription limits; always let unsubscribing
11599
// happen!
116100

117-
let RpcServiceCfg::CallsAndSubscriptions { .. } = self.cfg else {
118-
tracing::warn!(id = ?id, method = %name, "Attempted unsubscription on a service not configured for subscriptions.");
119-
let rp =
120-
MethodResponse::error(id, ErrorObject::from(ErrorCode::InternalError));
121-
return ResponseFuture::ready(rp);
122-
};
123-
124101
let rp = callback(id, params, conn_id, max_response_body_size, extensions);
125102
ResponseFuture::ready(rp)
126103
}

0 commit comments

Comments
 (0)