Add disable-federation flag, default false
This commit is contained in:
parent
72ea236d86
commit
ca0e8562f3
2 changed files with 42 additions and 33 deletions
|
@ -37,20 +37,21 @@ type Args struct {
|
|||
}
|
||||
|
||||
const (
|
||||
DefaultHost = "0.0.0.0"
|
||||
DefaultPort = "50051"
|
||||
DefaultEsHost = "http://localhost"
|
||||
DefaultEsIndex = "claims"
|
||||
DefaultEsPort = "9200"
|
||||
DefaultPrometheusPort = "2112"
|
||||
DefaultRefreshDelta = 5
|
||||
DefaultCacheTTL = 5
|
||||
DefaultPeerFile = "peers.txt"
|
||||
DefaultCountry = "US"
|
||||
DefaultLoadPeers = true
|
||||
DefaultStartPrometheus = true
|
||||
DefaultStartUDP = true
|
||||
DefaultWritePeers = true
|
||||
DefaultHost = "0.0.0.0"
|
||||
DefaultPort = "50051"
|
||||
DefaultEsHost = "http://localhost"
|
||||
DefaultEsIndex = "claims"
|
||||
DefaultEsPort = "9200"
|
||||
DefaultPrometheusPort = "2112"
|
||||
DefaultRefreshDelta = 5
|
||||
DefaultCacheTTL = 5
|
||||
DefaultPeerFile = "peers.txt"
|
||||
DefaultCountry = "US"
|
||||
DefaultLoadPeers = true
|
||||
DefaultStartPrometheus = true
|
||||
DefaultStartUDP = true
|
||||
DefaultWritePeers = true
|
||||
DefaultDisableFederation = false
|
||||
)
|
||||
|
||||
// GetEnvironment takes the environment variables as an array of strings
|
||||
|
@ -100,6 +101,7 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
|
|||
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})
|
||||
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"})
|
||||
name := parser.String("", "name", &argparse.Options{Required: false, Help: "name"})
|
||||
|
@ -118,23 +120,24 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
|
|||
}
|
||||
|
||||
args := &Args{
|
||||
CmdType: SearchCmd,
|
||||
Host: *host,
|
||||
Port: *port,
|
||||
EsHost: *esHost,
|
||||
EsPort: *esPort,
|
||||
PrometheusPort: *prometheusPort,
|
||||
EsIndex: *esIndex,
|
||||
RefreshDelta: *refreshDelta,
|
||||
CacheTTL: *cacheTTL,
|
||||
PeerFile: *peerFile,
|
||||
Country: *country,
|
||||
DisableEs: *disableEs,
|
||||
Debug: *debug,
|
||||
LoadPeers: *loadPeers,
|
||||
StartPrometheus: *startPrometheus,
|
||||
StartUDP: *startUdp,
|
||||
WritePeers: *writePeers,
|
||||
CmdType: SearchCmd,
|
||||
Host: *host,
|
||||
Port: *port,
|
||||
EsHost: *esHost,
|
||||
EsPort: *esPort,
|
||||
PrometheusPort: *prometheusPort,
|
||||
EsIndex: *esIndex,
|
||||
RefreshDelta: *refreshDelta,
|
||||
CacheTTL: *cacheTTL,
|
||||
PeerFile: *peerFile,
|
||||
Country: *country,
|
||||
DisableEs: *disableEs,
|
||||
Debug: *debug,
|
||||
LoadPeers: *loadPeers,
|
||||
StartPrometheus: *startPrometheus,
|
||||
StartUDP: *startUdp,
|
||||
WritePeers: *writePeers,
|
||||
DisableFederation: *disableFederation,
|
||||
}
|
||||
|
||||
if esHost, ok := environment["ELASTIC_HOST"]; ok {
|
||||
|
|
|
@ -267,7 +267,10 @@ func (s *Server) writePeers() {
|
|||
|
||||
// notifyPeer takes a peer to notify and a new peer we just learned about
|
||||
// and calls AddPeer on the first.
|
||||
func notifyPeer(peerToNotify *FederatedServer, newPeer *FederatedServer) error {
|
||||
func (s *Server) notifyPeer(peerToNotify *FederatedServer, newPeer *FederatedServer) error {
|
||||
if s.Args.DisableFederation {
|
||||
return nil
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
@ -303,7 +306,7 @@ func (s *Server) notifyPeerSubs(newServer *FederatedServer) {
|
|||
s.PeerSubsMut.RLock()
|
||||
for key, peer := range s.PeerSubs {
|
||||
log.Printf("Notifying peer %s of new node %+v\n", key, newServer)
|
||||
err := notifyPeer(peer, newServer)
|
||||
err := s.notifyPeer(peer, newServer)
|
||||
if err != nil {
|
||||
log.Println("Failed to send data to ", key)
|
||||
log.Println(err)
|
||||
|
@ -327,6 +330,9 @@ func (s *Server) notifyPeerSubs(newServer *FederatedServer) {
|
|||
// if they're online, and adds them to our list of peer. If we're not currently
|
||||
// subscribed to a peer, it will also subscribe to it.
|
||||
func (s *Server) addPeer(msg *pb.ServerMessage, ping bool, subscribe bool) error {
|
||||
if s.Args.DisableFederation {
|
||||
return nil
|
||||
}
|
||||
// First thing we get our external ip if we don't have it, otherwise we
|
||||
// could end up subscribed to our self, which is silly.
|
||||
nilIP := net.IP{}
|
||||
|
|
Loading…
Reference in a new issue