-
Notifications
You must be signed in to change notification settings - Fork 402
/
pieces.go
56 lines (47 loc) · 1.23 KB
/
pieces.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
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package audit
import (
"context"
"github.com/zeebo/errs"
"storj.io/common/errs2"
"storj.io/common/rpc"
"storj.io/common/rpc/rpcstatus"
)
// PieceAudit is piece audit status.
type PieceAudit int
const (
// PieceAuditUnknown is unknown piece audit.
PieceAuditUnknown PieceAudit = iota
// PieceAuditFailure is failed piece audit.
PieceAuditFailure
// PieceAuditOffline is offline node piece audit.
PieceAuditOffline
// PieceAuditContained is online but unresponsive node piece audit.
PieceAuditContained
// PieceAuditSuccess is successful piece audit.
PieceAuditSuccess
)
// PieceAuditFromErr returns piece audit based on error.
func PieceAuditFromErr(err error) PieceAudit {
if err == nil {
return PieceAuditSuccess
}
if rpc.Error.Has(err) {
switch {
case errs.Is(err, context.DeadlineExceeded), errs2.IsRPC(err, rpcstatus.Unknown):
return PieceAuditOffline
default:
// TODO: is this path not reachable?
return PieceAuditUnknown
}
}
switch {
case errs2.IsRPC(err, rpcstatus.NotFound):
return PieceAuditFailure
case errs2.IsRPC(err, rpcstatus.DeadlineExceeded):
return PieceAuditContained
default:
return PieceAuditUnknown
}
}