-
Notifications
You must be signed in to change notification settings - Fork 402
/
config.go
94 lines (80 loc) · 2.83 KB
/
config.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
86
87
88
89
90
91
92
93
94
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package kademlia
import (
"fmt"
"regexp"
"time"
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/storj/pkg/pb"
)
var (
// Error defines a Kademlia error
Error = errs.Class("kademlia error")
// mon = monkit.Package() // TODO: figure out whether this is needed
)
// Config defines all of the things that are needed to start up Kademlia
// server endpoints (and not necessarily client code).
type Config struct {
BootstrapAddr string `help:"the Kademlia node to bootstrap against" releaseDefault:"bootstrap.storj.io:8888" devDefault:""`
BootstrapBackoffMax time.Duration `help:"the maximum amount of time to wait when retrying bootstrap" default:"30s"`
BootstrapBackoffBase time.Duration `help:"the base interval to wait when retrying bootstrap" default:"1s"`
DBPath string `help:"the path for storage node db services to be created on" default:"$CONFDIR/kademlia"`
ExternalAddress string `user:"true" help:"the public address of the Kademlia node, useful for nodes behind NAT" default:""`
Operator OperatorConfig
// TODO: reduce the number of flags here
Alpha int `help:"alpha is a system wide concurrency parameter" default:"5"`
RoutingTableConfig
}
// BootstrapNodes returns bootstrap nodes defined in the config
func (c Config) BootstrapNodes() []pb.Node {
var nodes []pb.Node
if c.BootstrapAddr != "" {
nodes = append(nodes, pb.Node{
Address: &pb.NodeAddress{
Transport: pb.NodeTransport_TCP_TLS_GRPC,
Address: c.BootstrapAddr,
},
})
}
return nodes
}
// Verify verifies whether kademlia config is valid.
func (c Config) Verify(log *zap.Logger) error {
return c.Operator.Verify(log)
}
// OperatorConfig defines properties related to storage node operator metadata
type OperatorConfig struct {
Email string `user:"true" help:"operator email address" default:""`
Wallet string `user:"true" help:"operator wallet adress" default:""`
}
// Verify verifies whether operator config is valid.
func (c OperatorConfig) Verify(log *zap.Logger) error {
if err := isOperatorEmailValid(log, c.Email); err != nil {
return err
}
if err := isOperatorWalletValid(log, c.Wallet); err != nil {
return err
}
return nil
}
func isOperatorEmailValid(log *zap.Logger, email string) error {
if email == "" {
log.Sugar().Warn("Operator email address isn't specified.")
} else {
log.Sugar().Info("Operator email: ", email)
}
return nil
}
func isOperatorWalletValid(log *zap.Logger, wallet string) error {
if wallet == "" {
return fmt.Errorf("Operator wallet address isn't specified")
}
r := regexp.MustCompile("^0x[a-fA-F0-9]{40}$")
if match := r.MatchString(wallet); !match {
return fmt.Errorf("Operator wallet address isn't valid")
}
log.Sugar().Info("Operator wallet: ", wallet)
return nil
}