tor_dircommon/dir_plugin_backend.rs
1//! TEMPORARY, EXPERIMENTAL traits for using tor-dirmgr as a dirserver backend.
2//!
3//! This module will be removed in the future. It only exists for now so that
4//! we can test Arti relays as guards before tor-dirserver is finished.
5//
6// NOTE: Some aspects of this module are marked with "LIMITATION".
7// Don't just run in and fix these: remember, this is throw-away code.
8
9pub use http;
10
11/// An object that knows how to handle one or more kinds of directory requests.
12pub trait DirBackendPlugin: Send + Sync + 'static {
13 /// Handle a GET request.
14 ///
15 /// Returns an http Response if the request is recognized,
16 /// _whether it succeeds or fails_.
17 ///
18 /// Returns an error if the request type is not recognized,
19 /// or if an internal error occurs.
20 fn get(
21 &self,
22 request: &http::Request<()>,
23 ) -> Result<http::Response<Box<[u8]>>, DirBackendPluginError>;
24}
25
26/// An error that occurred while trying to handle a request.
27#[derive(Debug, Clone, thiserror::Error)]
28#[non_exhaustive]
29pub enum DirBackendPluginError {
30 /// The request was one which this plugin doesn't know how to handle.
31 #[error("URI not handled by plugin.")]
32 UriNotHandledByPlugin,
33
34 /// An internal error occurred while trying to handle the request.
35 #[error("Internal error")]
36 Bug(tor_error::Bug),
37}