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
//! Hyper connector for making HTTP requests through a WireGuard tunnel.
//!
//! This crate provides `WgConnector`, a `tower::Service` implementation that
//! creates HTTP connections through a WireGuard tunnel.
//!
//! # DNS Configuration
//!
//! You can configure different DNS servers for pre-connection (endpoint resolution)
//! and post-connection (HTTP request DNS resolution) using `DohServerConfig`:
//!
//! ```no_run
//! use wireguard_hyper_connector::{WgConnector, ManagedTunnel, WgConfigFile, DohServerConfig};
//! use hyper_util::client::legacy::Client;
//! use hyper_util::rt::TokioExecutor;
//! use http_body_util::Empty;
//! use bytes::Bytes;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Use Google DNS for resolving WireGuard endpoint
//! let config = WgConfigFile::from_file("wg.conf")?
//! .into_wireguard_config_with_dns(DohServerConfig::google())
//! .await?;
//!
//! let tunnel = ManagedTunnel::connect(config).await?;
//!
//! // Use Quad9 DNS for HTTP requests through the tunnel
//! let connector = WgConnector::with_dns(tunnel.netstack(), DohServerConfig::quad9());
//!
//! let client: Client<WgConnector, Empty<Bytes>> = Client::builder(TokioExecutor::new()).build(connector);
//!
//! // Make requests...
//!
//! tunnel.shutdown().await;
//! Ok(())
//! }
//! ```
//!
//! # Example (Default DNS)
//!
//! ```no_run
//! use wireguard_hyper_connector::{WgConnector, ManagedTunnel, WgConfigFile};
//! use hyper_util::client::legacy::Client;
//! use hyper_util::rt::TokioExecutor;
//! use http_body_util::Empty;
//! use bytes::Bytes;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Load config and connect (uses Cloudflare DNS by default)
//! let config = WgConfigFile::from_file("wg.conf")?
//! .into_wireguard_config()
//! .await?;
//!
//! let tunnel = ManagedTunnel::connect(config).await?;
//!
//! // Create the hyper connector (uses Cloudflare DNS by default)
//! let connector = WgConnector::new(tunnel.netstack());
//!
//! // Create a hyper client
//! let client: Client<WgConnector, Empty<Bytes>> = Client::builder(TokioExecutor::new()).build(connector);
//!
//! // Make requests...
//!
//! tunnel.shutdown().await;
//! Ok(())
//! }
//! ```
// Re-export connector types
pub use ;
pub use ;
// Re-export wireguard-netstack types for convenience
pub use ;