Skip to content

Commit

Permalink
Update copyright message to 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
locka99 committed Dec 30, 2023
1 parent 981fb99 commit 7826f90
Show file tree
Hide file tree
Showing 485 changed files with 107,770 additions and 32,703 deletions.
2 changes: 1 addition & 1 deletion lib/src/client/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

use std::path::PathBuf;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/callbacks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

//! Provides callback traits and concrete implementations that the client can use to register for notifications
//! with the client api.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

//! Client setup and session creation.

Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/comms/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

//! Client side communications

Expand Down
109 changes: 69 additions & 40 deletions lib/src/client/comms/tcp_transport.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

//! The OPC UA TCP transport client module. The transport is responsible for establishing a connection
//! with the server and processing requests.
Expand All @@ -12,8 +12,7 @@ use std::{
net::{SocketAddr, ToSocketAddrs},
result::Result,
sync::Arc,
thread,
time,
thread, time,
};

use futures::StreamExt;
Expand Down Expand Up @@ -315,9 +314,14 @@ impl TcpTransport {

/// Connects the stream to the specified endpoint
pub fn connect(&self, endpoint_url: &str) -> Result<(), StatusCode> {
debug_assert!(!self.is_connected(), "Should not try to connect when already connected");
let (host, port) =
hostname_port_from_url(endpoint_url, crate::core::constants::DEFAULT_OPC_UA_SERVER_PORT)?;
debug_assert!(
!self.is_connected(),
"Should not try to connect when already connected"
);
let (host, port) = hostname_port_from_url(
endpoint_url,
crate::core::constants::DEFAULT_OPC_UA_SERVER_PORT,
)?;

// Resolve the host name into a socket address
let addr = {
Expand All @@ -343,17 +347,14 @@ impl TcpTransport {
assert_eq!(addr.port(), port);
let endpoint_url = endpoint_url.to_string();

let (connection_state,
session_state,
secure_channel,
message_queue,
) = (self.connection_state.clone(),
self.session_state.clone(),
self.secure_channel.clone(),
self.message_queue.clone(), );
let (connection_state, session_state, secure_channel, message_queue) = (
self.connection_state.clone(),
self.session_state.clone(),
self.secure_channel.clone(),
self.message_queue.clone(),
);

let (connection_status_sender,
connection_status_receiver) = std::sync::mpsc::channel();
let (connection_status_sender, connection_status_receiver) = std::sync::mpsc::channel();
let conn_task = Self::connection_task(
addr,
connection_state.clone(),
Expand All @@ -366,16 +367,29 @@ impl TcpTransport {
thread::spawn(move || {
trace_lock!(runtime).block_on(async move {
let conn_result = conn_task.await;
let mut status = conn_result.as_ref().err().copied().unwrap_or(StatusCode::Good);
let _ = connection_status_sender.send(if status.is_bad() { Err(status) } else { Ok(()) });
let mut status = conn_result
.as_ref()
.err()
.copied()
.unwrap_or(StatusCode::Good);
let _ = connection_status_sender.send(if status.is_bad() {
Err(status)
} else {
Ok(())
});
if let Ok((read, write)) = conn_result {
status = Self::spawn_looping_tasks(read, write).await.err().unwrap_or(StatusCode::Good);
status = Self::spawn_looping_tasks(read, write)
.await
.err()
.unwrap_or(StatusCode::Good);
}
connection_state.set_finished(status);
trace_write_lock!(session_state).on_session_closed(status);
});
});
connection_status_receiver.recv().expect("channel should never be dropped here")
connection_status_receiver
.recv()
.expect("channel should never be dropped here")
}

/// Disconnects the stream from the server (if it is connected)
Expand Down Expand Up @@ -445,33 +459,42 @@ impl TcpTransport {
(hello, read_state, write_state)
};

write_state.writer.write_all(&hello.encode_to_vec()).await.map_err(|err| {
error!("Cannot send hello to server, err = {:?}", err);
StatusCode::BadCommunicationError
})?;
write_state
.writer
.write_all(&hello.encode_to_vec())
.await
.map_err(|err| {
error!("Cannot send hello to server, err = {:?}", err);
StatusCode::BadCommunicationError
})?;
connection_state.set_state(ConnectionState::WaitingForAck);
match read_state.framed_read.next().await {
Some(Ok(Message::Acknowledge(ack))) => {
// TODO revise our sizes and other things according to the ACK
log::trace!("Received acknowledgement: {:?}", ack)
}
other => {
error!("Unexpected error while waiting for server ACK. Expected ACK, got {:?}", other);
error!(
"Unexpected error while waiting for server ACK. Expected ACK, got {:?}",
other
);
return Err(StatusCode::BadConnectionClosed);
}
};
connection_state.set_state(ConnectionState::Processing);
Ok((read_state, write_state))
}

async fn write_bytes_task(
write_state: &mut WriteState,
) -> Result<(), StatusCode> {
async fn write_bytes_task(write_state: &mut WriteState) -> Result<(), StatusCode> {
let bytes_to_write = write_state.send_buffer.bytes_to_write();
write_state.writer.write_all(&bytes_to_write).await.map_err(|e| {
error!("write bytes task failed: {}", e);
StatusCode::BadCommunicationError
})
write_state
.writer
.write_all(&bytes_to_write)
.await
.map_err(|e| {
error!("write bytes task failed: {}", e);
StatusCode::BadCommunicationError
})
}

async fn spawn_reading_task(mut read_state: ReadState) -> Result<(), StatusCode> {
Expand Down Expand Up @@ -509,9 +532,9 @@ impl TcpTransport {
StatusCode::BadUnexpectedError
};
error!(
"Expecting a chunk, got an error message {}",
session_status_code
);
"Expecting a chunk, got an error message {}",
session_status_code
);
}
m => {
error!("Expected a recognized message, got {:?}", m);
Expand All @@ -528,7 +551,10 @@ impl TcpTransport {
}
}
}
debug!("Read loop finished, connection state = {:?}", read_state.state.state());
debug!(
"Read loop finished, connection state = {:?}",
read_state.state.state()
);
Ok(())
}

Expand All @@ -544,7 +570,8 @@ impl TcpTransport {
}
message_queue::Message::SupportedMessage(request) => {
trace!("Sending Request: {:?}", request);
let close_connection = matches!(request, SupportedMessage::CloseSecureChannelRequest(_));
let close_connection =
matches!(request, SupportedMessage::CloseSecureChannelRequest(_));
if close_connection {
debug!("Writer is about to send a CloseSecureChannelRequest which means it should close in a moment");
}
Expand All @@ -554,8 +581,7 @@ impl TcpTransport {
write_state.send_request(request)?;
// Indicate the request was processed
{
let mut message_queue =
trace_write_lock!(write_state.message_queue);
let mut message_queue = trace_write_lock!(write_state.message_queue);
message_queue.request_was_processed(request_handle);
}
Self::write_bytes_task(&mut write_state).await?;
Expand All @@ -571,7 +597,10 @@ impl TcpTransport {

/// This is the main processing loop for the connection. It writes requests and reads responses
/// over the socket to the server.
async fn spawn_looping_tasks(read_state: ReadState, write_state: WriteState) -> Result<(), StatusCode> {
async fn spawn_looping_tasks(
read_state: ReadState,
write_state: WriteState,
) -> Result<(), StatusCode> {
log::trace!("Spawning read and write loops");
// Spawn the reading task loop
let read_loop = Self::spawn_reading_task(read_state);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/comms/transport.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

/// A trait common to all transport implementations
pub(crate) trait Transport {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

//! Client configuration data.

Expand Down
11 changes: 5 additions & 6 deletions lib/src/client/message_queue.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

use std::{collections::HashMap, sync::mpsc::SyncSender};

Expand Down Expand Up @@ -40,9 +40,7 @@ impl MessageQueue {
}

// Creates the transmission queue that outgoing requests will be sent over
pub(crate) fn make_request_channel(
&mut self,
) -> UnboundedReceiver<Message> {
pub(crate) fn make_request_channel(&mut self) -> UnboundedReceiver<Message> {
let (tx, rx) = mpsc::unbounded_channel();
self.sender = Some(tx.clone());
rx
Expand All @@ -53,8 +51,9 @@ impl MessageQueue {
}

fn send_message(&self, message: Message) -> bool {
let sender = self.sender.as_ref()
.expect("MessageQueue::send_message should never be called before make_request_channel");
let sender = self.sender.as_ref().expect(
"MessageQueue::send_message should never be called before make_request_channel",
);
if sender.is_closed() {
error!("Send message will fail because sender has been closed");
false
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

//! The OPC UA Client module contains the functionality necessary for a client to connect to an OPC UA server,
//! authenticate itself, send messages, receive responses, get values, browse the address space and
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/session/services.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

use std::{convert::TryFrom, sync::mpsc::SyncSender};

Expand Down
16 changes: 8 additions & 8 deletions lib/src/client/session/session.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

//! Session functionality for the current open client connection. This module contains functions
//! to call for all typically synchronous operations during an OPC UA session.
Expand Down Expand Up @@ -155,8 +155,8 @@ impl Session {
ignore_clock_skew: bool,
single_threaded_executor: bool,
) -> Session
where
T: Into<UAString>,
where
T: Into<UAString>,
{
let session_name = session_name.into();

Expand Down Expand Up @@ -254,8 +254,8 @@ impl Session {
/// * `session_closed_callback` - the session closed callback
///
pub fn set_session_closed_callback<CB>(&mut self, session_closed_callback: CB)
where
CB: OnSessionClosed + Send + Sync + 'static,
where
CB: OnSessionClosed + Send + Sync + 'static,
{
let mut session_state = trace_write_lock!(self.session_state);
session_state.set_session_closed_callback(session_closed_callback);
Expand All @@ -269,8 +269,8 @@ impl Session {
/// * `connection_status_callback` - the connection status callback.
///
pub fn set_connection_status_callback<CB>(&mut self, connection_status_callback: CB)
where
CB: OnConnectionStatusChange + Send + Sync + 'static,
where
CB: OnConnectionStatusChange + Send + Sync + 'static,
{
let mut session_state = trace_write_lock!(self.session_state);
session_state.set_connection_status_callback(connection_status_callback);
Expand Down Expand Up @@ -2398,7 +2398,7 @@ impl AttributeService for Session {
// Turn the enums into ExtensionObjects
let history_update_details = history_update_details
.iter()
.map(|action|ExtensionObject::from(action))
.map(|action| ExtensionObject::from(action))
.collect::<Vec<ExtensionObject>>();

let request = HistoryUpdateRequest {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/session/session_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

use std::{
sync::{
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/session_retry_policy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

use crate::types::date_time::DateTime;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/subscription.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

//! Provides subscription and monitored item tracking.
//!
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/subscription_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

use std::collections::HashMap;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/console_logging/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

use std::{
fmt,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/core/comms/chunker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OPCUA for Rust
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2017-2022 Adam Lock
// Copyright (C) 2017-2024 Adam Lock

//! Contains code for turning messages into chunks and chunks into messages.

Expand Down
Loading

0 comments on commit 7826f90

Please sign in to comment.