2019-08-08 14:47:04 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package reputation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2020-12-11 21:15:17 +00:00
|
|
|
"storj.io/common/pb"
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/storj"
|
2019-08-08 14:47:04 +01:00
|
|
|
)
|
|
|
|
|
2020-12-05 16:01:42 +00:00
|
|
|
// DB works with reputation database.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Database
|
2019-08-08 14:47:04 +01:00
|
|
|
type DB interface {
|
|
|
|
// Store inserts or updates reputation stats into the DB
|
|
|
|
Store(ctx context.Context, stats Stats) error
|
|
|
|
// Get retrieves stats for specific satellite
|
|
|
|
Get(ctx context.Context, satelliteID storj.NodeID) (*Stats, error)
|
2019-08-28 21:54:12 +01:00
|
|
|
// All retrieves all stats from DB
|
|
|
|
All(ctx context.Context) ([]Stats, error)
|
2019-08-08 14:47:04 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Stats consist of reputation metrics.
|
2019-08-08 14:47:04 +01:00
|
|
|
type Stats struct {
|
|
|
|
SatelliteID storj.NodeID
|
|
|
|
|
2020-09-01 12:20:12 +01:00
|
|
|
Audit Metric
|
|
|
|
OnlineScore float64
|
2019-08-08 14:47:04 +01:00
|
|
|
|
2020-09-02 16:37:54 +01:00
|
|
|
DisqualifiedAt *time.Time
|
|
|
|
SuspendedAt *time.Time
|
|
|
|
OfflineSuspendedAt *time.Time
|
|
|
|
OfflineUnderReviewAt *time.Time
|
2020-12-11 21:15:17 +00:00
|
|
|
AuditHistory *pb.AuditHistory
|
2019-08-28 21:54:12 +01:00
|
|
|
|
2019-08-08 14:47:04 +01:00
|
|
|
UpdatedAt time.Time
|
2020-04-16 16:40:28 +01:00
|
|
|
JoinedAt time.Time
|
2019-08-08 14:47:04 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Metric encapsulates storagenode reputation metrics.
|
2019-08-08 14:47:04 +01:00
|
|
|
type Metric struct {
|
2019-08-14 13:17:11 +01:00
|
|
|
TotalCount int64 `json:"totalCount"`
|
|
|
|
SuccessCount int64 `json:"successCount"`
|
2019-08-08 14:47:04 +01:00
|
|
|
|
2020-05-03 17:30:54 +01:00
|
|
|
Alpha float64 `json:"alpha"`
|
|
|
|
Beta float64 `json:"beta"`
|
|
|
|
UnknownAlpha float64 `json:"unknownAlpha"`
|
|
|
|
UnknownBeta float64 `json:"unknownBeta"`
|
|
|
|
Score float64 `json:"score"`
|
2020-05-18 11:01:34 +01:00
|
|
|
UnknownScore float64 `json:"unknownScore"`
|
2019-08-08 14:47:04 +01:00
|
|
|
}
|
2020-12-31 16:34:16 +00:00
|
|
|
|
|
|
|
// AuditHistory encapsulates storagenode audit history.
|
|
|
|
type AuditHistory struct {
|
|
|
|
Score float64 `json:"score"`
|
|
|
|
Windows []AuditHistoryWindow `json:"windows"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// AuditHistoryWindow encapsulates storagenode audit history window.
|
|
|
|
type AuditHistoryWindow struct {
|
|
|
|
WindowStart time.Time `json:"windowStart"`
|
|
|
|
TotalCount int32 `json:"totalCount"`
|
|
|
|
OnlineCount int32 `json:"onlineCount"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAuditHistoryFromPB creates the AuditHistory json struct from a protobuf.
|
|
|
|
func GetAuditHistoryFromPB(auditHistoryPB *pb.AuditHistory) AuditHistory {
|
|
|
|
ah := AuditHistory{}
|
|
|
|
if auditHistoryPB == nil {
|
|
|
|
return ah
|
|
|
|
}
|
|
|
|
ah.Score = auditHistoryPB.Score
|
|
|
|
for _, window := range auditHistoryPB.Windows {
|
|
|
|
ah.Windows = append(ah.Windows, AuditHistoryWindow{
|
|
|
|
WindowStart: window.WindowStart,
|
|
|
|
TotalCount: window.TotalCount,
|
|
|
|
OnlineCount: window.OnlineCount,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return ah
|
|
|
|
}
|