Skip to content

Commit

Permalink
Bump version to 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
N3xed committed May 5, 2024
1 parent a7120aa commit a04f4ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ddns-update-daemon"
version = "0.3.0"
version = "1.0.0"
edition = "2021"
authors = ["Dominik Gschwind"]
description = "DynDNS update daemon using UPnP"
Expand All @@ -14,7 +14,7 @@ categories = ["command-line-utilities", "network-programming"]
rupnp = "2.0.0"
anyhow = "1.0"
parse-display = "0.9"
tokio = { version = "1.29", features = ["macros"] }
tokio = { version = "1.29", features = ["macros", "rt", "time"] }
reqwest = { version = "0.12", features = ["json", "charset", "http2", "macos-system-configuration"], default-features = false }
futures = "0.3"
serde = { version = "1.0", features = ["derive"] }
Expand Down
30 changes: 15 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub mod config {
}

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
pub async fn main() -> anyhow::Result<()> {
let args = Args::parse();
simple_logger::SimpleLogger::new()
.with_level(if args.verbose {
Expand Down Expand Up @@ -165,8 +165,8 @@ async fn main() -> anyhow::Result<()> {
let mut curr_ipv6: Option<Ipv6Addr> = None;
loop {
let (next_ipv4, next_ipv6) = match service.get_current_ips().await {
Ok(v) => v,
Err(_) => {
Some(v) => v,
None => {
log::info!("UPnP request failed; rediscovering internet gateway..");
// Try to recreate the IpService, since the previous call errored.
let new_service = IpService::new(config.router_ip, false).await;
Expand Down Expand Up @@ -305,18 +305,18 @@ async fn main() -> anyhow::Result<()> {
}
}

pub fn replace_placehoders(s: &str, ipv4: &str, ipv6: &str) -> String {
fn replace_placehoders(s: &str, ipv4: &str, ipv6: &str) -> String {
let s = s.replace("{ipv4}", ipv4);
s.replace("{ipv6}", ipv6)
}

enum IpService {
pub enum IpService {
UPnP(UPnPIpService),
Local,
}

impl IpService {
async fn get_current_ips(&self) -> Result<(Option<Ipv4Addr>, Option<Ipv6Addr>), ()> {
pub async fn get_current_ips(&self) -> Option<(Option<Ipv4Addr>, Option<Ipv6Addr>)> {
match self {
IpService::UPnP(s) => s.get_current_ips().await,
IpService::Local => get_current_local_ips(),
Expand All @@ -326,7 +326,7 @@ impl IpService {
/// Create an IP address service.
/// Query local IP address if `ipaddr` is loopback otherwise use UPnP to
/// query the router's given by `ipaddr` or the first discovered.
async fn new(ipaddr: Option<std::net::IpAddr>, verbose: bool) -> Result<Self> {
pub async fn new(ipaddr: Option<std::net::IpAddr>, verbose: bool) -> Result<Self> {
if ipaddr.as_ref().map(IpAddr::is_loopback).unwrap_or(false) {
if verbose {
log::info!("Watching the local IP address.");
Expand Down Expand Up @@ -434,7 +434,7 @@ impl UPnPIpService {
}

/// Get the external ip address.
pub async fn get_current_external_ip(&self) -> Result<Option<IpAddr>> {
async fn get_current_external_ip(&self) -> Result<Option<IpAddr>> {
const ACTION: &str = "GetExternalIPAddress";
const IPV4_ADDR_VAR: &str = "NewExternalIPAddress";

Expand All @@ -455,7 +455,7 @@ impl UPnPIpService {

/// Get the external IPV6 address. Currently only supported on FRITZ!Box with the
/// `X_AVM_DE_GetExternalIPv6Address` action.
pub async fn get_current_external_ipv6(&self) -> Result<Option<Ipv6Addr>> {
async fn get_current_external_ipv6(&self) -> Result<Option<Ipv6Addr>> {
const ACTION: &str = "X_AVM_DE_GetExternalIPv6Address";
const IPV6_ADDR_VAR: &str = "NewExternalIPv6Address";
const VALID_LIFETIME_VAR: &str = "NewValidLifetime";
Expand Down Expand Up @@ -493,14 +493,14 @@ impl UPnPIpService {
}
}

async fn get_current_ips(&self) -> Result<(Option<Ipv4Addr>, Option<Ipv6Addr>), ()> {
pub async fn get_current_ips(&self) -> Option<(Option<Ipv4Addr>, Option<Ipv6Addr>)> {
let (ipv4, ipv6) = match self.get_current_external_ip().await {
Ok(Some(IpAddr::V4(ip))) => (Some(ip), None),
Ok(Some(IpAddr::V6(ip))) => (None, Some(ip)),
Ok(None) => (None, None),
Err(err) => {
log::error!("{err:?}");
return Err(());
return None;
}
};
let ipv6 = if ipv6.is_some() {
Expand All @@ -510,16 +510,16 @@ impl UPnPIpService {
Ok(ip) => ip,
Err(err) => {
log::error!("{err:?}");
return Err(());
return None;
}
}
};

Ok((ipv4, ipv6))
Some((ipv4, ipv6))
}
}

fn get_current_local_ips() -> Result<(Option<Ipv4Addr>, Option<Ipv6Addr>), ()> {
pub fn get_current_local_ips() -> Option<(Option<Ipv4Addr>, Option<Ipv6Addr>)> {
let (ipv4, ipv6) = match local_ip_address::local_ip() {
Ok(IpAddr::V4(ip)) => (Some(ip), None),
Ok(IpAddr::V6(ip)) => (None, Some(ip)),
Expand All @@ -540,5 +540,5 @@ fn get_current_local_ips() -> Result<(Option<Ipv4Addr>, Option<Ipv6Addr>), ()> {
}
}
};
Ok((ipv4, ipv6))
Some((ipv4, ipv6))
}

0 comments on commit a04f4ff

Please sign in to comment.