mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 07:08:05 -05:00
bin/ircd: minor changes and some clean up
This commit is contained in:
@@ -5,7 +5,7 @@ use chrono::Utc;
|
||||
|
||||
use crate::Privmsg;
|
||||
|
||||
pub const SIZE_OF_MSGS_BUFFER: usize = 8191;
|
||||
pub const SIZE_OF_MSGS_BUFFER: usize = 4095;
|
||||
pub const LIFETIME_FOR_ORPHAN: i64 = 600;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -34,6 +34,10 @@ impl<T: Eq + PartialEq + Clone> RingBuffer<T> {
|
||||
self.items.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.items.is_empty()
|
||||
}
|
||||
|
||||
pub fn as_slice(&mut self) -> &mut [T] {
|
||||
self.items.make_contiguous()
|
||||
}
|
||||
@@ -102,7 +106,7 @@ impl PrivmsgsBuffer {
|
||||
}
|
||||
|
||||
fn term_exist(&self, term: u64) -> bool {
|
||||
self.buffer.items.iter().find(|p| p.term == term).is_some()
|
||||
self.buffer.items.iter().any(|p| p.term == term)
|
||||
}
|
||||
|
||||
fn sort(&mut self) {
|
||||
@@ -219,10 +223,10 @@ mod tests {
|
||||
assert_eq!(pms.orphans.len(), 0);
|
||||
|
||||
//
|
||||
// Fill the buffer with random generated terms in range 4000..9001
|
||||
// Fill the buffer with random generated terms in range 4000..7001
|
||||
// Since the buffer max size is SIZE_OF_MSGS_BUFFER it has to remove the old msges
|
||||
//
|
||||
let mut terms: Vec<u64> = (4001..9001).collect();
|
||||
let mut terms: Vec<u64> = (4001..7001).collect();
|
||||
terms.shuffle(&mut thread_rng());
|
||||
|
||||
for term in terms {
|
||||
@@ -233,15 +237,15 @@ mod tests {
|
||||
pms.update();
|
||||
|
||||
assert_eq!(pms.buffer.len(), SIZE_OF_MSGS_BUFFER);
|
||||
assert_eq!(pms.last_term(), 9000);
|
||||
assert_eq!(pms.last_term(), 7000);
|
||||
assert_eq!(pms.orphans.len(), 0);
|
||||
|
||||
//
|
||||
// Fill the buffer with random generated terms in range 9001..11001
|
||||
// Fill the buffer with random generated terms in range 7001..10001
|
||||
// This will occasionally update the buffer
|
||||
// At the end, the messages in the buffer have to be in correct order
|
||||
//
|
||||
let mut terms: Vec<u64> = (9001..11001).collect();
|
||||
let mut terms: Vec<u64> = (7001..10001).collect();
|
||||
terms.shuffle(&mut thread_rng());
|
||||
|
||||
for term in terms {
|
||||
@@ -255,7 +259,7 @@ mod tests {
|
||||
pms.update();
|
||||
|
||||
assert_eq!(pms.buffer.len(), SIZE_OF_MSGS_BUFFER);
|
||||
assert_eq!(pms.last_term(), 11000);
|
||||
assert_eq!(pms.last_term(), 10000);
|
||||
assert_eq!(pms.orphans.len(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ const RPL_ENDOFNAMES: u32 = 366;
|
||||
impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcServerConnection<C> {
|
||||
pub(super) fn on_quit(&self) -> Result<()> {
|
||||
// Close the connection
|
||||
return Err(Error::NetworkServiceStopped)
|
||||
Err(Error::NetworkServiceStopped)
|
||||
}
|
||||
|
||||
pub(super) async fn on_receive_user(&mut self) -> Result<()> {
|
||||
@@ -32,7 +32,7 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcServerConnection<C>
|
||||
}
|
||||
|
||||
pub(super) async fn on_receive_pass(&mut self, password: &str) -> Result<()> {
|
||||
if &self.password == password {
|
||||
if self.password == password {
|
||||
self.is_pass_init = true
|
||||
} else {
|
||||
// Close the connection
|
||||
@@ -164,7 +164,7 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcServerConnection<C>
|
||||
|
||||
pub(super) async fn on_receive_names(&mut self, channels: Vec<String>) -> Result<()> {
|
||||
for chan in channels.iter() {
|
||||
if !chan.starts_with("#") {
|
||||
if !chan.starts_with('#') {
|
||||
continue
|
||||
}
|
||||
if self.configured_chans.contains_key(chan) {
|
||||
@@ -246,7 +246,7 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcServerConnection<C>
|
||||
|
||||
pub(super) async fn on_receive_join(&mut self, channels: Vec<String>) -> Result<()> {
|
||||
for chan in channels.iter() {
|
||||
if !chan.starts_with("#") {
|
||||
if !chan.starts_with('#') {
|
||||
continue
|
||||
}
|
||||
if !self.configured_chans.contains_key(chan) {
|
||||
|
||||
@@ -244,5 +244,5 @@ fn parse_line(line: &str) -> Result<(String, String)> {
|
||||
// that for now to keep the protocol simple and focused.
|
||||
let command = tokens.next().ok_or(Error::MalformedPacket)?.to_uppercase();
|
||||
let value = tokens.next().ok_or(Error::MalformedPacket)?;
|
||||
Ok((command.to_owned(), value.to_owned()))
|
||||
Ok((command, value.to_owned()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user