mirror of
https://github.com/YGGverse/nexy.git
synced 2026-03-31 17:25:27 +00:00
rename members
This commit is contained in:
parent
40bc6f773f
commit
d82f09d659
7 changed files with 33 additions and 33 deletions
|
|
@ -32,7 +32,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle(mut self) {
|
pub fn handle(mut self) {
|
||||||
self.session.event.connection.update(&self.address.client);
|
self.session.stats.connections.add(&self.address.client);
|
||||||
let mut t = 0; // total bytes
|
let mut t = 0; // total bytes
|
||||||
match self.request() {
|
match self.request() {
|
||||||
Ok(q) => {
|
Ok(q) => {
|
||||||
|
|
@ -42,7 +42,7 @@ impl Connection {
|
||||||
));
|
));
|
||||||
self.session
|
self.session
|
||||||
.clone()
|
.clone()
|
||||||
.storage
|
.public
|
||||||
.request(&q, |r| t += self.response(r)); // chunk loop
|
.request(&q, |r| t += self.response(r)); // chunk loop
|
||||||
self.session
|
self.session
|
||||||
.access_log
|
.access_log
|
||||||
|
|
@ -74,8 +74,8 @@ impl Connection {
|
||||||
&if is_root {
|
&if is_root {
|
||||||
self.session.template.welcome(
|
self.session.template.welcome(
|
||||||
Some(s),
|
Some(s),
|
||||||
Some(self.session.event.connection.hosts()),
|
Some(self.session.stats.connections.count()),
|
||||||
Some(self.session.event.connection.hits()),
|
Some(self.session.stats.connections.total()),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.session.template.index(Some(s))
|
self.session.template.index(Some(s))
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
mod access_log;
|
mod access_log;
|
||||||
mod debug;
|
mod debug;
|
||||||
mod event;
|
mod public;
|
||||||
mod storage;
|
mod stats;
|
||||||
mod template;
|
mod template;
|
||||||
|
|
||||||
use {access_log::AccessLog, debug::Debug, event::Event, storage::Storage, template::Template};
|
use {access_log::AccessLog, debug::Debug, public::Public, stats::Stats, template::Template};
|
||||||
|
|
||||||
/// Shared, multi-thread features for the current server session
|
/// Shared, multi-thread features for the current server session
|
||||||
pub struct Session {
|
pub struct Session {
|
||||||
pub access_log: AccessLog,
|
pub access_log: AccessLog,
|
||||||
pub debug: Debug,
|
pub debug: Debug,
|
||||||
pub event: Event,
|
pub stats: Stats,
|
||||||
pub storage: Storage,
|
pub public: Public,
|
||||||
pub template: Template,
|
pub template: Template,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,11 +21,11 @@ impl Session {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
access_log: AccessLog::init(config)?,
|
access_log: AccessLog::init(config)?,
|
||||||
debug: Debug::init(config)?,
|
debug: Debug::init(config)?,
|
||||||
event: Event::init(
|
stats: Stats::init(
|
||||||
// do not init `Connection` event if its features not in use
|
// do not init `Connection` event if its features not in use
|
||||||
template.welcome.contains("{hosts}") || template.welcome.contains("{hits}"),
|
template.welcome.contains("{hosts}") || template.welcome.contains("{hits}"),
|
||||||
)?,
|
)?,
|
||||||
storage: Storage::init(config)?,
|
public: Public::init(config)?,
|
||||||
template,
|
template,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
mod connection;
|
|
||||||
use connection::Connection;
|
|
||||||
|
|
||||||
pub struct Event {
|
|
||||||
pub connection: Connection,
|
|
||||||
// another features...
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Event {
|
|
||||||
pub fn init(is_connection_enabled: bool) -> anyhow::Result<Self> {
|
|
||||||
Ok(Self {
|
|
||||||
connection: Connection::init(is_connection_enabled),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -11,7 +11,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// In-session disk storage API
|
/// In-session disk storage API
|
||||||
pub struct Storage {
|
pub struct Public {
|
||||||
/// Listing options
|
/// Listing options
|
||||||
list_config: ListConfig,
|
list_config: ListConfig,
|
||||||
/// Root path to storage, used also for the access validation
|
/// Root path to storage, used also for the access validation
|
||||||
|
|
@ -24,7 +24,7 @@ pub struct Storage {
|
||||||
show_hidden: bool,
|
show_hidden: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Storage {
|
impl Public {
|
||||||
pub fn init(config: &crate::config::Config) -> Result<Self> {
|
pub fn init(config: &crate::config::Config) -> Result<Self> {
|
||||||
let public_dir = PathBuf::from_str(&config.public)?.canonicalize()?;
|
let public_dir = PathBuf::from_str(&config.public)?.canonicalize()?;
|
||||||
let t = fs::metadata(&public_dir)?;
|
let t = fs::metadata(&public_dir)?;
|
||||||
15
src/session/stats.rs
Normal file
15
src/session/stats.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
mod connections;
|
||||||
|
use connections::Connections;
|
||||||
|
|
||||||
|
pub struct Stats {
|
||||||
|
pub connections: Connections,
|
||||||
|
// another features...
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Stats {
|
||||||
|
pub fn init(is_connection_enabled: bool) -> anyhow::Result<Self> {
|
||||||
|
Ok(Self {
|
||||||
|
connections: Connections::init(is_connection_enabled),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,9 +5,9 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Count peer connections (for the current server session)
|
/// Count peer connections (for the current server session)
|
||||||
pub struct Connection(Option<RwLock<HashMap<IpAddr, usize>>>);
|
pub struct Connections(Option<RwLock<HashMap<IpAddr, usize>>>);
|
||||||
|
|
||||||
impl Connection {
|
impl Connections {
|
||||||
pub fn init(is_enabled: bool) -> Self {
|
pub fn init(is_enabled: bool) -> Self {
|
||||||
if is_enabled {
|
if is_enabled {
|
||||||
Self(Some(RwLock::new(HashMap::with_capacity(100))))
|
Self(Some(RwLock::new(HashMap::with_capacity(100))))
|
||||||
|
|
@ -16,7 +16,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&self, peer: &SocketAddr) {
|
pub fn add(&self, peer: &SocketAddr) {
|
||||||
if let Some(ref this) = self.0 {
|
if let Some(ref this) = self.0 {
|
||||||
this.write()
|
this.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -26,7 +26,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hosts(&self) -> usize {
|
pub fn count(&self) -> usize {
|
||||||
if let Some(ref this) = self.0 {
|
if let Some(ref this) = self.0 {
|
||||||
this.read().unwrap().len()
|
this.read().unwrap().len()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -34,7 +34,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hits(&self) -> usize {
|
pub fn total(&self) -> usize {
|
||||||
if let Some(ref this) = self.0 {
|
if let Some(ref this) = self.0 {
|
||||||
this.read().unwrap().values().sum()
|
this.read().unwrap().values().sum()
|
||||||
} else {
|
} else {
|
||||||
Loading…
Add table
Add a link
Reference in a new issue