Skip to content

Conversation

@vincewoo
Copy link
Collaborator

@vincewoo vincewoo commented Jun 4, 2025

Related Issue(s) #3445
Has Unit Tests (y/n) y
Documentation Included (y/n) y

Change Description

This change adds the ability to support ephemeral ports when using UdpSocket.

In the sender case, you could set up your receive port as 0 to be assigned an ephemeral port for responses.
In the receiver case, you will be able to reply to the port that is specified in the UDP datagram of the first received message.

Rationale

This improves F' compliance to the UDP specification and allows for the use of ephemeral ports.

Testing/Review Recommendations

Added test case to TestUdp:

TestEphemeralPorts - Set up a receiver specifying 0 for the port to be assigned an ephemeral one. Setup a sender that is full duplex (with an ephemeral receive port). Send a message from the sender and ensure it is received properly by the receiver. Send a response back from the receiver and ensure that it is received properly by the sender.

Future Work

In the current implementation it only supports responding to messages from a single sender. If we need to support being able to reply to multiple senders this would require a different design.


struct sockaddr_in sender_addr;
socklen_t sender_addr_len = sizeof(sender_addr);
I32 received = static_cast<I32>(::recvfrom(socketDescriptor.fd, data, size, SOCKET_IP_RECV_FLAGS,

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter socketDescriptor has not been checked.

struct sockaddr_in sender_addr;
socklen_t sender_addr_len = sizeof(sender_addr);
I32 received = static_cast<I32>(::recvfrom(socketDescriptor.fd, data, size, SOCKET_IP_RECV_FLAGS,

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter data has not been checked.

struct sockaddr_in sender_addr;
socklen_t sender_addr_len = sizeof(sender_addr);
I32 received = static_cast<I32>(::recvfrom(socketDescriptor.fd, data, size, SOCKET_IP_RECV_FLAGS,

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter size has not been checked.
@vincewoo vincewoo requested a review from LeStarch June 4, 2025 08:08
Copy link
Collaborator

@LeStarch LeStarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add update and store and forward

@LeStarch LeStarch requested a review from zimri-leisher June 4, 2025 21:58
@LeStarch
Copy link
Collaborator

LeStarch commented Jun 4, 2025

@zimri-leisher change to UDP, would you take a look?

LeStarch
LeStarch previously approved these changes Jun 5, 2025
Copy link
Collaborator

@LeStarch LeStarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor question, but otherwise looks good.

@zimri-leisher
Copy link
Collaborator

zimri-leisher commented Jun 7, 2025

Aside from the confusing internal state of this component, this PR looks good to me. My highest priority is that this not change any existing behavior, and it doesn't appear to.

@LeStarch
Copy link
Collaborator

Thanks @zimri-leisher see #3716 for follow-up.

@LeStarch LeStarch merged commit bda0b25 into nasa:devel Jun 11, 2025
47 checks passed
@vincewoo vincewoo deleted the FP-3445 branch August 6, 2025 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants