https://github.com/lemon-mint/timeserver
Go HTTP Time Server
https://github.com/lemon-mint/timeserver
Last synced: 3 months ago
JSON representation
Go HTTP Time Server
- Host: GitHub
- URL: https://github.com/lemon-mint/timeserver
- Owner: lemon-mint
- License: mit
- Created: 2022-11-19T23:50:08.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-29T15:31:42.000Z (almost 2 years ago)
- Last Synced: 2025-01-20T10:11:42.903Z (4 months ago)
- Language: TypeScript
- Homepage:
- Size: 27.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Time Server
HTTP Time Server that returns the current server time
# How it works
## Terminology
- `t0`: time when the client sends the request
- `t1`: time when the server receives the request
- `t2`: time when the server sends the response
- `t3`: time when the client receives the response## Protocol
1. The Client sends a request `GET /tt` to the server.
The server is written in Go and returns the current time in the following format:
```plaintext
18446744073709551615$18446744073709551615
```2. The Client can parse the response by splitting the string by `$` and converting the first part to `t1` and the second part to `t2`.
3. The Client can calculate offset by the following formula:
```plaintext
offset = (t1 - t0 + t2 - t3) / 2;
```4. The Client also can calculate sync error by the following formula:
```plaintext
error = Math.abs(t3 - t0 - (t2 - t1)) / 2;
```5. The Client repeats the request several times and calculates and records the offset and error for each request.
6. After that client calculates the confidence interval using the [Intersection algorithm](https://en.wikipedia.org/wiki/Intersection_algorithm).