Add disable-federation flag, default false
This commit is contained in:
parent
72ea236d86
commit
ca0e8562f3
2 changed files with 42 additions and 33 deletions
|
@ -51,6 +51,7 @@ const (
|
|||
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"})
|
||||
|
@ -135,6 +137,7 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
|
|||
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