Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/rproxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::Parser;
use thiserror::Error;

use crate::server::{
config::{ConfigLoggingError, ConfigLogging, ConfigMetrics, ConfigMetricsError},
config::{ConfigLogging, ConfigLoggingError, ConfigMetrics, ConfigMetricsError},
proxy::config::{
ConfigAuthrpc,
ConfigAuthrpcError,
Expand Down
3 changes: 2 additions & 1 deletion crates/rproxy/src/jrpc/jrpc_request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::Deserialize;
use std::borrow::Cow;

use serde::Deserialize;

// JrpcRequestMeta -----------------------------------------------------

const JRPC_METHOD_FCUV1_WITH_PAYLOAD: Cow<'static, str> =
Expand Down
10 changes: 6 additions & 4 deletions crates/rproxy/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
server::{
metrics::Metrics,
proxy::{
ProxyInner,
circuit_breaker::CircuitBreaker,
config::{ConfigAuthrpc, ConfigFlashblocks, ConfigRpc},
http::{ProxyHttp, ProxyHttpInnerAuthrpc, ProxyHttpInnerRpc},
Expand Down Expand Up @@ -102,13 +101,14 @@ impl Server {
config,
tls,
metrics,
"rproxy-authrpc",
canceller.clone(),
resetter,
)
.await
.inspect_err(|err| {
error!(
proxy = ProxyHttpInnerRpc::name(),
proxy = "rproxy-authrpc",
error = ?err,
"Failed to start http-proxy, terminating...",
);
Expand All @@ -130,13 +130,14 @@ impl Server {
config,
tls,
metrics,
"rproxy-rpc",
canceller.clone(),
resetter,
)
.await
.inspect_err(|err| {
error!(
proxy = ProxyHttpInnerRpc::name(),
proxy = "rproxy-rpc",
error = ?err,
"Failed to start http-proxy, terminating...",
);
Expand All @@ -158,13 +159,14 @@ impl Server {
config,
tls,
metrics,
"rproxy-flashblocks",
canceller.clone(),
resetter,
)
.await
.inspect_err(|err| {
error!(
proxy = ProxyHttpInnerRpc::name(),
proxy = "rproxy-flashblocks",
error = ?err,
"Failed to start websocket-proxy, terminating...",
);
Expand Down
22 changes: 7 additions & 15 deletions crates/rproxy/src/server/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ use crate::server::metrics::{LabelsProxy, Metrics};

// Proxy ---------------------------------------------------------------

pub(crate) trait Proxy<P>
where
P: ProxyInner,
{
pub(crate) trait Proxy {
fn on_connect(
metrics: Arc<Metrics>,
client_connections_count: Arc<AtomicI64>,
proxy_name: &'static str,
) -> impl Fn(&dyn Any, &mut Extensions) {
move |connection, extensions| {
{
let val = client_connections_count.fetch_add(1, Ordering::Relaxed) + 1;
let metric_labels = LabelsProxy { proxy: P::name() };
let metric_labels = LabelsProxy { proxy: proxy_name };

metrics.client_connections_active_count.get_or_create(&metric_labels).set(val);
metrics.client_connections_established_count.get_or_create(&metric_labels).inc();
Expand All @@ -54,20 +52,20 @@ where
let remote_addr = match stream.peer_addr() {
Ok(local_addr) => Some(local_addr.to_string()),
Err(err) => {
warn!(proxy = P::name(), error = ?err, "Failed to get remote address");
warn!(proxy = proxy_name, error = ?err, "Failed to get remote address");
None
}
};
let local_addr = match stream.local_addr() {
Ok(local_addr) => Some(local_addr.to_string()),
Err(err) => {
warn!(proxy = P::name(), error = ?err, "Failed to get remote address");
warn!(proxy = proxy_name, error = ?err, "Failed to get remote address");
None
}
};

debug!(
proxy = P::name(),
proxy = proxy_name,
connection_id = %id,
remote_addr = remote_addr.as_ref().map_or("unknown", |v| v.as_str()),
local_addr = local_addr.as_ref().map_or("unknown", |v| v.as_str()),
Expand All @@ -76,7 +74,7 @@ where

extensions.insert(ProxyConnectionGuard::new(
id,
P::name(),
proxy_name,
remote_addr,
local_addr,
&metrics,
Expand All @@ -87,12 +85,6 @@ where
}
}

// ProxyInner ----------------------------------------------------------

pub(crate) trait ProxyInner: 'static {
fn name() -> &'static str;
}

// ProxyConnectionGuard ------------------------------------------------

pub struct ProxyConnectionGuard {
Expand Down
10 changes: 0 additions & 10 deletions crates/rproxy/src/server/proxy/http/authrpc.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
use crate::{
jrpc::{JrpcRequestMeta, JrpcRequestMetaMaybeBatch},
server::proxy::{
ProxyInner,
config::ConfigAuthrpc,
http::{ProxiedHttpRequest, ProxiedHttpResponse, ProxyHttpInner},
},
};

const PROXY_HTTP_INNER_AUTHRPC_NAME: &str = "rproxy-authrpc";

// ProxyHttpInnerAuthrpc -----------------------------------------------

#[derive(Clone)]
pub(crate) struct ProxyHttpInnerAuthrpc {
config: ConfigAuthrpc,
}

impl ProxyInner for ProxyHttpInnerAuthrpc {
#[inline]
fn name() -> &'static str {
PROXY_HTTP_INNER_AUTHRPC_NAME
}
}

impl ProxyHttpInner<ConfigAuthrpc> for ProxyHttpInnerAuthrpc {
fn new(config: ConfigAuthrpc) -> Self {
Self { config }
Expand Down
8 changes: 2 additions & 6 deletions crates/rproxy/src/server/proxy/http/inner.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use crate::{
jrpc::JrpcRequestMetaMaybeBatch,
server::proxy::{
ProxyInner,
http::{ProxiedHttpRequest, ProxiedHttpResponse, config::ConfigProxyHttp},
},
server::proxy::http::{ProxiedHttpRequest, ProxiedHttpResponse, config::ConfigProxyHttp},
};

// ProxyHttpInner ------------------------------------------------------

pub(crate) trait ProxyHttpInner<C>:
ProxyInner + Clone + Send + Sized + Sync + 'static
pub(crate) trait ProxyHttpInner<C>: Clone + Send + Sized + Sync + 'static
where
C: ConfigProxyHttp,
{
Expand Down
Loading