rpc: Implement the auth:get_rpc_protocol method.

This commit is contained in:
Nick Mathewson 2023-05-23 08:58:03 -04:00
parent d745e2d866
commit 2798dade00
1 changed files with 49 additions and 0 deletions

View File

@ -9,6 +9,55 @@ use std::sync::Arc;
use super::Connection;
use tor_rpcbase as rpc;
/// Declare the get_rpc_protocol method.
mod get_rpc_protocol {
use super::Connection;
use std::sync::Arc;
use tor_rpcbase as rpc;
/// Method to inquire about the RPC protocol.
#[derive(Debug, serde::Deserialize)]
struct GetRpcProtocol {}
/// Reply to the [`GetRpcProtocol`] method
#[derive(Debug, serde::Serialize)]
struct GetProtocolReply {
/// The version of the RPC protocol that this server speaks.
// TODO RPC: Should this be a list?
version: RpcProtocolId,
}
/// Identifier for a version of this RPC meta-protocol.
#[derive(Debug, Copy, Clone, serde::Serialize)]
enum RpcProtocolId {
/// Alpha version of the protocol. Things might break between here and the
/// stable protocol.
///
/// TODO RPC: CHange this to v0.
#[serde(rename = "alpha")]
Alpha,
}
rpc::decl_method! {"auth:get_rpc_protocol" => GetRpcProtocol}
impl rpc::Method for GetRpcProtocol {
type Output = GetProtocolReply;
type Update = rpc::NoUpdates;
}
/// Describe which version of the RPC protocol our connection implements.
async fn conn_get_rpc_protocol(
_conn: Arc<Connection>,
_method: Box<GetRpcProtocol>,
_ctx: Box<dyn rpc::Context>,
) -> Result<GetProtocolReply, rpc::RpcError> {
Ok(GetProtocolReply {
version: RpcProtocolId::Alpha,
})
}
rpc::rpc_invoke_fn! {
conn_get_rpc_protocol(Connection, GetRpcProtocol);
}
}
/// The authentication scheme as enumerated in the spec.
///
/// Conceptually, an authentication scheme answers the question "How can the