mirror of
https://codeberg.org/icewind/tasproxy.git
synced 2026-06-03 18:24:08 +02:00
bumb dependencies
This commit is contained in:
parent
2bfffb9434
commit
3cb8eeb8ea
5 changed files with 329 additions and 344 deletions
643
Cargo.lock
generated
643
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
11
Cargo.toml
11
Cargo.toml
|
|
@ -7,16 +7,15 @@ license = "MIT OR Apache-2.0"
|
|||
repository = "https://github.com/icewind1991/tasproxy"
|
||||
|
||||
[dependencies]
|
||||
rumqttc = "0.8"
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
rumqttc = "0.10"
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread", "signal"] }
|
||||
futures-util = "0.3"
|
||||
dashmap = "4"
|
||||
dashmap = "5"
|
||||
json = "0.12"
|
||||
warp = "0.3"
|
||||
dotenv = "0.15.0"
|
||||
ctrlc = { version = "3", features = ["termination"] }
|
||||
dotenv = "0.15"
|
||||
color-eyre = "0.5"
|
||||
async-stream = "0.3"
|
||||
pin-utils = "0.1"
|
||||
hostname = "^0.3"
|
||||
hostname = "0.3"
|
||||
warp-reverse-proxy = { version = "0.3", default_features = false, features = ["rustls-tls"] }
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
use color_eyre::{eyre::WrapErr, Report, Result};
|
||||
use rumqttc::MqttOptions;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Config {
|
||||
|
|
@ -56,7 +57,7 @@ impl Config {
|
|||
if let Some(credentials) = self.mqtt_credentials.as_ref() {
|
||||
mqtt_options.set_credentials(&credentials.username, &credentials.password);
|
||||
}
|
||||
mqtt_options.set_keep_alive(5);
|
||||
mqtt_options.set_keep_alive(Duration::from_secs(5));
|
||||
Ok(mqtt_options)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
src/main.rs
16
src/main.rs
|
|
@ -9,6 +9,7 @@ use pin_utils::pin_mut;
|
|||
use rumqttc::{AsyncClient, QoS};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::signal;
|
||||
use tokio::time::sleep;
|
||||
use warp::hyper::http::uri::Authority;
|
||||
use warp::Filter;
|
||||
|
|
@ -28,11 +29,6 @@ async fn main() -> Result<()> {
|
|||
|
||||
let device_states = DeviceStates::default();
|
||||
|
||||
ctrlc::set_handler(move || {
|
||||
std::process::exit(0);
|
||||
})
|
||||
.expect("Error setting Ctrl-C handler");
|
||||
|
||||
let states = device_states.clone();
|
||||
tokio::task::spawn(async move {
|
||||
loop {
|
||||
|
|
@ -77,7 +73,13 @@ async fn main() -> Result<()> {
|
|||
.and(extract_request_data_filter())
|
||||
.and_then(proxy_to_and_forward_response);
|
||||
|
||||
warp::serve(proxy).run(([0, 0, 0, 0], host_port)).await;
|
||||
let (_addr, server) =
|
||||
warp::serve(proxy).bind_with_graceful_shutdown(([0, 0, 0, 0], host_port), async {
|
||||
signal::ctrl_c().await.ok();
|
||||
});
|
||||
|
||||
server.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +99,7 @@ async fn mqtt_client(config: &Config, device_states: DeviceStates) -> Result<()>
|
|||
let topic = Topic::from(message.topic.as_str());
|
||||
|
||||
match topic {
|
||||
Topic::LWT(device) => match payload {
|
||||
Topic::Lwt(device) => match payload {
|
||||
"Online" => {
|
||||
println!("Discovered {}", device.hostname);
|
||||
query_device(client.clone(), device).await;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::devices::Device;
|
|||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum Topic {
|
||||
LWT(Device),
|
||||
Lwt(Device),
|
||||
State(Device),
|
||||
Sensor(Device),
|
||||
Result(Device),
|
||||
|
|
@ -19,7 +19,7 @@ impl From<&str> for Topic {
|
|||
hostname: hostname.to_string(),
|
||||
};
|
||||
match (prefix, cmd) {
|
||||
("tele", "LWT") => Topic::LWT(device),
|
||||
("tele", "LWT") => Topic::Lwt(device),
|
||||
("tele", "STATE") => Topic::State(device),
|
||||
("tele", "SENSOR") => Topic::Sensor(device),
|
||||
("stat", "RESULT") => Topic::Result(device),
|
||||
|
|
@ -36,7 +36,7 @@ fn parse_topic() {
|
|||
let device = Device {
|
||||
hostname: "hostname".to_string(),
|
||||
};
|
||||
assert_eq!(Topic::LWT(device.clone()), Topic::from("tele/hostname/LWT"));
|
||||
assert_eq!(Topic::Lwt(device.clone()), Topic::from("tele/hostname/LWT"));
|
||||
assert_eq!(
|
||||
Topic::State(device.clone()),
|
||||
Topic::from("tele/hostname/STATE")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue