@@ -6,7 +6,7 @@ use crate::messages::{
66use crate :: network:: add_network_layer;
77use crate :: { ipc, shutdown, MAX_PACKET_SIZE } ;
88use anyhow:: { anyhow, Context , Result } ;
9- use prost:: bytes:: { Bytes , BytesMut } ;
9+ use prost:: bytes:: Bytes ;
1010use prost:: Message ;
1111use std:: future:: Future ;
1212use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite , AsyncWriteExt } ;
@@ -53,11 +53,12 @@ async fn forward_packets<T: AsyncRead + AsyncWrite + Unpin>(
5353 mut conf_rx : UnboundedReceiver < InterceptConf > ,
5454 shutdown : shutdown:: Receiver ,
5555) -> Result < ( ) > {
56- let mut buf = BytesMut :: with_capacity ( IPC_BUF_SIZE ) ;
56+ let mut buf = Vec :: with_capacity ( IPC_BUF_SIZE ) ;
5757 let ( mut network_task_handle, net_tx, mut net_rx) =
5858 add_network_layer ( transport_events_tx, transport_commands_rx, shutdown) ;
5959
6060 loop {
61+ buf. clear ( ) ;
6162 tokio:: select! {
6263 // Monitor the network task for errors or planned shutdown.
6364 // This way we implicitly monitor the shutdown channel.
@@ -68,9 +69,7 @@ async fn forward_packets<T: AsyncRead + AsyncWrite + Unpin>(
6869 message: Some ( ipc:: from_proxy:: Message :: InterceptConf ( conf. into( ) ) ) ,
6970 } ;
7071 msg. encode( & mut buf) ?;
71-
72- // debug!("Sending IPC message to redirector: {} {:?}", buf.len(), buf);
73- channel. write_all_buf( & mut buf) . await . context( "failed to propagate interception config update" ) ?;
72+ channel. write_all( & buf) . await . context( "failed to propagate interception config update" ) ?;
7473 } ,
7574 // read packets from the IPC pipe into our network stack.
7675 _ = channel. read_buf( & mut buf) => {
@@ -85,10 +84,9 @@ async fn forward_packets<T: AsyncRead + AsyncWrite + Unpin>(
8584 return Err ( anyhow!( "redirect daemon exited prematurely." ) ) ;
8685 }
8786
88- let Ok ( PacketWithMeta { data, tunnel_info} ) = PacketWithMeta :: decode( & mut buf) else {
87+ let Ok ( PacketWithMeta { data, tunnel_info} ) = PacketWithMeta :: decode( buf. as_slice ( ) ) else {
8988 return Err ( anyhow!( "Received invalid IPC message from redirector: {:?}" , & buf) ) ;
9089 } ;
91- assert!( buf. is_empty( ) ) ;
9290
9391 // TODO: Use Bytes in SmolPacket to avoid copy
9492 let data = data. to_vec( ) ;
@@ -121,10 +119,9 @@ async fn forward_packets<T: AsyncRead + AsyncWrite + Unpin>(
121119 match e {
122120 NetworkCommand :: SendPacket ( packet) => {
123121 let packet = ipc:: FromProxy { message: Some ( ipc:: from_proxy:: Message :: Packet ( ipc:: Packet { data: Bytes :: from( packet. into_inner( ) ) } ) ) } ;
124- assert!( buf. is_empty( ) ) ;
125122 packet. encode( & mut buf) ?;
126123 // debug!("Sending packet: {} {:?}", buf.len(), &packet.message.as_ref().unwrap());
127- channel. write_all_buf ( & mut buf) . await . context( "failed to send packet" ) ?;
124+ channel. write_all ( & buf) . await . context( "failed to send packet" ) ?;
128125 }
129126 }
130127 }
0 commit comments