Compare commits
No commits in common. "e6e6b90201796676ee736daa2a5a0d4b3375ab31" and "6c4f09f4cba6659cf6f50d518526665c0b7c4d3c" have entirely different histories.
e6e6b90201
...
6c4f09f4cb
|
@ -24,6 +24,7 @@ To compile it , you need:
|
|||
Configuration contains:
|
||||
|
||||
```
|
||||
{
|
||||
"MulticastConfig": {
|
||||
"MIpAddr": "239.0.0.19",
|
||||
"MPort": "9898",
|
||||
|
@ -32,8 +33,8 @@ Configuration contains:
|
|||
"InterfaceConfig": {
|
||||
"ExistingInterface": "eth0",
|
||||
"BridgeIpCIDR": "10.0.1.1/24"
|
||||
},
|
||||
"debug": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Where:
|
||||
|
@ -44,7 +45,6 @@ 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
|
||||
|
|
7
conf.go
7
conf.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
@ -11,13 +10,11 @@ type AbstractConfig struct {
|
|||
MulticastConfig struct {
|
||||
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
|
||||
|
@ -47,10 +44,6 @@ 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)
|
||||
|
|
12
interface.go
12
interface.go
|
@ -71,8 +71,6 @@ 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())
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -107,22 +105,18 @@ 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 = 3
|
||||
pinger.Interval = time.Duration(100 * time.Millisecond)
|
||||
pinger.Count = 5
|
||||
pinger.Interval = time.Duration(10 * 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 == pinger.Count
|
||||
return stats.PacketsRecv == 5
|
||||
|
||||
}
|
||||
|
|
|
@ -116,20 +116,11 @@ 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 e rifare le elezioni
|
||||
if !isActive(string(brIp.String())) {
|
||||
// svuotare l'array
|
||||
entity.HierarchyArray = entity.HierarchyArray[:0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,5 @@
|
|||
"InterfaceConfig": {
|
||||
"ExistingInterface": "eth0",
|
||||
"BridgeIpCIDR": "10.0.1.1/24"
|
||||
},
|
||||
"debug": false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue