(
client: &mut crate::tls::GrpcClient,
socket: tokio::net::TcpStream,
sandbox_id: String,
target_host: String,
target_port: u16,
service_id: String,
authorization_token: St
| 3034 | } |
| 3035 | |
| 3036 | async fn forward_one_tcp_connection( |
| 3037 | client: &mut crate::tls::GrpcClient, |
| 3038 | socket: tokio::net::TcpStream, |
| 3039 | sandbox_id: String, |
| 3040 | target_host: String, |
| 3041 | target_port: u16, |
| 3042 | service_id: String, |
| 3043 | authorization_token: String, |
| 3044 | ) -> std::result::Result<(), ForwardTcpConnectionError> { |
| 3045 | use tokio::io::{AsyncReadExt, AsyncWriteExt}; |
| 3046 | use tokio_stream::wrappers::ReceiverStream; |
| 3047 | |
| 3048 | let (tx, rx) = tokio::sync::mpsc::channel::<TcpForwardFrame>(16); |
| 3049 | tx.send(TcpForwardFrame { |
| 3050 | payload: Some(openshell_core::proto::tcp_forward_frame::Payload::Init( |
| 3051 | TcpForwardInit { |
| 3052 | sandbox_id, |
| 3053 | service_id, |
| 3054 | target: Some(tcp_forward_init::Target::Tcp(TcpRelayTarget { |
| 3055 | host: target_host, |
| 3056 | port: u32::from(target_port), |
| 3057 | })), |
| 3058 | authorization_token, |
| 3059 | }, |
| 3060 | )), |
| 3061 | }) |
| 3062 | .await |
| 3063 | .map_err(|_| ForwardTcpConnectionError::transient("failed to initialize forward stream"))?; |
| 3064 | |
| 3065 | let mut response = match client.forward_tcp(ReceiverStream::new(rx)).await { |
| 3066 | Ok(response) => response.into_inner(), |
| 3067 | Err(status) => { |
| 3068 | let err = ForwardTcpConnectionError::from_status(status); |
| 3069 | drain_and_shutdown_local_socket(socket).await; |
| 3070 | return Err(err); |
| 3071 | } |
| 3072 | }; |
| 3073 | |
| 3074 | let (mut local_read, mut local_write) = socket.into_split(); |
| 3075 | |
| 3076 | let to_gateway = tokio::spawn(async move { |
| 3077 | let mut buf = vec![0u8; 64 * 1024]; |
| 3078 | loop { |
| 3079 | let n = local_read.read(&mut buf).await?; |
| 3080 | if n == 0 { |
| 3081 | break; |
| 3082 | } |
| 3083 | if tx |
| 3084 | .send(TcpForwardFrame { |
| 3085 | payload: Some(openshell_core::proto::tcp_forward_frame::Payload::Data( |
| 3086 | buf[..n].to_vec(), |
| 3087 | )), |
| 3088 | }) |
| 3089 | .await |
| 3090 | .is_err() |
| 3091 | { |
| 3092 | break; |
| 3093 | } |
nothing calls this directly
no test coverage detected