Compare commits

...

2 Commits

Author SHA1 Message Date
Uriel Fanelli e6e6b90201 Adding possibility to disable logs + fixes. 2023-08-10 21:09:17 +02:00
Uriel Fanelli 08f139c8d2 Made it asynchronous. 2023-08-10 20:39:26 +02:00
6 changed files with 35 additions and 12 deletions

View File

@ -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

11
conf.go
View File

@ -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)

View File

@ -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
}

View File

@ -116,11 +116,20 @@ func (b *AbstractBridge) WaitAndClean(entity AbstractMulticast) {
log.Println("Inizializing Escalator")
entity.AddUniqueAndSort(b.hIerarchyNumber)
brIp, _, err := net.ParseCIDR(b.BridgeIpCIDR)
if err != nil {
log.Println(err.Error())
}
for {
entity.AddUniqueAndSort(b.hIerarchyNumber)
pollTime := len(entity.HierarchyArray) + 1
time.Sleep(time.Duration(pollTime) * time.Second)
// svuotare l'array
entity.HierarchyArray = entity.HierarchyArray[:0]
// svuotare l'array e rifare le elezioni
if !isActive(string(brIp.String())) {
entity.HierarchyArray = entity.HierarchyArray[:0]
}
}
}

View File

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