Skip to content

Commit

Permalink
Add Sntp_ReceiveTimeResponse API (#16)
Browse files Browse the repository at this point in the history
Add a Sntp_ReceiveTimeResponse API to allow application to obtain the response for a time request that was made to a server (with Sntp_SendTimeRequest API).

The API looks at 3 different timeouts in its operations:

Server Response timeout - This PR adds a responseTimeoutMs state to the SntpContext_t to allow the application to specify timeouts for server responses (to time requests). The timeout period for a server starts after the Sntp_SendTimeRequest API is called to send a request to the server. The Sntp_ReceiveTimeResponse API keeps a track of whether server response has timed out whenever it is called, and returns a SntpServerResponseTimeout error code (even if the blockTimeMs value still allows more time window for waiting on server response).

Block Time - The API takes a blockTimeMs parameter which determines the maximum amount of time the function will block waiting for the server response UNLESS either the server response is received OR the server response has timed out OR there is a network read error encountered (like hitting a read retry timeout)

Read Retry Timeout - This PR adds an SNTP_RECV_POLLING_TIMEOUT_MS configuration macro that represents the maximum time window of retrying zero data reads. This window is only initiated after some partial data is initially read from the network. The rationale is that when some initial data is available from the network, then it is likely that the remaining SNTP response packet will be available and thus, the read retry timeout window starts. The Sntp_ReceiveTimeResponse API uses this configuration value to retry partial data reads on the network.
  • Loading branch information
aggarw13 authored May 13, 2021
1 parent d815239 commit cb9a306
Show file tree
Hide file tree
Showing 7 changed files with 781 additions and 50 deletions.
36 changes: 33 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,54 @@ jobs:
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_CLONE_SUBMODULES=ON \
-DCMAKE_C_FLAGS='-Wall -Wextra -Werror'
-DCMAKE_C_FLAGS='-O0 -Wall -Wextra -Werror -Wformat -Wformat-security -Warray-bounds'
make -C build/ coverity_analysis -j8
- name: Build Library in Release mode
run: |
rm -rf ./build
cmake -S test -B build/ -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_CLONE_SUBMODULES=ON \
-DCMAKE_C_FLAGS='-Wall -Wextra -Werror -DNDEBUG'
-DCMAKE_C_FLAGS='-Wall -Wextra -Werror -DNDEBUG -Wformat -Wformat-security -Warray-bounds'
make -C build/ coverity_analysis -j8
unittest-and-coverage:
unittest-with-sanitizer:
runs-on: ubuntu-latest
steps:
- name: Clone This Repo
uses: actions/checkout@v2
- name: Build Library and Unit Tests with Sanitizer
run: |
CFLAGS="-O0 -Wall -Wexta -Werror"
CFLAGS+=" -D_FORTIFY_SOURCE=2"
CFLAGS+=" -Wformat"
CLFAGS+=" -Wformat-security"
CFLAGS+=" -Warray-bounds"
CFLAGS+=" -fsanitize=address,undefined"
CFLAGS+=" -fsanitize=pointer-compare -fsanitize=pointer-subtract"
CFLAGS+=" -fsanitize-recover=undefined"
CFLAGS+=" -fsanitize-address-use-after-scope"
CFLAGS+=" -fsanitize-undefined-trap-on-error"
CFLAGS=" -fstack-protector-all -DLOGGING_LEVEL_DEBUG=1"
cmake -S test -B build/ \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_CLONE_SUBMODULES=ON \
-DCMAKE_C_FLAGS="${CFLAGS}"
make -C build all -j8
- name: Run unit tests with sanitizer
run: |
cd build
ctest -E system --output-on-failure
cd ..
unittest-for-coverage:
runs-on: ubuntu-latest
steps:
- name: Clone This Repo
uses: actions/checkout@v2
- name: Build
run: |
sudo apt-get install -y lcov sed
# Build with logging enabled.
cmake -S test -B build/ \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
Expand Down
12 changes: 12 additions & 0 deletions lexicon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ apis
ascii
auth
authcodesize
authintf
aws
backoff
beforelooptime
blocktimems
br
buffersize
bytesremaining
Expand All @@ -29,6 +31,8 @@ currenttimelist
de
deamon
december
deserialize
deserializer
deserializeresponse
desiredaccuracy
dns
Expand Down Expand Up @@ -65,6 +69,7 @@ jan
january
june
kod
leapsecondinfo
leapversionmode
lsb
misra
Expand Down Expand Up @@ -118,6 +123,7 @@ psntptime
ptimeserver
ptimeservers
ptr
ptransportintf
pudptransportintf
punixtimemicrosecs
punixtimesecs
Expand Down Expand Up @@ -149,6 +155,7 @@ serializerequest
serveraddr
servernamelen
serverport
serverresponsetimeoutms
setsystemtimefunc
sizeof
sntp
Expand All @@ -161,8 +168,11 @@ sntperrorbuffertoosmall
sntperrorchangeserver
sntperrordnsfailure
sntperrornetworkfailure
sntperrorresponsetimeout
sntperrortimenotsupported
sntpinvalidresponse
sntpnoresponse
sntprejectedresponse
sntprejectedresponsechangeserver
sntprejectedresponseothercode
sntprejectedresponseretrywithbackoff
Expand All @@ -182,10 +192,12 @@ transmittime
trng
tx
udp
udprecvretcodes
udpsendretcodes
uint
unix
utc
validateserverauth
wordmemory
wordval
www
Expand Down
Loading

0 comments on commit cb9a306

Please sign in to comment.