Adding possibility to disable logs + fixes.

master v1.0.0
Uriel Fanelli 2023-08-10 21:09:17 +02:00
parent 08f139c8d2
commit e6e6b90201
6 changed files with 24 additions and 10 deletions

View File

@ -24,7 +24,6 @@ To compile it , you need:
Configuration contains: Configuration contains:
``` ```
{
"MulticastConfig": { "MulticastConfig": {
"MIpAddr": "239.0.0.19", "MIpAddr": "239.0.0.19",
"MPort": "9898", "MPort": "9898",
@ -33,8 +32,8 @@ Configuration contains:
"InterfaceConfig": { "InterfaceConfig": {
"ExistingInterface": "eth0", "ExistingInterface": "eth0",
"BridgeIpCIDR": "10.0.1.1/24" "BridgeIpCIDR": "10.0.1.1/24"
} },
} "debug": false
``` ```
Where: 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) - 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. - BridgeIpCidr: the IP address and mask you want to share among servers.
- wether you want debug logs or not.
# FAQ # FAQ

11
conf.go
View File

@ -2,19 +2,22 @@ package main
import ( import (
"encoding/json" "encoding/json"
"io"
"log" "log"
"os" "os"
) )
type AbstractConfig struct { type AbstractConfig struct {
MulticastConfig struct { MulticastConfig struct {
MIPAddr string `json:"MIpAddr"` MIPAddr string `json:"MIpAddr"`
MPort string `json:"MPort"` MPort string `json:"MPort"`
MaxDatagramSize int `json:"MaxDatagramSize"`
} `json:"MulticastConfig"` } `json:"MulticastConfig"`
InterfaceConfig struct { InterfaceConfig struct {
ExistingInterface string `json:"ExistingInterface"` ExistingInterface string `json:"ExistingInterface"`
BridgeIPCIDR string `json:"BridgeIpCIDR"` BridgeIPCIDR string `json:"BridgeIpCIDR"`
} `json:"InterfaceConfig"` } `json:"InterfaceConfig"`
Debug bool `json:"debug"`
} }
var a AbstractConfig var a AbstractConfig
@ -44,6 +47,10 @@ func init() {
ZoreideBridge.ExistingInterface = a.InterfaceConfig.ExistingInterface ZoreideBridge.ExistingInterface = a.InterfaceConfig.ExistingInterface
ZoreideBridge.IsActive = false ZoreideBridge.IsActive = false
if !a.Debug {
log.SetOutput(io.Discard)
}
log.Println("Inizialized Generic Config: ", a) log.Println("Inizialized Generic Config: ", a)
log.Println("Inizialized Interface Config: ", ZoreideBridge) log.Println("Inizialized Interface Config: ", ZoreideBridge)
log.Println("Inizialized Multicast Config: ", MulticastEntity) log.Println("Inizialized Multicast Config: ", MulticastEntity)

View File

@ -71,6 +71,8 @@ func (b *AbstractBridge) configureIpAndBridgeUp() {
if err := br.SetLinkIp(brIp, brIpNet); err != nil { if err := br.SetLinkIp(brIp, brIpNet); err != nil {
log.Println("Error setting UP the IP: ", err.Error()) 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 { func isActive(bridgeip string) bool {
log.Println("Check for active IP: ", bridgeip)
pinger, err := ping.NewPinger(bridgeip) pinger, err := ping.NewPinger(bridgeip)
if err != nil { if err != nil {
log.Println("Ping error: " + err.Error()) log.Println("Ping error: " + err.Error())
} }
// just in case it doesn't stops alone // just in case it doesn't stops alone
defer pinger.Stop() defer pinger.Stop()
pinger.Count = 5 pinger.Count = 3
pinger.Interval = time.Duration(10 * time.Millisecond) pinger.Interval = time.Duration(100 * time.Millisecond)
pinger.Timeout = time.Duration(1 * time.Second) pinger.Timeout = time.Duration(1 * time.Second)
pinger.Run() // blocks until finished pinger.Run() // blocks until finished
stats := pinger.Statistics() 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
} }

View File

@ -128,7 +128,7 @@ func (b *AbstractBridge) WaitAndClean(entity AbstractMulticast) {
pollTime := len(entity.HierarchyArray) + 1 pollTime := len(entity.HierarchyArray) + 1
time.Sleep(time.Duration(pollTime) * time.Second) time.Sleep(time.Duration(pollTime) * time.Second)
// svuotare l'array e rifare le elezioni // svuotare l'array e rifare le elezioni
if !isActive(string(brIp)) { if !isActive(string(brIp.String())) {
entity.HierarchyArray = entity.HierarchyArray[:0] entity.HierarchyArray = entity.HierarchyArray[:0]
} }
} }

View File

@ -7,5 +7,6 @@
"InterfaceConfig": { "InterfaceConfig": {
"ExistingInterface": "eth0", "ExistingInterface": "eth0",
"BridgeIpCIDR": "10.0.1.1/24" "BridgeIpCIDR": "10.0.1.1/24"
} },
"debug": false
} }