This commit is contained in:
moznion
2020-12-07 23:28:38 +09:00
parent 93b951eff8
commit 3e6701b0b1
9 changed files with 79 additions and 13 deletions
+8
View File
@@ -3,7 +3,15 @@ use tokio::net::UdpSocket;
use radius::request::Request;
/// RequestHandler is a handler for the received RADIUS request.
#[async_trait]
pub trait RequestHandler<T, E>: 'static + Sync + Send {
/// This method has to implement the core feature of the server application what you need.
///
/// # Arguments
///
/// * conn - This connection is associated with the remote requester. In the most situations,
/// you have to send a response through this connection object.
/// * request - This is a request object that comes from the remote requester.
async fn handle_radius_request(&self, conn: &UdpSocket, request: &Request) -> Result<T, E>;
}
+3
View File
@@ -8,6 +8,9 @@ pub enum SecretProviderError {
FailedFetching(String),
}
/// SecretProvider is a provider for secret value.
pub trait SecretProvider: 'static + Sync + Send {
/// This method has to implement the generator of the secret value to verify the request of
/// `Accounting-Response`, `Accounting-Response` and `CoA-Request`.
fn fetch_secret(&self, remote_addr: SocketAddr) -> Result<Vec<u8>, SecretProviderError>;
}
+2
View File
@@ -13,9 +13,11 @@ use radius::packet::Packet;
use radius::request::Request;
use std::fmt::Debug;
/// A basic implementation of the RADIUS server.
pub struct Server {}
impl Server {
/// Start listening a UDP socket to process the RAIDUS requests.
pub async fn run<X, E: Debug, T: RequestHandler<X, E>, U: SecretProvider>(
host: &str,
port: u16,