gosh_lan_transfer/types.rs
1// SPDX-License-Identifier: MIT
2//! Domain types for gosh-lan-transfer
3//!
4//! This module contains domain entities and utility types that are
5//! internal to the engine or used for persistence/history.
6//!
7//! For types that cross the engine boundary (wire protocol, events),
8//! see the `protocol` module.
9
10use chrono::{DateTime, Utc};
11use serde::{Deserialize, Serialize};
12use uuid::Uuid;
13
14// Re-export protocol types that domain types depend on
15pub use crate::protocol::{TransferDirection, TransferFile, TransferStatus};
16
17// =============================================================================
18// Domain Entities - Persistence and history
19// =============================================================================
20
21/// A saved peer/favorite for quick access
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(rename_all = "camelCase")]
24pub struct Favorite {
25 /// Unique identifier
26 pub id: String,
27 /// User-friendly name (e.g., "Living Room PC")
28 pub name: String,
29 /// Hostname or IP address
30 pub address: String,
31 /// Last successfully resolved IP (if available)
32 pub last_resolved_ip: Option<String>,
33 /// When this favorite was last used
34 pub last_used: Option<DateTime<Utc>>,
35}
36
37impl Favorite {
38 pub fn new(name: String, address: String) -> Self {
39 Self {
40 id: Uuid::new_v4().to_string(),
41 name,
42 address,
43 last_resolved_ip: None,
44 last_used: None,
45 }
46 }
47}
48
49/// A completed or failed transfer record (for history)
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(rename_all = "camelCase")]
52pub struct TransferRecord {
53 /// Unique identifier
54 pub id: String,
55 /// Direction of transfer
56 pub direction: TransferDirection,
57 /// Status of the transfer
58 pub status: TransferStatus,
59 /// Peer address (IP or hostname)
60 pub peer_address: String,
61 /// Files transferred
62 pub files: Vec<TransferFile>,
63 /// Total size transferred
64 pub total_size: u64,
65 /// Bytes actually transferred (for progress/partial)
66 pub bytes_transferred: u64,
67 /// When the transfer started
68 pub started_at: DateTime<Utc>,
69 /// When the transfer completed (or failed)
70 pub completed_at: Option<DateTime<Utc>>,
71 /// Error message if failed
72 pub error: Option<String>,
73}
74
75// =============================================================================
76// Utility Types - Network and resolution
77// =============================================================================
78
79/// Network interface information
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(rename_all = "camelCase")]
82pub struct NetworkInterface {
83 /// Interface name
84 pub name: String,
85 /// IP address
86 pub ip: String,
87 /// Whether this is a loopback interface
88 pub is_loopback: bool,
89}
90
91/// DNS resolution result
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(rename_all = "camelCase")]
94pub struct ResolveResult {
95 /// Original hostname/address
96 pub hostname: String,
97 /// Resolved IP addresses
98 pub ips: Vec<String>,
99 /// Whether resolution was successful
100 pub success: bool,
101 /// Error message if failed
102 pub error: Option<String>,
103}