Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rustatio-cli/src/json/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ impl From<&FakerStats> for StatsEvent {
eta_ratio_secs: stats.eta_ratio.map(|d| d.as_secs()),
eta_uploaded_secs: stats.eta_uploaded.map(|d| d.as_secs()),
eta_seed_time_secs: stats.eta_seed_time.map(|d| d.as_secs()),
state: format_state(&stats.state),
state: format_state(stats.state),
elapsed_secs: stats.elapsed_time.as_secs(),
timestamp: Utc::now(),
}
}
}

fn format_state(state: &FakerState) -> String {
fn format_state(state: FakerState) -> String {
match state {
FakerState::Idle => "idle".to_string(),
FakerState::Starting => "starting".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion rustatio-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dirs = "6"
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "gzip"], optional = true }

# Async runtime
tokio = { version = "1.48", default-features = false, features = ["sync", "time", "macros", "rt"], optional = true }
tokio = { version = "1.48", default-features = false, features = ["sync", "time", "macros", "rt", "net", "io-util"], optional = true }

# Native-only dependencies
tauri = { version = "2.10", optional = true }
Expand Down
49 changes: 48 additions & 1 deletion rustatio-core/src/faker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::protocol::{
};
use crate::torrent::{ClientConfig, ClientType, TorrentInfo};
use crate::{log_debug, log_info, log_trace, log_warn};
#[cfg(not(target_arch = "wasm32"))]
use crate::{peer_listener::handle_is_connectable, protocol::peer_id_to_array};
use instant::Instant;
use rand::Rng;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -283,7 +285,7 @@ pub enum PostStopAction {
DeleteInstance,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum FakerState {
Idle,
Starting,
Expand Down Expand Up @@ -1169,6 +1171,18 @@ impl RatioFaker {
self.stats.clone()
}

pub fn peer_id(&self) -> &str {
&self.peer_id
}

pub fn info_hash(&self) -> [u8; 20] {
self.torrent.info_hash
}

pub const fn port(&self) -> u16 {
self.config.port
}

/// Get torrent info
pub const fn get_torrent(&self) -> &Arc<TorrentInfo> {
&self.torrent
Expand Down Expand Up @@ -1771,6 +1785,39 @@ impl RatioFakerHandle {
let _ = self.stats_tx.send(guard.stats_snapshot());
result
}

pub async fn peer_id(&self) -> String {
let guard = self.inner.lock().await;
guard.peer_id().to_string()
}

pub async fn peer_id_bytes(
&self,
) -> std::result::Result<[u8; 20], crate::protocol::PeerProtocolError> {
let peer_id = self.peer_id().await;
peer_id_to_array(&peer_id)
}

pub async fn info_hash(&self) -> [u8; 20] {
let guard = self.inner.lock().await;
guard.info_hash()
}

pub async fn effective_port(&self) -> u16 {
let guard = self.inner.lock().await;
guard.port()
}

pub async fn set_runtime_port(&self, port: u16) {
let mut guard = self.inner.lock().await;
guard.config.port = port;
let _ = self.stats_tx.send(guard.stats_snapshot());
}

pub async fn is_peer_connectable(&self) -> bool {
let guard = self.inner.lock().await;
handle_is_connectable(guard.stats.state)
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions rustatio-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ pub mod config;
pub mod faker;
pub mod grid;
pub mod logger;
#[cfg(not(target_arch = "wasm32"))]
pub mod peer_listener;
pub mod protocol;
pub mod torrent;
pub mod validation;
Expand All @@ -14,6 +16,8 @@ pub use faker::{
FakerConfig, FakerError, FakerState, FakerStats, PostStopAction, PresetSettings, RatioFaker,
};
pub use grid::{GridImportSettings, GridMode, InstanceSummary};
#[cfg(not(target_arch = "wasm32"))]
pub use peer_listener::{PeerCatalog, PeerListenerService, PeerListenerStatus, PeerLookup};
pub use torrent::{
ClientConfig, ClientInfo, ClientType, HttpVersion, TorrentError, TorrentFile, TorrentInfo,
TorrentSummary,
Expand Down
4 changes: 4 additions & 0 deletions rustatio-core/src/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod config;
pub mod faker;
pub mod logger;
#[cfg(not(target_arch = "wasm32"))]
pub mod peer_listener;
pub mod protocol;
pub mod torrent;
pub mod validation;
Expand All @@ -10,6 +12,8 @@ pub use config::AppConfig;
#[cfg(not(target_arch = "wasm32"))]
pub use faker::RatioFakerHandle;
pub use faker::{FakerConfig, FakerState, FakerStats, RatioFaker};
#[cfg(not(target_arch = "wasm32"))]
pub use peer_listener::{PeerCatalog, PeerListenerService, PeerListenerStatus, PeerLookup};
pub use protocol::{TrackerClient, TrackerError};
pub use torrent::{ClientConfig, ClientType, TorrentInfo, TorrentSummary};
pub use validation::ValidationError;
Loading
Loading