Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
09fd077
Add sst_support.
Jakio815 Jan 31, 2025
3fb0bf9
Add sst_priv_t struct.
Jakio815 Jan 31, 2025
27ac24e
Add initialize_netdrv for sst.
Jakio815 Jan 31, 2025
a814a07
Add free_netdrv for sst
Jakio815 Jan 31, 2025
82e63bd
Add create_server, with also passing path as global var in lf_sst_sup…
Jakio815 Jan 31, 2025
4a5f1b6
Add structure of accept_netdrv
Jakio815 Jan 31, 2025
001b5fe
Merge branch 'networkdriver' of github.com:lf-lang/reactor-c into sst
Jakio815 Jan 31, 2025
532922b
Merge branch 'networkdriver' of github.com:lf-lang/reactor-c into sst
Jakio815 Jan 31, 2025
4d28852
Add comments.
Jakio815 Jan 31, 2025
241d8da
Set handshake with client.
Jakio815 Jan 31, 2025
5be07ad
Add create_client and connect_to_netdrv for sst.
Jakio815 Jan 31, 2025
37145ff
Add user input path of sst config to federate.c
Jakio815 Jan 31, 2025
42a688c
Add get/set functions.
Jakio815 Jan 31, 2025
c374b72
Add read/write/shutdown functions.
Jakio815 Jan 31, 2025
a96d00e
Minor fix on adding void
Jakio815 Feb 1, 2025
8922c0d
Minor fix on adding `void` and new line on EOF.
Jakio815 Feb 1, 2025
ab3d92d
Enable finding the sst-c-api library, and include it in lf_sst_support.h
Jakio815 Feb 1, 2025
cedbddf
Merge branch 'networkdriver' of github.com:lf-lang/reactor-c into sst
Jakio815 Feb 1, 2025
2772e86
Add options to use user specified port for sst.
Jakio815 Feb 2, 2025
cb5b23b
Minor fix on including headers.
Jakio815 Feb 2, 2025
e7cea3b
Add -sst option for federate.
Jakio815 Feb 3, 2025
3fa7c48
Add usage for --sst for RTI.
Jakio815 Feb 4, 2025
a3887e9
Fix read/write to send header separately to match numbers. Fed-to-Fed…
Jakio815 Feb 6, 2025
53b2100
Minor cleanup.
Jakio815 Feb 6, 2025
af591a2
Fix read/write to match for fed2fed messages.
Jakio815 Feb 6, 2025
b92b737
Fix forwarding on port absent messages.
Jakio815 Feb 6, 2025
62bad67
Revert "Fix read/write to send header separately to match numbers. Fe…
Jakio815 Feb 12, 2025
f6e8674
Minor fix.
Jakio815 Feb 28, 2025
b2846c2
Minor fix on formatting.
Jakio815 Feb 28, 2025
01a4b55
Fix names to chan.
Jakio815 Feb 28, 2025
83b91d1
Merge branch 'networkdriver' of github.com:lf-lang/reactor-c into sst
Jakio815 Feb 28, 2025
1c48985
Merge branch 'networkdriver' of github.com:lf-lang/reactor-c into sst
Jakio815 Feb 28, 2025
c10017d
Merge branch 'shutdown' of github.com:lf-lang/reactor-c into sst
Jakio815 Mar 4, 2025
d1a967a
Minor change
Jakio815 Mar 14, 2025
ca6c10e
Merge branch 'networkdriver' of github.com:lf-lang/reactor-c into sst
Jakio815 Nov 10, 2025
ff0aecf
Add include to sst support.h
Jakio815 Nov 10, 2025
813d3f0
Add find openssl in cmake.
Jakio815 Nov 10, 2025
28e64cc
Fix to netchan to net_abstraction
Jakio815 Nov 10, 2025
e21fed9
Minor fix on name.
Jakio815 Nov 10, 2025
e1b7034
Merge branch 'networkdriver' of github.com:lf-lang/reactor-c into sst
Jakio815 Jan 29, 2026
d277420
Change api function name.
Jakio815 Jan 30, 2026
b8f189b
Fix to match newest network abstraction version.
Jakio815 Jan 30, 2026
de9bc3c
Add assert on net_abs.
Jakio815 Feb 2, 2026
e7347c3
Fix to set port on the net_abs. Need to fix to set function in future...
Jakio815 Feb 2, 2026
46cdaae
Fix to correct net_abs casting from socket to sst.
Jakio815 Feb 3, 2026
fc8080f
Add secure read and write using SST API functions.
Jakio815 Feb 3, 2026
b36044b
Add function `update_deadline` in Python target
byeonggiljun Feb 5, 2026
7955c34
Minor update
byeonggiljun Feb 5, 2026
96c53bf
Apply formatter
byeonggiljun Feb 5, 2026
6efb7a8
Point to python-update-deadline branch (Revert me)
byeonggiljun Feb 5, 2026
3e9e32a
Minor fix
byeonggiljun Feb 5, 2026
841dbcd
Enable handling floating-point deadline values
byeonggiljun Feb 5, 2026
b4b6743
Fix log.
Jakio815 Feb 6, 2026
365836e
Add sst_connection_params_t
Jakio815 Feb 6, 2026
03fe8ad
Add SST_ctx_t as global variable, to not init_SST multiple times. SST…
Jakio815 Feb 6, 2026
122e3b0
Minor fix.
Jakio815 Feb 10, 2026
90fabf9
Fix an error in the return value of `lf_check_deadline`
byeonggiljun Feb 10, 2026
88de99e
Match type with int and size_t.
Jakio815 Feb 10, 2026
c8777a0
Do not check deadline for reacions with no deadline
byeonggiljun Feb 11, 2026
e2ed06c
Clang format
byeonggiljun Feb 11, 2026
dfdd581
Add get/set socket related functions to support different net_abs_t t…
Jakio815 Feb 11, 2026
35e8ca1
Minor cleanup.
Jakio815 Feb 11, 2026
c9211d2
Add tls support including, and setting certificate and private key path.
Jakio815 Feb 12, 2026
ba0f7cd
Minor fix.
Jakio815 Feb 12, 2026
7ca5763
Minor fix.
Jakio815 Feb 12, 2026
9bf85ea
Fix cmake to enable TLS comm type.
Jakio815 Feb 12, 2026
1ebeb25
Minor fix on adding -tls options.
Jakio815 Feb 12, 2026
af0274f
Add ifdefs for connection_parameters_t
Jakio815 Feb 12, 2026
0a85506
Minor fix.
Jakio815 Feb 12, 2026
8bea08e
Minor fix.
Jakio815 Feb 12, 2026
05f978c
Minor bug fix.. Fixing invalid key request...
Jakio815 Feb 13, 2026
f5d0481
Fixed accept error in TLS. Created two separate SSL_CTX for client an…
Jakio815 Feb 13, 2026
a448166
Fix memory free problems, and set EOF returns to 1 following Lingua F…
Jakio815 Feb 13, 2026
3f9182b
Apply suggestions from code review
byeonggiljun Mar 27, 2026
6c07b83
Merge pull request #508 from lf-lang/networkdriver
Jakio815 Apr 6, 2026
d3142bd
Update lingua-franca-ref.txt
Jakio815 Apr 6, 2026
1d8e394
Merge branch 'main' of github.com:lf-lang/reactor-c into sst
Jakio815 Apr 7, 2026
9e4e4cb
Formatting.
Jakio815 Apr 7, 2026
2f63540
Merge pull request #575 from lf-lang/update-ref
Jakio815 Apr 8, 2026
10e8c01
Merge branch 'main' into python-update-deadline
byeonggiljun Mar 27, 2026
2da24fd
Merge branch 'main' into python-update-deadline
byeonggiljun Apr 9, 2026
3f85086
Typos in instructions
edwardalee Apr 10, 2026
1c8fcce
First version of initilize from file utility
edwardalee Apr 10, 2026
ae198f2
Format
edwardalee Apr 10, 2026
863c0e0
Added ability to read int values
edwardalee Apr 11, 2026
2c7c4a7
Added capability to initialize string parameters and state from a file
edwardalee Apr 11, 2026
a9509a4
Response to Copilot reviews
edwardalee Apr 11, 2026
e16ec15
Respond to Copilot reviews and point to utility-functions branch of l…
edwardalee Apr 11, 2026
6422f15
Correctly return py_update_deadline and update the LF reference
byeonggiljun Apr 11, 2026
ac025b2
Make compatible with CCpp
edwardalee Apr 12, 2026
d757b19
Format
edwardalee Apr 12, 2026
3c94571
Avoid freeing a token that has gone on the reaction queue.
edwardalee Apr 12, 2026
986d854
Comments only
edwardalee Apr 12, 2026
79a3a67
Attempt to fix double-free error
edwardalee Apr 12, 2026
b1766e5
Reverting previous attempt, which didn't work.
edwardalee Apr 12, 2026
40ba8d4
Merge branch 'python-update-deadline' into utility-functions
edwardalee Apr 12, 2026
a014200
Check calloc result
edwardalee Apr 12, 2026
7253f5f
Fix to not set pointers in stack to NULL.
Jakio815 Apr 12, 2026
53aee73
Fix lf_handle_p2p_connections_from_federates() to not return NULL whe…
Jakio815 Apr 12, 2026
c0d284c
Remove server_hostname from socket_priv_t, and following usages.
Jakio815 Apr 12, 2026
f76b307
Merge pull request #558 from lf-lang/python-update-deadline
edwardalee Apr 12, 2026
736f4b7
Add include guard.
edwardalee Apr 12, 2026
80f9730
Reverse incorrect patch
edwardalee Apr 12, 2026
89a240b
Merge branch 'main' into utility-functions
edwardalee Apr 12, 2026
ca77862
Removed redundant docs
edwardalee Apr 12, 2026
14f01c7
Reset lingua-franca-ref to point to master
edwardalee Apr 12, 2026
0bf11da
Trigger CI
edwardalee Apr 12, 2026
9a0e818
Merge pull request #577 from lf-lang/utility-functions
edwardalee Apr 13, 2026
5cf6adc
Merge branch 'main' into fix-check-deadline
edwardalee Apr 13, 2026
a930ffd
Optimized `connect_to_socket()` to bypass redundant `getaddrinfo` DNS…
Jakio815 Apr 13, 2026
fa343e0
Formatting.
Jakio815 Apr 13, 2026
bb1ae56
Merge branch 'main' of https://github.com/lf-lang/reactor-c into ipv4…
Jakio815 Apr 13, 2026
e71af80
Fixes to prevent segfault on shutting down network connections
edwardalee Apr 13, 2026
8a1effa
Typos in comments
edwardalee Apr 13, 2026
4a38791
Check the presence of deadline with the value of the deadline field
byeonggiljun Apr 13, 2026
8d60428
Apply formatter
byeonggiljun Apr 13, 2026
1416d01
Apply Copilot suggestions
edwardalee Apr 14, 2026
2ccb557
Merge pull request #559 from lf-lang/fix-check-deadline
edwardalee Apr 14, 2026
3bb3938
Merge branch 'main' into net-fixes
edwardalee Apr 14, 2026
bc75964
Merge pull request #579 from lf-lang/net-fixes
edwardalee Apr 14, 2026
3726122
Merge branch 'main' of https://github.com/lf-lang/reactor-c into ipv4…
Jakio815 Apr 14, 2026
f6b6b8a
Add copilot's suggestions.
Jakio815 Apr 14, 2026
bb0d53d
Add sleep before accept retries.
Jakio815 Apr 15, 2026
a8368c3
Changed to use CONNECT_RETRY_INTERVAL rather than hardwired constant
edwardalee Apr 15, 2026
fe69a79
Merge pull request #578 from lf-lang/ipv4-fix
edwardalee Apr 15, 2026
0b932aa
Decrement reference count of old token when template token is replaced.
edwardalee Apr 17, 2026
d33eca8
Fix race condition identified by Copilot
edwardalee Apr 17, 2026
af10061
Fixed race condition exposed by previous fixes
edwardalee Apr 17, 2026
51034b9
Merge pull request #581 from lf-lang/memory-leak-fix
edwardalee Apr 17, 2026
72e4196
Merge branch 'main' of github.com:lf-lang/reactor-c into sst
Jakio815 Apr 22, 2026
f948a47
Remove get/set on server_hostname.
Jakio815 Apr 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion core/federated/RTI/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void usage(int argc, const char* argv[]) {
lf_print(" -a, --auth Turn on HMAC authentication options.\n");
lf_print(" -t, --tracing Turn on tracing.\n");
lf_print(" -d, --disable_dnet Turn off the use of DNET signals.\n");
lf_print(" -sst, --sst SST config path for RTI.\n");
lf_print(" -tls, --tls <cert_path> <key_path> TLS certificate and private key paths.\n");

lf_print("Command given:");
for (int i = 0; i < argc; i++) {
Expand Down Expand Up @@ -220,7 +222,7 @@ int process_args(int argc, const char* argv[]) {
rti.base.number_of_scheduling_nodes = (int32_t)num_federates; // FIXME: Loses numbers on 64-bit machines
lf_print_info("RTI: Number of federates: %d", rti.base.number_of_scheduling_nodes);
} else if (strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--port") == 0) {
#ifdef COMM_TYPE_TCP
#if defined(COMM_TYPE_TCP) || defined(COMM_TYPE_SST) || defined(COMM_TYPE_TLS)
if (argc < i + 2) {
lf_print_error("--port needs a short unsigned integer argument ( > 0 and < %d).", UINT16_MAX);
usage(argc, argv);
Expand Down Expand Up @@ -252,6 +254,42 @@ int process_args(int argc, const char* argv[]) {
return 0;
#endif
rti.authentication_enabled = true;
} else if (strcmp(argv[i], "-sst") == 0 || strcmp(argv[i], "--sst") == 0) {
#ifndef COMM_TYPE_SST
lf_print_error("--sst requires the RTI to be built with the --DCOMM_TYPE=SST option.");
usage(argc, argv);
return 0;
#else
i++;
lf_set_sst_config_path(argv[i]);
#endif
} else if (strcmp(argv[i], "-tls") == 0 || strcmp(argv[i], "--tls") == 0) {
#ifndef COMM_TYPE_TLS
lf_print_error("--tls requires the RTI to be built with the -DCOMM_TYPE=TLS option.");
usage(argc, argv);
return 0;
#else
// Need two arguments: cert path and key path
if (argc < i + 3) {
lf_print_error("--tls needs two arguments: <certificate_path> <private_key_path>.");
usage(argc, argv);
return 0;
}
const char* cert_path = argv[i + 1];
const char* key_path = argv[i + 2];

// Optional: basic sanity check (avoid empty strings)
if (cert_path[0] == '\0' || key_path[0] == '\0') {
lf_print_error("--tls certificate_path and private_key_path must be non-empty.");
usage(argc, argv);
return 0;
}

lf_set_tls_configuration(cert_path, key_path);
lf_print_debug("RTI: TLS cert path: %s", cert_path);
lf_print_debug("RTI: TLS key path : %s", key_path);
i += 2;
#endif
} else if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--tracing") == 0) {
rti.base.tracing_enabled = true;
} else if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--dnet_disabled") == 0) {
Expand Down
22 changes: 8 additions & 14 deletions core/federated/RTI/rti_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,23 +636,20 @@ void handle_address_query(uint16_t fed_id) {

int32_t server_port;
uint32_t* ip_address;
char* server_host_name;
uint32_t temp = 0;

LF_MUTEX_LOCK(&rti_mutex);
// Check if the RTI has initialized the remote federate's network abstraction.
if (remote_fed->net == NULL) {
// RTI has not set up the remote federate. Respond with -1 to indicate an unknown port number.
server_port = -1;
uint32_t temp = 0;
ip_address = &temp;
server_host_name = "localhost";
} else {
// The network abstraction is initialized, but the RTI might still not know the port number. This can happen if the
// RTI has not yet received a MSG_TYPE_ADDRESS_ADVERTISEMENT message from the remote federate. In such cases, the
// returned port number might still be -1.
server_port = ((socket_priv_t*)remote_fed->net)->server_port;
ip_address = (uint32_t*)&((socket_priv_t*)remote_fed->net)->server_ip_addr;
server_host_name = ((socket_priv_t*)remote_fed->net)->server_hostname;
server_port = get_server_port(remote_fed->net);
ip_address = (uint32_t*)get_ip_addr(remote_fed->net);
}

encode_int32(server_port, (unsigned char*)&buffer[1]);
Expand All @@ -669,8 +666,7 @@ void handle_address_query(uint16_t fed_id) {
tracepoint_rti_to_federate(send_ADR_QR_REP, fed_id, NULL);
}

LF_PRINT_DEBUG("Replied to address query from federate %d with address %s:%d.", fed_id, server_host_name,
server_port);
LF_PRINT_DEBUG("Replied to address query from federate %d", fed_id);
}

void handle_address_ad(uint16_t federate_id) {
Expand All @@ -687,7 +683,8 @@ void handle_address_ad(uint16_t federate_id) {
assert(server_port < 65536);

LF_MUTEX_LOCK(&rti_mutex);
((socket_priv_t*)fed->net)->server_port = server_port;
// (((sst_priv_t*)fed->net)->socket_priv)->server_port = server_port;
set_server_port(fed->net, server_port);
LF_MUTEX_UNLOCK(&rti_mutex);

LF_PRINT_LOG("Received address advertisement with port %d from federate %d.", server_port, federate_id);
Expand Down Expand Up @@ -1057,7 +1054,6 @@ void send_reject(net_abstraction_t net_abs, unsigned char error_code) {
}
// Close the network abstraction without reading until EOF.
shutdown_net(net_abs, false);
net_abs = NULL;
LF_MUTEX_UNLOCK(&rti_mutex);
}

Expand Down Expand Up @@ -1325,7 +1321,7 @@ static int receive_udp_message_and_set_up_clock_sync(net_abstraction_t fed_net,
// Initialize the UDP_addr field of the federate struct
fed->UDP_addr.sin_family = AF_INET;
fed->UDP_addr.sin_port = htons(federate_UDP_port_number);
fed->UDP_addr.sin_addr = ((socket_priv_t*)fed_net)->server_ip_addr;
fed->UDP_addr.sin_addr = *get_ip_addr(fed_net);
}
} else {
// Disable clock sync after initial round.
Expand Down Expand Up @@ -1427,7 +1423,6 @@ void lf_connect_to_federates(net_abstraction_t rti_net) {
lf_print_warning("RTI failed to authenticate the incoming federate.");
// Close the network abstraction without reading until EOF.
shutdown_net(fed_net, false);
fed_net = NULL;
// Ignore the federate that failed authentication.
i--;
continue;
Expand Down Expand Up @@ -1496,7 +1491,6 @@ void* respond_to_erroneous_connections(void* nothing) {
}
// Close the network abstraction without reading until EOF.
shutdown_net(fed_net, false);
fed_net = NULL;
}
return NULL;
}
Expand All @@ -1513,7 +1507,7 @@ int start_rti_server() {
// Initialize RTI's network abstraction.
rti_remote->rti_net = initialize_net();
// Set the user specified port to the network abstraction.
((socket_priv_t*)rti_remote->rti_net)->user_specified_port = rti_remote->user_specified_port;
set_my_port(rti_remote->rti_net, rti_remote->user_specified_port);
// Create the server
if (create_server(rti_remote->rti_net)) {
lf_print_error_system_failure("RTI failed to create TCP server: %s.", strerror(errno));
Expand Down
2 changes: 1 addition & 1 deletion core/federated/RTI/rti_remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void handle_address_query(uint16_t fed_id);
* byte. The RTI will keep a record of this number in the .server_port
* field of the _RTI.federates[federate_id] array of structs.
*
* The server_hostname and server_ip_addr fields are assigned
* The server_ip_addr field is assigned
* in lf_connect_to_federates() upon accepting the socket
* from the remote federate.
*
Expand Down
94 changes: 61 additions & 33 deletions core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,16 @@ static int handle_tagged_message(net_abstraction_t net, int fed_id) {
" Discarding message and closing the network connection.",
env->current_tag.time - start_time, env->current_tag.microstep, intended_tag.time - start_time,
intended_tag.microstep);
// Free the allocated memory before returning
_lf_done_using(message_token);
// Close network abstraction, reading any incoming data and discarding it.
shutdown_net(_fed.net_for_inbound_p2p_connections[fed_id], false);
_fed.net_for_inbound_p2p_connections[fed_id] = NULL;
// The token was freshly allocated by _lf_new_token with ref_count 0 and was never
// scheduled, so _lf_done_using would incorrectly treat it as already freed.
// Use _lf_free_token directly, which handles ref_count == 0 correctly.
_lf_free_token(message_token);
#ifdef FEDERATED_DECENTRALIZED
_lf_decrement_tag_barrier_locked(env);
#endif
// Close the connection to unblock the listener, but do not free the memory;
// lf_terminate_execution will free it after joining the listener thread.
close_net(net, false);
LF_MUTEX_UNLOCK(&env->mutex);
return -1;
} else {
Expand Down Expand Up @@ -723,7 +728,6 @@ static int handle_port_absent_message(net_abstraction_t net, int fed_id) {
* network abstraction in _fed.net_for_inbound_p2p_connections
* to -1 and returns, terminating the thread.
* @param _args The remote federate ID (cast to void*).
* @param fed_id_ptr A pointer to a uint16_t containing federate ID being listened to.
* This procedure frees the memory pointed to before returning.
*/
static void* listen_to_federates(void* _args) {
Expand Down Expand Up @@ -1508,23 +1512,21 @@ static void* listen_to_rti_net(void* args) {
// Listen for messages from the federate.
while (!_lf_termination_executed) {
// Check whether the RTI network abstraction is still valid.
if (_fed.net_to_RTI == NULL) {
lf_print_warning("network abstraction to the RTI unexpectedly closed.");
if (_fed.net_to_RTI == NULL || !is_net_open(_fed.net_to_RTI)) {
lf_print_warning("network connection to the RTI unexpectedly closed.");
return NULL;
}
// Read one byte to get the message type.
// This will exit if the read fails.
int read_failed = read_from_net(_fed.net_to_RTI, 1, buffer);
if (read_failed < 0) {
lf_print_error("Connection to the RTI was closed by the RTI with an error. Considering this a soft error.");
shutdown_net(_fed.net_to_RTI, false);
_fed.net_to_RTI = NULL;
close_net(_fed.net_to_RTI, false);
return NULL;
} else if (read_failed > 0) {
// EOF received.
lf_print_info("Connection to the RTI closed with an EOF.");
shutdown_net(_fed.net_to_RTI, false);
_fed.net_to_RTI = NULL;
close_net(_fed.net_to_RTI, false);
return NULL;
}
switch (buffer[0]) {
Expand Down Expand Up @@ -1647,22 +1649,17 @@ void lf_terminate_execution(environment_t* env) {
}

LF_PRINT_DEBUG("Closing incoming P2P network abstractions.");
// Close any incoming P2P network abstractions that are still open.
// Close connections to unblock any listener threads that are blocking on reads,
// but do NOT free the memory yet because listener threads hold local pointers.
for (int i = 0; i < NUMBER_OF_FEDERATES; i++) {
shutdown_net(_fed.net_for_inbound_p2p_connections[i], false);
// Ignore errors. Mark the network abstraction closed.
_fed.net_for_inbound_p2p_connections[i] = NULL;
close_net(_fed.net_for_inbound_p2p_connections[i], false);
}

// Check for all outgoing physical connections in
// _fed.net_for_outbound_p2p_connections and
// if the network abstraction ID is not NULL, the connection is still open.
// Send an EOF by closing the network abstraction here.
for (int i = 0; i < NUMBER_OF_FEDERATES; i++) {

// Close outbound connections, in case they have not closed themselves.
// This will result in EOF being sent to the remote federate, except for
// abnormal termination, in which case it will just close the network abstraction.
close_outbound_net(i);
}

Expand All @@ -1681,6 +1678,14 @@ void lf_terminate_execution(environment_t* env) {
// Wait for the thread listening for messages from the RTI to close.
lf_thread_join(_fed.RTI_net_listener, NULL);

// All listener threads have now exited. Safe to free network abstraction memory.
for (int i = 0; i < NUMBER_OF_FEDERATES; i++) {
free_net(_fed.net_for_inbound_p2p_connections[i]);
_fed.net_for_inbound_p2p_connections[i] = NULL;
}
free_net(_fed.net_to_RTI);
_fed.net_to_RTI = NULL;

// For abnormal termination, there is no need to free memory.
if (_lf_normal_termination) {
LF_PRINT_DEBUG("Freeing memory occupied by the federate.");
Expand Down Expand Up @@ -1753,13 +1758,24 @@ void lf_connect_to_federate(uint16_t remote_federate_id) {
assert(port > 0);
uint16_t uport = (uint16_t)port;

char hostname[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &host_ip_addr, hostname, INET_ADDRSTRLEN);

socket_connection_params_t params;
#ifdef COMM_TYPE_TCP
socket_connection_params_t params = {0};
params.type = TCP;
params.port = uport;
params.server_hostname = hostname;
params.server_ip_addr = &host_ip_addr;
#elif defined(COMM_TYPE_SST)
sst_connection_params_t params = {0};
params.socket_params.type = TCP;
params.socket_params.port = uport;
params.socket_params.server_ip_addr = &host_ip_addr;
params.target = 1;
#elif defined(COMM_TYPE_TLS)
tls_connection_params_t params = {0};
params.socket_params.type = TCP;
params.socket_params.port = uport;
params.socket_params.server_ip_addr = &host_ip_addr;
#endif

net_abstraction_t net = connect_to_net((net_params_t)&params);
if (net == NULL) {
lf_print_error_and_exit("Failed to connect to federate.");
Expand Down Expand Up @@ -1837,10 +1853,24 @@ void lf_connect_to_rti(const char* hostname, int port) {
hostname = federation_metadata.rti_host ? federation_metadata.rti_host : hostname;
port = federation_metadata.rti_port >= 0 ? federation_metadata.rti_port : port;

socket_connection_params_t params;
#ifdef COMM_TYPE_TCP
socket_connection_params_t params = {0};
params.type = TCP;
params.port = port;
params.server_hostname = hostname;
#elif defined(COMM_TYPE_SST)
sst_connection_params_t params = {0};
params.socket_params.type = TCP;
params.socket_params.port = port;
params.socket_params.server_hostname = hostname;
params.target = 0;
#elif defined(COMM_TYPE_TLS)
tls_connection_params_t params = {0};
params.socket_params.type = TCP;
params.socket_params.port = port;
params.socket_params.server_hostname = hostname;
#endif

net_abstraction_t net = connect_to_net((net_params_t)&params);
if (net == NULL) {
lf_print_error_and_exit("Failed to connect to RTI.");
Expand Down Expand Up @@ -1949,14 +1979,13 @@ void lf_create_server(int specified_port) {
assert(specified_port <= UINT16_MAX && specified_port >= 0);

net_abstraction_t server_net = initialize_net();
((socket_priv_t*)server_net)->port = (uint16_t)specified_port;

set_my_port(server_net, specified_port);
if (create_server(server_net)) {
lf_print_error_system_failure("Failed to create server: %s.", strerror(errno));
};
_fed.server_net = server_net;
// Get the final server port to send to the RTI on an MSG_TYPE_ADDRESS_ADVERTISEMENT message.
int32_t server_port = ((socket_priv_t*)server_net)->port;
int32_t server_port = get_my_port(server_net);

LF_PRINT_LOG("Server for communicating with other federates started using port %d.", server_port);

Expand Down Expand Up @@ -2007,13 +2036,14 @@ void* lf_handle_p2p_connections_from_federates(void* env_arg) {
_fed.inbound_net_listeners = (lf_thread_t*)calloc(_fed.number_of_inbound_p2p_connections, sizeof(lf_thread_t));
while (received_federates < _fed.number_of_inbound_p2p_connections && !_lf_termination_executed) {
if (rti_failed()) {
break;
return NULL;
}
// Wait for an incoming connection request.
net_abstraction_t net = accept_net(_fed.server_net);
if (net == NULL) {
lf_print_warning("Federate failed to accept the network abstraction.");
return NULL;
lf_sleep(CONNECT_RETRY_INTERVAL);
continue;
}
LF_PRINT_LOG("Accepted new connection from remote federate.");

Expand All @@ -2034,7 +2064,6 @@ void* lf_handle_p2p_connections_from_federates(void* env_arg) {
write_to_net(net, 2, response);
}
shutdown_net(net, false);
net = NULL;
continue;
}

Expand All @@ -2055,7 +2084,6 @@ void* lf_handle_p2p_connections_from_federates(void* env_arg) {
write_to_net(net, 2, response);
}
shutdown_net(net, false);
net = NULL;
continue;
}

Expand Down
Loading
Loading