-
Notifications
You must be signed in to change notification settings - Fork 390
/
reputation.go
85 lines (72 loc) · 2.19 KB
/
reputation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package reputation
import (
"context"
"time"
"storj.io/common/pb"
"storj.io/common/storj"
)
// DB works with reputation database.
//
// architecture: Database
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)
// All retrieves all stats from DB
All(ctx context.Context) ([]Stats, error)
}
// Stats consist of reputation metrics.
type Stats struct {
SatelliteID storj.NodeID
Audit Metric
OnlineScore float64
DisqualifiedAt *time.Time
SuspendedAt *time.Time
OfflineSuspendedAt *time.Time
OfflineUnderReviewAt *time.Time
VettedAt *time.Time
AuditHistory *pb.AuditHistory
UpdatedAt time.Time
JoinedAt time.Time
}
// Metric encapsulates storagenode reputation metrics.
type Metric struct {
TotalCount int64 `json:"totalCount"`
SuccessCount int64 `json:"successCount"`
Alpha float64 `json:"alpha"`
Beta float64 `json:"beta"`
UnknownAlpha float64 `json:"unknownAlpha"`
UnknownBeta float64 `json:"unknownBeta"`
Score float64 `json:"score"`
UnknownScore float64 `json:"unknownScore"`
}
// 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
}