forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend.go
61 lines (47 loc) · 1.36 KB
/
frontend.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
package services
import (
"context"
"fmt"
"os"
"sync"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
)
// The frontend service manages load balancing between multiple
// frontends. Velociraptor clients may be redirected between active
// frontends to spread the load between them.
var (
frontend_mu sync.Mutex
gFrontend FrontendManager
FrontendIsMaster = os.ErrNotExist
)
func RegisterFrontendManager(frontend FrontendManager) {
frontend_mu.Lock()
defer frontend_mu.Unlock()
gFrontend = frontend
}
func GetFrontendManager() FrontendManager {
frontend_mu.Lock()
defer frontend_mu.Unlock()
return gFrontend
}
type FrontendManager interface {
GetMinionCount() int
// Establish a gRPC connection to the master node. If we are
// running on the master node already then returns a
// fs.ErrNotExist error. If we fail to connect returns another
// error.
GetMasterAPIClient(ctx context.Context) (
api_proto.APIClient, func() error, error)
}
// Are we running on the master node?
func IsMaster(config_obj *config_proto.Config) bool {
if config_obj.Frontend != nil {
return !config_obj.Frontend.IsMinion
}
return true
}
func GetNodeName(frontend_config *config_proto.FrontendConfig) string {
return fmt.Sprintf("%s-%d", frontend_config.Hostname,
frontend_config.BindPort)
}