Fix startup flags

This commit is contained in:
Jeffrey Picard 2021-11-24 18:56:34 -05:00
parent ca0e8562f3
commit 283686ecac
6 changed files with 81 additions and 93 deletions

14
main.go
View file

@ -26,19 +26,7 @@ func main() {
s := server.MakeHubServer(ctxWCancel, args) s := server.MakeHubServer(ctxWCancel, args)
s.Run() 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 return
} }

View file

@ -29,10 +29,10 @@ type Args struct {
Country string Country string
DisableEs bool DisableEs bool
Debug bool Debug bool
LoadPeers bool DisableLoadPeers bool
StartPrometheus bool DisableStartPrometheus bool
StartUDP bool DisableStartUDP bool
WritePeers bool DisableWritePeers bool
DisableFederation bool DisableFederation bool
} }
@ -47,10 +47,10 @@ const (
DefaultCacheTTL = 5 DefaultCacheTTL = 5
DefaultPeerFile = "peers.txt" DefaultPeerFile = "peers.txt"
DefaultCountry = "US" DefaultCountry = "US"
DefaultLoadPeers = true DefaultDisableLoadPeers = false
DefaultStartPrometheus = true DefaultDisableStartPrometheus = false
DefaultStartUDP = true DefaultDisableStartUDP = false
DefaultWritePeers = true DefaultDisableWritePeers = false
DefaultDisableFederation = 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}) 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}) 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}) disableLoadPeers := parser.Flag("", "disable-load-peers", &argparse.Options{Required: false, Help: "Disable load peers from disk at startup", Default: DefaultDisableLoadPeers})
startPrometheus := parser.Flag("", "start-prometheus", &argparse.Options{Required: false, Help: "Start prometheus server", Default: DefaultStartPrometheus}) disableStartPrometheus := parser.Flag("", "disable-start-prometheus", &argparse.Options{Required: false, Help: "Disable start prometheus server", Default: DefaultDisableStartPrometheus})
startUdp := parser.Flag("", "start-udp", &argparse.Options{Required: false, Help: "Start UDP ping server", Default: DefaultStartUDP}) disableStartUdp := parser.Flag("", "disable-start-udp", &argparse.Options{Required: false, Help: "Disable start UDP ping server", Default: DefaultDisableStartUDP})
writePeers := parser.Flag("", "write-peers", &argparse.Options{Required: false, Help: "Write peer to disk as we learn about them", Default: DefaultWritePeers}) 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}) 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"}) text := parser.String("", "text", &argparse.Options{Required: false, Help: "text query"})
@ -133,10 +133,10 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
Country: *country, Country: *country,
DisableEs: *disableEs, DisableEs: *disableEs,
Debug: *debug, Debug: *debug,
LoadPeers: *loadPeers, DisableLoadPeers: *disableLoadPeers,
StartPrometheus: *startPrometheus, DisableStartPrometheus: *disableStartPrometheus,
StartUDP: *startUdp, DisableStartUDP: *disableStartUdp,
WritePeers: *writePeers, DisableWritePeers: *disableWritePeers,
DisableFederation: *disableFederation, DisableFederation: *disableFederation,
} }

View file

@ -237,7 +237,7 @@ func (s *Server) helloPeer(server *FederatedServer) (*pb.HelloMessage, error) {
// writePeers writes our current known peers to disk. // writePeers writes our current known peers to disk.
func (s *Server) writePeers() { func (s *Server) writePeers() {
if !s.Args.WritePeers { if s.Args.DisableWritePeers {
return return
} }
f, err := os.Create(s.Args.PeerFile) f, err := os.Create(s.Args.PeerFile)

View file

@ -58,10 +58,10 @@ func makeDefaultArgs() *Args {
Country: DefaultCountry, Country: DefaultCountry,
DisableEs: true, DisableEs: true,
Debug: true, Debug: true,
LoadPeers: false, DisableLoadPeers: true,
StartPrometheus: false, DisableStartPrometheus: true,
StartUDP: false, DisableStartUDP: true,
WritePeers: false, DisableWritePeers: true,
} }
return args return args
@ -129,7 +129,7 @@ func TestAddPeer(t *testing.T) {
func TestPeerWriter(t *testing.T) { func TestPeerWriter(t *testing.T) {
ctx := context.Background() ctx := context.Background()
args := makeDefaultArgs() args := makeDefaultArgs()
args.WritePeers = true args.DisableWritePeers = false
tests := []struct { tests := []struct {
name string name string
@ -426,10 +426,10 @@ func TestAddPeerEndpoint3(t *testing.T) {
func TestUDPServer(t *testing.T) { func TestUDPServer(t *testing.T) {
ctx := context.Background() ctx := context.Background()
args := makeDefaultArgs() args := makeDefaultArgs()
args.StartUDP = true args.DisableStartUDP = false
args2 := makeDefaultArgs() args2 := makeDefaultArgs()
args2.Port = "50052" args2.Port = "50052"
args2.StartUDP = true args2.DisableStartUDP = false
tests := []struct { tests := []struct {
name string name string

View file

@ -205,10 +205,10 @@ func MakeHubServer(ctx context.Context, args *Args) *Server {
} }
// Start up our background services // Start up our background services
if args.StartPrometheus { if !args.DisableStartPrometheus {
go s.prometheusEndpoint(s.Args.PrometheusPort, "metrics") go s.prometheusEndpoint(s.Args.PrometheusPort, "metrics")
} }
if args.StartUDP { if !args.DisableStartUDP {
go func() { go func() {
err := UDPServer(args) err := UDPServer(args)
if err != nil { 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 // Load peers from disk and subscribe to one if there are any
if args.LoadPeers { if !args.DisableLoadPeers {
go func() { go func() {
err := s.loadPeers() err := s.loadPeers()
if err != nil { if err != nil {

View file

@ -10,7 +10,7 @@ import (
// TestAddPeer tests the ability to add peers // TestAddPeer tests the ability to add peers
func TestUDPPing(t *testing.T) { func TestUDPPing(t *testing.T) {
args := makeDefaultArgs() args := makeDefaultArgs()
args.StartUDP = false args.DisableStartUDP = true
tests := []struct { tests := []struct {
name string name string