From b924e4dc2f4afac15c3e5d8f67652e1d657752da Mon Sep 17 00:00:00 2001 From: "xea@blacklight.id" Date: Wed, 28 Feb 2024 16:48:47 +0000 Subject: [PATCH 1/3] Created emulate branch --- Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca8db61..f077ecb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -unicorn_hat_hd_2 = { version = "*" } -#unicorn_hat_hd_2 = { version = "*", default-features = false, features = [ "fake-hardware" ] } +unicorn_hat_hd_2 = { version = "*", default-features = false, features = [ "fake-hardware" ] } url = "*" reqwest = "*" trust-dns-client = "*" From bcbe002bebd64e344fbada3d190d6b19d19187dc Mon Sep 17 00:00:00 2001 From: Sandor Pecsi Date: Wed, 28 Feb 2024 17:41:21 +0000 Subject: [PATCH 2/3] Added dns and http client stubs --- .gitignore | 2 ++ src/dns.rs | 13 +++++++++++++ src/http.rs | 31 +++++++++++++++++++++++++++++++ src/main.rs | 30 ++++++++---------------------- 4 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 src/dns.rs create mode 100644 src/http.rs diff --git a/.gitignore b/.gitignore index 3ca43ae..a84f36c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb +# Vim swapfiles +*.swp diff --git a/src/dns.rs b/src/dns.rs new file mode 100644 index 0000000..6bf487a --- /dev/null +++ b/src/dns.rs @@ -0,0 +1,13 @@ +use crate::{Probe, ProbeResult}; +use trust_dns_client::client::Client; + +// DNS probe + +pub struct DnsProbe { +} + +impl Probe for DnsProbe { + fn execute() -> ProbeResult { + unimplemented!(); + } +} diff --git a/src/http.rs b/src/http.rs new file mode 100644 index 0000000..768c3a3 --- /dev/null +++ b/src/http.rs @@ -0,0 +1,31 @@ +use crate::{Probe, ProbeResult}; +use url::Url; + +use std::net::SocketAddr; + +#[derive(Debug)] +pub enum HttpError { + UrlError(url::ParseError) +} + +// HTTP probe +// +pub struct HttpProbe { + remote_addr: SocketAddr +} + +impl HttpProbe { + pub fn get(url: &str) -> Result { + let request = url::Url::parse(url) + .map_err(HttpError::UrlError); + + unimplemented!(); + } +} + +impl Probe for HttpProbe { + fn execute() -> ProbeResult { + unimplemented!(); + } +} + diff --git a/src/main.rs b/src/main.rs index 6b8b12a..af7b5f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ use unicorn_hat_hd_2::UnicornHatHd; -use url::Url; -use std::net::SocketAddr; +use self::http::HttpProbe; + +mod dns; +mod http; pub trait Probe { fn execute() -> ProbeResult; @@ -21,26 +23,6 @@ pub struct ProbeMetrics { pub latency_ms: u32 } -// HTTP probe -// -pub struct HttpProbe { - remote_addr: SocketAddr -} - -impl Probe for HttpProbe { - fn execute() -> ProbeResult { - unimplemented!(); - } -} - -// DNS probe - -pub struct DnsProbe { - fn execute() -> ProbeResult { - unimplemented!(); - } -} - fn main() { let mut hat_hd = UnicornHatHd::default(); @@ -50,5 +32,9 @@ fn main() { //hat_hd.set_pixel(x, y, [255, 255, 255].into()); //hat_hd.display().unwrap(); + let probes = vec![ + HttpProbe::get("https://google.co.uk").expect("Failed to parse URL") + ]; + } From 168621cd993adb0a19a105c4fa17641698866b2b Mon Sep 17 00:00:00 2001 From: Sandor Pecsi Date: Wed, 28 Feb 2024 17:42:06 +0000 Subject: [PATCH 3/3] Reverted emulation mode on main --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f077ecb..a38d520 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -unicorn_hat_hd_2 = { version = "*", default-features = false, features = [ "fake-hardware" ] } +unicorn_hat_hd_2 = { version = "*" } url = "*" reqwest = "*" trust-dns-client = "*"