ServiceBuilder

Struct ServiceBuilder 

Source
pub struct ServiceBuilder<K> { /* private fields */ }
Expand description

Builder for Service

Implementations§

Source§

impl<K> ServiceBuilder<K>
where K: KeyProvider,

Source

pub fn new() -> ServiceBuilder<K>

New a default empty builder

Source

pub fn build<H>(self, handle: H) -> Service<H, K>
where H: ServiceHandle + Unpin + 'static,

Combine the configuration of this builder with service handle to create a Service.

Source

pub fn insert_protocol(self, protocol: ProtocolMeta) -> ServiceBuilder<K>

Insert a custom protocol

Source

pub fn handshake_type( self, handshake_type: HandshakeType<K>, ) -> ServiceBuilder<K>

Handshake encryption layer protocol selection

If you do not need encrypted communication, you do not need to call this method

Source

pub fn forever(self, forever: bool) -> ServiceBuilder<K>

When the service has no tasks, it will be turned off by default. If you do not want to close service, set it to true.

Source

pub fn timeout(self, timeout: Duration) -> ServiceBuilder<K>

Timeout for handshake and connect

Default timeout is 10 second

Source

pub fn onion_timeout(self, onion_timeout: Duration) -> ServiceBuilder<K>

Onion Timeout for handshake and connect

Default onion_timeout is 120 second

Source

pub fn yamux_config(self, config: Config) -> ServiceBuilder<K>

Yamux config for service

Panic when max_frame_length < yamux_max_window_size

Source

pub fn max_frame_length(self, size: usize) -> ServiceBuilder<K>

Secio max frame length

Panic when max_frame_length < yamux_max_window_size

Source

pub fn set_channel_size(self, size: usize) -> ServiceBuilder<K>

Tentacle use lots of bound channel, default channel size is 128

Source

pub fn set_send_buffer_size(self, size: usize) -> ServiceBuilder<K>

Set send buffer size, default is 24Mb

Source

pub fn set_recv_buffer_size(self, size: usize) -> ServiceBuilder<K>

Set receive buffer size, default is 24Mb

Source

pub fn keep_buffer(self, keep: bool) -> ServiceBuilder<K>

If session is close by remote, did you want to keep unreceived message as more as possible default is false

Source

pub fn upnp(self, enable: bool) -> ServiceBuilder<K>

Whether to allow tentative registration upnp, default is disable(false)

upnp: https://en.wikipedia.org/wiki/Universal_Plug_and_Play

Upnp is a simple solution to nat penetration, which requires routing support for registration mapping.

The function provided here is that if the external ip of the query route is a public network, then an attempt is made to register the local listener port into the mapping so that it can receive the access request of the external network, and if the external ip of the route is not the public network, Then do nothing

Source

pub fn max_connection_number(self, number: usize) -> ServiceBuilder<K>

The limit of max open connection(file descriptors) If not limited, service will try to serve as many connections as possible until it exhausts system resources(os error), and then close the listener, no longer accepting new connection requests, and the established connections remain working

Default is 65535

Source

pub fn tcp_config<F>(self, f: F) -> ServiceBuilder<K>
where F: Fn(TcpSocket, TransformerContext) -> Result<TcpSocket, Error> + Send + Sync + 'static,

Users can make their own custom configuration for all tcp socket at the bottom of Tentacle according to their own needs, for example, use reuse port to try to build nat penetration

In this way, any actively connected outbound connection is potentially connectable. Through this setting, the device after NAT can have the opportunity to be connected to the public network.

TCP Hole Punching: http://bford.info/pub/net/p2pnat/ STUN: https://tools.ietf.org/html/rfc5389

for example, set all tcp bind to 127.0.0.1:1080, set keepalive:

 use socket2;
 use tentacle::{service::TcpSocket, builder::ServiceBuilder};
 #[cfg(unix)]
 use std::os::unix::io::{FromRawFd, IntoRawFd};
 #[cfg(windows)]
 use std::os::windows::io::{FromRawSocket, IntoRawSocket};
 use std::net::SocketAddr;

 let mut server = ServiceBuilder::new();
 server.tcp_config(|socket: TcpSocket, ctxt: TransformerContext| {
     let socket = unsafe {
        #[cfg(unix)]
        let socket = socket2::Socket::from_raw_fd(socket.into_raw_fd());
        #[cfg(windows)]
        let socket = socket2::Socket::from_raw_socket(socket.into_raw_socket());
        socket
     };
     #[cfg(all(unix, not(target_os = "solaris"), not(target_os = "illumos")))]
     socket.set_reuse_port(true)?;
     socket.set_reuse_address(true)?;
     if ctxt.is_dial() {
        socket.bind(&"127.0.0.1:1080".parse::<SocketAddr>().unwrap().into())?;
     }
     socket.set_keepalive(true)?;
     let socket = unsafe {
        #[cfg(unix)]
        let socket = TcpSocket::from_raw_fd(socket.into_raw_fd());
        #[cfg(windows)]
        let socket = TcpSocket::from_raw_socket(socket.into_raw_socket());
        socket
     };
     Ok(socket)
});
§Note

User use listen(2) or connect(2) on this closure will cause abnormal behavior

Proxy and onion config will be ignored this config

Source

pub fn tcp_proxy_config(self, proxy_url: &str) -> ServiceBuilder<K>

Proxy config for tcp

Example: socks5://127.0.0.1:9050 Example: socks5://username:password@127.0.0.1:9050

Source

pub fn tcp_onion_config(self, onion_url: &str) -> ServiceBuilder<K>

Onion config for tcp

Example: socks5://127.0.0.1:9050

Source

pub fn tcp_proxy_random_auth(self, proxy_random_auth: bool) -> ServiceBuilder<K>

Onion config for proxy, use random username/password is set for proxy connection

Source

pub fn tcp_config_on_ws<F>(self, f: F) -> ServiceBuilder<K>
where F: Fn(TcpSocket, TransformerContext) -> Result<TcpSocket, Error> + Send + Sync + 'static,

The same as tcp config, but use on ws transport

Source

pub fn clear(&mut self)

Clear all protocols

Trait Implementations§

Source§

impl<K> Default for ServiceBuilder<K>

Source§

fn default() -> ServiceBuilder<K>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K> Freeze for ServiceBuilder<K>
where K: Freeze,

§

impl<K> !RefUnwindSafe for ServiceBuilder<K>

§

impl<K> Send for ServiceBuilder<K>
where K: Send,

§

impl<K> !Sync for ServiceBuilder<K>

§

impl<K> Unpin for ServiceBuilder<K>
where K: Unpin,

§

impl<K> !UnwindSafe for ServiceBuilder<K>

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Cast to trait Any
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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,