no need to move the semaphore around like this
This commit is contained in:
parent
2273637a07
commit
0b62ffcdfc
@ -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
|
/// 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(
|
pub async fn ip_is_authorized(
|
||||||
app: &Arc<Web3ProxyApp>,
|
app: &Arc<Web3ProxyApp>,
|
||||||
ip: IpAddr,
|
ip: IpAddr,
|
||||||
@ -831,6 +832,7 @@ pub async fn ip_is_authorized(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// like app.rate_limit_by_rpc_key but converts to a Web3ProxyError;
|
/// 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(
|
pub async fn key_is_authorized(
|
||||||
app: &Arc<Web3ProxyApp>,
|
app: &Arc<Web3ProxyApp>,
|
||||||
rpc_key: RpcSecretKey,
|
rpc_key: RpcSecretKey,
|
||||||
@ -916,6 +918,7 @@ impl Web3ProxyApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Limit the number of concurrent requests for a given user across all of their keys
|
/// 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(
|
pub async fn user_semaphore(
|
||||||
&self,
|
&self,
|
||||||
authorization_checks: &AuthorizationChecks,
|
authorization_checks: &AuthorizationChecks,
|
||||||
@ -946,6 +949,7 @@ impl Web3ProxyApp {
|
|||||||
|
|
||||||
/// Verify that the given bearer token and address are allowed to take the specified action.
|
/// Verify that the given bearer token and address are allowed to take the specified action.
|
||||||
/// This includes concurrent request limiting.
|
/// This includes concurrent request limiting.
|
||||||
|
/// keep the semaphore alive until the user's request is entirely complete
|
||||||
pub async fn bearer_is_authorized(
|
pub async fn bearer_is_authorized(
|
||||||
&self,
|
&self,
|
||||||
bearer: Bearer,
|
bearer: Bearer,
|
||||||
|
@ -62,7 +62,7 @@ async fn _proxy_web3_rpc(
|
|||||||
|
|
||||||
let first_id = payload.first_id().map_err(|e| e.into_response())?;
|
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
|
.await
|
||||||
.map_err(|e| e.into_response_with_id(first_id.to_owned()))?;
|
.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
|
// 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)
|
.proxy_web3_rpc(authorization, payload)
|
||||||
.await
|
.await
|
||||||
.map(|(s, x, y)| (s, x, y, semaphore))
|
|
||||||
.map_err(|e| e.into_response_with_id(first_id.to_owned()))?;
|
.map_err(|e| e.into_response_with_id(first_id.to_owned()))?;
|
||||||
|
|
||||||
let mut response = (status_code, Json(response)).into_response();
|
let mut response = (status_code, Json(response)).into_response();
|
||||||
@ -227,7 +226,7 @@ async fn _proxy_web3_rpc_with_key(
|
|||||||
.parse()
|
.parse()
|
||||||
.map_err(|e: Web3ProxyError| e.into_response_with_id(first_id.to_owned()))?;
|
.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,
|
&app,
|
||||||
rpc_key,
|
rpc_key,
|
||||||
ip,
|
ip,
|
||||||
@ -243,10 +242,9 @@ async fn _proxy_web3_rpc_with_key(
|
|||||||
|
|
||||||
let rpc_secret_key_id = authorization.checks.rpc_secret_key_id;
|
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)
|
.proxy_web3_rpc(authorization, payload)
|
||||||
.await
|
.await
|
||||||
.map(|(s, x, y)| (s, x, y, semaphore))
|
|
||||||
.map_err(|e| e.into_response_with_id(first_id.to_owned()))?;
|
.map_err(|e| e.into_response_with_id(first_id.to_owned()))?;
|
||||||
|
|
||||||
let mut response = (status_code, Json(response)).into_response();
|
let mut response = (status_code, Json(response)).into_response();
|
||||||
|
Loading…
Reference in New Issue
Block a user