fix(db): use int for netspeed_active to prevent overflow
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
GetZoneStatsData and GetZoneStatsV2's netspeed_active values can exceed 2 billion, causing 32-bit integer overflow. Changed from int32/uint32 to int (64-bit on modern systems) to handle large network speed totals. - Update sqlc column overrides to use int type - Fix type compatibility in dnsanswers.go zoneTotals map - Regenerate database code with new types Fixes https://community.ntppool.org/t/error-message-displayed-on-the-monitoring-score-page/4063
This commit is contained in:
@@ -339,5 +339,5 @@ type ZoneServerCount struct {
|
||||
Date time.Time `db:"date" json:"date"`
|
||||
CountActive uint32 `db:"count_active" json:"count_active"`
|
||||
CountRegistered uint32 `db:"count_registered" json:"count_registered"`
|
||||
NetspeedActive uint32 `db:"netspeed_active" json:"netspeed_active"`
|
||||
NetspeedActive int `db:"netspeed_active" json:"netspeed_active"`
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ type GetZoneStatsDataRow struct {
|
||||
IpVersion ZoneServerCountsIpVersion `db:"ip_version" json:"ip_version"`
|
||||
CountActive uint32 `db:"count_active" json:"count_active"`
|
||||
CountRegistered uint32 `db:"count_registered" json:"count_registered"`
|
||||
NetspeedActive uint32 `db:"netspeed_active" json:"netspeed_active"`
|
||||
NetspeedActive int `db:"netspeed_active" json:"netspeed_active"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetZoneStatsData(ctx context.Context) ([]GetZoneStatsDataRow, error) {
|
||||
@@ -484,7 +484,7 @@ AS server_netspeed
|
||||
|
||||
type GetZoneStatsV2Row struct {
|
||||
ZoneName string `db:"zone_name" json:"zone_name"`
|
||||
NetspeedActive int32 `db:"netspeed_active" json:"netspeed_active"`
|
||||
NetspeedActive int `db:"netspeed_active" json:"netspeed_active"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetZoneStatsV2(ctx context.Context, ip string) ([]GetZoneStatsV2Row, error) {
|
||||
|
||||
@@ -123,7 +123,7 @@ func (srv *Server) dnsAnswers(c echo.Context) error {
|
||||
return c.String(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
zoneTotals := map[string]int32{}
|
||||
zoneTotals := map[string]int{}
|
||||
|
||||
for _, z := range zoneStats {
|
||||
zn := z.ZoneName
|
||||
@@ -145,7 +145,7 @@ func (srv *Server) dnsAnswers(c echo.Context) error {
|
||||
if zt == 0 {
|
||||
// if the recorded netspeed for the zone was zero, assume it's at least
|
||||
// this servers worth instead. Otherwise the Netspeed gets to be 'infinite'.
|
||||
zt = int32(serverNetspeed)
|
||||
zt = int(serverNetspeed)
|
||||
}
|
||||
cc.Netspeed = (pointBasis / float64(zt)) * float64(serverNetspeed)
|
||||
}
|
||||
|
||||
@@ -18,4 +18,8 @@ sql:
|
||||
- column: log_scores.attributes
|
||||
go_type: go.ntppool.org/common/types.LogScoreAttributes
|
||||
- column: "server_netspeed.netspeed_active"
|
||||
go_type: "uint64"
|
||||
go_type: "int"
|
||||
- column: "zone_server_counts.netspeed_active"
|
||||
go_type: "int"
|
||||
- db_type: "bigint"
|
||||
go_type: "int"
|
||||
|
||||
Reference in New Issue
Block a user