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
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Transit proxy system for intercepting and forwarding JSON-RPC communication.
//!
//! The `transit` module provides a proxy infrastructure that sits between a client and
//! a target application, enabling inspection, modification, and augmentation of the
//! communication between them. This is particularly useful for debugging, monitoring,
//! and extending functionality without modifying the target application.
//!
//! # Architecture
//!
//! The transit system consists of several key components:
//!
//! - **Transit Proxy**: The core proxy that manages connections and message routing
//! - **HTTP Server**: Provides HTTP/SSE/WebSocket endpoints for client communication
//! - **Stdio Server**: Alternative server using stdin/stdout for communication
//! - **Log Proxy**: Captures and provides access to logwise logs from the target
//! - **Builtin Tools**: Additional MCP tools available only in the proxy
//!
//! # Usage
//!
//! The transit proxy can be started in two modes:
//!
//! ## HTTP Mode
//! ```no_run
//! # // don't run in doctests
//! # #[cfg(feature = "transit")]
//! # {
//! use exfiltrate::transit::{transit_proxy::TransitProxy, http::Server};
//!
//! // Create a transit proxy
//! let proxy = TransitProxy::new();
//!
//! // Start HTTP server on port 1984
//! // Note: Server spawns background threads
//! let _server = Server::new("127.0.0.1:1984", proxy);
//!
//! // Server is now running in the background
//! // In a real application, you would keep the process alive
//! # }
//! ```
//!
//! ## Stdio Mode
//! ```no_run
//! # // don't run in doctests
//! # #[cfg(feature = "transit")]
//! # {
//! use exfiltrate::transit::{transit_proxy::TransitProxy, stdio::Server};
//!
//! // Create a transit proxy
//! let proxy = TransitProxy::new();
//!
//! // Start stdio server (communicates via stdin/stdout)
//! let _server = Server::new(proxy);
//!
//! // Server is now processing stdin/stdout in background thread
//! # }
//! ```
//!
//! # Features
//!
//! - **Protocol Support**: HTTP POST, Server-Sent Events (SSE), and WebSocket
//! - **Message Interception**: Inspect and modify JSON-RPC requests and responses
//! - **Tool Injection**: Add proxy-only tools that augment the target's capabilities
//! - **Log Capture**: When used with logwise, captures and provides searchable access to logs
//! - **Fallback Handling**: Provides basic functionality even when target is disconnected
//!
//! # Platform Restrictions
//!
//! This module is not available on wasm32 targets due to threading and networking
//! requirements. Attempting to compile with the `transit` feature on wasm32 will
//! result in a compilation error.
compile_error!;