Skip to main content

PortForward

Struct PortForward 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub(super) fn accept(headers: &Headers) -> Result<()>

Whether a stream is part of a valid request, by its headers.

Source

fn port(headers: &Headers) -> Result<u16>

Source

fn is_error_stream(stream: &Stream) -> bool

Source

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.

Source

pub(super) fn add( pending: &mut Pending, stream: Stream, namespace: &Arc<Namespace>, )

Add a stream to its request, which starts once both streams arrived.

Source

fn expire(pending: &mut Pending, request_id: Arc<str>)

Fail a request whose second stream did not arrive in time.

Source

async fn forward( request_id: Arc<str>, data: Stream, error: Stream, namespace: Arc<Namespace>, )

Forward a single connection, the error stream reports a failure.

Source

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.

Source

fn unless_reset(sender: &StreamSender, e: Error) -> Result<()>

A stream the client reset or whose connection ended is no failure.

Source§

impl PortForward

Source

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

pub(super) async fn tunnel<T>( socket: WebSocketStream<ClientIo<T>>, connection: DuplexStream, )
where T: AsyncRead + AsyncWrite + Unpin + Send + 'static,

Carry the bytes of the SPDY connection in binary messages, until either side ends.

Source§

impl PortForward

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn forward_error(port: u16, e: &Error) -> String

What the client gets told about a failed connection of a port.

Source

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.

Source

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.

Source

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§

Source§

impl Debug for PortForward

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more