pub(super) struct PortForward {
netns_path: PathBuf,
idle_timeout: Option<Duration>,
ping_interval: Option<Duration>,
}Expand description
A port forward session of a pod.
Fields§
§netns_path: PathBuf§idle_timeout: Option<Duration>§ping_interval: Option<Duration>Implementations§
Source§impl PortForward
impl PortForward
Sourcepub(crate) fn query_ports(query: Option<&str>) -> Result<Vec<u16>>
pub(crate) fn query_ports(query: Option<&str>) -> Result<Vec<u16>>
The ports a channel protocol request forwards, by its query. The
port parameter may repeat and hold several ports separated by
commas.
Sourcepub(super) fn percent_decode(s: &str) -> String
pub(super) fn percent_decode(s: &str) -> String
Decode a query component: a + is a space and %XX the byte of the
two hex digits. Invalid escapes stay as they are, and bytes which are
no UTF-8 become the replacement character.
Sourcepub(super) async fn serve_channels(
self,
socket: WebSocketStream<ClientIo<TokioIo<Upgraded>>>,
ports: Vec<u16>,
base64: bool,
)
pub(super) async fn serve_channels( self, socket: WebSocketStream<ClientIo<TokioIo<Upgraded>>>, ports: Vec<u16>, base64: bool, )
Serve the channel protocol: forward a connection per port until all of them ended, the client went away or the WebSocket was idle.
Sourcepub(super) async fn dispatch(
inputs: &[Sender<Held>],
budget: &Budget,
base64: bool,
message: Bytes,
idle: &CancellationToken,
)
pub(super) async fn dispatch( inputs: &[Sender<Held>], budget: &Budget, base64: bool, message: Bytes, idle: &CancellationToken, )
Hand a message of the client to the connection of its channel. Only
the data channels, the even ones, take input. Waits while a connected
port does not take its input or the ports hold all of the budget,
which stops reading the WebSocket like the reference implementation
does, the protocol has no flow control. Connecting ports take it, see
Self::drain_until, and the idle timeout still ends the wait.
Sourcepub(super) async fn forward_channel(
namespace: Arc<Namespace>,
port: u16,
input: Receiver<Held>,
output: ChannelOutput,
)
pub(super) async fn forward_channel( namespace: Arc<Namespace>, port: u16, input: Receiver<Held>, output: ChannelOutput, )
Forward the connection of a port, the error channel reports a failure.
Sourceasync fn copy_channel(
early: Early,
input: &mut Receiver<Held>,
output: &ChannelOutput,
connection: TcpStream,
) -> Result<()>
async fn copy_channel( early: Early, input: &mut Receiver<Held>, output: &ChannelOutput, connection: TcpStream, ) -> Result<()>
Copy between the channels of a port and its connection in the pod,
until the pod closed the connection, writing to it failed, see
Self::upstream_failed, or the client went away. The
protocol has no way to close a channel, the input after the pod closed
the connection does not matter.
Source§impl PortForward
impl PortForward
Sourcepub(crate) async fn serve_spdy<T>(self, io: T)where
T: AsyncRead + AsyncWrite + Send + 'static,
pub(crate) async fn serve_spdy<T>(self, io: T)where
T: AsyncRead + AsyncWrite + Send + 'static,
Serve port forward requests on the upgraded connection until it ends.
Sourcepub(super) fn accept(headers: &Headers) -> Result<()>
pub(super) fn accept(headers: &Headers) -> Result<()>
Whether a stream is part of a valid request, by its headers.
fn port(headers: &Headers) -> Result<u16>
fn is_error_stream(stream: &Stream) -> bool
Sourcefn request_id(stream: &Stream) -> Arc<str> ⓘ
fn request_id(stream: &Stream) -> Arc<str> ⓘ
The request a stream belongs to. Old clients send no ID, their requests use the IDs of the error streams, the data streams follow them.
Sourcepub(super) fn add(
pending: &mut Pending,
stream: Stream,
namespace: &Arc<Namespace>,
)
pub(super) fn add( pending: &mut Pending, stream: Stream, namespace: &Arc<Namespace>, )
Add a stream to its request, which starts once both streams arrived.
Sourcefn expire(pending: &mut Pending, request_id: Arc<str>)
fn expire(pending: &mut Pending, request_id: Arc<str>)
Fail a request whose second stream did not arrive in time.
Sourceasync fn forward(
request_id: Arc<str>,
data: Stream,
error: Stream,
namespace: Arc<Namespace>,
)
async fn forward( request_id: Arc<str>, data: Stream, error: Stream, namespace: Arc<Namespace>, )
Forward a single connection, the error stream reports a failure.
Sourceasync fn copy(
early: Early,
from_client: StreamReceiver,
to_client: StreamSender,
connection: TcpStream,
) -> Result<()>
async fn copy( early: Early, from_client: StreamReceiver, to_client: StreamSender, connection: TcpStream, ) -> Result<()>
Copy between the data stream and the connection in the pod, until both sides closed or either reset. A failure resets the data stream, and so does a side which does not close within its grace period after the other one did.
Sourcefn unless_reset(sender: &StreamSender, e: Error) -> Result<()>
fn unless_reset(sender: &StreamSender, e: Error) -> Result<()>
A stream the client reset or whose connection ended is no failure.
Source§impl PortForward
impl PortForward
Sourcepub(crate) async fn serve_websocket(
self,
socket: WebSocketStream<ClientIo<TokioIo<Upgraded>>>,
protocol: WebSocketProtocol,
ports: Vec<u16>,
)
pub(crate) async fn serve_websocket( self, socket: WebSocketStream<ClientIo<TokioIo<Upgraded>>>, protocol: WebSocketProtocol, ports: Vec<u16>, )
Serve port forwarding on the upgraded WebSocket until it ends. The channel protocol forwards the ports, the tunnel ignores them.
Source§impl PortForward
impl PortForward
Sourcepub(super) fn new(netns_path: PathBuf, idle_timeout: Option<Duration>) -> Self
pub(super) fn new(netns_path: PathBuf, idle_timeout: Option<Duration>) -> Self
A session for the network namespace at netns_path, which ends once it
was idle for idle_timeout.
Sourceasync fn establish(
namespace: &Namespace,
port: u16,
input: &mut impl Input,
) -> Result<(TcpStream, Early)>
async fn establish( namespace: &Namespace, port: u16, input: &mut impl Input, ) -> Result<(TcpStream, Early)>
Connect to the port in the pod while taking what the client sends meanwhile.
Sourceasync fn drain_until<T>(
connect: impl Future<Output = Result<T>>,
connect_budget: &Budget,
input: &mut impl Input,
) -> Result<(T, Early)>
async fn drain_until<T>( connect: impl Future<Output = Result<T>>, connect_budget: &Budget, input: &mut impl Input, ) -> Result<(T, Early)>
Wait for the connection to the pod while taking what the client sends
meanwhile, which may take until the connect timeout. The data moves
from the byte budget of the client into the connect budget, so that
the client can go on with its other connections. Without room in the
connect budget no more data gets taken, see CONNECT_BUDGET. A
client which sends more than CONNECT_BUFFER fails the forwarding.
Sourceasync fn read_pod(
from_container: &mut OwnedReadHalf,
buf: &mut BytesMut,
) -> Result<Option<Bytes>>
async fn read_pod( from_container: &mut OwnedReadHalf, buf: &mut BytesMut, ) -> Result<Option<Bytes>>
The next output of the pod, at most READ_BUFFER bytes, none once it
closed its side. Nothing gets lost if it got cancelled.
Sourcefn forward_error(port: u16, e: &Error) -> String
fn forward_error(port: u16, e: &Error) -> String
What the client gets told about a failed connection of a port.
Sourceasync fn write_input(
early: Early,
input: &mut impl Input,
to_container: &mut OwnedWriteHalf,
) -> Result<()>
async fn write_input( early: Early, input: &mut impl Input, to_container: &mut OwnedWriteHalf, ) -> Result<()>
Write what the client sends to the pod until the client is done, starting with what it sent while the connection got established, which gives its budget back once it got written.
Sourceasync fn upstream_failed(
e: Error,
downstream: impl Future<Output = Result<()>>,
) -> Result<()>
async fn upstream_failed( e: Error, downstream: impl Future<Output = Result<()>>, ) -> Result<()>
End a connection whose writes to the pod failed with e. The pod may
have answered before it closed the connection, like a server which
rejects an upload early, so the downstream copy gets up to
CLOSE_GRACE_PERIOD to forward that, like CRI-O waits for the other
direction.
Sourceasync fn connect(namespace: &Namespace, port: u16) -> Result<TcpStream>
async fn connect(namespace: &Namespace, port: u16) -> Result<TcpStream>
Connect to the port in the network namespace of the pod. The pod may listen on either family, they get tried one after the other like CRI-O does. Nagle’s algorithm is off like in Go, so that request frames which get written one by one do not wait for a delayed ACK.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PortForward
impl RefUnwindSafe for PortForward
impl Send for PortForward
impl Sync for PortForward
impl Unpin for PortForward
impl UnsafeUnpin for PortForward
impl UnwindSafe for PortForward
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].