pub struct Server(/* private fields */);Expand description
A host-owned address space with one application namespace.
Implementations§
Source§impl Server
impl Server
Sourcepub fn loopback(
port: NonZeroU16,
namespace_uri: &str,
) -> Result<(Self, ServerRunner), ServerError>
pub fn loopback( port: NonZeroU16, namespace_uri: &str, ) -> Result<(Self, ServerRunner), ServerError>
Configure anonymous connections on the IPv4 loopback interface.
Examples found in repository?
examples/local_server.rs (line 22)
15fn main() -> Result<(), Box<dyn Error>> {
16 let port = std::env::args()
17 .nth(1)
18 .unwrap_or_else(|| "4840".into())
19 .parse::<NonZeroU16>()?;
20 let args: Vec<String> = std::env::args().skip(2).collect();
21 let (host, runner) = match args.as_slice() {
22 [] => Server::loopback(port, "urn:example:line")?,
23 [uri, cert, key, client_uri, client_cert, policy @ ..] => Server::secure_with_policy(
24 SecureServerConfig {
25 bind: ([127, 0, 0, 1], port.get()).into(),
26 application_uri: uri,
27 certificate_der: &std::fs::read(cert)?,
28 private_key_der: &std::fs::read(key)?,
29 trusted_client_uri: client_uri,
30 trusted_client_certificate_der: &std::fs::read(client_cert)?,
31 },
32 "urn:example:line",
33 match policy {
34 [] => SecurityPolicy::Basic256Sha256,
35 [p] => [
36 SecurityPolicy::Basic256Sha256,
37 SecurityPolicy::Aes128Sha256RsaOaep,
38 SecurityPolicy::Aes256Sha256RsaPss,
39 ]
40 .into_iter()
41 .find(|policy| policy.uri().rsplit('#').next() == Some(p.as_str()))
42 .ok_or("unknown security policy")?,
43 _ => return Err("expected at most one security policy".into()),
44 },
45 )?,
46 _ => {
47 return Err(
48 "expected PORT [SERVER_URI SERVER.der SERVER_KEY.der CLIENT_URI CLIENT.der [POLICY]]".into(),
49 );
50 }
51 };
52 let counter = host.add_variable("PartsProduced", 0_u64)?;
53 let stop = Arc::new(AtomicBool::new(false));
54 let input_closed = Arc::clone(&stop);
55 thread::spawn(move || {
56 for line in io::stdin().lock().lines() {
57 let Ok(line) = line else { break };
58 match line.trim().parse() {
59 Ok(n) => {
60 if let Err(error) = counter.set(n) {
61 eprintln!("update failed: {error}");
62 }
63 }
64 Err(error) => eprintln!("expected a UInt64: {error}"),
65 }
66 }
67 input_closed.store(true, Ordering::Release);
68 });
69 eprintln!("Serving PartsProduced on opc.tcp://127.0.0.1:{port} while stdin is open");
70 runner.run_until(|| stop.load(Ordering::Acquire))?;
71 Ok(())
72}Sourcepub fn secure(
config: SecureServerConfig<'_>,
namespace_uri: &str,
) -> Result<(Self, ServerRunner), ServerError>
pub fn secure( config: SecureServerConfig<'_>, namespace_uri: &str, ) -> Result<(Self, ServerRunner), ServerError>
Configure a Basic256Sha256 SignAndEncrypt endpoint for one pinned reader.
Sourcepub fn secure_with_policy(
config: SecureServerConfig<'_>,
namespace_uri: &str,
policy: SecurityPolicy,
) -> Result<(Self, ServerRunner), ServerError>
pub fn secure_with_policy( config: SecureServerConfig<'_>, namespace_uri: &str, policy: SecurityPolicy, ) -> Result<(Self, ServerRunner), ServerError>
Configure one SignAndEncrypt policy for the pinned client and server identities.
Examples found in repository?
examples/local_server.rs (lines 23-45)
15fn main() -> Result<(), Box<dyn Error>> {
16 let port = std::env::args()
17 .nth(1)
18 .unwrap_or_else(|| "4840".into())
19 .parse::<NonZeroU16>()?;
20 let args: Vec<String> = std::env::args().skip(2).collect();
21 let (host, runner) = match args.as_slice() {
22 [] => Server::loopback(port, "urn:example:line")?,
23 [uri, cert, key, client_uri, client_cert, policy @ ..] => Server::secure_with_policy(
24 SecureServerConfig {
25 bind: ([127, 0, 0, 1], port.get()).into(),
26 application_uri: uri,
27 certificate_der: &std::fs::read(cert)?,
28 private_key_der: &std::fs::read(key)?,
29 trusted_client_uri: client_uri,
30 trusted_client_certificate_der: &std::fs::read(client_cert)?,
31 },
32 "urn:example:line",
33 match policy {
34 [] => SecurityPolicy::Basic256Sha256,
35 [p] => [
36 SecurityPolicy::Basic256Sha256,
37 SecurityPolicy::Aes128Sha256RsaOaep,
38 SecurityPolicy::Aes256Sha256RsaPss,
39 ]
40 .into_iter()
41 .find(|policy| policy.uri().rsplit('#').next() == Some(p.as_str()))
42 .ok_or("unknown security policy")?,
43 _ => return Err("expected at most one security policy".into()),
44 },
45 )?,
46 _ => {
47 return Err(
48 "expected PORT [SERVER_URI SERVER.der SERVER_KEY.der CLIENT_URI CLIENT.der [POLICY]]".into(),
49 );
50 }
51 };
52 let counter = host.add_variable("PartsProduced", 0_u64)?;
53 let stop = Arc::new(AtomicBool::new(false));
54 let input_closed = Arc::clone(&stop);
55 thread::spawn(move || {
56 for line in io::stdin().lock().lines() {
57 let Ok(line) = line else { break };
58 match line.trim().parse() {
59 Ok(n) => {
60 if let Err(error) = counter.set(n) {
61 eprintln!("update failed: {error}");
62 }
63 }
64 Err(error) => eprintln!("expected a UInt64: {error}"),
65 }
66 }
67 input_closed.store(true, Ordering::Release);
68 });
69 eprintln!("Serving PartsProduced on opc.tcp://127.0.0.1:{port} while stdin is open");
70 runner.run_until(|| stop.load(Ordering::Acquire))?;
71 Ok(())
72}Sourcepub fn add_variable<T: Into<Variant> + VariantType>(
&self,
name: &str,
initial: T,
) -> Result<Variable<T>, ServerError>
pub fn add_variable<T: Into<Variant> + VariantType>( &self, name: &str, initial: T, ) -> Result<Variable<T>, ServerError>
Add a typed, read-only scalar under Objects. Its browse name and string
NodeId both equal name. A duplicate leaves the existing value intact.
Examples found in repository?
examples/local_server.rs (line 52)
15fn main() -> Result<(), Box<dyn Error>> {
16 let port = std::env::args()
17 .nth(1)
18 .unwrap_or_else(|| "4840".into())
19 .parse::<NonZeroU16>()?;
20 let args: Vec<String> = std::env::args().skip(2).collect();
21 let (host, runner) = match args.as_slice() {
22 [] => Server::loopback(port, "urn:example:line")?,
23 [uri, cert, key, client_uri, client_cert, policy @ ..] => Server::secure_with_policy(
24 SecureServerConfig {
25 bind: ([127, 0, 0, 1], port.get()).into(),
26 application_uri: uri,
27 certificate_der: &std::fs::read(cert)?,
28 private_key_der: &std::fs::read(key)?,
29 trusted_client_uri: client_uri,
30 trusted_client_certificate_der: &std::fs::read(client_cert)?,
31 },
32 "urn:example:line",
33 match policy {
34 [] => SecurityPolicy::Basic256Sha256,
35 [p] => [
36 SecurityPolicy::Basic256Sha256,
37 SecurityPolicy::Aes128Sha256RsaOaep,
38 SecurityPolicy::Aes256Sha256RsaPss,
39 ]
40 .into_iter()
41 .find(|policy| policy.uri().rsplit('#').next() == Some(p.as_str()))
42 .ok_or("unknown security policy")?,
43 _ => return Err("expected at most one security policy".into()),
44 },
45 )?,
46 _ => {
47 return Err(
48 "expected PORT [SERVER_URI SERVER.der SERVER_KEY.der CLIENT_URI CLIENT.der [POLICY]]".into(),
49 );
50 }
51 };
52 let counter = host.add_variable("PartsProduced", 0_u64)?;
53 let stop = Arc::new(AtomicBool::new(false));
54 let input_closed = Arc::clone(&stop);
55 thread::spawn(move || {
56 for line in io::stdin().lock().lines() {
57 let Ok(line) = line else { break };
58 match line.trim().parse() {
59 Ok(n) => {
60 if let Err(error) = counter.set(n) {
61 eprintln!("update failed: {error}");
62 }
63 }
64 Err(error) => eprintln!("expected a UInt64: {error}"),
65 }
66 }
67 input_closed.store(true, Ordering::Release);
68 });
69 eprintln!("Serving PartsProduced on opc.tcp://127.0.0.1:{port} while stdin is open");
70 runner.run_until(|| stop.load(Ordering::Acquire))?;
71 Ok(())
72}Auto Trait Implementations§
impl Forget for Server
impl Freeze for Server
impl Move for Server
impl RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
impl UnwindSafe for Server
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more