Skip to content

Commit

Permalink
Merge branch 'main' into warnings-as-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj authored Mar 16, 2024
2 parents 280b213 + 7427d98 commit 9b66c77
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
6 changes: 3 additions & 3 deletions core/federated/RTI/rti_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void handle_port_absent_message(federate_info_t* sending_federate, unsigned char
}

void handle_timed_message(federate_info_t* sending_federate, unsigned char* buffer) {
size_t header_size = 1 + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(int32_t) + sizeof(int64_t) + sizeof(uint32_t);
size_t header_size = 1 + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(int64_t) + sizeof(uint32_t);
// Read the header, minus the first byte which has already been read.
read_from_socket_fail_on_error(&sending_federate->socket, header_size - 1, &(buffer[1]), NULL,
"RTI failed to read the timed message header from remote federate.");
Expand Down Expand Up @@ -721,8 +721,8 @@ void handle_address_query(uint16_t fed_id) {
// the port number because it has not yet received an MSG_TYPE_ADDRESS_ADVERTISEMENT message
// from this federate. In that case, it will respond by sending -1.

// Response message is also of type MSG_TYPE_ADDRESS_QUERY.
buffer[0] = MSG_TYPE_ADDRESS_QUERY;
// Response message is MSG_TYPE_ADDRESS_QUERY_REPLY.
buffer[0] = MSG_TYPE_ADDRESS_QUERY_REPLY;

// Encode the port number.
federate_info_t* remote_fed = GET_FED_INFO(remote_fed_id);
Expand Down
20 changes: 10 additions & 10 deletions core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ static bool handle_message_now(environment_t* env, trigger_t* trigger, tag_t int
static int handle_message(int* socket, int fed_id) {
(void)fed_id;
// Read the header.
size_t bytes_to_read = sizeof(uint16_t) + sizeof(uint16_t) + sizeof(int32_t);
size_t bytes_to_read = sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t);
unsigned char buffer[bytes_to_read];
if (read_from_socket_close_on_error(socket, bytes_to_read, buffer)) {
// Read failed, which means the socket has been closed between reading the
Expand Down Expand Up @@ -511,7 +511,7 @@ static int handle_tagged_message(int* socket, int fed_id) {

// Read the header which contains the timestamp.
size_t bytes_to_read =
sizeof(uint16_t) + sizeof(uint16_t) + sizeof(int32_t) + sizeof(instant_t) + sizeof(microstep_t);
sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(instant_t) + sizeof(microstep_t);
unsigned char buffer[bytes_to_read];
if (read_from_socket_close_on_error(socket, bytes_to_read, buffer)) {
return -1; // Read failed.
Expand Down Expand Up @@ -1713,8 +1713,8 @@ void lf_connect_to_federate(uint16_t remote_federate_id) {
"Failed to read the requested port number for federate %d from RTI.",
remote_federate_id);

if (buffer[0] != MSG_TYPE_ADDRESS_QUERY) {
// Unexpected reply. Could be that RTI has failed and sent a resignation.
if (buffer[0] != MSG_TYPE_ADDRESS_QUERY_REPLY) {
// Unexpected reply. Could be that RTI has failed and sent a resignation.
if (buffer[0] == MSG_TYPE_FAILED) {
lf_print_error_and_exit("RTI has failed.");
} else {
Expand Down Expand Up @@ -2271,7 +2271,7 @@ void lf_reset_status_fields_on_input_port_triggers() {

int lf_send_message(int message_type, unsigned short port, unsigned short federate, const char* next_destination_str,
size_t length, unsigned char* message) {
unsigned char header_buffer[1 + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(int32_t)];
unsigned char header_buffer[1 + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t)];
// First byte identifies this as a timed message.
if (message_type != MSG_TYPE_P2P_MESSAGE) {
lf_print_error("lf_send_message: Unsupported message type (%d).", message_type);
Expand All @@ -2286,12 +2286,12 @@ int lf_send_message(int message_type, unsigned short port, unsigned short federa
encode_uint16(federate, &(header_buffer[1 + sizeof(uint16_t)]));

// The next four bytes are the message length.
encode_int32((int32_t)length, &(header_buffer[1 + sizeof(uint16_t) + sizeof(uint16_t)]));
encode_uint32((uint32_t)length, &(header_buffer[1 + sizeof(uint16_t) + sizeof(uint16_t)]));

LF_PRINT_LOG("Sending untagged message to %s.", next_destination_str);

// Header: message_type + port_id + federate_id + length of message + timestamp + microstep
const int header_length = 1 + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(int32_t);
const int header_length = 1 + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t);

// Use a mutex lock to prevent multiple threads from simultaneously sending.
LF_MUTEX_LOCK(&lf_outbound_socket_mutex);
Expand Down Expand Up @@ -2542,7 +2542,7 @@ int lf_send_tagged_message(environment_t* env, interval_t additional_delay, int
assert(env != GLOBAL_ENVIRONMENT);

size_t header_length =
1 + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(int32_t) + sizeof(instant_t) + sizeof(microstep_t);
1 + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(instant_t) + sizeof(microstep_t);
unsigned char header_buffer[header_length];

if (message_type != MSG_TYPE_TAGGED_MESSAGE && message_type != MSG_TYPE_P2P_TAGGED_MESSAGE) {
Expand All @@ -2564,8 +2564,8 @@ int lf_send_tagged_message(environment_t* env, interval_t additional_delay, int
buffer_head += sizeof(uint16_t);

// The next four bytes are the message length.
encode_int32((int32_t)length, &(header_buffer[buffer_head]));
buffer_head += sizeof(int32_t);
encode_uint32((uint32_t)length, &(header_buffer[buffer_head]));
buffer_head += sizeof(uint32_t);

// Apply the additional delay to the current tag and use that as the intended
// tag of the outgoing message.
Expand Down
2 changes: 1 addition & 1 deletion core/federated/network/net_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void extract_header(unsigned char* buffer, uint16_t* port_id, uint16_t* federate
// printf("DEBUG: Message for port %d of federate %d.\n", *port_id, *federate_id);

// The next four bytes are the message length.
int32_t local_length_signed = extract_int32(&(buffer[sizeof(uint16_t) + sizeof(uint16_t)]));
uint32_t local_length_signed = extract_uint32(&(buffer[sizeof(uint16_t) + sizeof(uint16_t)]));
if (local_length_signed < 0) {
lf_print_error_and_exit("Received an invalid message length (%d) from federate %d.", local_length_signed,
*federate_id);
Expand Down
22 changes: 15 additions & 7 deletions include/core/federated/network/net_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Byte identifying a timestamped message to forward to another federate.
* The next two bytes will be the ID of the destination reactor port.
* The next two bytes are the destination federate ID.
* The four bytes after that will be the length of the message.
* The four bytes after that will be the length of the message (as an unsigned 32-bit int).
* The next eight bytes will be the timestamp of the message.
* The next four bytes will be the microstep of the message.
* The remaining bytes are the message.
Expand Down Expand Up @@ -528,12 +528,20 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Byte identifying a address query message, sent by a federate to RTI
* to ask for another federate's address and port number.
* The next two bytes are the other federate's ID.
* The reply from the RTI will a port number (an int32_t), which is -1
*/
#define MSG_TYPE_ADDRESS_QUERY 13

/**
* Byte identifying a address query message reply, sent by a RTI to a federate
* to reply with a remote federate's address and port number.
* The reply from the RTI will be a port number (an int32_t), which is -1
* if the RTI does not know yet (it has not received MSG_TYPE_ADDRESS_ADVERTISEMENT from
* the other federate), followed by the IP address of the other
* federate (an IPV4 address, which has length INET_ADDRSTRLEN).
* The next four bytes (or sizeof(int32_t)) will be the port number.
* The next four bytes (or sizeof(in_addr), which is uint32_t) will be the ip address.
*/
#define MSG_TYPE_ADDRESS_QUERY 13
#define MSG_TYPE_ADDRESS_QUERY_REPLY 14

/**
* Byte identifying a message advertising the port for the TCP connection server
Expand All @@ -543,7 +551,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* The sending federate will not wait for a response from the RTI and assumes its
* request will be processed eventually by the RTI.
*/
#define MSG_TYPE_ADDRESS_ADVERTISEMENT 14
#define MSG_TYPE_ADDRESS_ADVERTISEMENT 15

/**
* Byte identifying a first message that is sent by a federate directly to another federate
Expand All @@ -554,7 +562,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* federate does not expect this federate or federation to connect, it will respond
* instead with MSG_TYPE_REJECT.
*/
#define MSG_TYPE_P2P_SENDING_FED_ID 15
#define MSG_TYPE_P2P_SENDING_FED_ID 16

/**
* Byte identifying a message to send directly to another federate.
Expand All @@ -565,7 +573,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* The four bytes after will be the length of the message.
* The ramaining bytes are the message.
*/
#define MSG_TYPE_P2P_MESSAGE 16
#define MSG_TYPE_P2P_MESSAGE 17

/**
* Byte identifying a timestamped message to send directly to another federate.
Expand All @@ -582,7 +590,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* The next four bytes will be the microstep of the sender.
* The ramaining bytes are the message.
*/
#define MSG_TYPE_P2P_TAGGED_MESSAGE 17
#define MSG_TYPE_P2P_TAGGED_MESSAGE 18

////////////////////////////////////////////////
/**
Expand Down

0 comments on commit 9b66c77

Please sign in to comment.