diff options
| author | 2024-06-29 23:14:06 +0100 | |
|---|---|---|
| committer | 2024-06-29 23:14:06 +0100 | |
| commit | 50185514c9063ba064920b35218a0f819c5d217c (patch) | |
| tree | 31b2dbf2a1a1a81f1587c8ee590511852a6d8db3 | |
| parent | 056098b893a05b193afe80de9897f06d36b6c2b4 (diff) | |
| download | viewercount-50185514c9063ba064920b35218a0f819c5d217c.tar.gz viewercount-50185514c9063ba064920b35218a0f819c5d217c.tar.bz2 viewercount-50185514c9063ba064920b35218a0f819c5d217c.zip | |
Guard against unsupported platforms
| -rw-r--r-- | Cargo.toml | 4 | ||||
| -rw-r--r-- | src/main.rs | 18 | 
2 files changed, 14 insertions, 8 deletions
| @@ -20,7 +20,9 @@ nostr-relay-pool = "0.32.0"  nostr-sdk = { version = "0.32.0", default-features = false }  nostr-signer = { version = "0.32.0", default-features = false, features = ["nip46"] }  pretty_env_logger = "0.5.0" -procfs = { version = "0.16.0", default-features = false }  serde = { version = "1.0.203", features = ["derive"] }  serde_json = "1.0.118"  tokio = { version = "1.38.0", features = ["rt-multi-thread", "signal", "time"] } + +[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] +procfs = { version = "0.16.0", default-features = false } diff --git a/src/main.rs b/src/main.rs index bcbd969..01657a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use std::{      time::Duration,  }; -use anyhow::{anyhow, Context, Result}; +use anyhow::{anyhow, bail, Context, Result};  use clap::{command, Parser};  use futures::future::join_all;  use human_panic::setup_panic; @@ -23,14 +23,13 @@ use nostr_sdk::{      Client, Event, EventBuilder, Filter, Keys, Kind, Tag, TagKind, TagStandard, ToBech32,  };  use nostr_signer::{Nip46Signer, NostrSigner}; +#[cfg(any(target_os = "linux", target_os = "android"))]  use procfs::net::TcpState;  use serde::{Deserialize, Serialize};  use serde_json::{from_reader, to_string}; -use tokio::{ -    signal::unix::{signal, SignalKind}, -    spawn, -    time::sleep, -}; +#[cfg(unix)] +use tokio::signal::unix::{signal, SignalKind}; +use tokio::{spawn, time::sleep};  const DEFAULT_WATCH_INTERVAL_SEC: u64 = 60;  const NIP46_TIMEOUT_SEC: u64 = 60; @@ -276,9 +275,13 @@ async fn create_filters(naddrs: &[String], client: &Client) -> Result<Vec<Filter  }  async fn get_count() -> Result<u64> { -    get_count_from_procfs().await +    if cfg!(any(target_os = "linux", target_os = "android")) { +        return get_count_from_procfs().await; +    } +    bail!("unsupported OS")  } +#[cfg(any(target_os = "linux", target_os = "android"))]  async fn get_count_from_procfs() -> Result<u64> {      let mut tcp = get_https_connected_ips()?;      sleep(Duration::from_secs(TCP_CHECK_DELAY_SEC)).await; @@ -288,6 +291,7 @@ async fn get_count_from_procfs() -> Result<u64> {      Ok(tcp.len() as u64)  } +#[cfg(any(target_os = "linux", target_os = "android"))]  fn get_https_connected_ips() -> Result<Vec<IpAddr>> {      Ok(procfs::net::tcp()?          .into_iter() | 
