pub struct ServerBuilder { /* private fields */ }Expand description
Server builder, used to configure the server programatically, and for setting core components like node managers, authenticator, and type collections.
Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn new() -> ServerBuilder
pub fn new() -> ServerBuilder
Create a new server builder.
If the generated address space is enabled, this will add the core and diagnostic node managers.
Sourcepub fn from_config(config: ServerConfig) -> ServerBuilder
pub fn from_config(config: ServerConfig) -> ServerBuilder
Create a server builder from a config object.
Sourcepub fn new_anonymous(application_name: impl Into<String>) -> ServerBuilder
pub fn new_anonymous(application_name: impl Into<String>) -> ServerBuilder
Creates a simple endpoint that accepts anonymous connections.
Sourcepub fn new_sample() -> ServerBuilder
pub fn new_sample() -> ServerBuilder
Creates and yields a builder which is configured with the sample server configuration. Use this for testing and similar reasons. Do not rely upon this in production code because it could change.
Sourcepub fn config(&self) -> &ServerConfig
pub fn config(&self) -> &ServerConfig
Get the currently configured config.
Sourcepub fn with_config_from(self, path: impl Into<PathBuf>) -> ServerBuilder
pub fn with_config_from(self, path: impl Into<PathBuf>) -> ServerBuilder
Load config from a local file. Will panic if this fails, if you prefer to propagate errors use
with_config(ServerConfig::load(&"my_config.conf".into())?)
Sourcepub fn with_config(self, config: ServerConfig) -> ServerBuilder
pub fn with_config(self, config: ServerConfig) -> ServerBuilder
Set the entire config object, which may be loaded from somewhere else.
Sourcepub fn config_mut(&mut self) -> &mut ServerConfig
pub fn config_mut(&mut self) -> &mut ServerConfig
Get a mutable reference to the currently configured config.
Sourcepub fn limits_mut(&mut self) -> &mut Limits
pub fn limits_mut(&mut self) -> &mut Limits
Get a mutable reference to the limits object.
Sourcepub fn with_node_manager(
self,
node_manager: impl NodeManagerBuilder + 'static,
) -> ServerBuilder
pub fn with_node_manager( self, node_manager: impl NodeManagerBuilder + 'static, ) -> ServerBuilder
Add a node manager builder to the list of node managers.
Once the server is created you can retrieve it from
handle.node_managers(). This allows node managers to contain
core server types without late initialization.
Sourcepub fn without_node_managers(self) -> ServerBuilder
pub fn without_node_managers(self) -> ServerBuilder
Clear all node managers.
Warning: your server will not be compliant without presenting the core namespace. If you remove the core node manager you must implement the core namespace yourself.
Sourcepub fn with_authenticator(
self,
authenticator: Arc<dyn AuthManager>,
) -> ServerBuilder
pub fn with_authenticator( self, authenticator: Arc<dyn AuthManager>, ) -> ServerBuilder
Set a custom authenticator.
Sourcepub fn with_type_tree_getter(
self,
type_tree_getter: Arc<dyn TypeTreeForUser>,
) -> ServerBuilder
pub fn with_type_tree_getter( self, type_tree_getter: Arc<dyn TypeTreeForUser>, ) -> ServerBuilder
Set a custom type tree getter. Most servers do not need to touch this.
The type tree getter gets a type tree for a specific user, letting you have different type trees for different users, which is relevant for some servers.
This is currently used for constructing event filters, and when building external references.
You only need to set this if you intend to have types that are not in the global DefaultTypeTree.
Note that built in node managers do not use the type tree getter, if you want to have per-user types you need to implement a node manager that can correctly filter during browse, etc. This only lets you use the custom type tree for each individual user.
Sourcepub fn build_info(self, build_info: BuildInfo) -> ServerBuilder
pub fn build_info(self, build_info: BuildInfo) -> ServerBuilder
Set information about the application exposed to the user in the
ServerStatus/BuildInfo variable on the server.
Sourcepub fn application_name(
self,
application_name: impl Into<String>,
) -> ServerBuilder
pub fn application_name( self, application_name: impl Into<String>, ) -> ServerBuilder
Server application name.
Sourcepub fn application_uri(
self,
application_uri: impl Into<String>,
) -> ServerBuilder
pub fn application_uri( self, application_uri: impl Into<String>, ) -> ServerBuilder
Server application URI.
Sourcepub fn product_uri(self, product_uri: impl Into<String>) -> ServerBuilder
pub fn product_uri(self, product_uri: impl Into<String>) -> ServerBuilder
Server product URI.
Sourcepub fn create_sample_keypair(self, create_sample_keypair: bool) -> ServerBuilder
pub fn create_sample_keypair(self, create_sample_keypair: bool) -> ServerBuilder
Autocreates public / private keypair if they do not exist.
Sourcepub fn certificate_path(
self,
certificate_path: impl Into<PathBuf>,
) -> ServerBuilder
pub fn certificate_path( self, certificate_path: impl Into<PathBuf>, ) -> ServerBuilder
Path to a custom certificate, to be used instead of the default .der certificate
Sourcepub fn private_key_path(
self,
private_key_path: impl Into<PathBuf>,
) -> ServerBuilder
pub fn private_key_path( self, private_key_path: impl Into<PathBuf>, ) -> ServerBuilder
Path to a custom private key, used instead of the default private key.
Sourcepub fn trust_client_certs(self, trust_client_certs: bool) -> ServerBuilder
pub fn trust_client_certs(self, trust_client_certs: bool) -> ServerBuilder
Auto trust client certificates. Typically should only be used for testing or samples, as it is potentially unsafe.
Sourcepub fn check_cert_time(self, check_cert_time: bool) -> ServerBuilder
pub fn check_cert_time(self, check_cert_time: bool) -> ServerBuilder
Validate the valid from/to fields of a certificate.
Sourcepub fn pki_dir(self, pki_dir: impl Into<PathBuf>) -> ServerBuilder
pub fn pki_dir(self, pki_dir: impl Into<PathBuf>) -> ServerBuilder
PKI folder, either absolute or relative to executable.
Sourcepub fn discovery_server_url(self, url: impl Into<String>) -> ServerBuilder
pub fn discovery_server_url(self, url: impl Into<String>) -> ServerBuilder
URL to a discovery server. Adding this makes the server attempt to register itself with this discovery server.
Sourcepub fn hello_timeout(self, timeout: u32) -> ServerBuilder
pub fn hello_timeout(self, timeout: u32) -> ServerBuilder
Timeout for new connections to send a HELLO message, in seconds.
After this timeout expires without a valid hello message, the connection
is closed.
Sourcepub fn host(self, host: impl Into<String>) -> ServerBuilder
pub fn host(self, host: impl Into<String>) -> ServerBuilder
Hostname to listen to incoming TCP connections on.
Sourcepub fn port(self, port: u16) -> ServerBuilder
pub fn port(self, port: u16) -> ServerBuilder
Port number used to listen for incoming TCP connections.
Sourcepub fn limits(self, limits: Limits) -> ServerBuilder
pub fn limits(self, limits: Limits) -> ServerBuilder
General server limits.
Sourcepub fn locale_ids(self, locale_ids: Vec<String>) -> ServerBuilder
pub fn locale_ids(self, locale_ids: Vec<String>) -> ServerBuilder
Supported locale IDs.
Sourcepub fn add_user_token(
self,
key: impl Into<String>,
token: ServerUserToken,
) -> ServerBuilder
pub fn add_user_token( self, key: impl Into<String>, token: ServerUserToken, ) -> ServerBuilder
Add a user to the list of known user tokens. Used by the default authenticator, you can use a custom one instead.
Sourcepub fn discovery_urls(self, discovery_urls: Vec<String>) -> ServerBuilder
pub fn discovery_urls(self, discovery_urls: Vec<String>) -> ServerBuilder
List of discovery endpoint URLs which may or may not be the same as the service endpoints.
Sourcepub fn default_endpoint(self, endpoint_id: impl Into<String>) -> ServerBuilder
pub fn default_endpoint(self, endpoint_id: impl Into<String>) -> ServerBuilder
Default endpoint ID.
Sourcepub fn add_endpoint(
self,
id: impl Into<String>,
endpoint: impl Into<ServerEndpoint>,
) -> ServerBuilder
pub fn add_endpoint( self, id: impl Into<String>, endpoint: impl Into<ServerEndpoint>, ) -> ServerBuilder
Add an endpoint to the list of endpoints supported by the server.
Sourcepub fn subscription_poll_interval_ms(self, interval: u64) -> ServerBuilder
pub fn subscription_poll_interval_ms(self, interval: u64) -> ServerBuilder
Interval in milliseconds between each time the subscriptions are polled.
Sourcepub fn publish_timeout_default_ms(self, timeout: u64) -> ServerBuilder
pub fn publish_timeout_default_ms(self, timeout: u64) -> ServerBuilder
Default publish request timeout.
Sourcepub fn max_timeout_ms(self, timeout: u32) -> ServerBuilder
pub fn max_timeout_ms(self, timeout: u32) -> ServerBuilder
Max message timeout for non-publish requests. Will not be applied for requests that are handled synchronously. Set to 0 for no timeout, meaning that a timeout will only be applied if the client requests one. If this is greater than zero and the client requests a timeout of 0, this will be used.
Sourcepub fn max_secure_channel_token_lifetime_ms(
self,
lifetime: u32,
) -> ServerBuilder
pub fn max_secure_channel_token_lifetime_ms( self, lifetime: u32, ) -> ServerBuilder
Maximum lifetime of secure channel tokens. The client will request a number, this just sets an upper limit on that value. Note that there is no lower limit, if a client sets an expiry of 0, we will just instantly time out.
Sourcepub fn build(self) -> Result<(Server, ServerHandle), String>
pub fn build(self) -> Result<(Server, ServerHandle), String>
Try to construct a server from this builder, may fail if the configuration is invalid.
Sourcepub fn max_array_length(self, max_array_length: usize) -> ServerBuilder
pub fn max_array_length(self, max_array_length: usize) -> ServerBuilder
Maximum length of arrays when encoding or decoding messages.
Sourcepub fn max_string_length(self, max_string_length: usize) -> ServerBuilder
pub fn max_string_length(self, max_string_length: usize) -> ServerBuilder
Maximum length of strings in bytes when encoding or decoding messages.
Sourcepub fn max_byte_string_length(
self,
max_byte_string_length: usize,
) -> ServerBuilder
pub fn max_byte_string_length( self, max_byte_string_length: usize, ) -> ServerBuilder
Maximum byte string length in bytes when encoding or decoding messages.
Sourcepub fn max_message_size(self, max_message_size: usize) -> ServerBuilder
pub fn max_message_size(self, max_message_size: usize) -> ServerBuilder
Maximum allowed message size in bytes.
Sourcepub fn max_chunk_count(self, max_chunk_count: usize) -> ServerBuilder
pub fn max_chunk_count(self, max_chunk_count: usize) -> ServerBuilder
Maximum allowed chunk count per message.
Sourcepub fn send_buffer_size(self, send_buffer_size: usize) -> ServerBuilder
pub fn send_buffer_size(self, send_buffer_size: usize) -> ServerBuilder
Maximum send buffer size, can be negotiated lower with clients.
Sourcepub fn receive_buffer_size(self, receive_buffer_size: usize) -> ServerBuilder
pub fn receive_buffer_size(self, receive_buffer_size: usize) -> ServerBuilder
Maximum receive buffer size, can be negotiated lower with clients.
Sourcepub fn max_browse_continuation_points(
self,
max_browse_continuation_points: usize,
) -> ServerBuilder
pub fn max_browse_continuation_points( self, max_browse_continuation_points: usize, ) -> ServerBuilder
Maximum number of browse continuation points per session.
Sourcepub fn max_history_continuation_points(
self,
max_history_continuation_points: usize,
) -> ServerBuilder
pub fn max_history_continuation_points( self, max_history_continuation_points: usize, ) -> ServerBuilder
Maximum number of history continuation points per session.
Sourcepub fn max_query_continuation_points(
self,
max_query_continuation_points: usize,
) -> ServerBuilder
pub fn max_query_continuation_points( self, max_query_continuation_points: usize, ) -> ServerBuilder
Maximum number of query continuation points per session.
Sourcepub fn max_sessions(self, max_sessions: usize) -> ServerBuilder
pub fn max_sessions(self, max_sessions: usize) -> ServerBuilder
Maximum number of active sessions.
Sourcepub fn max_session_timeout_ms(
self,
max_session_timeout_ms: u64,
) -> ServerBuilder
pub fn max_session_timeout_ms( self, max_session_timeout_ms: u64, ) -> ServerBuilder
Maximum time in milliseconds a session can be inactive before it is timed out and removed. The client can request a lower value than this.
Sourcepub fn token(self, token: CancellationToken) -> ServerBuilder
pub fn token(self, token: CancellationToken) -> ServerBuilder
Set the cancellation token used by the server. You only need to
set the token if you need to use a token from somewhere else to cancel,
otherwise you can get the token after building the server with
handle.token().
Sourcepub fn with_type_loader(self, loader: Arc<dyn TypeLoader>) -> ServerBuilder
pub fn with_type_loader(self, loader: Arc<dyn TypeLoader>) -> ServerBuilder
Register a type loader. Any deserialization will use this type loader to handle types coming from the user.
If the user sends a type not in any registered type loader, decoding will fail.
Sourcepub fn diagnostics_enabled(self, enabled: bool) -> ServerBuilder
pub fn diagnostics_enabled(self, enabled: bool) -> ServerBuilder
Set whether to enable diagnostics on the server or not. Only users with the right permissions can read the diagnostics