mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 19:49:33 +00:00
rpc-interface: add restricted invariant comments
This commit is contained in:
parent
04cdc72f46
commit
3763dc9693
3 changed files with 20 additions and 1 deletions
|
@ -71,7 +71,12 @@ macro_rules! generate_endpoints_inner {
|
||||||
($variant:ident, $handler:ident, $request:expr_2021) => {
|
($variant:ident, $handler:ident, $request:expr_2021) => {
|
||||||
paste::paste! {
|
paste::paste! {
|
||||||
{
|
{
|
||||||
// Check if restricted.
|
// INVARIANT:
|
||||||
|
// The handler functions in `cuprated` depend on this line existing,
|
||||||
|
// the functions themselves do not check if they are being called
|
||||||
|
// from an (un)restricted context.
|
||||||
|
//
|
||||||
|
// This line must be here or all methods will be allowed to be called freely.
|
||||||
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
|
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
|
||||||
// TODO: mimic `monerod` behavior.
|
// TODO: mimic `monerod` behavior.
|
||||||
return Err(StatusCode::FORBIDDEN);
|
return Err(StatusCode::FORBIDDEN);
|
||||||
|
|
|
@ -37,6 +37,13 @@ pub(crate) async fn json_rpc<H: RpcHandler>(
|
||||||
|
|
||||||
// Return early if this RPC server is restricted and
|
// Return early if this RPC server is restricted and
|
||||||
// the requested method is only for non-restricted RPC.
|
// the requested method is only for non-restricted RPC.
|
||||||
|
//
|
||||||
|
// INVARIANT:
|
||||||
|
// The handler functions in `cuprated` depend on this line existing,
|
||||||
|
// the functions themselves do not check if they are being called
|
||||||
|
// from an (un)restricted context.
|
||||||
|
//
|
||||||
|
// This line must be here or all methods will be allowed to be called freely.
|
||||||
if request.body.is_restricted() && handler.is_restricted() {
|
if request.body.is_restricted() && handler.is_restricted() {
|
||||||
let error_object = ErrorObject {
|
let error_object = ErrorObject {
|
||||||
code: ErrorCode::ServerError(-1 /* TODO */),
|
code: ErrorCode::ServerError(-1 /* TODO */),
|
||||||
|
|
|
@ -75,6 +75,13 @@ macro_rules! generate_endpoints_inner {
|
||||||
paste::paste! {
|
paste::paste! {
|
||||||
{
|
{
|
||||||
// Check if restricted.
|
// Check if restricted.
|
||||||
|
//
|
||||||
|
// INVARIANT:
|
||||||
|
// The handler functions in `cuprated` depend on this line existing,
|
||||||
|
// the functions themselves do not check if they are being called
|
||||||
|
// from an (un)restricted context.
|
||||||
|
//
|
||||||
|
// This line must be here or all methods will be allowed to be called freely.
|
||||||
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
|
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
|
||||||
// TODO: mimic `monerod` behavior.
|
// TODO: mimic `monerod` behavior.
|
||||||
return Err(StatusCode::FORBIDDEN);
|
return Err(StatusCode::FORBIDDEN);
|
||||||
|
|
Loading…
Reference in a new issue