Skip to content

Commit

Permalink
Fix document of Lua script & clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
sorz committed Jun 17, 2020
1 parent cc68f30 commit d498d81
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 3 additions & 1 deletion conf/simple_score.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ function calc_score(proxy, delay)
-- proxy.config:
-- Proxy's configs,
-- includes test_dns, max_wait, and score_base.
-- proxy.traffic:
-- tx_bytes: total amount of traffics, upload to proxy server
-- rx_bytes: download from proxy server
-- proxy.status:
-- delay: the delay before this update, in secs in float.
-- nil = initial value; -1 = timed out.
-- score: the score before this update, may be nil.
-- traffic.tx_bytes, traffic.rx_bytes: total traffics
-- conn_alive, conn_total, conn_error: connection counters
-- close_history:
-- History of the 64 most recent closed connections, stored as
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async fn main() {
let mut signals = signal(SignalKind::hangup()).expect("cannot catch signal");
#[cfg(unix)]
tokio::spawn(async move {
while let Some(_) = signals.next().await {
while signals.next().await.is_some() {
#[cfg(all(feature = "systemd", target_os = "linux"))]
systemd::notify_realoding();

Expand Down
18 changes: 7 additions & 11 deletions src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,12 @@ impl Default for AtomicTraffic {
}

impl AtomicTraffic {
pub fn add_tx(&self, bytes: usize) {
self.tx_bytes.fetch_add(bytes, Ordering::Relaxed);
pub fn add(&self, amt: Traffic) {
self.rx_bytes.fetch_add(amt.rx_bytes, Ordering::Relaxed);
self.tx_bytes.fetch_add(amt.tx_bytes, Ordering::Relaxed);
}

pub fn add_rx(&self, bytes: usize) {
self.rx_bytes.fetch_add(bytes, Ordering::Relaxed);
}

pub fn read_traffic(&self) -> Traffic {
pub fn read(&self) -> Traffic {
Traffic {
tx_bytes: self.tx_bytes.load(Ordering::Relaxed),
rx_bytes: self.rx_bytes.load(Ordering::Relaxed),
Expand All @@ -268,7 +265,7 @@ impl AtomicTraffic {

impl Serialize for AtomicTraffic {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.read_traffic().serialize(serializer)
self.read().serialize(serializer)
}
}

Expand Down Expand Up @@ -426,7 +423,7 @@ impl ProxyServer {
}

pub fn traffic(&self) -> Traffic {
self.traffic.read_traffic()
self.traffic.read()
}

pub fn update_delay(&self, delay: Option<Duration>) {
Expand Down Expand Up @@ -483,8 +480,7 @@ impl ProxyServer {
}

pub fn add_traffic(&self, traffic: Traffic) {
self.traffic.add_rx(traffic.rx_bytes);
self.traffic.add_tx(traffic.tx_bytes);
self.traffic.add(traffic);
}

pub fn update_stats_conn_open(&self) {
Expand Down

0 comments on commit d498d81

Please sign in to comment.