synapse 1.1.0

Neural Communication Network with Federated Identity and Blockchain Trust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
//! Multi-transport layer for EMRP
//! 
//! This module provides the core transport abstraction and implementations
//! for different communication methods: TCP/UDP, auto-discovery, NAT traversal, and email.

// Core abstraction layer
pub mod abstraction;
pub mod manager;

// Dependency injection providers for testability
pub mod providers;

#[cfg(test)]
mod providers_test;

// Transport implementations
#[cfg(not(target_arch = "wasm32"))]
pub mod discovery; // New auto-discovery based implementation

#[cfg(not(target_arch = "wasm32"))]
pub mod udp_unified;

// Re-export key types
pub use abstraction::{TransportType, TransportCapabilities};
pub use discovery::DiscoveryTransport;
pub use auto_discovery::config::DiscoveryConfig;

// Simple, working transport implementation (template)
#[cfg(not(target_arch = "wasm32"))]
pub mod tcp_simple;

// Platform-specific transport modules (not available in WASM)
#[cfg(not(target_arch = "wasm32"))]
pub mod tcp;
#[cfg(not(target_arch = "wasm32"))]
pub mod tcp_enhanced;
#[cfg(not(target_arch = "wasm32"))]
pub mod udp;
#[cfg(not(target_arch = "wasm32"))]
pub mod http_unified;
// #[cfg(not(target_arch = "wasm32"))]
// pub mod mdns;
#[cfg(not(target_arch = "wasm32"))]
pub mod mdns_enhanced;
#[cfg(not(target_arch = "wasm32"))]
pub mod nat_traversal;
#[cfg(not(target_arch = "wasm32"))]
pub mod email_enhanced;
// Legacy implementations - temporarily disabled
// #[cfg(not(target_arch = "wasm32"))]
// pub mod websocket;
// #[cfg(not(target_arch = "wasm32"))]
// pub mod quic;
#[cfg(not(target_arch = "wasm32"))]
pub mod router;
#[cfg(not(target_arch = "wasm32"))]
pub mod llm_discovery;

use crate::{types::*, error::Result, circuit_breaker::{CircuitBreaker, RequestOutcome}};
use async_trait::async_trait;
use std::{time::{Duration, Instant}, sync::Arc};
use serde::{Serialize, Deserialize};

// Platform-specific imports
#[cfg(not(target_arch = "wasm32"))]
use tokio::time::timeout;

/// Available transport routes with performance characteristics
#[derive(Debug, Clone)]
pub enum TransportRoute {
    // Platform-specific transport routes (not available in WASM)
    #[cfg(not(target_arch = "wasm32"))]
    DirectTcp { 
        address: String,
        port: u16, 
        latency_ms: u32,
        established_at: Instant,
    },
    #[cfg(not(target_arch = "wasm32"))]
    DirectUdp {
        address: String, 
        port: u16,
        latency_ms: u32,
        established_at: Instant,
    },
    #[cfg(not(target_arch = "wasm32"))]
    Udp {
        address: String,
        latency: Duration,
        reliability: f64,
    },
    #[cfg(not(target_arch = "wasm32"))]
    WebSocket {
        url: String,
        latency: Duration,
        reliability: f64,
    },
    #[cfg(not(target_arch = "wasm32"))]
    Quic {
        address: String,
        latency: Duration,
        reliability: f64,
        multiplexed: bool,
    },
    #[cfg(not(target_arch = "wasm32"))]
    LocalMdns { 
        service_name: String,
        address: String,
        port: u16,
        latency_ms: u32,
        discovered_at: Instant,
    },
    #[cfg(not(target_arch = "wasm32"))]
    NatTraversal { 
        method: NatMethod,
        external_address: String,
        external_port: u16,
        latency_ms: u32,
        established_at: Instant,
    },
    #[cfg(not(target_arch = "wasm32"))]
    FastEmailRelay { 
        relay_server: String,
        estimated_latency_ms: u32,
    },
    #[cfg(not(target_arch = "wasm32"))]
    StandardEmail { 
        estimated_latency_min: u32,
    },
    #[cfg(not(target_arch = "wasm32"))]
    EmailDiscovery { 
        target_transport: Box<TransportRoute>,
    },
    
    // WASM-compatible transport routes
    #[cfg(target_arch = "wasm32")]
    WebSocket {
        url: String,
        latency_ms: u32,
        established_at: Instant,
    },
    #[cfg(target_arch = "wasm32")]
    WebRtc {
        peer_connection: String,
        latency_ms: u32,
        established_at: Instant,
    },
    #[cfg(target_arch = "wasm32")]
    WebAssembly {
        estimated_latency_ms: u32,
    },
}

/// NAT traversal methods (not available in WASM)
#[cfg(not(target_arch = "wasm32"))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum NatMethod {
    Upnp,
    Stun { server: String },
    Turn { server: String, username: String },
    IceCandidate,
}

/// Connection offer for transport negotiation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConnectionOffer {
    pub entity_id: String,
    // Platform-specific endpoints (not available in WASM)
    #[cfg(not(target_arch = "wasm32"))]
    pub tcp_endpoints: Vec<String>,
    #[cfg(not(target_arch = "wasm32"))]
    pub udp_endpoints: Vec<String>, 
    #[cfg(not(target_arch = "wasm32"))]
    pub stun_servers: Vec<String>,
    #[cfg(not(target_arch = "wasm32"))]
    pub turn_servers: Vec<TurnServer>,
    
    // Common fields
    pub capabilities: Vec<String>,
    pub public_key: String,
    pub expires_at: chrono::DateTime<chrono::Utc>,
    pub priority: u8, // 0-255, higher = more preferred
    
    // WASM-specific endpoints
    #[cfg(target_arch = "wasm32")]
    pub websocket_endpoints: Vec<String>,
    #[cfg(target_arch = "wasm32")]
    pub webrtc_endpoints: Vec<String>,
}

/// TURN server configuration (not available in WASM)
#[cfg(not(target_arch = "wasm32"))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TurnServer {
    pub url: String,
    pub username: String, 
    pub credential: String,
}

/// Transport performance metrics
#[derive(Debug, Clone)]
pub struct TransportMetrics {
    pub latency: Duration,
    pub throughput_bps: u64,
    pub packet_loss: f32,
    pub jitter_ms: u32,
    pub reliability_score: f32, // 0.0-1.0
    pub last_updated: Instant,
}

impl Default for TransportMetrics {
    fn default() -> Self {
        Self {
            latency: Duration::from_millis(50),
            throughput_bps: 1_000_000, // 1 Mbps
            packet_loss: 0.0,
            jitter_ms: 10,
            reliability_score: 0.95,
            last_updated: Instant::now(),
        }
    }
}

/// Hybrid connection combining multiple transports
#[derive(Debug)]
pub struct HybridConnection {
    pub primary: TransportRoute,
    pub fallback: TransportRoute,
    pub discovery_latency: Duration,
    pub connection_latency: Duration,
    pub total_setup_time: Duration,
    pub metrics: TransportMetrics,
}

/// Abstract transport trait for all communication methods
#[async_trait]
pub trait Transport: Send + Sync {
    /// Send a message via this transport
    async fn send_message(&self, target: &str, message: &SecureMessage) -> Result<String>;
    
    /// Send a message with circuit breaker protection
    async fn send_message_with_breaker(
        &self, 
        target: &str, 
        message: &SecureMessage,
        circuit_breaker: Option<Arc<CircuitBreaker>>
    ) -> Result<String> {
        if let Some(breaker) = circuit_breaker {
            // Check if circuit allows request
            if !breaker.can_proceed().await {
                return Err(crate::error::SynapseError::TransportError(
                    "Circuit breaker open - request rejected".to_string()
                ).into());
            }
            
            // Attempt the request
            match self.send_message(target, message).await {
                Ok(result) => {
                    breaker.record_outcome(RequestOutcome::Success).await;
                    Ok(result)
                }
                Err(e) => {
                    breaker.record_outcome(RequestOutcome::Failure(e.to_string())).await;
                    Err(e)
                }
            }
        } else {
            // No circuit breaker - direct call
            self.send_message(target, message).await
        }
    }
    
    /// Receive messages via this transport  
    async fn receive_messages(&self) -> Result<Vec<SecureMessage>>;
    
    /// Test connectivity and measure latency
    async fn test_connectivity(&self, target: &str) -> Result<TransportMetrics>;
    
    /// Test connectivity with circuit breaker integration
    async fn test_connectivity_with_breaker(
        &self,
        target: &str,
        circuit_breaker: Option<Arc<CircuitBreaker>>
    ) -> Result<TransportMetrics> {
        if let Some(breaker) = circuit_breaker {
            if !breaker.can_proceed().await {
                return Err(crate::error::SynapseError::TransportError(
                    "Circuit breaker open - connectivity test rejected".to_string()
                ).into());
            }
            
            let start_time = Instant::now();
            match self.test_connectivity(target).await {
                Ok(metrics) => {
                    breaker.record_outcome(RequestOutcome::Success).await;
                    
                    // Update circuit breaker with latest metrics
                    breaker.check_external_triggers(&metrics).await;
                    
                    Ok(metrics)
                }
                Err(e) => {
                    let elapsed = start_time.elapsed();
                    if elapsed > Duration::from_secs(10) {
                        breaker.record_outcome(RequestOutcome::Timeout).await;
                    } else {
                        breaker.record_outcome(RequestOutcome::Failure(e.to_string())).await;
                    }
                    Err(e)
                }
            }
        } else {
            self.test_connectivity(target).await
        }
    }
    
    /// Check if this transport can reach the target
    async fn can_reach(&self, target: &str) -> bool;
    
    /// Get transport-specific capabilities
    fn get_capabilities(&self) -> Vec<String>;
    
    /// Get estimated latency for this transport
    fn estimated_latency(&self) -> Duration;
    
    /// Get reliability score (0.0-1.0)
    fn reliability_score(&self) -> f32;
}

/// Transport discovery and testing utilities
pub struct TransportDiscovery {
    discovery_timeout: Duration,
    #[allow(dead_code)]
    connectivity_cache: dashmap::DashMap<String, (TransportMetrics, Instant)>,
}

impl TransportDiscovery {
    pub fn new() -> Self {
        Self {
            discovery_timeout: Duration::from_secs(10),
            connectivity_cache: dashmap::DashMap::new(),
        }
    }
    
    /// Discover all available transports to a target (non-WASM platforms)
    #[cfg(not(target_arch = "wasm32"))]
    pub async fn discover_transports(&mut self, target: &str) -> Result<Vec<TransportRoute>> {
        let mut routes = Vec::new();
        
        // Try direct TCP connection
        if let Ok(tcp_route) = self.test_direct_tcp(target).await {
            routes.push(tcp_route);
        }
        
        // Try direct UDP connection
        if let Ok(udp_route) = self.test_direct_udp(target).await {
            routes.push(udp_route);
        }
        
        // Try mDNS discovery on local network
        if let Ok(mdns_route) = self.discover_mdns_peer(target).await {
            routes.push(mdns_route);
        }
        
        // Try NAT traversal techniques
        if let Ok(nat_routes) = self.establish_nat_traversal(target).await {
            routes.extend(nat_routes);
        }
        
        // Always include email fallback
        routes.push(TransportRoute::StandardEmail { 
            estimated_latency_min: 1 // 1+ minute typical email latency
        });
        
        Ok(routes)
    }
    
    /// WASM stub for transport discovery
    #[cfg(target_arch = "wasm32")]
    pub async fn discover_transports(&mut self, _target: &str) -> Result<Vec<TransportRoute>> {
        // WASM currently only supports basic message passing
        Ok(vec![TransportRoute::WebAssembly { 
            estimated_latency_ms: 50 
        }])
    }
    
    #[cfg(not(target_arch = "wasm32"))]
    async fn test_direct_tcp(&self, target: &str) -> Result<TransportRoute> {
        // Try common ports for EMRP TCP transport
        let ports = vec![8080, 8443, 9090, 7777];
        
        for port in ports {
            let address = format!("{}:{}", target, port);
            let start = Instant::now();
            
            match timeout(self.discovery_timeout, tokio::net::TcpStream::connect(&address)).await {
                Ok(Ok(_stream)) => {
                    let latency = start.elapsed();
                    return Ok(TransportRoute::DirectTcp {
                        address: target.to_string(),
                        port,
                        latency_ms: latency.as_millis() as u32,
                        established_at: Instant::now(),
                    });
                }
                _ => continue,
            }
        }
        
        Err(crate::error::SynapseError::TransportError("No direct TCP connection available".into()))
    }
    
    #[cfg(not(target_arch = "wasm32"))]
    async fn test_direct_udp(&self, target: &str) -> Result<TransportRoute> {
        // Try common ports for EMRP UDP transport
        let ports = vec![8080, 8443, 9090, 7777];
        
        for port in ports {
            let address = format!("{}:{}", target, port);
            let start = Instant::now();
            
            match timeout(
                self.discovery_timeout,
                tokio::net::UdpSocket::bind("0.0.0.0:0")
            ).await {
                Ok(Ok(socket)) => {
                    // Test UDP connectivity with a ping packet
                    if socket.connect(&address).await.is_ok() {
                        let latency = start.elapsed();
                        return Ok(TransportRoute::DirectUdp {
                            address: target.to_string(),
                            port,
                            latency_ms: latency.as_millis() as u32,
                            established_at: Instant::now(),
                        });
                    }
                }
                _ => continue,
            }
        }
        
        Err(crate::error::SynapseError::TransportError("No direct UDP connection available".into()))
    }
    
    #[cfg(not(target_arch = "wasm32"))]
    async fn discover_mdns_peer(&self, _target: &str) -> Result<TransportRoute> {
        // mDNS discovery implementation will be in mdns.rs
        // For now, return an error indicating it's not available
        Err(crate::error::SynapseError::TransportError("mDNS discovery not yet implemented".into()))
    }
    
    #[cfg(not(target_arch = "wasm32"))]
    async fn establish_nat_traversal(&self, _target: &str) -> Result<Vec<TransportRoute>> {
        // NAT traversal implementation will be in nat_traversal.rs
        // For now, return empty vec
        Ok(Vec::new())
    }
}

/// Transport selection algorithm
pub struct TransportSelector {
    discovery: TransportDiscovery,
    performance_weights: TransportWeights,
}

#[derive(Debug, Clone)]
pub struct TransportWeights {
    pub latency_weight: f32,
    pub reliability_weight: f32, 
    pub throughput_weight: f32,
    pub setup_time_weight: f32,
}

impl Default for TransportWeights {
    fn default() -> Self {
        Self {
            latency_weight: 0.4,
            reliability_weight: 0.3,
            throughput_weight: 0.2,
            setup_time_weight: 0.1,
        }
    }
}

impl TransportSelector {
    pub fn new() -> Self {
        Self {
            discovery: TransportDiscovery::new(),
            performance_weights: TransportWeights::default(),
        }
    }
    
    /// Choose the optimal transport for a message (non-WASM platforms)
    #[cfg(not(target_arch = "wasm32"))]
    pub async fn choose_optimal_transport(
        &mut self, 
        target: &str, 
        urgency: abstraction::MessageUrgency
    ) -> Result<TransportRoute> {
        let available_routes = self.discovery.discover_transports(target).await?;
        
        match urgency {
            abstraction::MessageUrgency::Critical | abstraction::MessageUrgency::RealTime => {
                // Only use transports with <100ms latency
                for route in available_routes {
                    match route {
                        TransportRoute::DirectTcp { latency_ms, .. } 
                        | TransportRoute::DirectUdp { latency_ms, .. }
                        | TransportRoute::LocalMdns { latency_ms, .. } 
                        | TransportRoute::NatTraversal { latency_ms, .. } 
                            if latency_ms < 100 => return Ok(route),
                        _ => continue,
                    }
                }
                Err(crate::error::SynapseError::TransportError("No real-time transport available".into()))
            }
            abstraction::MessageUrgency::Interactive => {
                // Accept up to 1s latency, prefer faster options
                self.select_best_route(available_routes, 1000).await
            }
            abstraction::MessageUrgency::Background | abstraction::MessageUrgency::Batch => {
                // Prefer reliability over speed
                self.select_most_reliable_route(available_routes).await
            }
        }
    }
    
    /// Choose the optimal transport for a message (WASM platforms)
    #[cfg(target_arch = "wasm32")]
    pub async fn choose_optimal_transport(
        &mut self, 
        _target: &str, 
        _urgency: abstraction::MessageUrgency
    ) -> Result<TransportRoute> {
        // WASM currently only supports basic message passing
        Ok(TransportRoute::WebAssembly { 
            estimated_latency_ms: 50 
        })
    }
    
    #[cfg(not(target_arch = "wasm32"))]
    async fn select_best_route(&self, routes: Vec<TransportRoute>, max_latency_ms: u32) -> Result<TransportRoute> {
        let mut best_route = None;
        let mut best_score = f32::MIN;
        
        for route in routes {
            let latency_ms = self.get_route_latency(&route);
            if latency_ms <= max_latency_ms {
                let score = self.calculate_route_score(&route);
                if score > best_score {
                    best_score = score;
                    best_route = Some(route);
                }
            }
        }
        
        best_route.ok_or_else(|| {
            crate::error::SynapseError::TransportError("No suitable transport found".into())
        })
    }
    
    #[cfg(not(target_arch = "wasm32"))]
    async fn select_most_reliable_route(&self, routes: Vec<TransportRoute>) -> Result<TransportRoute> {
        // Prefer email and other reliable transports
        for route in &routes {
            match route {
                TransportRoute::StandardEmail { .. } => return Ok(route.clone()),
                TransportRoute::FastEmailRelay { .. } => return Ok(route.clone()),
                _ => continue,
            }
        }
        
        // If no email available, use the best alternative
        self.select_best_route(routes, u32::MAX).await
    }
    
    #[cfg(not(target_arch = "wasm32"))]
    fn get_route_latency(&self, route: &TransportRoute) -> u32 {
        match route {
            TransportRoute::DirectTcp { latency_ms, .. } 
            | TransportRoute::DirectUdp { latency_ms, .. }
            | TransportRoute::LocalMdns { latency_ms, .. }
            | TransportRoute::NatTraversal { latency_ms, .. } => *latency_ms,
            TransportRoute::FastEmailRelay { estimated_latency_ms, .. } => *estimated_latency_ms,
            TransportRoute::StandardEmail { estimated_latency_min } => estimated_latency_min * 60 * 1000, // Convert minutes to ms
            TransportRoute::EmailDiscovery { .. } => 30_000, // 30s for discovery
            TransportRoute::Udp { .. } => 5, // 5ms estimated for UDP
            TransportRoute::WebSocket { .. } => 20, // 20ms estimated for WebSocket
            TransportRoute::Quic { .. } => 10, // 10ms estimated for QUIC
        }
    }
    
    #[cfg(not(target_arch = "wasm32"))]
    fn calculate_route_score(&self, route: &TransportRoute) -> f32 {
        let latency_ms = self.get_route_latency(route) as f32;
        let reliability = self.get_route_reliability(route);
        let setup_time = self.get_route_setup_time(route);
        
        // Lower latency and setup time = higher score
        // Higher reliability = higher score
        let latency_score = 1.0 / (1.0 + latency_ms / 1000.0); // Normalize to 0-1
        let setup_score = 1.0 / (1.0 + setup_time);
        
        latency_score * self.performance_weights.latency_weight +
        reliability * self.performance_weights.reliability_weight +
        setup_score * self.performance_weights.setup_time_weight
    }
    
    #[cfg(not(target_arch = "wasm32"))]
    fn get_route_reliability(&self, route: &TransportRoute) -> f32 {
        match route {
            TransportRoute::StandardEmail { .. } => 0.95,
            TransportRoute::FastEmailRelay { .. } => 0.90,
            TransportRoute::DirectTcp { .. } => 0.85,
            TransportRoute::DirectUdp { .. } => 0.80,
            TransportRoute::LocalMdns { .. } => 0.95,
            TransportRoute::NatTraversal { .. } => 0.70,
            TransportRoute::EmailDiscovery { .. } => 0.95,
            TransportRoute::Udp { .. } => 0.80,
            TransportRoute::WebSocket { .. } => 0.85,
            TransportRoute::Quic { .. } => 0.90,
        }
    }
    
    #[cfg(not(target_arch = "wasm32"))]
    fn get_route_setup_time(&self, route: &TransportRoute) -> f32 {
        match route {
            TransportRoute::DirectTcp { .. } => 0.1, // 100ms
            TransportRoute::DirectUdp { .. } => 0.05, // 50ms
            TransportRoute::LocalMdns { .. } => 0.05, // 50ms
            TransportRoute::NatTraversal { .. } => 2.0, // 2s
            TransportRoute::FastEmailRelay { .. } => 1.0, // 1s
            TransportRoute::StandardEmail { .. } => 1.0, // 1s
            TransportRoute::EmailDiscovery { .. } => 30.0, // 30s
            TransportRoute::Udp { .. } => 0.05, // 50ms
            TransportRoute::WebSocket { .. } => 0.2, // 200ms
            TransportRoute::Quic { .. } => 0.1, // 100ms
        }
    }
}

// Re-export all major components for easy access
pub use abstraction::*;
pub use manager::*;

// Unified transport implementations (temporarily disabled)
// #[cfg(not(target_arch = "wasm32"))]
// pub use tcp_unified::{TcpTransportImpl, TcpTransportFactory};
#[cfg(not(target_arch = "wasm32"))]
pub use udp_unified::{UdpTransportImpl, UdpTransportFactory};
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "http")]
pub use http_unified::{HttpTransportImpl, HttpTransportFactory};

// Simple transport implementations
#[cfg(not(target_arch = "wasm32"))]
pub use tcp_simple::{SimpleTcpTransport, SimpleTcpTransportFactory};

// Platform-specific re-exports (only on non-WASM platforms)
#[cfg(not(target_arch = "wasm32"))]
pub use tcp::TcpTransport;
#[cfg(not(target_arch = "wasm32"))]
pub use tcp_enhanced::EnhancedTcpTransport;
// #[cfg(not(target_arch = "wasm32"))]
// #[cfg(feature = "mdns")]
// pub use mdns::{MdnsTransport, MdnsAdvertiser};
#[cfg(not(target_arch = "wasm32"))]
pub use mdns_enhanced::{EnhancedMdnsTransport, MdnsConfig};
#[cfg(not(target_arch = "wasm32"))]
pub use nat_traversal::{NatTraversalTransport, IceCandidate};
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "email")]
pub use email_enhanced::{EmailEnhancedTransport, FastEmailRelay};
#[cfg(not(target_arch = "wasm32"))]
pub use router::MultiTransportRouter;
#[cfg(not(target_arch = "wasm32"))]
pub use llm_discovery::{
    LlmDiscoveryManager, LlmDiscoveryConfig, DiscoveredLlm, LlmConnection,
    LlmModelInfo, LlmConnectionInfo, LlmPerformanceMetrics, LlmStatus,
    LlmRequest, LlmResponse, LlmResponseMetadata
};