pub struct ServiceBuilder { /* private fields */ }
Expand description

Builder for Service

Implementations§

source§

impl ServiceBuilder

source

pub fn new() -> ServiceBuilder

New a default empty builder

source

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

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

source

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

Insert a custom protocol

source

pub fn key_pair(self, key_pair: SecioKeyPair) -> ServiceBuilder

Enable encrypted communication mode.

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

source

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

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

Timeout for handshake and connect

Default 10 second

source

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

Yamux config for service

Panic when max_frame_length < yamux_max_window_size

source

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

Secio max frame length

Panic when max_frame_length < yamux_max_window_size

source

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

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

source

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

Set send buffer size, default is 24Mb

source

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

Set receive buffer size, default is 24Mb

source

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

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

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

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
where F: Fn(TcpSocket) -> 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| {
     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)?;
     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

source

pub fn clear(&mut self)

Clear all protocols

Trait Implementations§

source§

impl Default for ServiceBuilder

source§

fn default() -> ServiceBuilder

Returns the “default value” for a type. 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
§

impl<T> AsAny for T
where T: Any,

§

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.

§

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.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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