Skip to content

Commit

Permalink
Improved build size
Browse files Browse the repository at this point in the history
  • Loading branch information
vladvasiliu committed Oct 3, 2020
1 parent 14c5c9a commit 50378ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
21 changes: 3 additions & 18 deletions Cargo.lock

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

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ version = "0.1.1"
authors = ["Vlad Vasiliu"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "~2.33", features = ["color"] }
#confy = "0.4"
external-ip = "~2.0"
external-ip = "~4.0"
fern = "~0.6"
http = "~0.2"
lazy_static = "~1.4"
log = "~0.4"
regex = "~1"
roxmltree = "~0.11"
#roxmltree = "~0.11"
rusoto_core = "~0.45"
rusoto_ec2 = "~0.45"
tokio = { version = "~0.2", features = ["rt-core", "macros", "signal", "time"] }

[dev-dependencies]
rusoto_mock = "~0.45"

[profile.release]
lto = true
incremental = true
codegen-units = 1
panic = "abort"
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod config;
use crate::aws::{AWSClient, AWSError};
use crate::config::Config;

use external_ip::get_ip;
use external_ip::{Consensus, Policy};
use log::{debug, error, info, LevelFilter};
use rusoto_core::Region;
use rusoto_ec2::Ec2Client;
Expand Down Expand Up @@ -49,10 +49,11 @@ async fn work(config: Config) -> Result<(), Box<dyn Error>> {
config.interval
);
let mut current_ip: Option<IpAddr> = None;
let consensus = external_ip_consensus();
loop {
tokio::select! {
_ = timer.tick() => {
let new_ip = get_ip().await;
let new_ip: Option<IpAddr> = consensus.get_consensus().await;
if new_ip.is_none() {
error!("Failed to determine external ip.");
continue;
Expand Down Expand Up @@ -85,6 +86,14 @@ async fn work(config: Config) -> Result<(), Box<dyn Error>> {
Ok(())
}

fn external_ip_consensus() -> Consensus {
let sources: external_ip::Sources = external_ip::get_sources();
external_ip::ConsensusBuilder::new()
.add_sources(sources)
.policy(Policy::All)
.build()
}

fn setup_logger(level: log::LevelFilter) -> Result<(), fern::InitError> {
fern::Dispatch::new()
.format(move |out, message, record| {
Expand Down

0 comments on commit 50378ca

Please sign in to comment.