// A minimal Proxy trait subset for the muxer. More methods
// (process_event, status, etc.) can be added as the async backend
// surfaces them.

use super::packet::{Header, RxPacket};

/// A backend connected to a (local_port, peer_port) pair on the
/// muxer. Implementations:
///   tsi_stream::TsiStreamProxy — bridges to host TCP
///   echo (test only) — sends back what was received
pub trait Proxy: Send + Sync {
    fn local_port(&self) -> u32;
    fn peer_port(&self) -> u32;

    /// Guest sent us a control op (REQUEST, RESPONSE, RW, ...).
    /// Returns RxPackets to deliver back to the guest in response.
    fn handle_packet(&mut self, hdr: &Header, payload: &[u8]) -> Vec<RxPacket>;

    /// Has this proxy logically closed? Muxer reaper drops it.
    fn closed(&self) -> bool {
        false
    }
}

/// Pack (local_port, peer_port) into a u64 key for the proxy map.
pub fn proxy_key(local_port: u32, peer_port: u32) -> u64 {
    ((local_port as u64) << 32) | (peer_port as u64)
}
