Open Jakio815 opened 2 weeks ago
It does look like the clock sync code should be sending and receiving uint16_t
. This should be a small fix. Do you want to issue a PR?
The use of an int32_t for recording the ID, I think, is so that -1 can be used to indicate an error or unknown. I don't see why this would create problems. Can you clarify?
I don't understand the question about 16-bit systems. Even a 16-bit system should respect these data types.
Oh, now I see why it's recording it as int32_t.
The point I was concerned is on this part.
// util.c
/**
* The ID of this federate. For a non-federated execution, this will be -1.
* For a federated execution, it will be assigned in the generated code.
*/
int _lf_my_fed_id = -1;
It's just saving it as an int
type not uint16_t
or int32_t
. In this case, wouldn't the int
type be saved in int16_t
in 16 byte systems?
Oh, possibly, yes. This would be better declared as an int32_t
.
I made a PR on this issue. #453
The use of federate_id's type is being mixed.
Definition of federate_id on the federate side. It is defined as int.
The federate sends the federate_id on
MSG_TYPE_FED_IDS
. It is sending it as unit16_t.The RTI receives the federate_id. Receives as uint16_t.
The function which received the federate_id, returns it as int32_t.
RTI mixes up using it.
Later on clock synchronization. Federate sends
MSG_TYPE_CLOCK_SYNC_T3
with its federate_id as int32_t. However the buffer size is defined as1 +sizeof(int)
which can be critical for 16-bit systems.RTI receives this message, and compares the federate_id. It extracts the received federate_id as int32_t. However, it compares with the
fed->enclave.id
, which is uint16_tSo, is this intended? Or is it just a bug. It seems it didn't really matter because we are not using federates more than 2^16. However, it seems that the part
int _lf_my_fed_id = -1;
that defines the federate_id asint
seems dangerous, when considering using 16-bit systems. Sending MSG_TYPE_CLOCK_SYNC_T3 on 16-bit systems will only send 1+2 bytes, and the RTI will attempt to read 1 + 4bytes, which will block on the read().