-
Notifications
You must be signed in to change notification settings - Fork 0
/
send-client.go
51 lines (45 loc) · 1.08 KB
/
send-client.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
package bloom
import (
"context"
"github.com/elek/stbb/pkg/util"
"github.com/pkg/errors"
"os"
"storj.io/common/pb"
"storj.io/common/storj"
"storj.io/storj/satellite/internalpb"
"storj.io/uplink/private/piecestore"
)
type SendClient struct {
util.DialerHelper
URL storj.NodeURL
Filter string `arg:""`
}
func (s SendClient) Run() error {
ctx := context.Background()
dialer, err := s.DialerHelper.CreateRPCDialer()
if err != nil {
return errors.WithStack(err)
}
client, err := piecestore.Dial(ctx, dialer, s.URL, piecestore.DefaultConfig)
if err != nil {
return errors.WithStack(err)
}
defer client.Close()
filter, err := os.ReadFile(s.Filter)
if err != nil {
return errors.WithStack(err)
}
retainInfo := &internalpb.RetainInfo{}
err = pb.Unmarshal(filter, retainInfo)
if retainInfo.StorageNodeId != s.URL.ID {
panic("invalid storagenode " + retainInfo.StorageNodeId.String())
}
err = client.Retain(ctx, &pb.RetainRequest{
CreationDate: retainInfo.CreationDate,
Filter: retainInfo.Filter,
})
if err != nil {
return errors.WithStack(err)
}
return nil
}