Compare commits
14 Commits
15672536f6
...
CI
| Author | SHA1 | Date | |
|---|---|---|---|
| b887d2475f | |||
| e98c996874 | |||
| c3444b927a | |||
| fbd9d268bb | |||
| 3a93a3bc90 | |||
| 885115289e | |||
| 8de50fbe7e | |||
| 97230c7b1f | |||
| 9b6658dfe2 | |||
| 1dba1ab298 | |||
| 64f10d978d | |||
| 5c2049af94 | |||
| 3cae37852a | |||
| eb4c6854f0 |
38
.gitea/workflows/checks.yaml
Normal file
38
.gitea/workflows/checks.yaml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
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
|
||||||
15
src/main.rs
15
src/main.rs
@@ -1,5 +1,5 @@
|
|||||||
#![warn(clippy::pedantic)]
|
#![warn(clippy::pedantic)]
|
||||||
// #![allow(clippy::missing_errors_doc)]
|
#![allow(clippy::let_underscore_untyped)] // false positive in stable
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
@@ -350,11 +350,7 @@ async fn tokio_main(config: Arc<Config>) -> eyre::Result<()> {
|
|||||||
"centralex server listening"
|
"centralex server listening"
|
||||||
);
|
);
|
||||||
|
|
||||||
loop {
|
while let Ok((stream, addr)) = listener.accept().await {
|
||||||
let connection = listener.accept().await;
|
|
||||||
|
|
||||||
match connection {
|
|
||||||
Ok((stream, addr)) => {
|
|
||||||
info!(%addr, "new connection");
|
info!(%addr, "new connection");
|
||||||
|
|
||||||
spawn(
|
spawn(
|
||||||
@@ -362,11 +358,8 @@ async fn tokio_main(config: Arc<Config>) -> eyre::Result<()> {
|
|||||||
connection_handler(stream, addr, config.clone(), port_handler.clone()),
|
connection_handler(stream, addr, config.clone(), port_handler.clone()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
|
||||||
error!(%err, "failed to accept connection");
|
Ok(())
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::{ffi::CStr, fmt::Debug};
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
@@ -85,18 +85,18 @@ impl Debug for Packet {
|
|||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let data = &self.data;
|
let data = &self.data;
|
||||||
|
|
||||||
let mut debugger = f.debug_struct("Packet");
|
let str_data = std::str::from_utf8(&data[..data.len().saturating_sub(1)]).ok();
|
||||||
|
|
||||||
debugger.field("kind", &PacketKind::from_u8(self.header.kind));
|
let data = if let Some(str_data) = str_data.as_ref() {
|
||||||
|
str_data as &dyn Debug
|
||||||
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 {
|
} else {
|
||||||
debugger.field("data", &data);
|
&data as &dyn Debug
|
||||||
}
|
};
|
||||||
|
|
||||||
debugger.finish()
|
f.debug_struct("Packet")
|
||||||
|
.field("kind", &PacketKind::from_u8(self.header.kind))
|
||||||
|
.field("data", &data)
|
||||||
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
20
src/ports.rs
20
src/ports.rs
@@ -283,7 +283,7 @@ impl PortHandler {
|
|||||||
self.last_update = Some(now);
|
self.last_update = Some(now);
|
||||||
self.change_sender
|
self.change_sender
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("PortHandler is missing its change_sender")
|
.expect("PortHandler is missing it's change_sender")
|
||||||
.send(now)
|
.send(now)
|
||||||
.expect("failed to notify cache writer");
|
.expect("failed to notify cache writer");
|
||||||
}
|
}
|
||||||
@@ -301,9 +301,15 @@ impl PortHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::missing_errors_doc)]
|
#[allow(clippy::missing_errors_doc)]
|
||||||
pub fn load(cache: &Path) -> std::io::Result<Self> {
|
#[instrument(skip(change_sender))]
|
||||||
|
pub fn load(
|
||||||
|
cache: &Path,
|
||||||
|
change_sender: tokio::sync::watch::Sender<Instant>,
|
||||||
|
) -> std::io::Result<Self> {
|
||||||
info!("loading cache");
|
info!("loading cache");
|
||||||
Ok(serde_json::from_reader(BufReader::new(File::open(cache)?))?)
|
let mut cache: Self = serde_json::from_reader(BufReader::new(File::open(cache)?))?;
|
||||||
|
cache.change_sender = Some(change_sender);
|
||||||
|
Ok(cache)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
@@ -312,14 +318,10 @@ impl PortHandler {
|
|||||||
path: &Path,
|
path: &Path,
|
||||||
change_sender: tokio::sync::watch::Sender<Instant>,
|
change_sender: tokio::sync::watch::Sender<Instant>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut this = Self::load(path).unwrap_or_else(|error| {
|
Self::load(path, change_sender).unwrap_or_else(|error| {
|
||||||
error!(?path, %error, "failed to parse cache file");
|
error!(?path, %error, "failed to parse cache file");
|
||||||
Self::default()
|
Self::default()
|
||||||
});
|
})
|
||||||
|
|
||||||
this.change_sender = Some(change_sender);
|
|
||||||
|
|
||||||
this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_allowed_ports(&mut self, allowed_ports: &AllowedList) {
|
pub fn update_allowed_ports(&mut self, allowed_ports: &AllowedList) {
|
||||||
|
|||||||
Reference in New Issue
Block a user