Skip to content

fix!: rename timestamp fields to embed time unit in field name#44

Open
VasilevNStas wants to merge 1 commit into
APN-Network:masterfrom
VasilevNStas:12-fix/time-unit-names
Open

fix!: rename timestamp fields to embed time unit in field name#44
VasilevNStas wants to merge 1 commit into
APN-Network:masterfrom
VasilevNStas:12-fix/time-unit-names

Conversation

@VasilevNStas

Copy link
Copy Markdown
Contributor

Description

Renames three timestamp fields across auth.proto, ping.proto, and pong.proto to embed their time unit in the field name, preventing silent arithmetic errors when values in different units are inadvertently combined.

Problem

The protocol uses three different time units with identical field names:

Field Unit Epoch
Auth.timestamp minutes 2024-01-01 UTC
Ping.timestamp / Pong.timestamp milliseconds Unix
All lease/expiry/cutoff fields seconds Unix

A client computing Pong.cutoff - Pong.timestamp would get a result in mixed seconds-minus-milliseconds. Proto3 provides no type-level guard since all fields are uint64.

Fix

Before After Same wire number
Auth.timestamp = 2 Auth.timestamp_min = 2
Ping.timestamp = 1 Ping.timestamp_ms = 1
Pong.timestamp = 1 Pong.timestamp_ms = 1

Migration

Wire format is backward-compatible (field numbers unchanged). Source-level: all generated struct field names change from timestamp to timestamp_min / timestamp_ms.

Closes #12

Three different time units were used across the protocol with no
naming distinction: Auth.timestamp (minutes since project epoch),
Ping/Pong.timestamp (ms since Unix epoch), and all lease/expiry
fields (seconds since Unix epoch). A client computing e.g.
Pong.cutoff - Pong.timestamp would get a result in mixed
seconds-minus-milliseconds with no type-level guard.

Rename:
  Auth.timestamp     -> timestamp_min   (minutes since 2024-01-01 UTC)
  Ping.timestamp     -> timestamp_ms    (ms since Unix epoch)
  Pong.timestamp     -> timestamp_ms    (echo of Ping.timestamp_ms)

Field numbers are unchanged, so the wire format is compatible.
Generated code symbols change (source break).
@VasilevNStas

Copy link
Copy Markdown
Contributor Author

@davvd plz review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Three inconsistent time units across proto files cause silent arithmetic errors

1 participant