File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ echo "Starting vsock proxy..."
2424
2525TIME_SYNC_URL=" http://127.0.0.1:27015/getCurrentTime"
2626TIME_SYNC_INTERVAL_SECONDS=" ${TIME_SYNC_INTERVAL_SECONDS:- 300} "
27+ TIME_SYNC_OFFSET_SECONDS=" ${TIME_SYNC_OFFSET_SECONDS:- 30} "
2728
2829sync_enclave_time () {
2930 local current_time
@@ -48,14 +49,34 @@ sync_enclave_time() {
4849 fi
4950}
5051
52+ sync_enclave_time_with_offset_once () {
53+ local current_time
54+ local parent_epoch
55+ if current_time=$( curl -s -f -x socks5h://127.0.0.1:3305 " ${TIME_SYNC_URL} " ) ; then
56+ parent_epoch=$( date -u -d " ${current_time} " +%s 2> /dev/null || true)
57+ if [[ -n " ${parent_epoch} " ]]; then
58+ parent_epoch=$(( parent_epoch + TIME_SYNC_OFFSET_SECONDS))
59+ if ! date -u -s " @${parent_epoch} " ; then
60+ echo " Time sync: failed to set enclave time from '${current_time} ' with offset ${TIME_SYNC_OFFSET_SECONDS} s"
61+ return 1
62+ fi
63+ echo " Time sync: updated enclave time to ${current_time} + ${TIME_SYNC_OFFSET_SECONDS} s"
64+ fi
65+ else
66+ echo " Time sync: failed to fetch time from parent instance"
67+ return 1
68+ fi
69+ }
70+
71+ sync_enclave_time_with_offset_once || true
72+
5173start_time_sync_loop () {
5274 while true ; do
5375 sync_enclave_time || true
5476 sleep " ${TIME_SYNC_INTERVAL_SECONDS} "
5577 done
5678}
5779
58- sync_enclave_time || true
5980start_time_sync_loop &
6081
6182build_parameterized_config () {
You can’t perform that action at this time.
0 commit comments