🐛 bug: P2 no longer exits when P1 closes the connection
							parent
							
								
									fe25ff3d34
								
							
						
					
					
						commit
						c8e44bb740
					
				| 
						 | 
				
			
			@ -27,35 +27,42 @@ async fn main () -> anyhow::Result <()> {
 | 
			
		|||
	let mut resp_buf = [0u8, 0, 0, 0];
 | 
			
		||||
	recv.read_exact (&mut resp_buf).await?;
 | 
			
		||||
	
 | 
			
		||||
	debug! ("Waiting for local TCP client to connect to us");
 | 
			
		||||
	
 | 
			
		||||
	let listener = TcpListener::bind ("127.0.0.1:30381").await?;
 | 
			
		||||
	let (tcp_socket, _) = listener.accept ().await?;
 | 
			
		||||
	let (local_recv, local_send) = tcp_socket.into_split ();
 | 
			
		||||
	
 | 
			
		||||
	debug! ("Connecting to end server");
 | 
			
		||||
	debug! ("Accepting local TCP connections");
 | 
			
		||||
	
 | 
			
		||||
	let (mut relay_send, mut relay_recv) = connection.open_bi ().await?;
 | 
			
		||||
	
 | 
			
		||||
	let req_buf = [1, 43, 0, 0, 1, 0, 0, 0];
 | 
			
		||||
	relay_send.write_all (&req_buf).await?;
 | 
			
		||||
	
 | 
			
		||||
	let mut resp_buf = [0; 8];
 | 
			
		||||
	relay_recv.read_exact (&mut resp_buf).await?;
 | 
			
		||||
	
 | 
			
		||||
	debug! ("Relaying bytes...");
 | 
			
		||||
	
 | 
			
		||||
	let ptth_conn = PtthNewConnection {
 | 
			
		||||
		local_send,
 | 
			
		||||
		local_recv,
 | 
			
		||||
		relay_send,
 | 
			
		||||
		relay_recv,
 | 
			
		||||
	}.build ();
 | 
			
		||||
	
 | 
			
		||||
	ptth_conn.uplink_task.await??;
 | 
			
		||||
	ptth_conn.downlink_task.await??;
 | 
			
		||||
	
 | 
			
		||||
	Ok (())
 | 
			
		||||
	loop {
 | 
			
		||||
		let (tcp_socket, _) = listener.accept ().await?;
 | 
			
		||||
		let connection = connection.clone ();
 | 
			
		||||
		
 | 
			
		||||
		tokio::spawn (async move {
 | 
			
		||||
			let (local_recv, local_send) = tcp_socket.into_split ();
 | 
			
		||||
			
 | 
			
		||||
			debug! ("Connecting to end server");
 | 
			
		||||
			
 | 
			
		||||
			let (mut relay_send, mut relay_recv) = connection.open_bi ().await?;
 | 
			
		||||
			
 | 
			
		||||
			let req_buf = [1, 43, 0, 0, 1, 0, 0, 0];
 | 
			
		||||
			relay_send.write_all (&req_buf).await?;
 | 
			
		||||
			
 | 
			
		||||
			let mut resp_buf = [0; 8];
 | 
			
		||||
			relay_recv.read_exact (&mut resp_buf).await?;
 | 
			
		||||
			
 | 
			
		||||
			debug! ("Relaying bytes...");
 | 
			
		||||
			
 | 
			
		||||
			let ptth_conn = PtthNewConnection {
 | 
			
		||||
				local_send,
 | 
			
		||||
				local_recv,
 | 
			
		||||
				relay_send,
 | 
			
		||||
				relay_recv,
 | 
			
		||||
			}.build ();
 | 
			
		||||
			
 | 
			
		||||
			ptth_conn.uplink_task.await??;
 | 
			
		||||
			ptth_conn.downlink_task.await??;
 | 
			
		||||
			
 | 
			
		||||
			Ok::<_, anyhow::Error> (())
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct PtthNewConnection {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue