A Python port of the Invisible Internet Project (I2P)
at main 53 lines 1.6 kB view raw
1"""Build time sanity checks — earliest/latest reasonable system clock values. 2 3Ported from net.i2p.time.BuildTime. 4""" 5 6import time 7from datetime import datetime, timezone 8 9 10# Hardcoded earliest reasonable time (update periodically) 11_EARLIEST_STR = "2025-05-26 12:00:00" 12_EARLIEST_LONG_MS = 1748217600 * 1000 # fallback if parse fails 13_YEARS_25_MS = 25 * 365 * 24 * 60 * 60 * 1000 14 15 16def _parse_earliest() -> int: 17 """Parse the earliest reasonable time string, return ms since epoch.""" 18 try: 19 dt = datetime.strptime(_EARLIEST_STR, "%Y-%m-%d %H:%M:%S").replace( 20 tzinfo=timezone.utc 21 ) 22 return int(dt.timestamp() * 1000) 23 except (ValueError, OverflowError): 24 return _EARLIEST_LONG_MS 25 26 27_earliest_time = _parse_earliest() 28_latest_time = _earliest_time + _YEARS_25_MS 29# In Python context, we don't read JAR manifests — build time = earliest 30_build_time = _earliest_time 31 32 33class BuildTime: 34 """Get build date sanity bounds for clock validation. 35 36 In the Python port, we don't read JAR manifests, so build_time 37 defaults to the hardcoded earliest time. 38 """ 39 40 @staticmethod 41 def get_build_time() -> int: 42 """Return build time in milliseconds since epoch.""" 43 return _build_time 44 45 @staticmethod 46 def get_earliest_time() -> int: 47 """Return the earliest reasonable time in ms since epoch.""" 48 return _earliest_time 49 50 @staticmethod 51 def get_latest_time() -> int: 52 """Return the latest reasonable time in ms since epoch.""" 53 return _latest_time