Skip to content

Commit c24fe9f

Browse files
committed
remove the ProxyInner trait
1 parent ffeb1a9 commit c24fe9f

File tree

10 files changed

+133
-111
lines changed

10 files changed

+133
-111
lines changed

crates/rproxy/src/server.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::{
2020
server::{
2121
metrics::Metrics,
2222
proxy::{
23-
ProxyInner,
2423
circuit_breaker::CircuitBreaker,
2524
config::{ConfigAuthrpc, ConfigFlashblocks, ConfigRpc},
2625
http::{ProxyHttp, ProxyHttpInnerAuthrpc, ProxyHttpInnerRpc},
@@ -102,14 +101,15 @@ impl Server {
102101
config,
103102
tls,
104103
metrics,
104+
"rproxy-authrpc",
105105
canceller.clone(),
106106
resetter,
107107
)
108108
.instrument(info_span!("proxy_name", proxy = "rproxy-authrpc"))
109109
.await
110110
.inspect_err(|err| {
111111
error!(
112-
proxy = ProxyHttpInnerRpc::name(),
112+
proxy = "rproxy-authrpc",
113113
error = ?err,
114114
"Failed to start http-proxy, terminating...",
115115
);
@@ -131,14 +131,15 @@ impl Server {
131131
config,
132132
tls,
133133
metrics,
134+
"rproxy-rpc",
134135
canceller.clone(),
135136
resetter,
136137
)
137138
.instrument(info_span!("proxy_name", proxy = "rproxy-rpc"))
138139
.await
139140
.inspect_err(|err| {
140141
error!(
141-
proxy = ProxyHttpInnerRpc::name(),
142+
proxy = "rproxy-rpc",
142143
error = ?err,
143144
"Failed to start http-proxy, terminating...",
144145
);
@@ -160,14 +161,15 @@ impl Server {
160161
config,
161162
tls,
162163
metrics,
164+
"rproxy-flashblocks",
163165
canceller.clone(),
164166
resetter,
165167
)
166168
.instrument(info_span!("proxy_name", proxy = "rproxy-flashblocks"))
167169
.await
168170
.inspect_err(|err| {
169171
error!(
170-
proxy = ProxyHttpInnerRpc::name(),
172+
proxy = "rproxy-flashblocks",
171173
error = ?err,
172174
"Failed to start websocket-proxy, terminating...",
173175
);

crates/rproxy/src/server/metrics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,29 +368,29 @@ impl Metrics {
368368

369369
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, EncodeLabelSet)]
370370
pub(crate) struct LabelsProxy {
371-
pub(crate) proxy: &'static str,
371+
pub(crate) proxy: String,
372372
}
373373

374374
// LabelsProxyClientInfo -----------------------------------------------
375375

376376
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, EncodeLabelSet)]
377377
pub(crate) struct LabelsProxyClientInfo {
378-
pub(crate) proxy: &'static str,
378+
pub(crate) proxy: String,
379379
pub(crate) user_agent: String,
380380
}
381381

382382
// LabelsProxyHttpJrpc -------------------------------------------------
383383

384384
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, EncodeLabelSet)]
385385
pub(crate) struct LabelsProxyHttpJrpc {
386-
pub(crate) proxy: &'static str,
386+
pub(crate) proxy: String,
387387
pub(crate) jrpc_method: Cow<'static, str>,
388388
}
389389

390390
// LabelsProxyWs -------------------------------------------------------
391391

392392
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, EncodeLabelSet)]
393393
pub(crate) struct LabelsProxyWs {
394-
pub(crate) proxy: &'static str,
394+
pub(crate) proxy: String,
395395
pub(crate) destination: &'static str,
396396
}

crates/rproxy/src/server/proxy.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@ use crate::server::metrics::{LabelsProxy, Metrics};
2121

2222
// Proxy ---------------------------------------------------------------
2323

24-
pub(crate) trait Proxy<P>
25-
where
26-
P: ProxyInner,
27-
{
24+
pub(crate) trait Proxy {
2825
fn on_connect(
2926
metrics: Arc<Metrics>,
3027
client_connections_count: Arc<AtomicI64>,
28+
proxy_name: String,
3129
) -> impl Fn(&dyn Any, &mut Extensions) {
3230
move |connection, extensions| {
3331
{
3432
let val = client_connections_count.fetch_add(1, Ordering::Relaxed) + 1;
35-
let metric_labels = LabelsProxy { proxy: P::name() };
33+
let metric_labels = LabelsProxy { proxy: proxy_name.clone() };
3634

3735
metrics.client_connections_active_count.get_or_create(&metric_labels).set(val);
3836
metrics.client_connections_established_count.get_or_create(&metric_labels).inc();
@@ -75,7 +73,7 @@ where
7573

7674
extensions.insert(ProxyConnectionGuard::new(
7775
id,
78-
P::name(),
76+
&proxy_name,
7977
remote_addr,
8078
local_addr,
8179
&metrics,
@@ -86,28 +84,22 @@ where
8684
}
8785
}
8886

89-
// ProxyInner ----------------------------------------------------------
90-
91-
pub(crate) trait ProxyInner: 'static {
92-
fn name() -> &'static str;
93-
}
94-
9587
// ProxyConnectionGuard ------------------------------------------------
9688

9789
pub struct ProxyConnectionGuard {
9890
pub id: Uuid,
9991
pub remote_addr: Option<String>,
10092
pub local_addr: Option<String>,
10193

102-
proxy_name: &'static str,
94+
proxy_name: String,
10395
metrics: Arc<Metrics>,
10496
client_connections_count: Arc<AtomicI64>,
10597
}
10698

10799
impl ProxyConnectionGuard {
108100
fn new(
109101
id: Uuid,
110-
proxy_name: &'static str,
102+
proxy_name: &str,
111103
remote_addr: Option<String>,
112104
local_addr: Option<String>,
113105
metrics: &Arc<Metrics>,
@@ -117,7 +109,7 @@ impl ProxyConnectionGuard {
117109
id,
118110
remote_addr,
119111
local_addr,
120-
proxy_name,
112+
proxy_name: proxy_name.to_string(),
121113
metrics: metrics.clone(),
122114
client_connections_count,
123115
}
@@ -128,7 +120,7 @@ impl Drop for ProxyConnectionGuard {
128120
fn drop(&mut self) {
129121
let val = self.client_connections_count.fetch_sub(1, Ordering::Relaxed) - 1;
130122

131-
let metric_labels = LabelsProxy { proxy: self.proxy_name };
123+
let metric_labels = LabelsProxy { proxy: self.proxy_name.clone() };
132124

133125
self.metrics.client_connections_active_count.get_or_create(&metric_labels).set(val);
134126
self.metrics.client_connections_closed_count.get_or_create(&metric_labels).inc();

crates/rproxy/src/server/proxy/http/authrpc.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
use crate::{
22
jrpc::{JrpcRequestMeta, JrpcRequestMetaMaybeBatch},
33
server::proxy::{
4-
ProxyInner,
54
config::ConfigAuthrpc,
65
http::{ProxiedHttpRequest, ProxiedHttpResponse, ProxyHttpInner},
76
},
87
};
98

10-
const PROXY_HTTP_INNER_AUTHRPC_NAME: &str = "rproxy-authrpc";
11-
129
// ProxyHttpInnerAuthrpc -----------------------------------------------
1310

1411
#[derive(Clone)]
1512
pub(crate) struct ProxyHttpInnerAuthrpc {
1613
config: ConfigAuthrpc,
1714
}
1815

19-
impl ProxyInner for ProxyHttpInnerAuthrpc {
20-
#[inline]
21-
fn name() -> &'static str {
22-
PROXY_HTTP_INNER_AUTHRPC_NAME
23-
}
24-
}
25-
2616
impl ProxyHttpInner<ConfigAuthrpc> for ProxyHttpInnerAuthrpc {
2717
fn new(config: ConfigAuthrpc) -> Self {
2818
Self { config }

crates/rproxy/src/server/proxy/http/inner.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
use crate::{
22
jrpc::JrpcRequestMetaMaybeBatch,
3-
server::proxy::{
4-
ProxyInner,
5-
http::{ProxiedHttpRequest, ProxiedHttpResponse, config::ConfigProxyHttp},
6-
},
3+
server::proxy::http::{ProxiedHttpRequest, ProxiedHttpResponse, config::ConfigProxyHttp},
74
};
85

96
// ProxyHttpInner ------------------------------------------------------
107

11-
pub(crate) trait ProxyHttpInner<C>:
12-
ProxyInner + Clone + Send + Sized + Sync + 'static
8+
pub(crate) trait ProxyHttpInner<C>: Clone + Send + Sized + Sync + 'static
139
where
1410
C: ConfigProxyHttp,
1511
{

0 commit comments

Comments
 (0)