Restructure the project tree

This commit is contained in:
moznion
2020-11-29 12:45:35 +09:00
parent 388abee17a
commit 0ef10d8554
31 changed files with 113 additions and 149 deletions

View File

@@ -1,19 +1,11 @@
[package]
name = "radius-rs"
version = "0.1.0"
authors = ["moznion <moznion@gmail.com>"]
edition = "2018"
license-file = "LICENSE"
[workspace]
[dependencies]
md5 = "0.7.0"
chrono = "0.4"
rand = "0.7.3"
num_enum = "0.5.1"
tokio = { version = "0.3.4", features = ["full"] }
log = "0.4.11"
thiserror = "1.0"
async-trait = "0.1.42"
members = [
"radius",
"radius-server",
"radius-client",
[dev-dependencies]
env_logger = "0.8.2"
# Internal
"code-generator",
"examples",
]

View File

@@ -8,4 +8,4 @@ lint:
cargo clippy
gen:
bash ./scripts/generate_code.sh
bash ./scripts/generate-code.sh

11
code-generator/Cargo.toml Normal file
View File

@@ -0,0 +1,11 @@
[package]
name = "code-generator"
version = "0.1.0"
edition = "2018"
license-file = "../LICENSE"
publish = false
[dependencies]
regex = "1"
getopts = "0.2"
Inflector = "0.11"

View File

@@ -1,2 +0,0 @@
/target

View File

@@ -1,83 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "Inflector"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
dependencies = [
"lazy_static",
"regex",
]
[[package]]
name = "aho-corasick"
version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
dependencies = [
"memchr",
]
[[package]]
name = "code_generator"
version = "0.1.0"
dependencies = [
"Inflector",
"getopts",
"regex",
]
[[package]]
name = "getopts"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
dependencies = [
"unicode-width",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "memchr"
version = "2.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
[[package]]
name = "regex"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
"thread_local",
]
[[package]]
name = "regex-syntax"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
[[package]]
name = "thread_local"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
dependencies = [
"lazy_static",
]
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"

View File

@@ -1,13 +0,0 @@
[package]
name = "code_generator"
version = "0.1.0"
authors = ["moznion <moznion@gmail.com>"]
edition = "2018"
license-file = "LICENSE"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
regex = "1"
getopts = "0.2"
Inflector = "0.11"

View File

@@ -1,9 +0,0 @@
test:
cargo test
build:
cargo build
lint:
cargo clippy

25
examples/Cargo.toml Normal file
View File

@@ -0,0 +1,25 @@
[package]
name = "examples"
version = "0.1.0"
publish = false
edition = "2018"
license-file = "../LICENSE"
repository = "https://github.com/moznion/radius-rs"
[dev-dependencies]
radius = { version = "0.1.0", path = "../radius" }
radius-client = { version = "0.1.0", path = "../radius-client" }
radius-server = { version = "0.1.0", path = "../radius-server" }
log = "0.4.11"
env_logger = "0.8.2"
tokio = { version = "0.3.4", features = ["signal", "net"] }
async-trait = "0.1.42"
[[example]]
name = "server"
path = "server.rs"
[[example]]
name = "client"
path = "client.rs"

View File

@@ -1,9 +1,9 @@
#[macro_use]
extern crate log;
use radius_rs::client::Client;
use radius_rs::code::Code;
use radius_rs::packet::Packet;
use radius_rs::rfc2865;
use radius::code::Code;
use radius::packet::Packet;
use radius::rfc2865;
use radius_client::client::Client;
use std::net::SocketAddr;
#[tokio::main]

View File

@@ -8,12 +8,12 @@ use async_trait::async_trait;
use tokio::net::UdpSocket;
use tokio::signal;
use radius_rs::code::Code;
use radius_rs::request::Request;
use radius_rs::request_handler::RequestHandler;
use radius_rs::rfc2865;
use radius_rs::secret_provider::{SecretProvider, SecretProviderError};
use radius_rs::server::Server;
use radius::code::Code;
use radius::request::Request;
use radius::rfc2865;
use radius_server::request_handler::RequestHandler;
use radius_server::secret_provider::{SecretProvider, SecretProviderError};
use radius_server::server::Server;
#[tokio::main]
async fn main() {

13
radius-client/Cargo.toml Normal file
View File

@@ -0,0 +1,13 @@
[package]
name = "radius-client"
version = "0.1.0"
authors = ["moznion <moznion@gmail.com>"]
edition = "2018"
license-file = "../LICENSE"
repository = "https://github.com/moznion/radius-rs"
keywords = ["radius", "client"]
[dependencies]
radius = { path = "../radius" }
tokio = { version = "0.3.4", features = ["net"] }
thiserror = "1.0"

View File

@@ -7,7 +7,7 @@ use crate::client::ClientError::{
FailedConnection, FailedParsingUDPResponse, FailedRadiusPacketEncoding,
FailedReceivingResponse, FailedSendingPacket, FailedUdpSocketBinding,
};
use crate::packet::Packet;
use radius::packet::Packet;
#[derive(Error, Debug)]
pub enum ClientError {

1
radius-client/src/lib.rs Normal file
View File

@@ -0,0 +1 @@
pub mod client;

15
radius-server/Cargo.toml Normal file
View File

@@ -0,0 +1,15 @@
[package]
name = "radius-server"
version = "0.1.0"
authors = ["moznion <moznion@gmail.com>"]
edition = "2018"
license-file = "../LICENSE"
repository = "https://github.com/moznion/radius-rs"
keywords = ["radius", "client"]
[dependencies]
radius = { path = "../radius" }
tokio = { version = "0.3.4", features = ["full"] }
log = "0.4.11"
thiserror = "1.0"
async-trait = "0.1.42"

6
radius-server/src/lib.rs Normal file
View File

@@ -0,0 +1,6 @@
#[macro_use]
extern crate log;
pub mod request_handler;
pub mod secret_provider;
pub mod server;

View File

@@ -1,7 +1,7 @@
use async_trait::async_trait;
use tokio::net::UdpSocket;
use crate::request::Request;
use radius::request::Request;
#[async_trait]
pub trait RequestHandler<T, E>: 'static + Sync + Send {

View File

@@ -7,10 +7,10 @@ use std::sync::{Arc, RwLock};
use tokio::net::UdpSocket;
use crate::packet::Packet;
use crate::request::Request;
use crate::request_handler::RequestHandler;
use crate::secret_provider::SecretProvider;
use radius::packet::Packet;
use radius::request::Request;
use std::fmt::Debug;
pub struct Server {}

15
radius/Cargo.toml Normal file
View File

@@ -0,0 +1,15 @@
[package]
name = "radius"
version = "0.1.0"
authors = ["moznion <moznion@gmail.com>"]
edition = "2018"
license-file = "../LICENSE"
repository = "https://github.com/moznion/radius-rs"
keywords = ["radius"]
[dependencies]
md5 = "0.7.0"
chrono = "0.4"
rand = "0.7.3"
num_enum = "0.5.1"
thiserror = "1.0"

View File

@@ -1,15 +1,8 @@
#[macro_use]
extern crate log;
pub(crate) mod attributes;
pub mod avp;
pub mod client;
pub mod code;
pub mod packet;
pub mod request;
pub mod request_handler;
pub mod rfc2865;
pub mod rfc2866;
pub mod rfc2867;
pub mod secret_provider;
pub mod server;

View File

@@ -9,7 +9,7 @@ pub struct Request {
}
impl Request {
pub(crate) fn new(local_addr: SocketAddr, remote_addr: SocketAddr, packet: Packet) -> Self {
pub fn new(local_addr: SocketAddr, remote_addr: SocketAddr, packet: Packet) -> Self {
Self {
local_addr,
remote_addr,

0
radius/src/rfc2868.rs Normal file
View File

View File

@@ -4,7 +4,7 @@ set -eu
REPO_ROOT="$(cd ./"$(git rev-parse --show-cdup)" || exit; pwd)"
DICTS_DIR="${REPO_ROOT}/dicts"
SRC_DIR="${REPO_ROOT}/src"
SRC_DIR="${REPO_ROOT}/radius/src"
DICTS=$(ls "$DICTS_DIR")
@@ -17,7 +17,7 @@ done
# shellcheck disable=SC2068
for DICT in ${DICTS[@]}; do
DICT_NAME="${DICT##*.}"
(cd "${REPO_ROOT}/code_generator"; cargo run "${DICTS_DIR}/dictionary.${DICT_NAME}" "${SRC_DIR}/${DICT_NAME}.rs")
cargo run --bin code-generator "${DICTS_DIR}/dictionary.${DICT_NAME}" "${SRC_DIR}/${DICT_NAME}.rs"
done
cargo fix --allow-dirty --allow-staged