-
Notifications
You must be signed in to change notification settings - Fork 402
/
pathcollector.go
57 lines (48 loc) · 1.81 KB
/
pathcollector.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
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package audit
import (
"context"
"math/rand"
"storj.io/common/pb"
"storj.io/common/storj"
"storj.io/storj/satellite/metainfo"
"storj.io/storj/satellite/metainfo/metabase"
)
var _ metainfo.Observer = (*PathCollector)(nil)
// PathCollector uses the metainfo loop to add paths to node reservoirs
//
// architecture: Observer
type PathCollector struct {
Reservoirs map[storj.NodeID]*Reservoir
slotCount int
rand *rand.Rand
}
// NewPathCollector instantiates a path collector.
func NewPathCollector(reservoirSlots int, r *rand.Rand) *PathCollector {
return &PathCollector{
Reservoirs: make(map[storj.NodeID]*Reservoir),
slotCount: reservoirSlots,
rand: r,
}
}
// RemoteSegment takes a remote segment found in metainfo and creates a reservoir for it if it doesn't exist already.
func (collector *PathCollector) RemoteSegment(ctx context.Context, location metabase.SegmentLocation, pointer *pb.Pointer) (err error) {
// TODO change Sample to accept SegmentLocation
key := string(location.Encode())
for _, piece := range pointer.GetRemote().GetRemotePieces() {
if _, ok := collector.Reservoirs[piece.NodeId]; !ok {
collector.Reservoirs[piece.NodeId] = NewReservoir(collector.slotCount)
}
collector.Reservoirs[piece.NodeId].Sample(collector.rand, key)
}
return nil
}
// Object returns nil because the audit service does not interact with objects.
func (collector *PathCollector) Object(ctx context.Context, location metabase.SegmentLocation, pointer *pb.Pointer) (err error) {
return nil
}
// InlineSegment returns nil because we're only auditing for storage nodes for now.
func (collector *PathCollector) InlineSegment(ctx context.Context, location metabase.SegmentLocation, pointer *pb.Pointer) (err error) {
return nil
}