mirror of
https://github.com/aramperes/onetun.git
synced 2025-09-10 06:34:03 -04:00
Move TCP tunneling code to separate module
This commit is contained in:
parent
c2d0b9719a
commit
703f261344
5 changed files with 230 additions and 217 deletions
29
src/tunnel/mod.rs
Normal file
29
src/tunnel/mod.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use std::net::IpAddr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::config::{PortForwardConfig, PortProtocol};
|
||||
use crate::port_pool::PortPool;
|
||||
use crate::wg::WireGuardTunnel;
|
||||
|
||||
mod tcp;
|
||||
|
||||
pub async fn port_forward(
|
||||
port_forward: PortForwardConfig,
|
||||
source_peer_ip: IpAddr,
|
||||
port_pool: Arc<PortPool>,
|
||||
wg: Arc<WireGuardTunnel>,
|
||||
) -> anyhow::Result<()> {
|
||||
info!(
|
||||
"Tunneling {} [{}]->[{}] (via [{}] as peer {})",
|
||||
port_forward.protocol,
|
||||
port_forward.source,
|
||||
port_forward.destination,
|
||||
&wg.endpoint,
|
||||
source_peer_ip
|
||||
);
|
||||
|
||||
match port_forward.protocol {
|
||||
PortProtocol::Tcp => tcp::tcp_proxy_server(port_forward, port_pool, wg).await,
|
||||
PortProtocol::Udp => Err(anyhow::anyhow!("UDP isn't supported just yet.")),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue