From 66928a9128cafa66b7cce8fdc9b98fc7c921ee0f Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Wed, 17 Apr 2024 08:49:13 -0600 Subject: [PATCH 1/8] use dashes instead of underscores in naming of folders/libraries --- Cargo.lock | 14 +++++++------- Cargo.toml | 2 +- src/bin/{sdre_hub => sdre-hub}/Cargo.toml | 4 ++-- src/bin/{sdre_hub => sdre-hub}/src/main.rs | 0 .../{sdrehub_config => sdrehub-config}/Cargo.toml | 0 .../src/acars_router_source.rs | 0 .../src/address.rs | 0 .../src/adsb_source.rs | 0 .../{sdrehub_config => sdrehub-config}/src/lib.rs | 0 .../{sdrehub_config => sdrehub-config}/src/map.rs | 0 .../src/sdrehub.rs | 0 .../src/source.rs | 0 12 files changed, 10 insertions(+), 10 deletions(-) rename src/bin/{sdre_hub => sdre-hub}/Cargo.toml (81%) rename src/bin/{sdre_hub => sdre-hub}/src/main.rs (100%) rename src/libraries/{sdrehub_config => sdrehub-config}/Cargo.toml (100%) rename src/libraries/{sdrehub_config => sdrehub-config}/src/acars_router_source.rs (100%) rename src/libraries/{sdrehub_config => sdrehub-config}/src/address.rs (100%) rename src/libraries/{sdrehub_config => sdrehub-config}/src/adsb_source.rs (100%) rename src/libraries/{sdrehub_config => sdrehub-config}/src/lib.rs (100%) rename src/libraries/{sdrehub_config => sdrehub-config}/src/map.rs (100%) rename src/libraries/{sdrehub_config => sdrehub-config}/src/sdrehub.rs (100%) rename src/libraries/{sdrehub_config => sdrehub-config}/src/source.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index a4b9ae7..e668e65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -358,6 +358,13 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +[[package]] +name = "sdre-hub" +version = "4.0.0-alpha1" +dependencies = [ + "sdrehub_config", +] + [[package]] name = "sdre-rust-logging" version = "0.3.1" @@ -370,13 +377,6 @@ dependencies = [ "log", ] -[[package]] -name = "sdre_hub" -version = "4.0.0-alpha1" -dependencies = [ - "sdrehub_config", -] - [[package]] name = "sdrehub_config" version = "4.0.0-alpha1" diff --git a/Cargo.toml b/Cargo.toml index 0a0a6cc..7545e3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["src/libraries/sdrehub_config", "src/bin/sdre_hub"] +members = ["src/libraries/sdrehub-config", "src/bin/sdre-hub"] resolver = "2" diff --git a/src/bin/sdre_hub/Cargo.toml b/src/bin/sdre-hub/Cargo.toml similarity index 81% rename from src/bin/sdre_hub/Cargo.toml rename to src/bin/sdre-hub/Cargo.toml index 9338493..b3e99b2 100644 --- a/src/bin/sdre_hub/Cargo.toml +++ b/src/bin/sdre-hub/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sdre_hub" +name = "sdre-hub" version.workspace = true edition.workspace = true authors.workspace = true @@ -14,4 +14,4 @@ categories.workspace = true keywords.workspace = true [dependencies] -sdrehub_config = { path = "../../libraries/sdrehub_config" } +sdrehub_config = { path = "../../libraries/sdrehub-config" } diff --git a/src/bin/sdre_hub/src/main.rs b/src/bin/sdre-hub/src/main.rs similarity index 100% rename from src/bin/sdre_hub/src/main.rs rename to src/bin/sdre-hub/src/main.rs diff --git a/src/libraries/sdrehub_config/Cargo.toml b/src/libraries/sdrehub-config/Cargo.toml similarity index 100% rename from src/libraries/sdrehub_config/Cargo.toml rename to src/libraries/sdrehub-config/Cargo.toml diff --git a/src/libraries/sdrehub_config/src/acars_router_source.rs b/src/libraries/sdrehub-config/src/acars_router_source.rs similarity index 100% rename from src/libraries/sdrehub_config/src/acars_router_source.rs rename to src/libraries/sdrehub-config/src/acars_router_source.rs diff --git a/src/libraries/sdrehub_config/src/address.rs b/src/libraries/sdrehub-config/src/address.rs similarity index 100% rename from src/libraries/sdrehub_config/src/address.rs rename to src/libraries/sdrehub-config/src/address.rs diff --git a/src/libraries/sdrehub_config/src/adsb_source.rs b/src/libraries/sdrehub-config/src/adsb_source.rs similarity index 100% rename from src/libraries/sdrehub_config/src/adsb_source.rs rename to src/libraries/sdrehub-config/src/adsb_source.rs diff --git a/src/libraries/sdrehub_config/src/lib.rs b/src/libraries/sdrehub-config/src/lib.rs similarity index 100% rename from src/libraries/sdrehub_config/src/lib.rs rename to src/libraries/sdrehub-config/src/lib.rs diff --git a/src/libraries/sdrehub_config/src/map.rs b/src/libraries/sdrehub-config/src/map.rs similarity index 100% rename from src/libraries/sdrehub_config/src/map.rs rename to src/libraries/sdrehub-config/src/map.rs diff --git a/src/libraries/sdrehub_config/src/sdrehub.rs b/src/libraries/sdrehub-config/src/sdrehub.rs similarity index 100% rename from src/libraries/sdrehub_config/src/sdrehub.rs rename to src/libraries/sdrehub-config/src/sdrehub.rs diff --git a/src/libraries/sdrehub_config/src/source.rs b/src/libraries/sdrehub-config/src/source.rs similarity index 100% rename from src/libraries/sdrehub_config/src/source.rs rename to src/libraries/sdrehub-config/src/source.rs From bc8d50a620e2ac1adae8e6d61d40b9304cbf4eb5 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Wed, 17 Apr 2024 08:56:37 -0600 Subject: [PATCH 2/8] basic build structure --- Dockerfile | 52 ++++++++++++++++++++++++++++ Dockerfile.build_binary | 13 +++++++ Dockerfile.local | 50 ++++++++++++++++++++++++++ rootfs/rename_current_arch_binary.sh | 17 +++++++++ 4 files changed, 132 insertions(+) create mode 100644 Dockerfile create mode 100644 Dockerfile.build_binary create mode 100644 Dockerfile.local create mode 100755 rootfs/rename_current_arch_binary.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9729988 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,52 @@ +FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base + +ENV AR_LISTEN_UDP_ACARS=5550 \ + AR_LISTEN_TCP_ACARS=5550 \ + AR_LISTEN_UDP_VDLM2=5555 \ + AR_LISTEN_TCP_VDLM2=5555 \ + AR_LISTEN_UDP_HFDL=5556 \ + AR_LISTEN_TCP_HFDL=5556 \ + AR_LISTEN_ZMQ_ACARS=35550 \ + AR_LISTEN_ZMQ_VDLM2=35555 \ + AR_LISTEN_ZMQ_HFDL=35556 \ + AR_SERVE_TCP_ACARS=15550 \ + AR_SERVE_TCP_VDLM2=15555 \ + AR_SERVE_TCP_HFDL=15556 \ + AR_SERVE_ZMQ_ACARS=45550 \ + AR_SERVE_ZMQ_VDLM2=45555 \ + AR_SERVE_ZMQ_HFDL=45556 \ + AR_ADD_PROXY_ID=true + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +COPY ./rootfs / +COPY ./bin/sdre-hub.armv7/sdre-hub /opt/sdre-hub.armv7 +COPY ./bin/sdre-hub.arm64/sdre-hub /opt/sdre-hub.arm64 +COPY ./bin/sdre-hub.amd64/sdre-hub /opt/sdre-hub.amd64 + +# hadolint ignore=DL3008,DL3003,SC1091 +RUN set -x && \ + KEPT_PACKAGES=() && \ + TEMP_PACKAGES=() && \ + KEPT_PACKAGES+=(libzmq5) && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + "${KEPT_PACKAGES[@]}" \ + "${TEMP_PACKAGES[@]}"\ + && \ + # ensure binaries are executable + chmod -v a+x \ + /opt/sdre-hub.armv7 \ + /opt/sdre-hub.arm64 \ + /opt/sdre-hub.amd64 \ + && \ + # remove foreign architecture binaries + /rename_current_arch_binary.sh && \ + rm -fv \ + /opt/sdre-hub.* \ + && \ + # clean up + apt-get remove -y "${TEMP_PACKAGES[@]}" && \ + apt-get autoremove -y && \ + rm -rf /src/* /tmp/* /var/lib/apt/lists/* && \ + # test + /opt/sdre-hub --version diff --git a/Dockerfile.build_binary b/Dockerfile.build_binary new file mode 100644 index 0000000..8e8c755 --- /dev/null +++ b/Dockerfile.build_binary @@ -0,0 +1,13 @@ +FROM rust:1.77.2 as builder +ENV CARGO_NET_GIT_FETCH_WITH_CLI=true +WORKDIR /tmp/sdre-hub +# hadolint ignore=DL3008,DL3003,SC1091,DL3009 +RUN set -x && \ + apt-get update && \ + apt-get install -y --no-install-recommends libzmq3-dev +COPY . . + +RUN cargo build --release + +FROM scratch +COPY --from=builder /tmp/sdre-hub/target/release/sdre-hub /sdre-hub diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 0000000..c8e2315 --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,50 @@ +FROM rust:1.77.2 as builder +WORKDIR /tmp/sdre-hub +# hadolint ignore=DL3008,DL3003,SC1091 +RUN set -x && \ + apt-get update && \ + apt-get install -y --no-install-recommends libzmq3-dev +COPY . . + +RUN cargo build --release + +FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base + +ENV AR_LISTEN_UDP_ACARS=5550 \ + AR_LISTEN_TCP_ACARS=5550 \ + AR_LISTEN_UDP_VDLM2=5555 \ + AR_LISTEN_TCP_VDLM2=5555 \ + AR_LISTEN_UDP_HFDL=5556 \ + AR_LISTEN_TCP_HFDL=5556 \ + AR_LISTEN_ZMQ_ACARS=35550 \ + AR_LISTEN_ZMQ_VDLM2=35555 \ + AR_LISTEN_ZMQ_HFDL=35556 \ + AR_SERVE_TCP_ACARS=15550 \ + AR_SERVE_TCP_VDLM2=15555 \ + AR_SERVE_TCP_HFDL=15556 \ + AR_SERVE_ZMQ_ACARS=45550 \ + AR_SERVE_ZMQ_VDLM2=45555 \ + AR_SERVE_ZMQ_HFDL=45556 \ + AR_ADD_PROXY_ID=true + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +COPY rootfs / +COPY --from=builder /tmp/sdre-hub/target/release/sdre-hub /opt/sdre-hub +# hadolint ignore=DL3008,DL3003,SC1091 +RUN set -x && \ + KEPT_PACKAGES=() && \ + TEMP_PACKAGES=() && \ + KEPT_PACKAGES+=(libzmq5) && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + "${KEPT_PACKAGES[@]}" \ + "${TEMP_PACKAGES[@]}"\ + && \ + # ensure binaries are executable + chmod -v a+x \ + /opt/sdre-hub \ + && \ + # clean up + apt-get remove -y "${TEMP_PACKAGES[@]}" && \ + apt-get autoremove -y && \ + rm -rf /src/* /tmp/* /var/lib/apt/lists/* diff --git a/rootfs/rename_current_arch_binary.sh b/rootfs/rename_current_arch_binary.sh new file mode 100755 index 0000000..55a2785 --- /dev/null +++ b/rootfs/rename_current_arch_binary.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -x + +ls -la /opt/ + +# determine which binary to keep +if /opt/sdre-hub.amd64 --version > /dev/null 2>&1; then + mv -v /opt/sdre-hub.amd64 /opt/sdre-hub +elif /opt/sdre-hub.arm64 --version > /dev/null 2>&1; then + mv -v /opt/sdre-hub.arm64 /opt/sdre-hub +elif /opt/sdre-hub.armv7 --version > /dev/null 2>&1; then + mv -v /opt/sdre-hub.armv7 /opt/sdre-hub +else + >&2 echo "ERROR: Unsupported architecture" + exit 1 +fi From 7e4af7bb6ef67ce04f54f22f0010299918280300 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Wed, 17 Apr 2024 09:29:18 -0600 Subject: [PATCH 3/8] s6 services --- Dockerfile | 17 -------------- Dockerfile.local | 17 -------------- .../s6-overlay/s6-rc.d/01-config-check/type | 1 + .../etc/s6-overlay/s6-rc.d/01-config-check/up | 2 ++ .../sdre-hub/dependencies.d/01-config-check | 0 .../s6-rc.d/sdre-hub/dependencies.d/base | 0 rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/run | 2 ++ rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/type | 1 + .../s6-rc.d/user/contents.d/01-config-check | 0 .../s6-rc.d/user/contents.d/sdre-hub | 0 rootfs/etc/s6-overlay/scripts/01-config-check | 22 +++++++++++++++++++ rootfs/etc/s6-overlay/scripts/sdre-hub | 4 ++++ rootfs/opt/sdre-hub-data/.empty | 0 13 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/01-config-check/type create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/01-config-check/up create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/dependencies.d/01-config-check create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/dependencies.d/base create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/run create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/01-config-check create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/sdre-hub create mode 100755 rootfs/etc/s6-overlay/scripts/01-config-check create mode 100755 rootfs/etc/s6-overlay/scripts/sdre-hub create mode 100644 rootfs/opt/sdre-hub-data/.empty diff --git a/Dockerfile b/Dockerfile index 9729988..9188dbf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,5 @@ FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base -ENV AR_LISTEN_UDP_ACARS=5550 \ - AR_LISTEN_TCP_ACARS=5550 \ - AR_LISTEN_UDP_VDLM2=5555 \ - AR_LISTEN_TCP_VDLM2=5555 \ - AR_LISTEN_UDP_HFDL=5556 \ - AR_LISTEN_TCP_HFDL=5556 \ - AR_LISTEN_ZMQ_ACARS=35550 \ - AR_LISTEN_ZMQ_VDLM2=35555 \ - AR_LISTEN_ZMQ_HFDL=35556 \ - AR_SERVE_TCP_ACARS=15550 \ - AR_SERVE_TCP_VDLM2=15555 \ - AR_SERVE_TCP_HFDL=15556 \ - AR_SERVE_ZMQ_ACARS=45550 \ - AR_SERVE_ZMQ_VDLM2=45555 \ - AR_SERVE_ZMQ_HFDL=45556 \ - AR_ADD_PROXY_ID=true - SHELL ["/bin/bash", "-o", "pipefail", "-c"] COPY ./rootfs / COPY ./bin/sdre-hub.armv7/sdre-hub /opt/sdre-hub.armv7 diff --git a/Dockerfile.local b/Dockerfile.local index c8e2315..785d1ec 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -10,23 +10,6 @@ RUN cargo build --release FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base -ENV AR_LISTEN_UDP_ACARS=5550 \ - AR_LISTEN_TCP_ACARS=5550 \ - AR_LISTEN_UDP_VDLM2=5555 \ - AR_LISTEN_TCP_VDLM2=5555 \ - AR_LISTEN_UDP_HFDL=5556 \ - AR_LISTEN_TCP_HFDL=5556 \ - AR_LISTEN_ZMQ_ACARS=35550 \ - AR_LISTEN_ZMQ_VDLM2=35555 \ - AR_LISTEN_ZMQ_HFDL=35556 \ - AR_SERVE_TCP_ACARS=15550 \ - AR_SERVE_TCP_VDLM2=15555 \ - AR_SERVE_TCP_HFDL=15556 \ - AR_SERVE_ZMQ_ACARS=45550 \ - AR_SERVE_ZMQ_VDLM2=45555 \ - AR_SERVE_ZMQ_HFDL=45556 \ - AR_ADD_PROXY_ID=true - SHELL ["/bin/bash", "-o", "pipefail", "-c"] COPY rootfs / COPY --from=builder /tmp/sdre-hub/target/release/sdre-hub /opt/sdre-hub diff --git a/rootfs/etc/s6-overlay/s6-rc.d/01-config-check/type b/rootfs/etc/s6-overlay/s6-rc.d/01-config-check/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/01-config-check/type @@ -0,0 +1 @@ +oneshot diff --git a/rootfs/etc/s6-overlay/s6-rc.d/01-config-check/up b/rootfs/etc/s6-overlay/s6-rc.d/01-config-check/up new file mode 100755 index 0000000..fb421ac --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/01-config-check/up @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/01-config-check diff --git a/rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/dependencies.d/01-config-check b/rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/dependencies.d/01-config-check new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/dependencies.d/base b/rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/dependencies.d/base new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/run b/rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/run new file mode 100755 index 0000000..52df734 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/sdre-hub diff --git a/rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/type b/rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/sdre-hub/type @@ -0,0 +1 @@ +longrun diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/01-config-check b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/01-config-check new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/sdre-hub b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/sdre-hub new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/scripts/01-config-check b/rootfs/etc/s6-overlay/scripts/01-config-check new file mode 100755 index 0000000..96c1ba4 --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/01-config-check @@ -0,0 +1,22 @@ +#!/command/with-contenv bash +# shellcheck shell=bash + +# check the environment and see if there are any SH_* variables set +# if so, warn the user that they really should be mapping a file +# to /opt/sdre-hub-data and using /opt/sdre-hub-data/sh_config.toml + +SH_DATA=$(env | grep '^SH_') + +if [ -n "$SH_DATA" ]; then + echo "[01-config-check] WARNING: You have SH_* environment variables set. You should be using a config file instead." + echo " Please map a directory to /opt/sdre-hub-data and use /opt/sdre-hub-data/sh_config.toml" +fi + +# check and see if /opt/sdre-hub-data/.empty exists. If it does, warn them that +# the dir isn't mapped and no data will be persisted between sessions + +if [ -f /opt/sdre-hub-data/.empty ]; then + echo "[01-config-check] WARNING: /opt/sdre-hub-data is not mapped. No data will be persisted between sessions." +fi + +exit 0 diff --git a/rootfs/etc/s6-overlay/scripts/sdre-hub b/rootfs/etc/s6-overlay/scripts/sdre-hub new file mode 100755 index 0000000..0422b2f --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/sdre-hub @@ -0,0 +1,4 @@ +#!/command/with-contenv bash +#shellcheck shell=bash + +/opt/sdre-hub diff --git a/rootfs/opt/sdre-hub-data/.empty b/rootfs/opt/sdre-hub-data/.empty new file mode 100644 index 0000000..e69de29 From 52210c3f1c3ef30da931778e96cf0c429992b3fe Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Wed, 17 Apr 2024 09:31:38 -0600 Subject: [PATCH 4/8] Clippy remove unneeded debug statements clippy first hack rename lat to latitude and lon to longitude Code consistency bug fix enabled data source array serialize / deserialize enabled sources sanely --- Cargo.lock | 333 +++++++++++++++++- Cargo.toml | 7 +- src/bin/sdre-hub/Cargo.toml | 2 + src/bin/sdre-hub/src/main.rs | 14 +- src/libraries/sdrehub-api/Cargo.toml | 19 + src/libraries/sdrehub-api/src/lib.rs | 13 + .../sdrehub-config/src/acars_router_source.rs | 40 +-- src/libraries/sdrehub-config/src/address.rs | 71 ++-- .../sdrehub-config/src/adsb_source.rs | 72 ++-- src/libraries/sdrehub-config/src/lib.rs | 51 +-- src/libraries/sdrehub-config/src/map.rs | 4 +- src/libraries/sdrehub-config/src/sdrehub.rs | 2 +- src/libraries/sdrehub-config/src/source.rs | 61 +++- 13 files changed, 538 insertions(+), 151 deletions(-) create mode 100644 src/libraries/sdrehub-api/Cargo.toml create mode 100644 src/libraries/sdrehub-api/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index e668e65..d8f24bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "1.1.3" @@ -61,7 +76,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -71,7 +86,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -89,6 +104,27 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bumpalo" version = "3.16.0" @@ -101,6 +137,12 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + [[package]] name = "cc" version = "1.0.94" @@ -124,7 +166,7 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-targets", + "windows-targets 0.52.5", ] [[package]] @@ -182,12 +224,24 @@ dependencies = [ "version_check", ] +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + [[package]] name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + [[package]] name = "humantime" version = "2.1.0" @@ -248,6 +302,16 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.21" @@ -260,6 +324,26 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -269,12 +353,54 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + [[package]] name = "pear" version = "0.2.9" @@ -298,6 +424,12 @@ dependencies = [ "syn", ] +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + [[package]] name = "proc-macro2" version = "1.0.80" @@ -329,6 +461,15 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" version = "1.10.4" @@ -358,11 +499,25 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "sdre-hub" version = "4.0.0-alpha1" dependencies = [ + "sdrehub_api", "sdrehub_config", + "tokio", ] [[package]] @@ -377,6 +532,13 @@ dependencies = [ "log", ] +[[package]] +name = "sdrehub_api" +version = "4.0.0-alpha1" +dependencies = [ + "tokio", +] + [[package]] name = "sdrehub_config" version = "4.0.0-alpha1" @@ -430,6 +592,31 @@ dependencies = [ "serde", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "syn" version = "2.0.59" @@ -441,6 +628,37 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "tracing", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "toml" version = "0.8.12" @@ -475,6 +693,25 @@ dependencies = [ "winnow", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + [[package]] name = "uncased" version = "0.9.10" @@ -508,6 +745,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasm-bindgen" version = "0.2.92" @@ -568,7 +811,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", ] [[package]] @@ -577,7 +829,22 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -586,28 +853,46 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.5" @@ -620,24 +905,48 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.5" diff --git a/Cargo.toml b/Cargo.toml index 7545e3c..73faf57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,13 @@ [workspace] -members = ["src/libraries/sdrehub-config", "src/bin/sdre-hub"] +members = [ + "src/libraries/sdrehub-config", + "src/bin/sdre-hub", + "src/libraries/sdrehub-api", +] resolver = "2" [workspace.package] -name = "sdre-hub" version = "4.0.0-alpha1" edition = "2021" authors = ["Fred Clausen"] diff --git a/src/bin/sdre-hub/Cargo.toml b/src/bin/sdre-hub/Cargo.toml index b3e99b2..bc17714 100644 --- a/src/bin/sdre-hub/Cargo.toml +++ b/src/bin/sdre-hub/Cargo.toml @@ -14,4 +14,6 @@ categories.workspace = true keywords.workspace = true [dependencies] +sdrehub_api = { path = "../../libraries/sdrehub-api" } sdrehub_config = { path = "../../libraries/sdrehub-config" } +tokio = { version = "1.37.0", features = ["full", "tracing"] } diff --git a/src/bin/sdre-hub/src/main.rs b/src/bin/sdre-hub/src/main.rs index f097b80..8d63ef2 100644 --- a/src/bin/sdre-hub/src/main.rs +++ b/src/bin/sdre-hub/src/main.rs @@ -5,7 +5,7 @@ #![deny( clippy::pedantic, - clippy::cargo, + //clippy::cargo, clippy::nursery, clippy::style, clippy::correctness, @@ -13,10 +13,20 @@ )] use sdrehub_config::ShConfig; +use std::error::Error; -fn main() { +#[tokio::main] +async fn main() -> Result<(), Box> { let config = ShConfig::new(); config.enable_logging(); config.write_config(); config.show_config(); + + // start sleep loop + + loop { + tokio::time::sleep(std::time::Duration::from_secs(60)).await; + } + + //Ok(()) } diff --git a/src/libraries/sdrehub-api/Cargo.toml b/src/libraries/sdrehub-api/Cargo.toml new file mode 100644 index 0000000..386e542 --- /dev/null +++ b/src/libraries/sdrehub-api/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "sdrehub_api" +version.workspace = true +edition.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +homepage.workspace = true +repository.workspace = true +readme.workspace = true +license.workspace = true +rust-version.workspace = true +categories.workspace = true +keywords.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = { version = "1.37.0", features = ["full", "tracing"] } diff --git a/src/libraries/sdrehub-api/src/lib.rs b/src/libraries/sdrehub-api/src/lib.rs new file mode 100644 index 0000000..2e40186 --- /dev/null +++ b/src/libraries/sdrehub-api/src/lib.rs @@ -0,0 +1,13 @@ +// Copyright (C) 2024 Fred Clausen +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +#![deny( + clippy::pedantic, +// clippy::cargo, + clippy::nursery, + clippy::style, + clippy::correctness, + clippy::all +)] diff --git a/src/libraries/sdrehub-config/src/acars_router_source.rs b/src/libraries/sdrehub-config/src/acars_router_source.rs index 2ba1f82..11e1257 100644 --- a/src/libraries/sdrehub-config/src/acars_router_source.rs +++ b/src/libraries/sdrehub-config/src/acars_router_source.rs @@ -11,25 +11,25 @@ use serde::{ }; use void::Void; -use crate::address::AcarsRouterAddress; +use crate::address::ShAcarsRouterConfig; pub trait SourceTrait { fn new() -> Self; - fn insert(&mut self, value: AcarsRouterAddress); + fn insert(&mut self, value: ShAcarsRouterConfig); } #[derive(Debug, Serialize, Deserialize, Default)] pub struct AcarsRouterSource { - addresses: Vec, + addresses: Vec, } impl FromStr for AcarsRouterSource { type Err = Void; fn from_str(s: &str) -> Result { - let mut output = AcarsRouterSource::new(); + let mut output = Self::new(); for address in s.split(',') { - if let Some(address) = AcarsRouterAddress::new(address.to_string()) { + if let Some(address) = ShAcarsRouterConfig::new(address) { output.insert(address); } } @@ -40,12 +40,12 @@ impl FromStr for AcarsRouterSource { impl SourceTrait for AcarsRouterSource { fn new() -> Self { - AcarsRouterSource { + Self { addresses: Vec::new(), } } - fn insert(&mut self, value: AcarsRouterAddress) { + fn insert(&mut self, value: ShAcarsRouterConfig) { self.addresses.push(value); } } @@ -56,9 +56,11 @@ enum FieldTypes { #[serde(rename = "address")] Address(String), #[serde(rename = "port")] - Port(i32), + Port(u32), } +/// # Errors +/// Returns an error if the input fails to deserialize pub fn string_or_struct<'de, T, D>(deserializer: D) -> Result where T: Deserialize<'de> + FromStr + SourceTrait, @@ -100,42 +102,36 @@ where let mut source = T::new(); if let Some(_key) = map.next_key::()? { - println!("key: {}", _key); - // loop through the keys and values match map.next_value::>>() { Ok(value) => { - println!("value: {:?}", value); - if value.is_empty() { return Ok(source); } - for item in value.iter() { - println!("item: {:?}", item); - + for item in &value { let port = match item.get("port").unwrap().to_owned() { FieldTypes::Port(port) => { - if !(0..=65535).contains(&port) { - return Err(de::Error::custom("Port out of range")); + if (0..=65535).contains(&port) { + port } else { - port as u32 + return Err(de::Error::custom("Port out of range")); } } - _ => { + FieldTypes::Address(_) => { return Err(de::Error::custom("Port not found")); } }; let address = match item.get("address").unwrap().to_owned() { FieldTypes::Address(address) => address, - _ => { + FieldTypes::Port(_) => { return Err(de::Error::custom("Address not found")); } }; - let address = AcarsRouterAddress::new_from_parts(address, port); + let address = ShAcarsRouterConfig::new_from_parts(address, port); source.insert(address); } @@ -164,7 +160,7 @@ where let mut source = T::new(); while let Some(value) = seq.next_element::()? { - if let Some(address) = AcarsRouterAddress::new(value) { + if let Some(address) = ShAcarsRouterConfig::new(&value) { source.insert(address); } } diff --git a/src/libraries/sdrehub-config/src/address.rs b/src/libraries/sdrehub-config/src/address.rs index 15fdfbd..d160c14 100644 --- a/src/libraries/sdrehub-config/src/address.rs +++ b/src/libraries/sdrehub-config/src/address.rs @@ -7,55 +7,55 @@ use serde::{Deserialize, Serialize}; /// Struct to store the address of an ACARS router #[derive(Debug, Deserialize, Serialize)] -pub struct AcarsRouterAddress { +pub struct ShAcarsRouterConfig { address: String, port: u32, } -impl AcarsRouterAddress { - /// Create a new AcarsRouterAddress from a string +impl ShAcarsRouterConfig { + /// Create a new `AcarsRouterAddress` from a string /// Input should be in the format "address:port" - /// Returns an Option containing the AcarsRouterAddress if successful + /// Returns an Option containing the `AcarsRouterAddress` if successful - pub fn new(input: String) -> Option { + #[must_use] + pub fn new(input: &str) -> Option { let parts: Vec<&str> = input.split(':').collect(); if parts.len() != 2 { return None; } - let port = match parts[1].parse::() { - Ok(port) => port, - Err(_) => { - return None; - } + let Ok(port) = parts[1].parse::() else { + return None; }; - Some(AcarsRouterAddress { + Some(Self { address: parts[0].trim().to_string(), port, }) } - pub fn new_from_parts(address: String, port: u32) -> Self { - AcarsRouterAddress { address, port } + #[must_use] + pub const fn new_from_parts(address: String, port: u32) -> Self { + Self { address, port } } } #[derive(Debug, Deserialize, Serialize)] -pub struct AdsbAddress { +pub struct SHAdsbConfig { address: String, port: u32, - lat: f64, - lon: f64, + latitude: f64, + longitude: f64, } -impl AdsbAddress { - /// Create a new AcarsRouterAddress from a string +impl SHAdsbConfig { + /// Create a new `AcarsRouterAddress` from a string /// Input should be in the format "address:port" - /// Returns an Option containing the AcarsRouterAddress if successful + /// Returns an Option containing the `AcarsRouterAddress` if successful - pub fn new(input: String) -> Option { + #[must_use] + pub fn new(input: &str) -> Option { let parts: Vec<&str> = input.split(':').collect(); if parts.len() != 4 { @@ -77,50 +77,51 @@ impl AdsbAddress { } }; - let lat = match parts[2].parse::() { - Ok(lat) => { + let latitude = match parts[2].parse::() { + Ok(latitude) => { // verify that the latitude is in the correct range - if !(-90.0..=90.0).contains(&lat) { + if !(-90.0..=90.0).contains(&latitude) { return None; } - lat + latitude } Err(_) => { return None; } }; - let lon = match parts[3].parse::() { - Ok(lon) => { + let longitude = match parts[3].parse::() { + Ok(longitude) => { // verify that the longitude is in the correct range - if !(-180.0..=180.0).contains(&lon) { + if !(-180.0..=180.0).contains(&longitude) { return None; } - lon + longitude } Err(_) => { return None; } }; - Some(AdsbAddress::new_from_parts( + Some(Self::new_from_parts( parts[0].trim().to_string(), port, - lat, - lon, + latitude, + longitude, )) } - pub fn new_from_parts(address: String, port: u32, lat: f64, lon: f64) -> Self { - AdsbAddress { + #[must_use] + pub const fn new_from_parts(address: String, port: u32, latitude: f64, longitude: f64) -> Self { + Self { address, port, - lat, - lon, + latitude, + longitude, } } } diff --git a/src/libraries/sdrehub-config/src/adsb_source.rs b/src/libraries/sdrehub-config/src/adsb_source.rs index fcdf93f..2434300 100644 --- a/src/libraries/sdrehub-config/src/adsb_source.rs +++ b/src/libraries/sdrehub-config/src/adsb_source.rs @@ -11,26 +11,26 @@ use serde::{ }; use void::Void; -use crate::address::AdsbAddress; +use crate::address::SHAdsbConfig; pub trait SourceTrait { fn new() -> Self; - fn insert(&mut self, value: AdsbAddress); + fn insert(&mut self, value: SHAdsbConfig); } #[derive(Debug, Serialize, Deserialize, Default)] pub struct AdsbSource { - addresses: Vec, + addresses: Vec, } impl FromStr for AdsbSource { type Err = Void; fn from_str(s: &str) -> Result { - let mut output = AdsbSource::new(); + let mut output = Self::new(); for address in s.split(',') { - if let Some(address) = AdsbAddress::new(address.to_string()) { + if let Some(address) = SHAdsbConfig::new(address) { output.insert(address); } } @@ -41,12 +41,12 @@ impl FromStr for AdsbSource { impl SourceTrait for AdsbSource { fn new() -> Self { - AdsbSource { + Self { addresses: Vec::new(), } } - fn insert(&mut self, value: AdsbAddress) { + fn insert(&mut self, value: SHAdsbConfig) { self.addresses.push(value); } } @@ -54,17 +54,14 @@ impl SourceTrait for AdsbSource { #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(untagged)] enum FieldTypes { - #[serde(rename = "address")] Address(String), - #[serde(rename = "port")] - Port(i32), - #[serde(rename = "lat")] - Lat(f64), - #[serde(rename = "lon")] - Lon(f64), + Port(u32), + Position(f64) } -pub fn string_or_struct<'de, T, D>(deserializer: D) -> Result +///# Errors +/// will return an error if the input fails to deserialize + pub fn string_or_struct<'de, T, D>(deserializer: D) -> Result where T: Deserialize<'de> + FromStr + SourceTrait, D: Deserializer<'de>, @@ -105,27 +102,21 @@ where let mut source = T::new(); if let Some(_key) = map.next_key::()? { - println!("key: {}", _key); - // loop through the keys and values match map.next_value::>>() { Ok(value) => { - println!("value: {:?}", value); - if value.is_empty() { return Ok(source); } - for item in value.iter() { - println!("item: {:?}", item); - + for item in &value { let port = match item.get("port").unwrap().to_owned() { FieldTypes::Port(port) => { - if !(0..=65535).contains(&port) { - return Err(de::Error::custom("Port out of range")); + if (0..=65535).contains(&port) { + port } else { - port as u32 + return Err(de::Error::custom("Port out of range")); } } _ => { @@ -133,19 +124,16 @@ where } }; - let address = match item.get("address").unwrap().to_owned() { - FieldTypes::Address(address) => address, - _ => { - return Err(de::Error::custom("Address not found")); - } + let FieldTypes::Address(address) = item.get("address").unwrap().to_owned() else { + return Err(de::Error::custom("Address not found")); }; - let lat = match item.get("lat").unwrap().to_owned() { - FieldTypes::Lat(lat) => { - if !(-90.0..=90.0).contains(&lat) { - return Err(de::Error::custom("Latitude out of range")); + let latitude = match item.get("latitude").unwrap().to_owned() { + FieldTypes::Position(latitutde) => { + if (-90.0..=90.0).contains(&latitutde) { + latitutde } else { - lat + return Err(de::Error::custom("Latitude out of range")); } } _ => { @@ -153,12 +141,12 @@ where } }; - let lon = match item.get("lon").unwrap().to_owned() { - FieldTypes::Lon(lon) => { - if !(-180.0..=180.0).contains(&lon) { - return Err(de::Error::custom("Longitude out of range")); + let longitude = match item.get("longitude").unwrap().to_owned() { + FieldTypes::Position(longitude) => { + if (-180.0..=180.0).contains(&longitude) { + longitude } else { - lon + return Err(de::Error::custom("Longitude out of range")); } } _ => { @@ -166,7 +154,7 @@ where } }; - let address = AdsbAddress::new_from_parts(address, port, lat, lon); + let address = SHAdsbConfig::new_from_parts(address, port, latitude, longitude); source.insert(address); } @@ -195,7 +183,7 @@ where let mut source = T::new(); while let Some(value) = seq.next_element::()? { - if let Some(address) = AdsbAddress::new(value) { + if let Some(address) = SHAdsbConfig::new(&value) { source.insert(address); } } diff --git a/src/libraries/sdrehub-config/src/lib.rs b/src/libraries/sdrehub-config/src/lib.rs index 16da409..4f386ed 100644 --- a/src/libraries/sdrehub-config/src/lib.rs +++ b/src/libraries/sdrehub-config/src/lib.rs @@ -3,12 +3,22 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. + +#![deny( + clippy::pedantic, +// clippy::cargo, + clippy::nursery, + clippy::style, + clippy::correctness, + clippy::all +)] + use figment::{ providers::{Env, Format, Toml}, Figment, }; use log::debug; -use map::MapConfig; +use map::ShMapConfig; use sdre_rust_logging::SetupLogging; use sdrehub::SDREHub; use serde::{Deserialize, Serialize}; @@ -33,26 +43,27 @@ pub struct ShConfig { pub enabled_data_sources: EnabledDataSources, #[serde_inline_default(DataSources::default())] pub data_sources: DataSources, - #[serde_inline_default(MapConfig::default())] - pub map: MapConfig, + #[serde_inline_default(ShMapConfig::default())] + pub map: ShMapConfig, } impl ShConfig { - pub fn new() -> Self { - ShConfig::get_and_validate_config() + #[must_use] pub fn new() -> Self { + Self::get_and_validate_config() } fn get_file_path() -> String { - match std::env::consts::OS { - "linux" => "./sh_config.toml", - "macos" => "./sh_config.toml", - "windows" => "./sh_config.toml", - _ => "./sh_config.toml", - } - .to_string() + "./sh_config.toml".to_string() // FIXME: commented out the logic below to make clippy happy until we featurize the code + // match std::env::consts::OS { + // "linux" => "./sh_config.toml", + // "macos" => "./sh_config.toml", + // "windows" => "./sh_config.toml", + // _ => "./sh_config.toml", + // } + // .to_string() } - fn get_config(file_path: &str) -> ShConfig { + fn get_config(file_path: &str) -> Self { match Figment::new() .merge(Toml::file(file_path)) .merge(Env::prefixed("SH_")) @@ -60,16 +71,16 @@ impl ShConfig { { Ok(config) => config, Err(e) => { - println!("Error reading config file: {}", e); + println!("Error reading config file: {e}"); println!("Exiting"); std::process::exit(1); } } } - fn get_and_validate_config() -> ShConfig { - let file_path = ShConfig::get_file_path(); - ShConfig::get_config(&file_path) + fn get_and_validate_config() -> Self { + let file_path = Self::get_file_path(); + Self::get_config(&file_path) } pub fn show_config(&self) { @@ -85,13 +96,13 @@ impl ShConfig { } pub fn write_config(&self) { - let file_path = ShConfig::get_file_path(); + let file_path = Self::get_file_path(); let config = self.get_config_as_toml_string(); match std::fs::write(file_path, config) { - Ok(_) => (), + Ok(()) => (), Err(e) => { - println!("Error writing config file: {}", e); + println!("Error writing config file: {e}"); println!("Exiting"); std::process::exit(1); } diff --git a/src/libraries/sdrehub-config/src/map.rs b/src/libraries/sdrehub-config/src/map.rs index b150f39..75b4523 100644 --- a/src/libraries/sdrehub-config/src/map.rs +++ b/src/libraries/sdrehub-config/src/map.rs @@ -5,9 +5,9 @@ use serde::{Deserialize, Serialize}; -/// MapConfig is a struct for storing global map values +/// `MapConfig` is a struct for storing global map values #[derive(Debug, Serialize, Deserialize, Default)] -pub struct MapConfig { +pub struct ShMapConfig { /// center_latitude is the latitude of the center of the map /// This value will be used to center the map on the web interface /// Default value is 0.0 diff --git a/src/libraries/sdrehub-config/src/sdrehub.rs b/src/libraries/sdrehub-config/src/sdrehub.rs index ff91c27..8ae5567 100644 --- a/src/libraries/sdrehub-config/src/sdrehub.rs +++ b/src/libraries/sdrehub-config/src/sdrehub.rs @@ -24,7 +24,7 @@ pub struct SDREHub { impl Default for SDREHub { fn default() -> Self { - SDREHub { + Self { database_url: "sqlite://sdre-hub.db".to_string(), data_path: "./data".to_string(), log_level: "info".to_string(), diff --git a/src/libraries/sdrehub-config/src/source.rs b/src/libraries/sdrehub-config/src/source.rs index cd802be..8b9f922 100644 --- a/src/libraries/sdrehub-config/src/source.rs +++ b/src/libraries/sdrehub-config/src/source.rs @@ -8,21 +8,56 @@ use serde_inline_default::serde_inline_default; use crate::{acars_router_source::AcarsRouterSource, adsb_source::AdsbSource}; -#[serde_inline_default] +#[derive(Debug, Deserialize, Default)] +#[serde(rename_all = "snake_case", try_from = "String")] +pub enum ShEnabledDataSources { + Acars, + Adsb, + Hfdl, + Inmarsat, + Iridium, + Vdlm2, + #[default] + None +} + +impl TryFrom for ShEnabledDataSources { + type Error = String; + + fn try_from(value: String) -> Result { + match value.to_lowercase().as_str() { + "acars" => Ok(Self::Acars), + "adsb" => Ok(Self::Adsb), + "hfdl" => Ok(Self::Hfdl), + "inmarsat" => Ok(Self::Inmarsat), + "iridium" => Ok(Self::Iridium), + "vdlm2" => Ok(Self::Vdlm2), + _ => Err(format!("Invalid value for ShEnabledDataSources: {}", value)), + } + } +} + +impl Serialize for ShEnabledDataSources { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + match self { + Self::Acars => serializer.serialize_str("acars"), + Self::Adsb => serializer.serialize_str("adsb"), + Self::Hfdl => serializer.serialize_str("hfdl"), + Self::Inmarsat => serializer.serialize_str("inmarsat"), + Self::Iridium => serializer.serialize_str("iridium"), + Self::Vdlm2 => serializer.serialize_str("vdlm2"), + // None should not write out anything + Self::None => serializer.serialize_none(), + } + } +} + #[derive(Debug, Serialize, Deserialize, Default)] pub struct EnabledDataSources { - #[serde_inline_default(false)] - pub adsb: bool, - #[serde_inline_default(false)] - pub acars: bool, - #[serde_inline_default(false)] - pub hfdl: bool, - #[serde_inline_default(false)] - pub inmarsat: bool, - #[serde_inline_default(false)] - pub iridium: bool, - #[serde_inline_default(false)] - pub vdlm2: bool, + pub enabled_sources: Vec, } #[serde_inline_default] From 9fa84453fb69ed4d829ed22553e697f33d78dbd2 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:40:07 -0600 Subject: [PATCH 5/8] very initial ws server --- .pre-commit-config.yaml | 7 + Cargo.lock | 592 ++++++++++++++++++ src/bin/sdre-hub/Cargo.toml | 1 + src/bin/sdre-hub/src/main.rs | 18 +- src/libraries/sdrehub-api/Cargo.toml | 2 + src/libraries/sdrehub-api/src/lib.rs | 57 ++ .../sdrehub-config/src/adsb_source.rs | 11 +- src/libraries/sdrehub-config/src/lib.rs | 21 +- src/libraries/sdrehub-config/src/source.rs | 4 +- 9 files changed, 691 insertions(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9af744e..c2c12e6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -69,3 +69,10 @@ repos: hooks: - id: check-github-actions - id: check-github-workflows + + - repo: https://github.com/doublify/pre-commit-rust + rev: v1.0 + hooks: + - id: fmt + - id: cargo-check + - id: clippy diff --git a/Cargo.lock b/Cargo.lock index d8f24bb..91bccdc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,6 +89,17 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "async-trait" +version = "0.1.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "atomic" version = "0.6.0" @@ -104,6 +115,64 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +[[package]] +name = "axum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +dependencies = [ + "async-trait", + "axum-core", + "base64", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sha1", + "sync_wrapper 1.0.1", + "tokio", + "tokio-tungstenite", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 0.1.2", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "backtrace" version = "0.3.71" @@ -119,12 +188,27 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -137,6 +221,12 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.6.0" @@ -181,6 +271,41 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "env_filter" version = "0.1.0" @@ -224,6 +349,83 @@ dependencies = [ "version_check", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -242,12 +444,93 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "hyper" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", +] + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -271,6 +554,16 @@ dependencies = [ "cc", ] +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "2.2.6" @@ -287,6 +580,12 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb" +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + [[package]] name = "js-sys" version = "0.3.69" @@ -318,12 +617,24 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "memchr" version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "miniz_oxide" version = "0.7.2" @@ -424,12 +735,50 @@ dependencies = [ "syn", ] +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" version = "1.0.80" @@ -461,6 +810,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -505,6 +884,18 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustversion" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + [[package]] name = "scopeguard" version = "1.2.0" @@ -515,6 +906,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" name = "sdre-hub" version = "4.0.0-alpha1" dependencies = [ + "log", "sdrehub_api", "sdrehub_config", "tokio", @@ -536,6 +928,8 @@ dependencies = [ name = "sdrehub_api" version = "4.0.0-alpha1" dependencies = [ + "axum", + "log", "tokio", ] @@ -583,6 +977,27 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_spanned" version = "0.6.5" @@ -592,6 +1007,29 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -601,6 +1039,15 @@ dependencies = [ "libc", ] +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.13.2" @@ -628,6 +1075,53 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.37.0" @@ -659,6 +1153,18 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + [[package]] name = "toml" version = "0.8.12" @@ -693,12 +1199,41 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ + "log", "pin-project-lite", "tracing-core", ] @@ -712,6 +1247,31 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand", + "sha1", + "thiserror", + "url", + "utf-8", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "uncased" version = "0.9.10" @@ -721,12 +1281,44 @@ dependencies = [ "version_check", ] +[[package]] +name = "unicode-bidi" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/src/bin/sdre-hub/Cargo.toml b/src/bin/sdre-hub/Cargo.toml index bc17714..32dd8f7 100644 --- a/src/bin/sdre-hub/Cargo.toml +++ b/src/bin/sdre-hub/Cargo.toml @@ -14,6 +14,7 @@ categories.workspace = true keywords.workspace = true [dependencies] +log = "0.4.21" sdrehub_api = { path = "../../libraries/sdrehub-api" } sdrehub_config = { path = "../../libraries/sdrehub-config" } tokio = { version = "1.37.0", features = ["full", "tracing"] } diff --git a/src/bin/sdre-hub/src/main.rs b/src/bin/sdre-hub/src/main.rs index 8d63ef2..37af746 100644 --- a/src/bin/sdre-hub/src/main.rs +++ b/src/bin/sdre-hub/src/main.rs @@ -11,9 +11,15 @@ clippy::correctness, clippy::all )] - +// FIXME: This is a temporary fix because there is an upstream error(I think) +// in the tokio::select macro +#![allow(clippy::redundant_pub_crate)] +#[macro_use] +extern crate log; +pub use sdrehub_api::run_webserver; use sdrehub_config::ShConfig; use std::error::Error; +use tokio::select; #[tokio::main] async fn main() -> Result<(), Box> { @@ -22,11 +28,11 @@ async fn main() -> Result<(), Box> { config.write_config(); config.show_config(); - // start sleep loop - - loop { - tokio::time::sleep(std::time::Duration::from_secs(60)).await; + select! { + () = run_webserver() => { + error!("Webserver exited"); + } } - //Ok(()) + Ok(()) } diff --git a/src/libraries/sdrehub-api/Cargo.toml b/src/libraries/sdrehub-api/Cargo.toml index 386e542..bf336a1 100644 --- a/src/libraries/sdrehub-api/Cargo.toml +++ b/src/libraries/sdrehub-api/Cargo.toml @@ -16,4 +16,6 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +axum = { version = "0.7.5", features = ["ws"] } +log = "0.4.21" tokio = { version = "1.37.0", features = ["full", "tracing"] } diff --git a/src/libraries/sdrehub-api/src/lib.rs b/src/libraries/sdrehub-api/src/lib.rs index 2e40186..214ff8d 100644 --- a/src/libraries/sdrehub-api/src/lib.rs +++ b/src/libraries/sdrehub-api/src/lib.rs @@ -11,3 +11,60 @@ clippy::correctness, clippy::all )] + +use axum::{ + extract::ws::{Message, WebSocket, WebSocketUpgrade}, + response::Response, + routing::get, + Router, +}; +#[macro_use] +extern crate log; + +pub async fn run_webserver() { + let listener = match tokio::net::TcpListener::bind("0.0.0.0:3000").await { + Ok(listener) => listener, + Err(e) => { + error!("Error binding socket for websocket server: {e}"); + return; + } + }; + + let local_addr = match listener.local_addr() { + Ok(addr) => addr, + Err(e) => { + error!("Error getting local address for websocket server: {e}"); + return; + } + }; + + info!("listening for websocket connections on {}", local_addr); + if axum::serve(listener, app()).await.is_err() { + error!("Error starting WebSocket server"); + } +} + +fn app() -> Router { + debug!("Starting WebSocket server"); + + Router::new().route("/sdre-hub", get(ws_handler)) +} + +async fn ws_handler(ws: WebSocketUpgrade) -> Response { + debug!("WebSocket connection initiated"); + ws.on_upgrade(ws_handle_socket) +} + +async fn ws_handle_socket(mut socket: WebSocket) { + while let Some(Ok(msg)) = socket.recv().await { + if let Message::Text(msg) = msg { + if socket + .send(Message::Text(format!("You said: {msg}"))) + .await + .is_err() + { + break; + } + } + } +} diff --git a/src/libraries/sdrehub-config/src/adsb_source.rs b/src/libraries/sdrehub-config/src/adsb_source.rs index 2434300..74583da 100644 --- a/src/libraries/sdrehub-config/src/adsb_source.rs +++ b/src/libraries/sdrehub-config/src/adsb_source.rs @@ -56,12 +56,12 @@ impl SourceTrait for AdsbSource { enum FieldTypes { Address(String), Port(u32), - Position(f64) + Position(f64), } ///# Errors /// will return an error if the input fails to deserialize - pub fn string_or_struct<'de, T, D>(deserializer: D) -> Result +pub fn string_or_struct<'de, T, D>(deserializer: D) -> Result where T: Deserialize<'de> + FromStr + SourceTrait, D: Deserializer<'de>, @@ -124,7 +124,9 @@ where } }; - let FieldTypes::Address(address) = item.get("address").unwrap().to_owned() else { + let FieldTypes::Address(address) = + item.get("address").unwrap().to_owned() + else { return Err(de::Error::custom("Address not found")); }; @@ -154,7 +156,8 @@ where } }; - let address = SHAdsbConfig::new_from_parts(address, port, latitude, longitude); + let address = + SHAdsbConfig::new_from_parts(address, port, latitude, longitude); source.insert(address); } diff --git a/src/libraries/sdrehub-config/src/lib.rs b/src/libraries/sdrehub-config/src/lib.rs index 4f386ed..b259422 100644 --- a/src/libraries/sdrehub-config/src/lib.rs +++ b/src/libraries/sdrehub-config/src/lib.rs @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. - #![deny( clippy::pedantic, // clippy::cargo, @@ -17,7 +16,8 @@ use figment::{ providers::{Env, Format, Toml}, Figment, }; -use log::debug; +#[macro_use] +extern crate log; use map::ShMapConfig; use sdre_rust_logging::SetupLogging; use sdrehub::SDREHub; @@ -48,19 +48,20 @@ pub struct ShConfig { } impl ShConfig { - #[must_use] pub fn new() -> Self { + #[must_use] + pub fn new() -> Self { Self::get_and_validate_config() } fn get_file_path() -> String { "./sh_config.toml".to_string() // FIXME: commented out the logic below to make clippy happy until we featurize the code - // match std::env::consts::OS { - // "linux" => "./sh_config.toml", - // "macos" => "./sh_config.toml", - // "windows" => "./sh_config.toml", - // _ => "./sh_config.toml", - // } - // .to_string() + // match std::env::consts::OS { + // "linux" => "./sh_config.toml", + // "macos" => "./sh_config.toml", + // "windows" => "./sh_config.toml", + // _ => "./sh_config.toml", + // } + // .to_string() } fn get_config(file_path: &str) -> Self { diff --git a/src/libraries/sdrehub-config/src/source.rs b/src/libraries/sdrehub-config/src/source.rs index 8b9f922..d958b83 100644 --- a/src/libraries/sdrehub-config/src/source.rs +++ b/src/libraries/sdrehub-config/src/source.rs @@ -18,7 +18,7 @@ pub enum ShEnabledDataSources { Iridium, Vdlm2, #[default] - None + None, } impl TryFrom for ShEnabledDataSources { @@ -32,7 +32,7 @@ impl TryFrom for ShEnabledDataSources { "inmarsat" => Ok(Self::Inmarsat), "iridium" => Ok(Self::Iridium), "vdlm2" => Ok(Self::Vdlm2), - _ => Err(format!("Invalid value for ShEnabledDataSources: {}", value)), + _ => Err(format!("Invalid value for ShEnabledDataSources: {value}")), } } } From a1e99fddcd6d6384003f250dc50491645c9347d5 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Wed, 17 Apr 2024 14:17:39 -0600 Subject: [PATCH 6/8] some new github actions --- .github/workflows/markdownlint.yml | 23 +++ .github/workflows/on_pr.yaml | 261 +++++++++++++++++++++++++++++ .github/workflows/yamllint.yml | 27 +++ 3 files changed, 311 insertions(+) create mode 100644 .github/workflows/markdownlint.yml create mode 100644 .github/workflows/on_pr.yaml create mode 100644 .github/workflows/yamllint.yml diff --git a/.github/workflows/markdownlint.yml b/.github/workflows/markdownlint.yml new file mode 100644 index 0000000..442cd7e --- /dev/null +++ b/.github/workflows/markdownlint.yml @@ -0,0 +1,23 @@ +--- +name: Linting (Markdown) + +on: + pull_request: + branches: + - main + # only run these if markdown files are updated + paths: + - "**.md" + - "**.MD" + +jobs: + markdownlint: + name: Run markdownlint against markdown files + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4.1.2 + - name: Pull markdownlint/markdownlint:latest Image + run: docker pull markdownlint/markdownlint:latest + - name: Run markdownlint against *.md files + run: docker run --rm -i -v "$(pwd)":/workdir --workdir /workdir markdownlint/markdownlint:latest --rules ~MD013,~MD033,~MD026,~MD002,~MD022,~MD007 $(find . -type f -iname '*.md' | grep -v '/.git/') diff --git a/.github/workflows/on_pr.yaml b/.github/workflows/on_pr.yaml new file mode 100644 index 0000000..c1f3442 --- /dev/null +++ b/.github/workflows/on_pr.yaml @@ -0,0 +1,261 @@ +--- +name: Pull Request + +on: + # Enable manual running of action if necessary + workflow_dispatch: + # Build and test deployment the image on pushes to main branch + pull_request: + # # Only publish on push to main branch + # branches: + # - main + # Only run if the PR yaml, Dockerfile, sh, py or rs files have changed + paths: + - Dockerfile** + - "**on_pr.yaml" + - "**.py" + - "**.rs" + - "**.sh" + - "**.toml" + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: check + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + override: true + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features + name: Clippy Output + + hadolint: + name: "Linting: hadolint" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.2 + - name: Pull hadolint/hadolint:latest Image + run: docker pull hadolint/hadolint:latest + - name: Run hadolint against Dockerfiles + run: docker run --rm -i -v "$PWD":/workdir --workdir /workdir --entrypoint hadolint hadolint/hadolint --ignore DL3013 --ignore DL3008 $(find . -type f -iname "Dockerfile*") + + test_rust_functionality: + name: Build and test rust functionality + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4.1.2 + with: + fetch-depth: 0 + + - name: Install Rust and deps + run: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + sudo apt-get update + sudo apt-get install -y --no-install-recommends libzmq3-dev + + - name: Get binary version from Cargo.toml + id: release_version + run: | + # Get version from Cargo.toml + RELEASE_VERSION=$(cat ./rust/bin/sdre-hub/Cargo.toml | grep '\[package\]' -A9999 | grep -m 1 'version = ' | tr -d " " | tr -d '"' | tr -d "'" | cut -d = -f 2) + echo "$RELEASE_VERSION" + + binary_build_armv7: + name: Build Binary - armv7 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.2 + with: + fetch-depth: 0 + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build armv7 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: sdre-hub:armv7 + platforms: linux/arm/v7 + outputs: type=local,dest=./image_armv7/ + + - name: Upload artifact armv7 binary + uses: actions/upload-artifact@v4.3.1 + with: + name: sdre-hub.armv7 + path: ./image_armv7/sdre-hub + + binary_build_arm64: + name: Build Binary - arm64 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.2 + with: + fetch-depth: 0 + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build arm64 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: sdre-hub:arm64 + platforms: linux/arm64 + outputs: type=local,dest=./image_arm64/ + + - name: Upload artifact arm64 binary + uses: actions/upload-artifact@v4.3.1 + with: + name: sdre-hub.arm64 + path: ./image_arm64/sdre-hub + + binary_build_amd64: + name: Build Binary - amd64 + runs-on: ubuntu-latest + needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.2 + with: + fetch-depth: 0 + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build amd64 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: sdre-hub:amd64 + platforms: linux/amd64 + outputs: type=local,dest=./image_amd64/ + + - name: Upload artifact amd64 binary + uses: actions/upload-artifact@v4.3.1 + with: + name: sdre-hub.amd64 + path: ./image_amd64/sdre-hub + + consolidate_binaries: + name: Consolidate & Cache Binaries + runs-on: ubuntu-latest + needs: [binary_build_amd64, binary_build_arm64, binary_build_armv7] + steps: + - run: mkdir -p ./bin + + - uses: actions/download-artifact@v4.1.4 + with: + name: sdre-hub.amd64 + path: ./bin/sdre-hub.amd64 + + - uses: actions/download-artifact@v4.1.4 + with: + name: sdre-hub.armv7 + path: ./bin/sdre-hub.armv7 + + - uses: actions/download-artifact@v4.1.4 + with: + name: sdre-hub.arm64 + path: ./bin/sdre-hub.arm64 + + - run: ls -la ./bin/* + + - name: Cache Binaries + uses: actions/cache@v4 + with: + path: ./bin/ + key: ${{ github.run_id }} + + test_docker_image_build: + name: Test Docker Image Build + needs: [hadolint, consolidate_binaries, test_rust_functionality] + uses: sdr-enthusiasts/common-github-workflows/.github/workflows/build_and_push_image.yml@main + with: + get_version_method: cargo_toml_file_in_repo:file=/Cargo.toml + build_with_tmpfs: true + build_nohealthcheck: false + cache_enabled: true + cache_path: ./bin/ + cache_key: ${{ github.run_id }} diff --git a/.github/workflows/yamllint.yml b/.github/workflows/yamllint.yml new file mode 100644 index 0000000..61e7a07 --- /dev/null +++ b/.github/workflows/yamllint.yml @@ -0,0 +1,27 @@ +--- +name: Linting (YAML) + +on: + pull_request: + branches: + - main + # only run when yaml files are updated + paths: + - "**.yml" + - "**.yaml" + +jobs: + yamllint: + name: Run yamllint against YAML files + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.2 + - name: yaml-lint + uses: ibiqlik/action-yamllint@v3 + with: + config_data: | + extends: default + rules: + line-length: + max: 120 + level: warning From 1e1e023a9d4839ef443160773a0ae62b8c863038 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Thu, 18 Apr 2024 12:08:09 -0600 Subject: [PATCH 7/8] wip server structure --- Cargo.lock | 22 +++++- Cargo.toml | 4 +- src/bin/sdre-hub/Cargo.toml | 2 +- src/bin/sdre-hub/src/main.rs | 21 +++--- src/libraries/libsdrehub/Cargo.toml | 23 ++++++ src/libraries/libsdrehub/src/lib.rs | 86 +++++++++++++++++++++++ src/libraries/libsdrehubcommon/Cargo.toml | 19 +++++ src/libraries/libsdrehubcommon/src/lib.rs | 26 +++++++ src/libraries/sdrehub-api/Cargo.toml | 2 + src/libraries/sdrehub-api/src/lib.rs | 64 ++++++++++++----- 10 files changed, 236 insertions(+), 33 deletions(-) create mode 100644 src/libraries/libsdrehub/Cargo.toml create mode 100644 src/libraries/libsdrehub/src/lib.rs create mode 100644 src/libraries/libsdrehubcommon/Cargo.toml create mode 100644 src/libraries/libsdrehubcommon/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 91bccdc..6d1fb2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -601,6 +601,24 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libsdrehub" +version = "4.0.0-alpha1" +dependencies = [ + "libsdrehubcommon", + "log", + "sdrehub_api", + "sdrehub_config", + "tokio", +] + +[[package]] +name = "libsdrehubcommon" +version = "4.0.0-alpha1" +dependencies = [ + "async-trait", +] + [[package]] name = "lock_api" version = "0.4.11" @@ -906,7 +924,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" name = "sdre-hub" version = "4.0.0-alpha1" dependencies = [ - "log", + "libsdrehub", "sdrehub_api", "sdrehub_config", "tokio", @@ -928,7 +946,9 @@ dependencies = [ name = "sdrehub_api" version = "4.0.0-alpha1" dependencies = [ + "async-trait", "axum", + "libsdrehubcommon", "log", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 73faf57..914e105 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,10 @@ [workspace] members = [ - "src/libraries/sdrehub-config", "src/bin/sdre-hub", + "src/libraries/libsdrehub", + "src/libraries/libsdrehubcommon", "src/libraries/sdrehub-api", + "src/libraries/sdrehub-config", ] resolver = "2" diff --git a/src/bin/sdre-hub/Cargo.toml b/src/bin/sdre-hub/Cargo.toml index 32dd8f7..324c943 100644 --- a/src/bin/sdre-hub/Cargo.toml +++ b/src/bin/sdre-hub/Cargo.toml @@ -14,7 +14,7 @@ categories.workspace = true keywords.workspace = true [dependencies] -log = "0.4.21" +libsdrehub = { path = "../../libraries/libsdrehub" } sdrehub_api = { path = "../../libraries/sdrehub-api" } sdrehub_config = { path = "../../libraries/sdrehub-config" } tokio = { version = "1.37.0", features = ["full", "tracing"] } diff --git a/src/bin/sdre-hub/src/main.rs b/src/bin/sdre-hub/src/main.rs index 37af746..ca7f14d 100644 --- a/src/bin/sdre-hub/src/main.rs +++ b/src/bin/sdre-hub/src/main.rs @@ -11,26 +11,21 @@ clippy::correctness, clippy::all )] -// FIXME: This is a temporary fix because there is an upstream error(I think) -// in the tokio::select macro -#![allow(clippy::redundant_pub_crate)] -#[macro_use] -extern crate log; -pub use sdrehub_api::run_webserver; + +use libsdrehub::SdreHub; use sdrehub_config::ShConfig; use std::error::Error; -use tokio::select; #[tokio::main] async fn main() -> Result<(), Box> { let config = ShConfig::new(); - config.enable_logging(); - config.write_config(); - config.show_config(); + let hub = SdreHub::new(config); - select! { - () = run_webserver() => { - error!("Webserver exited"); + match hub.run().await { + Ok(()) => {} + Err(e) => { + eprintln!("Error running SDRE Hub: {e}"); + return Err(e); } } diff --git a/src/libraries/libsdrehub/Cargo.toml b/src/libraries/libsdrehub/Cargo.toml new file mode 100644 index 0000000..e47631e --- /dev/null +++ b/src/libraries/libsdrehub/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "libsdrehub" +version.workspace = true +edition.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +homepage.workspace = true +repository.workspace = true +readme.workspace = true +license.workspace = true +rust-version.workspace = true +categories.workspace = true +keywords.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +libsdrehubcommon = { path = "../libsdrehubcommon" } +log = "0.4.21" +sdrehub_api = { path = "../sdrehub-api" } +sdrehub_config = { path = "../sdrehub-config" } +tokio = { version = "1.37.0", features = ["full", "tracing"] } diff --git a/src/libraries/libsdrehub/src/lib.rs b/src/libraries/libsdrehub/src/lib.rs new file mode 100644 index 0000000..153af9d --- /dev/null +++ b/src/libraries/libsdrehub/src/lib.rs @@ -0,0 +1,86 @@ +// Copyright (C) 2024 Fred Clausen +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +// This is the brain of the entire operation. This is the state machine that +// Will take in the configuration, start, stop, restart consumers on config change +// (if applicable to the SDRE Hub implementation), and handle the incoming messages +// from the producers, generating the app state, and responding with information to user +// inputs. + +// Additionally, this module will send data out to consumers, such as the database and any +// connected users (web interface) or the application window (if applicable). + +// This is the main loop of the SDRE Hub. +#![deny( + clippy::pedantic, + //clippy::cargo, + clippy::nursery, + clippy::style, + clippy::correctness, + clippy::all +)] + +#[macro_use] +extern crate log; + +use libsdrehubcommon::ShDataUserList; +use sdrehub_api::ShWebServer; +use sdrehub_config::ShConfig; +use tokio::task::JoinSet; + +pub struct SdreHub { + config: ShConfig, + data_users: ShDataUserList, +} + +impl SdreHub { + #[must_use] + pub fn new(config: ShConfig) -> Self { + Self { + config, + data_users: Vec::new(), + } + } + + /// # Errors + /// - Error starting consumer: {e} + pub async fn run(mut self) -> Result<(), Box> { + // init logging and stuff + self.config.enable_logging(); + self.config.write_config(); + self.config.show_config(); + // Start the web server + + let mut consumer_set = JoinSet::new(); + + // lets generate the consumers + + self.data_users.push(Box::new(ShWebServer {})); + + debug!("Starting consumers"); + + for fut in self.data_users { + consumer_set.spawn(tokio::spawn(async move { + match fut.start().await { + Ok(()) => {} + Err(e) => { + error!("Error starting consumer: {e}"); + } + } + })); + } + + while let Some(res) = consumer_set.join_next().await { + match res { + Ok(_) => {} + Err(e) => { + error!("Error starting consumer: {e}"); + } + }; + } + + Ok(()) + } +} diff --git a/src/libraries/libsdrehubcommon/Cargo.toml b/src/libraries/libsdrehubcommon/Cargo.toml new file mode 100644 index 0000000..933e37e --- /dev/null +++ b/src/libraries/libsdrehubcommon/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "libsdrehubcommon" +version.workspace = true +edition.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +homepage.workspace = true +repository.workspace = true +readme.workspace = true +license.workspace = true +rust-version.workspace = true +categories.workspace = true +keywords.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +async-trait = "0.1.80" diff --git a/src/libraries/libsdrehubcommon/src/lib.rs b/src/libraries/libsdrehubcommon/src/lib.rs new file mode 100644 index 0000000..285b8ef --- /dev/null +++ b/src/libraries/libsdrehubcommon/src/lib.rs @@ -0,0 +1,26 @@ +// Copyright (C) 2024 Fred Clausen +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +// This is the brain of the entire operation. This is the state machine that +// Will take in the configuration, start, stop, restart consumers on config change +// (if applicable to the SDRE Hub implementation), and handle the incoming messages +// from the producers, generating the app state, and responding with information to user +// inputs. + +// Additionally, this module will send data out to consumers, such as the database and any +// connected users (web interface) or the application window (if applicable). + +// This is the main loop of the SDRE Hub. + +use async_trait::async_trait; + +#[async_trait] +pub trait ShDataUser { + async fn start(&self) -> Result<(), Box>; + fn stop(&self); + fn restart(&self); +} + +pub type ShDataUserList = Vec>; diff --git a/src/libraries/sdrehub-api/Cargo.toml b/src/libraries/sdrehub-api/Cargo.toml index bf336a1..c6093ef 100644 --- a/src/libraries/sdrehub-api/Cargo.toml +++ b/src/libraries/sdrehub-api/Cargo.toml @@ -16,6 +16,8 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +async-trait = "0.1.80" axum = { version = "0.7.5", features = ["ws"] } log = "0.4.21" +libsdrehubcommon = { path = "../libsdrehubcommon" } tokio = { version = "1.37.0", features = ["full", "tracing"] } diff --git a/src/libraries/sdrehub-api/src/lib.rs b/src/libraries/sdrehub-api/src/lib.rs index 214ff8d..264d3a5 100644 --- a/src/libraries/sdrehub-api/src/lib.rs +++ b/src/libraries/sdrehub-api/src/lib.rs @@ -12,35 +12,65 @@ clippy::all )] +use async_trait::async_trait; use axum::{ extract::ws::{Message, WebSocket, WebSocketUpgrade}, response::Response, routing::get, Router, }; +use libsdrehubcommon::ShDataUser; #[macro_use] extern crate log; -pub async fn run_webserver() { - let listener = match tokio::net::TcpListener::bind("0.0.0.0:3000").await { - Ok(listener) => listener, - Err(e) => { - error!("Error binding socket for websocket server: {e}"); - return; - } - }; +pub struct ShWebServer {} + +#[async_trait] +impl ShDataUser for ShWebServer { + async fn start(&self) -> Result<(), Box> { + // Start the web server + self.run_webserver().await + } + + fn stop(&self) { + // Stop the web server + } + + fn restart(&self) { + // Restart the web server + } +} + +impl ShWebServer { + /// # Errors + /// - Error binding socket for websocket server: {e} + pub async fn run_webserver(&self) -> Result<(), Box> { + let listener = match tokio::net::TcpListener::bind("0.0.0.0:3000").await { + Ok(listener) => listener, + Err(e) => { + error!("Error binding socket for websocket server: {e}"); + return Err(Box::new(e)); + } + }; + + let local_addr = match listener.local_addr() { + Ok(addr) => addr, + Err(e) => { + error!("Error getting local address for websocket server: {e}"); + return Err(Box::new(e)); + } + }; - let local_addr = match listener.local_addr() { - Ok(addr) => addr, - Err(e) => { - error!("Error getting local address for websocket server: {e}"); - return; + info!("listening for websocket connections on {}", local_addr); + if axum::serve(listener, app()).await.is_err() { + error!("Error starting WebSocket server"); + return Err(Box::new(std::io::Error::new( + std::io::ErrorKind::Other, + "Error starting WebSocket server", + ))); } - }; - info!("listening for websocket connections on {}", local_addr); - if axum::serve(listener, app()).await.is_err() { - error!("Error starting WebSocket server"); + Ok(()) } } From b0422c1d505135d4b3c3188d0f294120688b86e2 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:33:57 -0600 Subject: [PATCH 8/8] refactor library names --- Cargo.lock | 56 +++++++++---------- Cargo.toml | 4 +- src/bin/sdre-hub/Cargo.toml | 4 +- src/bin/sdre-hub/src/main.rs | 2 +- src/libraries/libsdrehub/Cargo.toml | 4 +- src/libraries/libsdrehub/src/lib.rs | 4 +- .../{sdrehub-api => libshapi}/Cargo.toml | 2 +- .../{sdrehub-api => libshapi}/src/lib.rs | 0 .../Cargo.toml | 2 +- .../src/acars_router_source.rs | 0 .../src/address.rs | 0 .../src/adsb_source.rs | 0 .../src/lib.rs | 0 .../src/map.rs | 0 .../src/sdrehub.rs | 0 .../src/source.rs | 0 16 files changed, 39 insertions(+), 39 deletions(-) rename src/libraries/{sdrehub-api => libshapi}/Cargo.toml (96%) rename src/libraries/{sdrehub-api => libshapi}/src/lib.rs (100%) rename src/libraries/{sdrehub-config => libshconfig}/Cargo.toml (96%) rename src/libraries/{sdrehub-config => libshconfig}/src/acars_router_source.rs (100%) rename src/libraries/{sdrehub-config => libshconfig}/src/address.rs (100%) rename src/libraries/{sdrehub-config => libshconfig}/src/adsb_source.rs (100%) rename src/libraries/{sdrehub-config => libshconfig}/src/lib.rs (100%) rename src/libraries/{sdrehub-config => libshconfig}/src/map.rs (100%) rename src/libraries/{sdrehub-config => libshconfig}/src/sdrehub.rs (100%) rename src/libraries/{sdrehub-config => libshconfig}/src/source.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 6d1fb2e..0a6b43d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -606,9 +606,9 @@ name = "libsdrehub" version = "4.0.0-alpha1" dependencies = [ "libsdrehubcommon", + "libshapi", + "libshconfig", "log", - "sdrehub_api", - "sdrehub_config", "tokio", ] @@ -619,6 +619,30 @@ dependencies = [ "async-trait", ] +[[package]] +name = "libshapi" +version = "4.0.0-alpha1" +dependencies = [ + "async-trait", + "axum", + "libsdrehubcommon", + "log", + "tokio", +] + +[[package]] +name = "libshconfig" +version = "4.0.0-alpha1" +dependencies = [ + "figment", + "log", + "sdre-rust-logging", + "serde", + "serde-inline-default", + "toml", + "void", +] + [[package]] name = "lock_api" version = "0.4.11" @@ -925,8 +949,8 @@ name = "sdre-hub" version = "4.0.0-alpha1" dependencies = [ "libsdrehub", - "sdrehub_api", - "sdrehub_config", + "libshapi", + "libshconfig", "tokio", ] @@ -942,30 +966,6 @@ dependencies = [ "log", ] -[[package]] -name = "sdrehub_api" -version = "4.0.0-alpha1" -dependencies = [ - "async-trait", - "axum", - "libsdrehubcommon", - "log", - "tokio", -] - -[[package]] -name = "sdrehub_config" -version = "4.0.0-alpha1" -dependencies = [ - "figment", - "log", - "sdre-rust-logging", - "serde", - "serde-inline-default", - "toml", - "void", -] - [[package]] name = "serde" version = "1.0.197" diff --git a/Cargo.toml b/Cargo.toml index 914e105..e7588da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [workspace] members = [ "src/bin/sdre-hub", + "src/libraries/libshapi", + "src/libraries/libshconfig", "src/libraries/libsdrehub", "src/libraries/libsdrehubcommon", - "src/libraries/sdrehub-api", - "src/libraries/sdrehub-config", ] resolver = "2" diff --git a/src/bin/sdre-hub/Cargo.toml b/src/bin/sdre-hub/Cargo.toml index 324c943..4a31d17 100644 --- a/src/bin/sdre-hub/Cargo.toml +++ b/src/bin/sdre-hub/Cargo.toml @@ -15,6 +15,6 @@ keywords.workspace = true [dependencies] libsdrehub = { path = "../../libraries/libsdrehub" } -sdrehub_api = { path = "../../libraries/sdrehub-api" } -sdrehub_config = { path = "../../libraries/sdrehub-config" } +libshapi = { path = "../../libraries/libshapi" } +libshconfig = { path = "../../libraries/libshconfig" } tokio = { version = "1.37.0", features = ["full", "tracing"] } diff --git a/src/bin/sdre-hub/src/main.rs b/src/bin/sdre-hub/src/main.rs index ca7f14d..122e207 100644 --- a/src/bin/sdre-hub/src/main.rs +++ b/src/bin/sdre-hub/src/main.rs @@ -13,7 +13,7 @@ )] use libsdrehub::SdreHub; -use sdrehub_config::ShConfig; +use libshconfig::ShConfig; use std::error::Error; #[tokio::main] diff --git a/src/libraries/libsdrehub/Cargo.toml b/src/libraries/libsdrehub/Cargo.toml index e47631e..67d851d 100644 --- a/src/libraries/libsdrehub/Cargo.toml +++ b/src/libraries/libsdrehub/Cargo.toml @@ -18,6 +18,6 @@ keywords.workspace = true [dependencies] libsdrehubcommon = { path = "../libsdrehubcommon" } log = "0.4.21" -sdrehub_api = { path = "../sdrehub-api" } -sdrehub_config = { path = "../sdrehub-config" } +libshapi = { path = "../libshapi" } +libshconfig = { path = "../libshconfig" } tokio = { version = "1.37.0", features = ["full", "tracing"] } diff --git a/src/libraries/libsdrehub/src/lib.rs b/src/libraries/libsdrehub/src/lib.rs index 153af9d..1ab6543 100644 --- a/src/libraries/libsdrehub/src/lib.rs +++ b/src/libraries/libsdrehub/src/lib.rs @@ -26,8 +26,8 @@ extern crate log; use libsdrehubcommon::ShDataUserList; -use sdrehub_api::ShWebServer; -use sdrehub_config::ShConfig; +use libshapi::ShWebServer; +use libshconfig::ShConfig; use tokio::task::JoinSet; pub struct SdreHub { diff --git a/src/libraries/sdrehub-api/Cargo.toml b/src/libraries/libshapi/Cargo.toml similarity index 96% rename from src/libraries/sdrehub-api/Cargo.toml rename to src/libraries/libshapi/Cargo.toml index c6093ef..67c6758 100644 --- a/src/libraries/sdrehub-api/Cargo.toml +++ b/src/libraries/libshapi/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sdrehub_api" +name = "libshapi" version.workspace = true edition.workspace = true authors.workspace = true diff --git a/src/libraries/sdrehub-api/src/lib.rs b/src/libraries/libshapi/src/lib.rs similarity index 100% rename from src/libraries/sdrehub-api/src/lib.rs rename to src/libraries/libshapi/src/lib.rs diff --git a/src/libraries/sdrehub-config/Cargo.toml b/src/libraries/libshconfig/Cargo.toml similarity index 96% rename from src/libraries/sdrehub-config/Cargo.toml rename to src/libraries/libshconfig/Cargo.toml index 90d3e4d..33d7820 100644 --- a/src/libraries/sdrehub-config/Cargo.toml +++ b/src/libraries/libshconfig/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sdrehub_config" +name = "libshconfig" version.workspace = true edition.workspace = true authors.workspace = true diff --git a/src/libraries/sdrehub-config/src/acars_router_source.rs b/src/libraries/libshconfig/src/acars_router_source.rs similarity index 100% rename from src/libraries/sdrehub-config/src/acars_router_source.rs rename to src/libraries/libshconfig/src/acars_router_source.rs diff --git a/src/libraries/sdrehub-config/src/address.rs b/src/libraries/libshconfig/src/address.rs similarity index 100% rename from src/libraries/sdrehub-config/src/address.rs rename to src/libraries/libshconfig/src/address.rs diff --git a/src/libraries/sdrehub-config/src/adsb_source.rs b/src/libraries/libshconfig/src/adsb_source.rs similarity index 100% rename from src/libraries/sdrehub-config/src/adsb_source.rs rename to src/libraries/libshconfig/src/adsb_source.rs diff --git a/src/libraries/sdrehub-config/src/lib.rs b/src/libraries/libshconfig/src/lib.rs similarity index 100% rename from src/libraries/sdrehub-config/src/lib.rs rename to src/libraries/libshconfig/src/lib.rs diff --git a/src/libraries/sdrehub-config/src/map.rs b/src/libraries/libshconfig/src/map.rs similarity index 100% rename from src/libraries/sdrehub-config/src/map.rs rename to src/libraries/libshconfig/src/map.rs diff --git a/src/libraries/sdrehub-config/src/sdrehub.rs b/src/libraries/libshconfig/src/sdrehub.rs similarity index 100% rename from src/libraries/sdrehub-config/src/sdrehub.rs rename to src/libraries/libshconfig/src/sdrehub.rs diff --git a/src/libraries/sdrehub-config/src/source.rs b/src/libraries/libshconfig/src/source.rs similarity index 100% rename from src/libraries/sdrehub-config/src/source.rs rename to src/libraries/libshconfig/src/source.rs