File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,30 @@ TIME_SYNC_URL="http://127.0.0.1:27015/getCurrentTime"
2626TIME_SYNC_PROXY=" socks5h://127.0.0.1:3305"
2727TIME_SYNC_INTERVAL_SECONDS=" 300"
2828
29+ TIME_SYNC_OFFSET_SECONDS=" ${TIME_SYNC_OFFSET_SECONDS:- 30} "
30+
31+ sync_enclave_time_with_offset_once () {
32+ local current_time
33+ local parent_epoch
34+ if current_time=$( curl -s -f -x socks5h://127.0.0.1:3305 " ${TIME_SYNC_URL} " ) ; then
35+ parent_epoch=$( date -u -d " ${current_time} " +%s 2> /dev/null || true)
36+ if [[ -n " ${parent_epoch} " ]]; then
37+ parent_epoch=$(( parent_epoch + TIME_SYNC_OFFSET_SECONDS))
38+ if ! date -u -s " @${parent_epoch} " ; then
39+ echo " Time sync: failed to set enclave time from '${current_time} ' with offset ${TIME_SYNC_OFFSET_SECONDS} s"
40+ return 1
41+ fi
42+ echo " Time sync: updated enclave time to ${current_time} + ${TIME_SYNC_OFFSET_SECONDS} s"
43+ fi
44+ else
45+ echo " Time sync: failed to fetch time from parent instance"
46+ return 1
47+ fi
48+ }
49+
50+ sync_enclave_time_with_offset_once || true
51+
52+
2953enable_time_sync_timer () {
3054 if ! command -v systemctl > /dev/null 2>&1 || [[ ! -d /run/systemd/system ]]; then
3155 echo " Time sync: systemd not available; skipping timer setup" >&2
4872Description=UID2 enclave time sync timer
4973
5074[Timer]
51- OnBootSec=30s
75+ OnBootSec=300s
5276OnUnitActiveSec=${TIME_SYNC_INTERVAL_SECONDS} s
5377Unit=uid2-time-sync.service
5478Persistent=true
You can’t perform that action at this time.
0 commit comments