Compare commits
No commits in common. "41d10c5c94c5d09bd418a801b3ea19d785282878" and "635488ddeb1067c3ea7c264097b862ee713be336" have entirely different histories.
41d10c5c94
...
635488ddeb
@ -1 +0,0 @@
|
|||||||
target/
|
|
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
@ -4,6 +4,7 @@ name: CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
branches: [main]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
@ -11,11 +12,11 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
MY_DOCKER_USERNAME: ${{ secrets.MY_DOCKER_USERNAME }}
|
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||||
MY_DOCKER_PASSWORD: ${{ secrets.MY_DOCKER_PASSWORD }}
|
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
|
||||||
FORCE_COLOR: 1
|
FORCE_COLOR: 1
|
||||||
steps:
|
steps:
|
||||||
- uses: https://github.com/earthly/actions-setup@v1
|
- uses: earthly/actions/setup-earthly@v1
|
||||||
with:
|
with:
|
||||||
version: v0.7.0
|
version: v0.7.0
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@ -29,7 +30,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
git checkout -b "$branch" || true
|
git checkout -b "$branch" || true
|
||||||
- name: Docker Login
|
- name: Docker Login
|
||||||
run: docker login git.hibas.dev --username "$MY_DOCKER_USERNAME" --password "$MY_DOCKER_PASSWORD"
|
run: docker login docker.hibas123.de --username "$DOCKER_USERNAME" --password "$DOCKER_TOKEN"
|
||||||
- name: Earthly version
|
- name: Earthly version
|
||||||
run: earthly --version
|
run: earthly --version
|
||||||
- name: Run build
|
- name: Run build
|
||||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -838,7 +838,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustocat"
|
name = "rustocat"
|
||||||
version = "0.1.12"
|
version = "0.1.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rustocat"
|
name = "rustocat"
|
||||||
version = "0.1.12"
|
version = "0.1.10"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Socat in rust with many less features and a configuration file"
|
description = "Socat in rust with many less features and a configuration file"
|
||||||
license = "ISC"
|
license = "ISC"
|
||||||
|
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
FROM rust:alpine as builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN apk add --no-cache musl-dev libssl3 openssl-dev
|
||||||
|
|
||||||
|
# This should fetch the index and cache it. This should reduce the time required of subsequent builds
|
||||||
|
RUN cargo search test
|
||||||
|
|
||||||
|
COPY Cargo.toml Cargo.lock /app/
|
||||||
|
# COPY .cargo /app/.cargo
|
||||||
|
|
||||||
|
COPY src /app/src
|
||||||
|
|
||||||
|
|
||||||
|
RUN cargo build --release
|
||||||
|
|
||||||
|
FROM alpine
|
||||||
|
|
||||||
|
RUN apk add --no-cache libssl3
|
||||||
|
COPY --from=builder /app/target/release/rustocat /usr/bin/rustocat
|
||||||
|
|
||||||
|
ENTRYPOINT ["/bin/sh"]
|
||||||
|
CMD [ "-c", "/usr/bin/rustocat" ]
|
||||||
|
|
||||||
|
|
@ -19,7 +19,9 @@ docker:
|
|||||||
FROM alpine
|
FROM alpine
|
||||||
RUN apk add --no-cache libssl3
|
RUN apk add --no-cache libssl3
|
||||||
COPY +build/rustocat rustocat
|
COPY +build/rustocat rustocat
|
||||||
ENTRYPOINT ["./rustocat"]
|
ENTRYPOINT ["/bin/sh"]
|
||||||
|
CMD ["-c", "/rustbuild/rustocat"]
|
||||||
ARG EARTHLY_TARGET_TAG
|
ARG EARTHLY_TARGET_TAG
|
||||||
ARG TAG=$EARTHLY_TARGET_TAG
|
ARG TAG=$EARTHLY_TARGET_TAG
|
||||||
SAVE IMAGE --push git.hibas.dev/hibas123/rustocat:$TAG
|
SAVE IMAGE --push docker.hibas123.de/rustocat:latest
|
||||||
|
SAVE IMAGE --push docker.hibas123.de/rustocat:$TAG
|
@ -1,11 +1,9 @@
|
|||||||
use crate::shutdown::ShutdownReceiver;
|
use crate::shutdown::ShutdownReceiver;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::broadcast;
|
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
pub(crate) struct Listener {
|
pub(crate) struct Listener {
|
||||||
pub(crate) shutdown: ShutdownReceiver,
|
pub(crate) shutdown: ShutdownReceiver,
|
||||||
pub(crate) source: String,
|
pub(crate) source: String,
|
||||||
pub(crate) targets: Arc<RwLock<Vec<String>>>,
|
pub(crate) targets: Arc<RwLock<Vec<String>>>,
|
||||||
pub(crate) targets_changed: broadcast::Receiver<()>,
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
|
|||||||
struct ActiveListener {
|
struct ActiveListener {
|
||||||
notify_shutdown: broadcast::Sender<()>,
|
notify_shutdown: broadcast::Sender<()>,
|
||||||
targets: Arc<RwLock<Vec<String>>>,
|
targets: Arc<RwLock<Vec<String>>>,
|
||||||
notify_targets: broadcast::Sender<()>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -120,24 +119,19 @@ async fn run_loop(
|
|||||||
warn!("Found invalid targets! Adjusting!");
|
warn!("Found invalid targets! Adjusting!");
|
||||||
let mut w = listener.targets.write().await;
|
let mut w = listener.targets.write().await;
|
||||||
*w = target.targets;
|
*w = target.targets;
|
||||||
|
|
||||||
_ = listener.notify_targets.send(())?; //TODO: Maybe ignore this error
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let (notify_shutdown, _) = broadcast::channel(1);
|
let (notify_shutdown, _) = broadcast::channel(1);
|
||||||
let (notify_targets, _) = broadcast::channel(1);
|
|
||||||
|
|
||||||
let listener = ActiveListener {
|
let listener = ActiveListener {
|
||||||
notify_shutdown: notify_shutdown,
|
notify_shutdown: notify_shutdown,
|
||||||
targets: Arc::new(RwLock::new(target.targets)),
|
targets: Arc::new(RwLock::new(target.targets)),
|
||||||
notify_targets: notify_targets,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let l = listener::Listener {
|
let l = listener::Listener {
|
||||||
shutdown: shutdown::ShutdownReceiver::new(listener.notify_shutdown.subscribe()),
|
shutdown: shutdown::ShutdownReceiver::new(listener.notify_shutdown.subscribe()),
|
||||||
source: target.source.clone(),
|
source: target.source.clone(),
|
||||||
targets: listener.targets.clone(),
|
targets: listener.targets.clone(),
|
||||||
targets_changed: listener.notify_targets.subscribe(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
@ -174,8 +168,6 @@ async fn run_loop(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Maybe Wait for the listener to shut down
|
|
||||||
|
|
||||||
debug!("Removing listener!");
|
debug!("Removing listener!");
|
||||||
listeners.remove(&del_key);
|
listeners.remove(&del_key);
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,6 @@ pub(crate) async fn start_tcp_listener(
|
|||||||
loop {
|
loop {
|
||||||
let (next_socket, _) = tokio::select! {
|
let (next_socket, _) = tokio::select! {
|
||||||
res = listener.accept() => res?,
|
res = listener.accept() => res?,
|
||||||
_ = listener_config.targets_changed.recv() => {
|
|
||||||
info!("Targets changed!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
_ = listener_config.shutdown.recv() => {
|
_ = listener_config.shutdown.recv() => {
|
||||||
info!("Exiting listener!");
|
info!("Exiting listener!");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
11
src/udp.rs
11
src/udp.rs
@ -180,15 +180,6 @@ pub(crate) async fn start_udp_listener(mut listener_config: Listener) -> Result<
|
|||||||
trace!("Waiting for packet or shutdown");
|
trace!("Waiting for packet or shutdown");
|
||||||
let (num_bytes, src_addr) = tokio::select! {
|
let (num_bytes, src_addr) = tokio::select! {
|
||||||
res = listener.recv_from(&mut buf) => res?,
|
res = listener.recv_from(&mut buf) => res?,
|
||||||
_ = listener_config.targets_changed.recv() => {
|
|
||||||
info!("Targets changed!");
|
|
||||||
info!("Closing all connections!");
|
|
||||||
for (_, handler) in connections.lock().await.iter_mut() {
|
|
||||||
handler.close().await;
|
|
||||||
}
|
|
||||||
info!("Closed all connections!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
_ = listener_config.shutdown.recv() => {
|
_ = listener_config.shutdown.recv() => {
|
||||||
info!("Exiting listener!");
|
info!("Exiting listener!");
|
||||||
break;
|
break;
|
||||||
@ -229,7 +220,5 @@ pub(crate) async fn start_udp_listener(mut listener_config: Listener) -> Result<
|
|||||||
handler.close().await;
|
handler.close().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Listener closed.");
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user