Fix startup flags
This commit is contained in:
parent
ca0e8562f3
commit
283686ecac
6 changed files with 81 additions and 93 deletions
14
main.go
14
main.go
|
@ -26,19 +26,7 @@ func main() {
|
|||
|
||||
s := server.MakeHubServer(ctxWCancel, args)
|
||||
s.Run()
|
||||
//l, err := net.Listen("tcp", ":"+args.Port)
|
||||
//if err != nil {
|
||||
// log.Fatalf("failed to listen: %v", err)
|
||||
//}
|
||||
//
|
||||
//pb.RegisterHubServer(s.GrpcServer, s)
|
||||
//reflection.Register(s.GrpcServer)
|
||||
//
|
||||
//log.Printf("listening on %s\n", l.Addr().String())
|
||||
//log.Println(s.Args)
|
||||
//if err := s.GrpcServer.Serve(l); err != nil {
|
||||
// log.Fatalf("failed to serve: %v", err)
|
||||
//}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,10 @@ type Args struct {
|
|||
Country string
|
||||
DisableEs bool
|
||||
Debug bool
|
||||
LoadPeers bool
|
||||
StartPrometheus bool
|
||||
StartUDP bool
|
||||
WritePeers bool
|
||||
DisableLoadPeers bool
|
||||
DisableStartPrometheus bool
|
||||
DisableStartUDP bool
|
||||
DisableWritePeers bool
|
||||
DisableFederation bool
|
||||
}
|
||||
|
||||
|
@ -47,10 +47,10 @@ const (
|
|||
DefaultCacheTTL = 5
|
||||
DefaultPeerFile = "peers.txt"
|
||||
DefaultCountry = "US"
|
||||
DefaultLoadPeers = true
|
||||
DefaultStartPrometheus = true
|
||||
DefaultStartUDP = true
|
||||
DefaultWritePeers = true
|
||||
DefaultDisableLoadPeers = false
|
||||
DefaultDisableStartPrometheus = false
|
||||
DefaultDisableStartUDP = false
|
||||
DefaultDisableWritePeers = false
|
||||
DefaultDisableFederation = false
|
||||
)
|
||||
|
||||
|
@ -97,10 +97,10 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
|
|||
|
||||
debug := parser.Flag("", "debug", &argparse.Options{Required: false, Help: "enable debug logging", Default: false})
|
||||
disableEs := parser.Flag("", "disable-es", &argparse.Options{Required: false, Help: "Disable elastic search, for running/testing independently", Default: false})
|
||||
loadPeers := parser.Flag("", "load-peers", &argparse.Options{Required: false, Help: "load peers from disk at startup", Default: DefaultLoadPeers})
|
||||
startPrometheus := parser.Flag("", "start-prometheus", &argparse.Options{Required: false, Help: "Start prometheus server", Default: DefaultStartPrometheus})
|
||||
startUdp := parser.Flag("", "start-udp", &argparse.Options{Required: false, Help: "Start UDP ping server", Default: DefaultStartUDP})
|
||||
writePeers := parser.Flag("", "write-peers", &argparse.Options{Required: false, Help: "Write peer to disk as we learn about them", Default: DefaultWritePeers})
|
||||
disableLoadPeers := parser.Flag("", "disable-load-peers", &argparse.Options{Required: false, Help: "Disable load peers from disk at startup", Default: DefaultDisableLoadPeers})
|
||||
disableStartPrometheus := parser.Flag("", "disable-start-prometheus", &argparse.Options{Required: false, Help: "Disable start prometheus server", Default: DefaultDisableStartPrometheus})
|
||||
disableStartUdp := parser.Flag("", "disable-start-udp", &argparse.Options{Required: false, Help: "Disable start UDP ping server", Default: DefaultDisableStartUDP})
|
||||
disableWritePeers := parser.Flag("", "disable-write-peers", &argparse.Options{Required: false, Help: "Disable write peer to disk as we learn about them", Default: DefaultDisableWritePeers})
|
||||
disableFederation := parser.Flag("", "disable-federation", &argparse.Options{Required: false, Help: "Disable server federation", Default: DefaultDisableFederation})
|
||||
|
||||
text := parser.String("", "text", &argparse.Options{Required: false, Help: "text query"})
|
||||
|
@ -133,10 +133,10 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
|
|||
Country: *country,
|
||||
DisableEs: *disableEs,
|
||||
Debug: *debug,
|
||||
LoadPeers: *loadPeers,
|
||||
StartPrometheus: *startPrometheus,
|
||||
StartUDP: *startUdp,
|
||||
WritePeers: *writePeers,
|
||||
DisableLoadPeers: *disableLoadPeers,
|
||||
DisableStartPrometheus: *disableStartPrometheus,
|
||||
DisableStartUDP: *disableStartUdp,
|
||||
DisableWritePeers: *disableWritePeers,
|
||||
DisableFederation: *disableFederation,
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ func (s *Server) helloPeer(server *FederatedServer) (*pb.HelloMessage, error) {
|
|||
|
||||
// writePeers writes our current known peers to disk.
|
||||
func (s *Server) writePeers() {
|
||||
if !s.Args.WritePeers {
|
||||
if s.Args.DisableWritePeers {
|
||||
return
|
||||
}
|
||||
f, err := os.Create(s.Args.PeerFile)
|
||||
|
|
|
@ -58,10 +58,10 @@ func makeDefaultArgs() *Args {
|
|||
Country: DefaultCountry,
|
||||
DisableEs: true,
|
||||
Debug: true,
|
||||
LoadPeers: false,
|
||||
StartPrometheus: false,
|
||||
StartUDP: false,
|
||||
WritePeers: false,
|
||||
DisableLoadPeers: true,
|
||||
DisableStartPrometheus: true,
|
||||
DisableStartUDP: true,
|
||||
DisableWritePeers: true,
|
||||
}
|
||||
|
||||
return args
|
||||
|
@ -129,7 +129,7 @@ func TestAddPeer(t *testing.T) {
|
|||
func TestPeerWriter(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
args := makeDefaultArgs()
|
||||
args.WritePeers = true
|
||||
args.DisableWritePeers = false
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -426,10 +426,10 @@ func TestAddPeerEndpoint3(t *testing.T) {
|
|||
func TestUDPServer(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
args := makeDefaultArgs()
|
||||
args.StartUDP = true
|
||||
args.DisableStartUDP = false
|
||||
args2 := makeDefaultArgs()
|
||||
args2.Port = "50052"
|
||||
args2.StartUDP = true
|
||||
args2.DisableStartUDP = false
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
@ -205,10 +205,10 @@ func MakeHubServer(ctx context.Context, args *Args) *Server {
|
|||
}
|
||||
|
||||
// Start up our background services
|
||||
if args.StartPrometheus {
|
||||
if !args.DisableStartPrometheus {
|
||||
go s.prometheusEndpoint(s.Args.PrometheusPort, "metrics")
|
||||
}
|
||||
if args.StartUDP {
|
||||
if !args.DisableStartUDP {
|
||||
go func() {
|
||||
err := UDPServer(args)
|
||||
if err != nil {
|
||||
|
@ -217,7 +217,7 @@ func MakeHubServer(ctx context.Context, args *Args) *Server {
|
|||
}()
|
||||
}
|
||||
// Load peers from disk and subscribe to one if there are any
|
||||
if args.LoadPeers {
|
||||
if !args.DisableLoadPeers {
|
||||
go func() {
|
||||
err := s.loadPeers()
|
||||
if err != nil {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
// TestAddPeer tests the ability to add peers
|
||||
func TestUDPPing(t *testing.T) {
|
||||
args := makeDefaultArgs()
|
||||
args.StartUDP = false
|
||||
args.DisableStartUDP = true
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
Loading…
Reference in a new issue