diff --git a/README.md b/README.md index 16ff4af..d3db4a3 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ To compile it , you need: Configuration contains: ``` -{ "MulticastConfig": { "MIpAddr": "239.0.0.19", "MPort": "9898", @@ -33,8 +32,8 @@ Configuration contains: "InterfaceConfig": { "ExistingInterface": "eth0", "BridgeIpCIDR": "10.0.1.1/24" - } -} + }, + "debug": false ``` Where: @@ -45,6 +44,7 @@ Where: - ExistingInterface: the name of your ingress interface (eth0, eno0 , enps18, whatever your system is using. This may be different node by node) - BridgeIpCidr: the IP address and mask you want to share among servers. +- wether you want debug logs or not. # FAQ diff --git a/conf.go b/conf.go index d45ae47..677736c 100644 --- a/conf.go +++ b/conf.go @@ -2,19 +2,22 @@ package main import ( "encoding/json" + "io" "log" "os" ) type AbstractConfig struct { MulticastConfig struct { - MIPAddr string `json:"MIpAddr"` - MPort string `json:"MPort"` + MIPAddr string `json:"MIpAddr"` + MPort string `json:"MPort"` + MaxDatagramSize int `json:"MaxDatagramSize"` } `json:"MulticastConfig"` InterfaceConfig struct { ExistingInterface string `json:"ExistingInterface"` BridgeIPCIDR string `json:"BridgeIpCIDR"` } `json:"InterfaceConfig"` + Debug bool `json:"debug"` } var a AbstractConfig @@ -44,6 +47,10 @@ func init() { ZoreideBridge.ExistingInterface = a.InterfaceConfig.ExistingInterface ZoreideBridge.IsActive = false + if !a.Debug { + log.SetOutput(io.Discard) + } + log.Println("Inizialized Generic Config: ", a) log.Println("Inizialized Interface Config: ", ZoreideBridge) log.Println("Inizialized Multicast Config: ", MulticastEntity) diff --git a/interface.go b/interface.go index e2d5c38..0494729 100644 --- a/interface.go +++ b/interface.go @@ -71,6 +71,8 @@ func (b *AbstractBridge) configureIpAndBridgeUp() { if err := br.SetLinkIp(brIp, brIpNet); err != nil { log.Println("Error setting UP the IP: ", err.Error()) + } else { + log.Printf("%s configured with %s\n", b.ExistingInterface, brIp.String()) } } @@ -105,18 +107,22 @@ func (b *AbstractBridge) removeIPandBridgeInt() { func isActive(bridgeip string) bool { + log.Println("Check for active IP: ", bridgeip) + pinger, err := ping.NewPinger(bridgeip) if err != nil { log.Println("Ping error: " + err.Error()) } // just in case it doesn't stops alone defer pinger.Stop() - pinger.Count = 5 - pinger.Interval = time.Duration(10 * time.Millisecond) + pinger.Count = 3 + pinger.Interval = time.Duration(100 * time.Millisecond) pinger.Timeout = time.Duration(1 * time.Second) pinger.Run() // blocks until finished stats := pinger.Statistics() + log.Println("Ping results for: ", bridgeip) + log.Printf("%d packet sent, %d packet recv", pinger.Count, stats.PacketsRecv) - return stats.PacketsRecv == 5 + return stats.PacketsRecv == pinger.Count } diff --git a/00.memory.go b/memory.go similarity index 100% rename from 00.memory.go rename to memory.go diff --git a/orchestrator.go b/orchestrator.go index c0b87eb..904565e 100644 --- a/orchestrator.go +++ b/orchestrator.go @@ -128,7 +128,7 @@ func (b *AbstractBridge) WaitAndClean(entity AbstractMulticast) { pollTime := len(entity.HierarchyArray) + 1 time.Sleep(time.Duration(pollTime) * time.Second) // svuotare l'array e rifare le elezioni - if !isActive(string(brIp)) { + if !isActive(string(brIp.String())) { entity.HierarchyArray = entity.HierarchyArray[:0] } } diff --git a/zoreide.json b/zoreide.json index 19dd6df..18bf0c7 100644 --- a/zoreide.json +++ b/zoreide.json @@ -7,5 +7,6 @@ "InterfaceConfig": { "ExistingInterface": "eth0", "BridgeIpCIDR": "10.0.1.1/24" - } + }, + "debug": false }