Compare commits

..

9 Commits

Author SHA1 Message Date
cscherrNT 9f9ea39e58 automatic cargo CI changes 2024-08-21 10:18:07 +00:00
Christoph J. Scherr 670a4bd192 fix it again because of tokio updates
cargo devel CI / cargo CI (push) Successful in 1m36s Details
2024-08-21 12:16:35 +02:00
Christoph J. Scherr 7ec2e55ec5 fix ci
cargo devel CI / cargo CI (push) Failing after 1m36s Details
2024-08-21 12:01:30 +02:00
Christoph J. Scherr cd6a5c21d2 fix bugs
cargo devel CI / cargo CI (push) Failing after 6s Details
2024-08-21 11:56:52 +02:00
Christoph J. Scherr ffd8461368
Merge branch 'devel'
cargo devel CI / cargo CI (push) Failing after 2s Details
2024-02-09 17:53:47 +01:00
Christoph J. Scherr 9fbf8ecdf5
ready for release
cargo devel CI / cargo CI (push) Successful in 2m4s Details
2024-01-24 22:05:35 +01:00
Christoph J. Scherr 52ac674e50
Merge branch 'devel'
cargo devel CI / cargo CI (push) Successful in 2m7s Details
2024-01-24 21:57:45 +01:00
Christoph J. Scherr 26521989be
Merge branch 'devel'
cargo devel CI / cargo CI (push) Successful in 2m59s Details
2024-01-24 16:29:25 +01:00
Christoph J. Scherr b7fcd9c455 Merge pull request 'We have a server at least' (#3) from devel into master
cargo devel CI / cargo CI (push) Successful in 1m59s Details
Reviewed-on: #3
2024-01-19 16:40:16 +01:00
13 changed files with 77 additions and 68 deletions

View File

@ -16,9 +16,11 @@ jobs:
- name: get repo - name: get repo
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: install rust - name: install rust
uses: dtolnay/rust-toolchain@stable uses: https://github.com/dtolnay/rust-toolchain@stable
- name: install additional rust things - name: install additional rust things
run: rustup component add rustfmt run: |
rustup component add rustfmt
rustup component add clippy
- name: config custom registry - name: config custom registry
run: | run: |
mkdir -p ~/.cargo/ mkdir -p ~/.cargo/
@ -28,16 +30,16 @@ jobs:
echo '[registries.cscherr]' >> ~/.cargo/config.toml echo '[registries.cscherr]' >> ~/.cargo/config.toml
echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml
cat ~/.cargo/config.toml cat ~/.cargo/config.toml
- name: cargo check - name: cargo clippy check
run: cargo check --all-features --all-targets run: cargo clippy --all-features --all-targets
- name: cargo fix - name: cargo clippy fix
run: cargo fix --all-features --all-targets run: cargo clippy --fix --all-features --all-targets
- name: cargo fmt - name: cargo fmt
run: cargo fmt --all run: cargo fmt --all
- name: cargo test - name: cargo test
run: cargo test --all-features --all-targets run: cargo test --all-features --all-targets
- name: commit back to repository - name: commit back to repository
uses: stefanzweifel/git-auto-commit-action@v5 uses: https://github.com/stefanzweifel/git-auto-commit-action@v5
with: with:
# Optional. Commit message for the created commit. # Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes" # Defaults to "Apply automatic changes"

View File

@ -1,7 +1,6 @@
workspace = { members = ["spammer"] }
[package] [package]
name = "netpong" name = "netpong"
version = "0.2.1" version = "0.2.2"
edition = "2021" edition = "2021"
publish = true publish = true
authors = ["Christoph J. Scherr <software@cscherr.de>"] authors = ["Christoph J. Scherr <software@cscherr.de>"]
@ -18,12 +17,12 @@ anyhow = "1.0.79"
clap = "4.4.18" clap = "4.4.18"
clap-num = "1.0.2" clap-num = "1.0.2"
clap-verbosity-flag = "2.1.2" clap-verbosity-flag = "2.1.2"
libpt = { version = "0.3.11", features = ["net"] }
thiserror = "1.0.56" thiserror = "1.0.56"
tokio = { version = "1.35.1", features = ["net", "rt", "macros"] } tokio = { version = "1.35.1", features = ["net", "rt-multi-thread", "macros", "time", "io-util"] }
rustls-pemfile = "2.0.0" rustls-pemfile = "2.0.0"
tokio-rustls = "0.25.0" tokio-rustls = "0.25.0"
webpki-roots = "0.26.0" webpki-roots = "0.26.0"
libpt = { version = "0.6.0", features = ["log"] }
[features] [features]
default = ["server"] default = ["server"]

View File

@ -1,3 +1,3 @@
# rs-base # netpong
Base repository for rust projects Let your hosts play Pingpong over a tls connection.

View File

@ -1,5 +0,0 @@
#!/bin/bash
mkdir data
echo create ca
# non-interactive and 10 years expiration
openssl req -x509 -nodes -newkey rsa:4096 -keyout data/key.pem -out data/cert.pem -sha256 -days 3650 -subj '/CN=localhost'

11
scripts/publish.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
set -e
cargo check --all-features
echo ">>>>>>>> PUBLISHING RELEASE FOR REPO"
bash scripts/release.sh
echo ">>>>>>>> PUBLISHING TO CRATES.IO NEXT"
sleep 2
cargo publish
echo ">>>>>>>> PUBLISHING TO CSCHERR.DE NEXT"
sleep 2
cargo publish --registry cscherr

24
scripts/release.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
TOKEN=$(cat ~/.git-credentials | grep 'git.cscherr.de' | grep -P '(?:)[^:]*(?=@)' -o)
NEW_VERSION=$(cat Cargo.toml | rg '^\s*version\s*=\s*"([^"]*)"\s*$' -or '$1')
GIT_COMMIT_SHA=$(git rev-parse HEAD)
REPO=${PWD##*/} # name of cwd
BODY="
$(git log $(git describe --tags --abbrev=0)..HEAD --pretty="- %s" --oneline --decorate)
"
USER=PlexSheep
git tag "v$NEW_VERSION-test" || echo "could not tag"
curl -X 'POST' \
'https://git.cscherr.de/api/v1/repos/PlexSheep/'$REPO'/releases' \
-H 'accept: application/json' \
-H "Authorization: token $TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"body": "'"$BODY"'",
"draft": false,
"name": "v'$NEW_VERSION'",
"prerelease": true,
"tag_name": "v'$NEW_VERSION'",
"target_commitish": "'$GIT_COMMIT_SHA'"
}' | python -m json.tool
git push || echo "could not push"

View File

@ -1,9 +0,0 @@
[package]
name = "spammer"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
threadpool = "1.8.1"

View File

@ -1,18 +0,0 @@
use threadpool::ThreadPool;
const MAX: usize = 20;
use std::process::Command;
fn main() {
let pool = ThreadPool::new(MAX);
loop {
if pool.queued_count() < MAX {
pool.execute(|| {
let mut cmd = Command::new("/usr/bin/python3");
cmd.args(["../scripts/client.py"]);
let _ = cmd.output().unwrap();
});
}
std::thread::sleep(std::time::Duration::from_millis(100));
}
}

View File

@ -3,17 +3,14 @@ use std::{fs::File, io::BufReader, sync::Arc};
use crate::{common::decode, Config}; use crate::{common::decode, Config};
use anyhow;
use libpt::log::{error, info, trace}; use libpt::log::{error, info, trace};
use rustls_pemfile::certs; use rustls_pemfile::certs;
use tokio::{ use tokio::io::{AsyncReadExt, AsyncWriteExt};
io::{AsyncReadExt, AsyncWriteExt}, use tokio::net::TcpStream;
net::TcpStream,
};
use tokio_rustls::{ use tokio_rustls::{
rustls::{self, pki_types}, TlsConnector, TlsStream rustls::{self, pki_types},
TlsConnector, TlsStream,
}; };
use webpki_roots;
const BUF_SIZE: usize = 512; const BUF_SIZE: usize = 512;
@ -47,11 +44,13 @@ impl Client {
return Err(err.into()); return Err(err.into());
} }
}; };
let mut stream = connector.connect(domain, TcpStream::connect(&cfg.addr).await?).await?; let stream = connector
.connect(domain.clone(), TcpStream::connect(&cfg.addr).await?)
.await?;
Ok(Client { Ok(Client {
cfg: cfg.clone(), cfg: cfg.clone(),
stream, stream: tokio_rustls::TlsStream::Client(stream),
connector, connector,
domain, domain,
}) })

View File

@ -6,11 +6,11 @@ use clap::Parser;
use clap_verbosity_flag::{InfoLevel, Verbosity}; use clap_verbosity_flag::{InfoLevel, Verbosity};
/// short about section displayed in help /// short about section displayed in help
const ABOUT_ROOT: &'static str = r##" const ABOUT_ROOT: &str = r##"
Let your hosts play ping pong over the network Let your hosts play ping pong over the network
"##; "##;
/// longer about section displayed in help, is combined with [the short help](ABOUT_ROOT) /// longer about section displayed in help, is combined with [the short help](ABOUT_ROOT)
static LONG_ABOUT_ROOT: &'static str = r##" static LONG_ABOUT_ROOT: &str = r##"
Connect to a ping pong server and periodically send a ping. The server will reply with a pong. Connect to a ping pong server and periodically send a ping. The server will reply with a pong.
That's it really. You can also host your own netpong server (server feature). That's it really. You can also host your own netpong server (server feature).
@ -74,11 +74,18 @@ impl Cli {
} }
}; };
if cli.meta { if cli.meta {
Logger::init(None, Some(ll), true).expect("could not initialize Logger"); let _ = Logger::builder()
.set_level(ll)
.display_filename(true)
.build()
.expect("could not initialize Logger");
} else { } else {
// less verbose version // less verbose version
Logger::init_mini(Some(ll)).expect("could not initialize Logger"); let _ = Logger::builder()
.set_level(ll)
.build()
.expect("could not initialize Logger");
} }
return cli; cli
} }
} }

View File

@ -7,7 +7,7 @@ pub mod conf;
pub fn decode(buf: &[u8]) -> Result<String, Utf8Error> { pub fn decode(buf: &[u8]) -> Result<String, Utf8Error> {
Ok(match std::str::from_utf8(buf) { Ok(match std::str::from_utf8(buf) {
Ok(s) => s.to_string(), Ok(s) => s.to_string(),
Err(err) => return Err(err.into()), Err(err) => return Err(err),
} }
.trim_matches(char::from(0)) .trim_matches(char::from(0))
.to_string()) .to_string())

View File

@ -5,7 +5,6 @@
use anyhow::Result; use anyhow::Result;
use libpt::log::*; use libpt::log::*;
use tokio;
mod client; mod client;
mod common; mod common;

View File

@ -13,7 +13,7 @@ use rustls_pemfile::{certs, private_key};
use tokio::{ use tokio::{
io::{AsyncReadExt, AsyncWriteExt}, io::{AsyncReadExt, AsyncWriteExt},
net::{TcpListener, TcpStream}, net::{TcpListener, TcpStream},
time::{self}, time,
}; };
use tokio_rustls::{rustls, TlsAcceptor}; use tokio_rustls::{rustls, TlsAcceptor};
@ -109,10 +109,10 @@ impl Server {
error!("the server needs a key!"); error!("the server needs a key!");
return Err(std::io::ErrorKind::InvalidInput.into()); return Err(std::io::ErrorKind::InvalidInput.into());
} }
let key = private_key(&mut std::io::BufReader::new(File::open(
private_key(&mut std::io::BufReader::new(File::open(
cfg.key.clone().unwrap(), cfg.key.clone().unwrap(),
)?)); )?))
return key;
} }
fn load_certs(cfg: Config) -> std::io::Result<Vec<CertificateDer<'static>>> { fn load_certs(cfg: Config) -> std::io::Result<Vec<CertificateDer<'static>>> {
@ -121,18 +121,18 @@ impl Server {
return Err(std::io::ErrorKind::InvalidInput.into()); return Err(std::io::ErrorKind::InvalidInput.into());
} }
match certs(&mut std::io::BufReader::new(File::open( match certs(&mut std::io::BufReader::new(File::open(
&cfg.certs.clone().unwrap(), cfg.certs.clone().unwrap(),
)?)) )?))
.collect::<std::io::Result<Vec<CertificateDer<'static>>>>() .collect::<std::io::Result<Vec<CertificateDer<'static>>>>()
{ {
Ok(v) if !v.is_empty() => Ok(v), Ok(v) if !v.is_empty() => Ok(v),
Ok(_) => { Ok(_) => {
error!("no certs found in provided file {:?}", cfg.certs); error!("no certs found in provided file {:?}", cfg.certs);
return Err(std::io::ErrorKind::InvalidInput.into()); Err(std::io::ErrorKind::InvalidInput.into())
} }
Err(err) => { Err(err) => {
error!("could not load certs: {err:?}"); error!("could not load certs: {err:?}");
return Err(err); Err(err)
} }
} }
} }