A workaround is added in https://github.com/openenclave/openenclave/pull/3719 in host.cpp file to wait for a one and half minute till the socket connections are moved from TIME_WAIT state to TIME_CLOSE state. This is a forced delay and test cases will take longer time to complete. Find a fix to remove or reduce this forced delay.
This should be simple to fix. host.cpp line 21 has:
define SERVER_PORT "12345"
which is then passed to
setup_tls_server()andlaunch_tls_client().
The bug is that the same static port is used every run. Instead, a different port should be used each run. The best answer would be to make the server use an ephemeral port by passing 0, an then looking up what port was chosen and passing that back out of setup_tls_server(), but it appears the mbedtls net_sockets library does not expose a wrapper around getsockaddr so you'd have to modify mbedtls to take that approach. Without changing mbedtls you can still pick different ports from the host and pass them in instead of a fixed port. You can pick a random number, or a series of sequential ports, but the main point is to be able to try multiple until the server's bind succeeds and then use that with the client.
Do we need to communicate the port number back to the client once socket bind succeeds on the server side? I am guessing this would mean lot of code change. @dthaler .
Do we need to communicate the port number back to the client once socket bind succeeds on the server side? I am guessing this would mean lot of code change. @dthaler .
Yes, that's how you fix it. "A lot" is subjective (I wouldn't say it's a lot myself), but if you consider fixing the design to be "a lot" then yes, since "a lot" of the code is broken in that respect.
@dthaler As server and client are completely independent enclaves with seperate host files, what could be the interface through which server can communicate the port number to the client?
You either return it from the ECALL, or you generate it from the host and pass it into both the client and the server via an ECALL parameter.
FYI server port 12345 is allocated to someone else:
https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=12345
Service Name | Port Number | Transport Protocol | Description | Assignee | Contact | Registration Date | Modification Date | Reference | Service Code | Unauthorized Use Reported | Assignment Notes
-- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | --
italk | 12345 | tcp | Italk Chat System | [Takayuki_Ito] | [Takayuki_Ito] | 聽 | 聽 | 聽 | 聽 | 聽 | 聽