opcua_server/
lib.rs

1// OPCUA for Rust
2// SPDX-License-Identifier: MPL-2.0
3// Copyright (C) 2017-2022 Adam Lock
4
5//! The OPC UA Server module contains the server side functionality - address space, services,
6//! server security, session management, local discovery server registration and subscriptions.
7//!
8//! # Usage
9//!
10//! An implementation will usually start by building a [`ServerConfig`], either
11//! from a configuration file, or through code. Then it will construct a [`Server`], initialise
12//! its address space, and then run it.
13//!
14//! [`Server`]: ./server/struct.Server.html
15//! [`ServerConfig`]: ./config/struct.ServerConfig.html
16//!
17//! # Example
18//!
19//! This is a very simple server which runs with the default address space on the default port.
20//!
21//!  ```no_run
22//!  use opcua_server::prelude::*;
23//!
24//!  fn main() {
25//!      let server: Server = ServerBuilder::new_sample().server().unwrap();
26//!      server.run();
27//!  }
28//!  ```
29#[cfg(feature = "http")]
30extern crate actix_web;
31#[macro_use]
32extern crate lazy_static;
33#[macro_use]
34extern crate log;
35#[macro_use]
36extern crate bitflags;
37#[macro_use]
38extern crate serde_derive;
39#[macro_use]
40extern crate derivative;
41#[macro_use]
42extern crate opcua_core;
43
44/// Returns true of the Option<Vec<Foo>> is None or the vec inside is empty. This is particularly
45/// used by services where the spec says "All Services with arrays of operations in the request
46/// shall return a bad code in the serviceResult if the array is empty."
47macro_rules! is_empty_option_vec {
48    ( $v: expr ) => {
49        $v.is_none() || $v.as_ref().unwrap().is_empty()
50    };
51}
52
53mod identity_token;
54mod services;
55
56#[cfg(feature = "discovery-server-registration")]
57mod discovery;
58
59mod session_diagnostics;
60
61#[cfg(feature = "http")]
62pub mod http;
63
64pub mod address_space;
65pub mod builder;
66pub mod callbacks;
67pub mod comms;
68pub mod config;
69pub mod continuation_point;
70pub mod diagnostics;
71#[macro_use]
72pub mod events;
73pub mod historical;
74pub mod metrics;
75pub mod server;
76pub mod session;
77pub mod state;
78pub mod subscriptions;
79pub mod util;
80
81pub mod prelude {
82    //! Provides a way to use most types and functions commonly used by server implementations from a
83    //! single use statement.
84    pub use crate::{
85        address_space::types::*,
86        address_space::{AccessLevel, EventNotifier, UserAccessLevel},
87        builder::*,
88        callbacks::*,
89        config::*,
90        events::event::*,
91        historical::*,
92        server::*,
93        subscriptions::*,
94        util::*,
95    };
96    pub use opcua_core::prelude::*;
97    pub use opcua_crypto::*;
98    pub use opcua_types::service_types::*;
99    pub use opcua_types::status_code::StatusCode;
100    pub use opcua_types::*;
101}
102
103pub mod constants {
104    //! Provides constants that govern the internal workings of the server implementation.
105    /// The default hello timeout period in seconds
106    pub const DEFAULT_HELLO_TIMEOUT_SECONDS: u32 = 5;
107    /// Default OPC UA server port for this implementation
108    pub const DEFAULT_RUST_OPC_UA_SERVER_PORT: u16 = 4855;
109    /// Default maximum number of subscriptions in a session
110    pub const DEFAULT_MAX_SUBSCRIPTIONS: u32 = 100;
111    /// Default maximum number of monitored items per subscription
112    pub const DEFAULT_MAX_MONITORED_ITEMS_PER_SUB: u32 = 1000;
113    /// Default, well known address for TCP discovery server
114    pub const DEFAULT_DISCOVERY_SERVER_URL: &str = "opc.tcp://localhost:4840/UADiscovery";
115
116    // Internally controlled values
117
118    /// The polling interval in millis on subscriptions and monitored items. The more
119    /// fine-grained this is, the more often subscriptions will be checked for changes. The minimum
120    /// publish interval cannot be less than this.
121    pub const SUBSCRIPTION_TIMER_RATE_MS: u64 = 100;
122    /// Minimum publishing interval for subscriptions
123    pub const MIN_PUBLISHING_INTERVAL: f64 = (SUBSCRIPTION_TIMER_RATE_MS as f64) / 1000.0;
124    /// Minimum sampling interval on monitored items
125    pub const MIN_SAMPLING_INTERVAL: f64 = (SUBSCRIPTION_TIMER_RATE_MS as f64) / 1000.0;
126    /// Maximum data change queue allowed by clients on monitored items
127    pub const MAX_DATA_CHANGE_QUEUE_SIZE: usize = 10;
128    /// The default size of preallocated vecs of monitored items per subscription
129    pub const DEFAULT_MONITORED_ITEM_CAPACITY: usize = 100;
130    /// Interval to check for HELLO timeout in millis. This can be fairly coarse because it's not
131    /// something that requires huge accuracy.
132    pub const HELLO_TIMEOUT_POLL_MS: u64 = 500;
133    /// Maximum time in MS that a session can be inactive before a timeout
134    pub const MAX_SESSION_TIMEOUT: f64 = 60000f64;
135    /// Maximum size in bytes that a request message is allowed to be
136    pub const MAX_REQUEST_MESSAGE_SIZE: u32 = 32768;
137    /// Default keep alive count
138    pub const DEFAULT_KEEP_ALIVE_COUNT: u32 = 10;
139    /// Maximum keep alive count
140    pub const MAX_KEEP_ALIVE_COUNT: u32 = 30000;
141    /// Maximum browse continuation points
142    pub const MAX_BROWSE_CONTINUATION_POINTS: usize = 20;
143    /// Maximum history continuation points
144    pub const MAX_HISTORY_CONTINUATION_POINTS: usize = 10;
145    /// Maximum query continuation points
146    pub const MAX_QUERY_CONTINUATION_POINTS: usize = 10;
147
148    /// Maximum number of nodes in a TranslateBrowsePathsToNodeIdsRequest
149    pub const MAX_NODES_PER_TRANSLATE_BROWSE_PATHS_TO_NODE_IDS: usize = 10;
150    pub const MAX_NODES_PER_READ: usize = 50;
151    pub const MAX_NODES_PER_WRITE: usize = 10;
152    pub const MAX_NODES_PER_METHOD_CALL: usize = 10;
153    pub const MAX_NODES_PER_BROWSE: usize = 50;
154    pub const MAX_NODES_PER_REGISTER_NODES: usize = 10;
155    /// Maximum number of nodes / references per node manaument operation
156    pub const MAX_NODES_PER_NODE_MANAGEMENT: usize = 100;
157    pub const MAX_MONITORED_ITEMS_PER_CALL: usize = 10;
158    pub const MAX_NODES_PER_HISTORY_READ_DATA: usize = 10;
159    pub const MAX_NODES_PER_HISTORY_READ_EVENTS: usize = 10;
160    pub const MAX_NODES_PER_HISTORY_UPDATE_DATA: usize = 10;
161    pub const MAX_NODES_PER_HISTORY_UPDATE_EVENTS: usize = 10;
162}
163
164#[cfg(test)]
165mod tests;