mirror of
https://codeberg.org/icewind/tasproxy.git
synced 2026-06-03 10:14:09 +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"
|
repository = "https://github.com/icewind1991/tasproxy"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rumqttc = "0.8"
|
rumqttc = "0.10"
|
||||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1", features = ["macros", "rt-multi-thread", "signal"] }
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
dashmap = "4"
|
dashmap = "5"
|
||||||
json = "0.12"
|
json = "0.12"
|
||||||
warp = "0.3"
|
warp = "0.3"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15"
|
||||||
ctrlc = { version = "3", features = ["termination"] }
|
|
||||||
color-eyre = "0.5"
|
color-eyre = "0.5"
|
||||||
async-stream = "0.3"
|
async-stream = "0.3"
|
||||||
pin-utils = "0.1"
|
pin-utils = "0.1"
|
||||||
hostname = "^0.3"
|
hostname = "0.3"
|
||||||
warp-reverse-proxy = { version = "0.3", default_features = false, features = ["rustls-tls"] }
|
warp-reverse-proxy = { version = "0.3", default_features = false, features = ["rustls-tls"] }
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use color_eyre::{eyre::WrapErr, Report, Result};
|
use color_eyre::{eyre::WrapErr, Report, Result};
|
||||||
use rumqttc::MqttOptions;
|
use rumqttc::MqttOptions;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|
@ -56,7 +57,7 @@ impl Config {
|
||||||
if let Some(credentials) = self.mqtt_credentials.as_ref() {
|
if let Some(credentials) = self.mqtt_credentials.as_ref() {
|
||||||
mqtt_options.set_credentials(&credentials.username, &credentials.password);
|
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)
|
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 rumqttc::{AsyncClient, QoS};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use tokio::signal;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use warp::hyper::http::uri::Authority;
|
use warp::hyper::http::uri::Authority;
|
||||||
use warp::Filter;
|
use warp::Filter;
|
||||||
|
|
@ -28,11 +29,6 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let device_states = DeviceStates::default();
|
let device_states = DeviceStates::default();
|
||||||
|
|
||||||
ctrlc::set_handler(move || {
|
|
||||||
std::process::exit(0);
|
|
||||||
})
|
|
||||||
.expect("Error setting Ctrl-C handler");
|
|
||||||
|
|
||||||
let states = device_states.clone();
|
let states = device_states.clone();
|
||||||
tokio::task::spawn(async move {
|
tokio::task::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -77,7 +73,13 @@ async fn main() -> Result<()> {
|
||||||
.and(extract_request_data_filter())
|
.and(extract_request_data_filter())
|
||||||
.and_then(proxy_to_and_forward_response);
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,7 +99,7 @@ async fn mqtt_client(config: &Config, device_states: DeviceStates) -> Result<()>
|
||||||
let topic = Topic::from(message.topic.as_str());
|
let topic = Topic::from(message.topic.as_str());
|
||||||
|
|
||||||
match topic {
|
match topic {
|
||||||
Topic::LWT(device) => match payload {
|
Topic::Lwt(device) => match payload {
|
||||||
"Online" => {
|
"Online" => {
|
||||||
println!("Discovered {}", device.hostname);
|
println!("Discovered {}", device.hostname);
|
||||||
query_device(client.clone(), device).await;
|
query_device(client.clone(), device).await;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use crate::devices::Device;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum Topic {
|
pub enum Topic {
|
||||||
LWT(Device),
|
Lwt(Device),
|
||||||
State(Device),
|
State(Device),
|
||||||
Sensor(Device),
|
Sensor(Device),
|
||||||
Result(Device),
|
Result(Device),
|
||||||
|
|
@ -19,7 +19,7 @@ impl From<&str> for Topic {
|
||||||
hostname: hostname.to_string(),
|
hostname: hostname.to_string(),
|
||||||
};
|
};
|
||||||
match (prefix, cmd) {
|
match (prefix, cmd) {
|
||||||
("tele", "LWT") => Topic::LWT(device),
|
("tele", "LWT") => Topic::Lwt(device),
|
||||||
("tele", "STATE") => Topic::State(device),
|
("tele", "STATE") => Topic::State(device),
|
||||||
("tele", "SENSOR") => Topic::Sensor(device),
|
("tele", "SENSOR") => Topic::Sensor(device),
|
||||||
("stat", "RESULT") => Topic::Result(device),
|
("stat", "RESULT") => Topic::Result(device),
|
||||||
|
|
@ -36,7 +36,7 @@ fn parse_topic() {
|
||||||
let device = Device {
|
let device = Device {
|
||||||
hostname: "hostname".to_string(),
|
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!(
|
assert_eq!(
|
||||||
Topic::State(device.clone()),
|
Topic::State(device.clone()),
|
||||||
Topic::from("tele/hostname/STATE")
|
Topic::from("tele/hostname/STATE")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue