Struct ockam_transport_tcp::TcpTransport
source · pub struct TcpTransport { /* private fields */ }
Expand description
High level management interface for TCP transports
Be aware that only one TcpTransport
can exist per node, as it
registers itself as a router for the TCP
address type. Multiple
calls to TcpTransport::create
will fail.
To listen for incoming connections use
tcp.listen()
.
To register additional connections on an already initialised
TcpTransport
, use tcp.connect()
.
This step is optional because the underlying TcpRouter is capable of lazily
establishing a connection upon arrival of an initial message.
use ockam_transport_tcp::{TcpConnectionOptions, TcpListenerOptions, TcpTransport};
let tcp = TcpTransport::create(&ctx).await?;
tcp.listen("127.0.0.1:8000", TcpListenerOptions::new()).await?; // Listen on port 8000
tcp.connect("127.0.0.1:5000", TcpConnectionOptions::new()).await?; // And connect to port 5000
The same TcpTransport
can also bind to multiple ports.
use ockam_transport_tcp::{TcpListenerOptions, TcpTransport};
let tcp = TcpTransport::create(&ctx).await?;
tcp.listen("127.0.0.1:8000", TcpListenerOptions::new()).await?; // Listen on port 8000
tcp.listen("127.0.0.1:9000", TcpListenerOptions::new()).await?; // Listen on port 9000
Implementations§
source§impl TcpTransport
impl TcpTransport
sourcepub async fn connect(
&self,
peer: impl Into<String>,
options: TcpConnectionOptions
) -> Result<TcpConnection>
pub async fn connect( &self, peer: impl Into<String>, options: TcpConnectionOptions ) -> Result<TcpConnection>
Establish an outgoing TCP connection.
use ockam_transport_tcp::{TcpConnectionOptions, TcpListenerOptions, TcpTransport};
let tcp = TcpTransport::create(&ctx).await?;
tcp.listen("127.0.0.1:8000", TcpListenerOptions::new()).await?; // Listen on port 8000
let connection = tcp.connect("127.0.0.1:5000", TcpConnectionOptions::new()).await?; // and connect to port 5000
source§impl TcpTransport
impl TcpTransport
source§impl TcpTransport
impl TcpTransport
sourcepub fn registry(&self) -> &TcpRegistry
pub fn registry(&self) -> &TcpRegistry
Registry of all active connections
sourcepub fn find_connection_by_socketaddr(
&self,
socket_address: SocketAddr
) -> Option<TcpSenderInfo>
pub fn find_connection_by_socketaddr( &self, socket_address: SocketAddr ) -> Option<TcpSenderInfo>
Search for a connection with the provided socket address
sourcepub fn find_connection(&self, address: String) -> Option<TcpSenderInfo>
pub fn find_connection(&self, address: String) -> Option<TcpSenderInfo>
Search for a connection with the provided address
sourcepub fn find_listener_by_socketaddress(
&self,
socket_address: SocketAddr
) -> Option<TcpListenerInfo>
pub fn find_listener_by_socketaddress( &self, socket_address: SocketAddr ) -> Option<TcpListenerInfo>
Search for a listener with the provided socket address
sourcepub fn find_listener(&self, address: String) -> Option<TcpListenerInfo>
pub fn find_listener(&self, address: String) -> Option<TcpListenerInfo>
Search for a listener with the provided address
source§impl TcpTransport
impl TcpTransport
sourcepub async fn listen(
&self,
bind_addr: impl AsRef<str>,
options: TcpListenerOptions
) -> Result<TcpListener>
pub async fn listen( &self, bind_addr: impl AsRef<str>, options: TcpListenerOptions ) -> Result<TcpListener>
Start listening to incoming connections on an existing transport
Returns the local address that this transport is bound to.
This can be useful, for example, when binding to port 0 to figure out which port was actually bound.
use ockam_transport_tcp::{TcpListenerOptions, TcpTransport};
let tcp = TcpTransport::create(&ctx).await?;
tcp.listen("127.0.0.1:8000", TcpListenerOptions::new()).await?;
sourcepub async fn stop_listener(&self, address: &Address) -> Result<()>
pub async fn stop_listener(&self, address: &Address) -> Result<()>
Interrupt an active TCP listener given its Address
source§impl TcpTransport
impl TcpTransport
sourcepub async fn create_inlet(
&self,
bind_addr: impl Into<String> + Clone + Debug,
outlet_route: impl Into<Route> + Clone + Debug,
options: TcpInletOptions
) -> Result<(SocketAddr, Address)>
pub async fn create_inlet( &self, bind_addr: impl Into<String> + Clone + Debug, outlet_route: impl Into<Route> + Clone + Debug, options: TcpInletOptions ) -> Result<(SocketAddr, Address)>
Create Tcp Inlet that listens on bind_addr, transforms Tcp stream into Ockam Routable Messages and forward them to Outlet using outlet_route. Inlet is bidirectional: Ockam Messages sent to Inlet from Outlet (using return route) will be streamed to Tcp connection. Pair of corresponding Inlet and Outlet is called Portal.
use ockam_transport_tcp::{TcpInletOptions, TcpTransport};
let route_path = route!["outlet"];
let tcp = TcpTransport::create(&ctx).await?;
tcp.create_inlet("inlet", route_path, TcpInletOptions::new()).await?;
sourcepub async fn stop_inlet(
&self,
addr: impl Into<Address> + Clone + Debug
) -> Result<()>
pub async fn stop_inlet( &self, addr: impl Into<Address> + Clone + Debug ) -> Result<()>
Stop inlet at addr
use ockam_transport_tcp::{TcpInletOptions, TcpTransport};
let route = route!["outlet"];
let tcp = TcpTransport::create(&ctx).await?;
tcp.create_inlet("inlet", route, TcpInletOptions::new()).await?;
tcp.stop_inlet("inlet").await?;
sourcepub async fn create_outlet(
&self,
address: impl Into<Address> + Clone + Debug,
hostname_port: impl TryInto<HostnamePort, Error = Error> + Clone + Debug,
options: TcpOutletOptions
) -> Result<()>
pub async fn create_outlet( &self, address: impl Into<Address> + Clone + Debug, hostname_port: impl TryInto<HostnamePort, Error = Error> + Clone + Debug, options: TcpOutletOptions ) -> Result<()>
Create Tcp Outlet Listener at address, that connects to peer using Tcp, transforms Ockam Messages received from Inlet into stream and sends it to peer Tcp stream. Outlet is bidirectional: Tcp stream received from peer is transformed into Ockam Routable Messages and sent to Inlet using return route. Pair of corresponding Inlet and Outlet is called Portal.
use ockam_transport_tcp::{HostnamePort, TcpOutletOptions, TcpTransport};
let tcp = TcpTransport::create(&ctx).await?;
tcp.create_outlet("outlet", "localhost:9000", TcpOutletOptions::new()).await?;
sourcepub async fn create_tcp_outlet(
&self,
address: Address,
hostname_port: HostnamePort,
options: TcpOutletOptions
) -> Result<()>
pub async fn create_tcp_outlet( &self, address: Address, hostname_port: HostnamePort, options: TcpOutletOptions ) -> Result<()>
Create Tcp Outlet Listener at address, that connects to peer using Tcp
sourcepub async fn stop_outlet(
&self,
addr: impl Into<Address> + Clone + Debug
) -> Result<()>
pub async fn stop_outlet( &self, addr: impl Into<Address> + Clone + Debug ) -> Result<()>
Stop outlet at addr
use ockam_transport_tcp::{HostnamePort, TcpOutletOptions, TcpTransport};
let tcp = TcpTransport::create(&ctx).await?;
tcp.create_outlet("outlet", "127.0.0.1:5000", TcpOutletOptions::new()).await?;
tcp.stop_outlet("outlet").await?;
Trait Implementations§
source§impl Clone for TcpTransport
impl Clone for TcpTransport
source§fn clone(&self) -> TcpTransport
fn clone(&self) -> TcpTransport
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for TcpTransport
impl Debug for TcpTransport
source§impl Transport for TcpTransport
impl Transport for TcpTransport
source§fn transport_type(&self) -> TransportType
fn transport_type(&self) -> TransportType
source§fn resolve_address<'life0, 'async_trait>(
&'life0 self,
address: Address
) -> Pin<Box<dyn Future<Output = Result<Address>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn resolve_address<'life0, 'async_trait>(
&'life0 self,
address: Address
) -> Pin<Box<dyn Future<Output = Result<Address>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl Freeze for TcpTransport
impl !RefUnwindSafe for TcpTransport
impl Send for TcpTransport
impl Sync for TcpTransport
impl Unpin for TcpTransport
impl !UnwindSafe for TcpTransport
Blanket Implementations§
source§impl<D> AsyncTryClone for D
impl<D> AsyncTryClone for D
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
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more