Compare commits

..

14 Commits

Author SHA1 Message Date
b887d2475f Update '.gitea/workflows/checks.yaml'
All checks were successful
Code Checks / cargo clippy (pull_request) Successful in 3m10s
Code Checks / cargo test (pull_request) Successful in 3m10s
Code Checks / cargo fmt (pull_request) Successful in 3m4s
2023-05-07 02:32:36 +02:00
e98c996874 don't test all-features
All checks were successful
Code Checks / cargo fmt (pull_request) Successful in 3m4s
Code Checks / cargo clippy (pull_request) Successful in 3m10s
Code Checks / cargo test (pull_request) Successful in 3m10s
2023-05-07 02:21:09 +02:00
c3444b927a fix CI
Some checks failed
Code Checks / cargo fmt (pull_request) Successful in 3m4s
Code Checks / cargo clippy (pull_request) Successful in 3m10s
Code Checks / cargo test (pull_request) Failing after 3m17s
2023-05-07 02:13:31 +02:00
fbd9d268bb Update '.gitea/workflows/checks.yaml'
Some checks failed
Code Checks / cargo fmt (pull_request) Successful in 3m5s
Code Checks / cargo clippy (pull_request) Failing after 3m10s
Code Checks / cargo test (pull_request) Failing after 3m17s
2023-05-07 02:01:36 +02:00
3a93a3bc90 Update '.gitea/workflows/checks.yaml'
Some checks failed
Code Checks / cargo fmt (pull_request) Successful in 3m6s
Code Checks / cargo test (pull_request) Failing after 1s
Code Checks / cargo clippy (pull_request) Has started running
2023-05-07 01:53:43 +02:00
885115289e unify actions
Some checks failed
Code Checks / cargo fmt (pull_request) Failing after 13m16s
Code Checks / cargo clippy (pull_request) Has started running
Code Checks / cargo test (pull_request) Has started running
2023-05-07 01:28:13 +02:00
8de50fbe7e remove github prefix again
Some checks failed
Code Checks / cargo fmt (pull_request) Failing after 14m11s
Test Suite / cargo test (pull_request) Failing after 12m23s
Code Checks / cargo clippy (pull_request) Failing after 14m53s
2023-05-07 01:27:08 +02:00
97230c7b1f add github prefix again
Some checks failed
Test Suite / cargo test (pull_request) Failing after 2s
Code Checks / cargo fmt (pull_request) Failing after 2s
Code Checks / cargo clippy (pull_request) Failing after 16s
2023-05-07 01:24:21 +02:00
9b6658dfe2 add version
Some checks failed
Test Suite / cargo test (push) Failing after 2s
Code Checks / cargo fmt (pull_request) Failing after 2s
Code Checks / cargo clippy (pull_request) Failing after 3s
Test Suite / cargo test (pull_request) Failing after 2s
2023-05-07 01:18:56 +02:00
1dba1ab298 remove github prefix?
Some checks failed
Test Suite / cargo test (push) Failing after 14s
Code Checks / cargo fmt (pull_request) Failing after 11s
Code Checks / cargo clippy (pull_request) Failing after 2s
Test Suite / cargo test (pull_request) Failing after 2s
2023-05-07 01:17:59 +02:00
64f10d978d remove github prefix? 2023-05-07 01:17:49 +02:00
5c2049af94 fix actions?
Some checks failed
Code Checks / cargo fmt (push) Failing after 3s
Code Checks / cargo clippy (push) Failing after 2s
Test Suite / cargo test (push) Failing after 2s
Code Checks / cargo fmt (pull_request) Failing after 2s
Code Checks / cargo clippy (pull_request) Failing after 2s
Test Suite / cargo test (pull_request) Failing after 2s
2023-05-07 01:15:55 +02:00
3cae37852a fully specify actions-rust-lang url
Some checks failed
Code Checks / cargo fmt (push) Failing after 27s
Code Checks / cargo clippy (push) Failing after 4s
Test Suite / cargo test (push) Failing after 24s
Test Suite / cargo test (pull_request) Failing after 24s
Code Checks / cargo clippy (pull_request) Failing after 4s
Code Checks / cargo fmt (pull_request) Failing after 25s
2023-05-07 01:07:57 +02:00
eb4c6854f0 add actions
Some checks failed
Code Checks / cargo fmt (push) Failing after 3s
Code Checks / cargo clippy (push) Failing after 3s
Test Suite / cargo test (push) Failing after 2s
Code Checks / cargo fmt (pull_request) Failing after 3s
Code Checks / cargo clippy (pull_request) Failing after 2s
Test Suite / cargo test (pull_request) Failing after 3s
2023-05-07 01:05:34 +02:00
4 changed files with 68 additions and 35 deletions

View 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

View File

@@ -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,23 +350,16 @@ 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; info!(%addr, "new connection");
match connection { spawn(
Ok((stream, addr)) => { &format!("connection to {addr}"),
info!(%addr, "new connection"); connection_handler(stream, addr, config.clone(), port_handler.clone()),
);
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)] #[derive(Debug, Default)]

View File

@@ -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()
} }
} }

View File

@@ -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) {