summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStuart Stock <stuart@int08h.com>2019-02-09 08:28:30 -0600
committerStuart Stock <stuart@int08h.com>2019-02-09 08:28:30 -0600
commit55a15d8b1110e80e7874340fddb3b4c46a894e3b (patch)
tree7c4fcf4d20e5d80338252cdf1966d609f2e360c1 /src
parent3e2ebd590839ddf173f7b307582602abc22b7db7 (diff)
downloadroughenough-55a15d8b1110e80e7874340fddb3b4c46a894e3b.zip
Add ServerStats member to the server
Diffstat (limited to 'src')
-rw-r--r--src/server.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/server.rs b/src/server.rs
index b910e2a..9f93b60 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -35,12 +35,12 @@ use mio::{Events, Poll, PollOpt, Ready, Token};
use mio::tcp::Shutdown;
use mio_extras::timer::Timer;
+use crate::{Error, RtMessage, Tag, MIN_REQUEST_LENGTH};
use crate::config::ServerConfig;
use crate::key::{LongTermKey, OnlineKey};
use crate::kms;
use crate::merkle::MerkleTree;
-use crate::{Error, RtMessage, Tag, MIN_REQUEST_LENGTH};
-use crate::stats::{ServerStats, PerClientStats};
+use crate::stats::{AggregatedStats, PerClientStats, ServerStats};
macro_rules! check_ctrlc {
($keep_running:expr) => {
@@ -86,11 +86,11 @@ pub struct Server {
public_key: String,
+ stats: Box<dyn ServerStats>,
+
// Used to send requests to ourselves in fuzzing mode
#[cfg(fuzzing)]
fake_client_socket: UdpSocket,
-
- stats: PerClientStats,
}
impl Server {
@@ -98,7 +98,7 @@ impl Server {
/// Create a new server instance from the provided
/// [`ServerConfig`](../config/trait.ServerConfig.html) trait object instance.
///
- pub fn new(config: Box<ServerConfig>) -> Server {
+ pub fn new(config: Box<dyn ServerConfig>) -> Server {
let online_key = OnlineKey::new();
let public_key: String;
@@ -148,6 +148,12 @@ impl Server {
None
};
+ let stats: Box<dyn ServerStats> = if config.client_stats_enabled() {
+ Box::new(PerClientStats::new())
+ } else {
+ Box::new(AggregatedStats::new())
+ };
+
let merkle = MerkleTree::new();
let requests = Vec::with_capacity(config.batch_size() as usize);
@@ -169,10 +175,10 @@ impl Server {
public_key,
+ stats,
+
#[cfg(fuzzing)]
fake_client_socket: UdpSocket::bind(&"127.0.0.1:0".parse().unwrap()).unwrap(),
-
- stats: PerClientStats::new(),
}
}
@@ -374,7 +380,7 @@ impl Server {
bytes_sent,
src_addr,
hex::encode(&nonce[0..4]),
- i,
+ i + 1,
self.stats.total_responses_sent()
);
}