Compare commits
4 Commits
CI
...
15672536f6
| Author | SHA1 | Date | |
|---|---|---|---|
| 15672536f6 | |||
| b5d2a63909 | |||
| 904091c455 | |||
| 02f44cfab6 |
@@ -1,38 +0,0 @@
|
||||
name: "Code Checks"
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
# Check formatting with rustfmt
|
||||
formatting:
|
||||
name: cargo fmt
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
# Ensure rustfmt is installed and setup problem matcher
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
components: rustfmt
|
||||
- name: Rustfmt Check
|
||||
uses: actions-rust-lang/rustfmt@v1
|
||||
|
||||
# Check code with clippy
|
||||
clippy:
|
||||
name: cargo clippy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
# Ensure clippy is installed and setup problem matcher
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
components: clippy
|
||||
- run: cargo clippy -- -D warnings
|
||||
|
||||
# Run tests
|
||||
test:
|
||||
name: cargo test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
- run: cargo test
|
||||
25
src/main.rs
25
src/main.rs
@@ -1,5 +1,5 @@
|
||||
#![warn(clippy::pedantic)]
|
||||
#![allow(clippy::let_underscore_untyped)] // false positive in stable
|
||||
// #![allow(clippy::missing_errors_doc)]
|
||||
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
@@ -350,16 +350,23 @@ async fn tokio_main(config: Arc<Config>) -> eyre::Result<()> {
|
||||
"centralex server listening"
|
||||
);
|
||||
|
||||
while let Ok((stream, addr)) = listener.accept().await {
|
||||
info!(%addr, "new connection");
|
||||
loop {
|
||||
let connection = listener.accept().await;
|
||||
|
||||
spawn(
|
||||
&format!("connection to {addr}"),
|
||||
connection_handler(stream, addr, config.clone(), port_handler.clone()),
|
||||
);
|
||||
match connection {
|
||||
Ok((stream, addr)) => {
|
||||
info!(%addr, "new connection");
|
||||
|
||||
spawn(
|
||||
&format!("connection to {addr}"),
|
||||
connection_handler(stream, addr, config.clone(), port_handler.clone()),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
error!(%err, "failed to accept connection");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::fmt::Debug;
|
||||
use std::{ffi::CStr, fmt::Debug};
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use eyre::eyre;
|
||||
@@ -85,18 +85,18 @@ impl Debug for Packet {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let data = &self.data;
|
||||
|
||||
let str_data = std::str::from_utf8(&data[..data.len().saturating_sub(1)]).ok();
|
||||
let mut debugger = f.debug_struct("Packet");
|
||||
|
||||
let data = if let Some(str_data) = str_data.as_ref() {
|
||||
str_data as &dyn Debug
|
||||
debugger.field("kind", &PacketKind::from_u8(self.header.kind));
|
||||
|
||||
let c_str = CStr::from_bytes_until_nul(data).ok();
|
||||
if let Some(str_data) = c_str.as_ref().and_then(|x| x.to_str().ok()) {
|
||||
debugger.field("data", &str_data);
|
||||
} else {
|
||||
&data as &dyn Debug
|
||||
};
|
||||
debugger.field("data", &data);
|
||||
}
|
||||
|
||||
f.debug_struct("Packet")
|
||||
.field("kind", &PacketKind::from_u8(self.header.kind))
|
||||
.field("data", &data)
|
||||
.finish()
|
||||
debugger.finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
20
src/ports.rs
20
src/ports.rs
@@ -283,7 +283,7 @@ impl PortHandler {
|
||||
self.last_update = Some(now);
|
||||
self.change_sender
|
||||
.as_ref()
|
||||
.expect("PortHandler is missing it's change_sender")
|
||||
.expect("PortHandler is missing its change_sender")
|
||||
.send(now)
|
||||
.expect("failed to notify cache writer");
|
||||
}
|
||||
@@ -301,15 +301,9 @@ impl PortHandler {
|
||||
}
|
||||
|
||||
#[allow(clippy::missing_errors_doc)]
|
||||
#[instrument(skip(change_sender))]
|
||||
pub fn load(
|
||||
cache: &Path,
|
||||
change_sender: tokio::sync::watch::Sender<Instant>,
|
||||
) -> std::io::Result<Self> {
|
||||
pub fn load(cache: &Path) -> std::io::Result<Self> {
|
||||
info!("loading cache");
|
||||
let mut cache: Self = serde_json::from_reader(BufReader::new(File::open(cache)?))?;
|
||||
cache.change_sender = Some(change_sender);
|
||||
Ok(cache)
|
||||
Ok(serde_json::from_reader(BufReader::new(File::open(cache)?))?)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@@ -318,10 +312,14 @@ impl PortHandler {
|
||||
path: &Path,
|
||||
change_sender: tokio::sync::watch::Sender<Instant>,
|
||||
) -> Self {
|
||||
Self::load(path, change_sender).unwrap_or_else(|error| {
|
||||
let mut this = Self::load(path).unwrap_or_else(|error| {
|
||||
error!(?path, %error, "failed to parse cache file");
|
||||
Self::default()
|
||||
})
|
||||
});
|
||||
|
||||
this.change_sender = Some(change_sender);
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
pub fn update_allowed_ports(&mut self, allowed_ports: &AllowedList) {
|
||||
|
||||
Reference in New Issue
Block a user