no need to move the semaphore around like this

This commit is contained in:
Bryan Stitt 2023-05-30 21:08:21 -07:00
parent 2273637a07
commit 0b62ffcdfc
2 changed files with 8 additions and 6 deletions

View File

@ -766,6 +766,7 @@ pub async fn login_is_authorized(app: &Web3ProxyApp, ip: IpAddr) -> Web3ProxyRes
}
/// semaphore won't ever be None, but its easier if key auth and ip auth work the same way
/// keep the semaphore alive until the user's request is entirely complete
pub async fn ip_is_authorized(
app: &Arc<Web3ProxyApp>,
ip: IpAddr,
@ -831,6 +832,7 @@ pub async fn ip_is_authorized(
}
/// like app.rate_limit_by_rpc_key but converts to a Web3ProxyError;
/// keep the semaphore alive until the user's request is entirely complete
pub async fn key_is_authorized(
app: &Arc<Web3ProxyApp>,
rpc_key: RpcSecretKey,
@ -916,6 +918,7 @@ impl Web3ProxyApp {
}
/// Limit the number of concurrent requests for a given user across all of their keys
/// keep the semaphore alive until the user's request is entirely complete
pub async fn user_semaphore(
&self,
authorization_checks: &AuthorizationChecks,
@ -946,6 +949,7 @@ impl Web3ProxyApp {
/// Verify that the given bearer token and address are allowed to take the specified action.
/// This includes concurrent request limiting.
/// keep the semaphore alive until the user's request is entirely complete
pub async fn bearer_is_authorized(
&self,
bearer: Bearer,

View File

@ -62,7 +62,7 @@ async fn _proxy_web3_rpc(
let first_id = payload.first_id().map_err(|e| e.into_response())?;
let (authorization, semaphore) = ip_is_authorized(&app, ip, origin, proxy_mode)
let (authorization, _semaphore) = ip_is_authorized(&app, ip, origin, proxy_mode)
.await
.map_err(|e| e.into_response_with_id(first_id.to_owned()))?;
@ -70,10 +70,9 @@ async fn _proxy_web3_rpc(
// TODO: calculate payload bytes here (before turning into serde_json::Value). that will save serializing later
let (status_code, response, rpcs, _semaphore) = app
let (status_code, response, rpcs) = app
.proxy_web3_rpc(authorization, payload)
.await
.map(|(s, x, y)| (s, x, y, semaphore))
.map_err(|e| e.into_response_with_id(first_id.to_owned()))?;
let mut response = (status_code, Json(response)).into_response();
@ -227,7 +226,7 @@ async fn _proxy_web3_rpc_with_key(
.parse()
.map_err(|e: Web3ProxyError| e.into_response_with_id(first_id.to_owned()))?;
let (authorization, semaphore) = key_is_authorized(
let (authorization, _semaphore) = key_is_authorized(
&app,
rpc_key,
ip,
@ -243,10 +242,9 @@ async fn _proxy_web3_rpc_with_key(
let rpc_secret_key_id = authorization.checks.rpc_secret_key_id;
let (status_code, response, rpcs, _semaphore) = app
let (status_code, response, rpcs) = app
.proxy_web3_rpc(authorization, payload)
.await
.map(|(s, x, y)| (s, x, y, semaphore))
.map_err(|e| e.into_response_with_id(first_id.to_owned()))?;
let mut response = (status_code, Json(response)).into_response();