Truncation error in int64 numbers fixed

master
Uriel Fanelli 2023-08-13 10:54:00 +02:00
parent 2604347e8b
commit ba3ba3099b
5 changed files with 12 additions and 23 deletions

View File

@ -28,7 +28,7 @@ func init() {
MulticastEntity.MIpAddr = a.MulticastConfig.MIPAddr
MulticastEntity.MPort = a.MulticastConfig.MPort
MulticastEntity.MaxDatagramSize = numberlenght
MulticastEntity.MaxDatagramSize = a.MulticastConfig.MaxDatagramSize
ZoreideBridge.BridgeIpCIDR = a.InterfaceConfig.BridgeIPCIDR
ZoreideBridge.ExistingInterface = a.InterfaceConfig.ExistingInterface

View File

@ -5,7 +5,6 @@ import (
"log"
"math/rand"
"net"
"strconv"
"time"
"github.com/go-ping/ping"
@ -46,22 +45,8 @@ func (b *AbstractBridge) RefreshArp() {
func (b *AbstractBridge) initializeHierarchy() {
var letterRunes = []rune("123456789")
num := make([]rune, numberlenght)
for i := range num {
num[i] = letterRunes[rand.Intn(len(letterRunes))]
}
zz, err := strconv.ParseInt(string(num), 10, 64)
if err != nil {
log.Println("Error generating number: ", err.Error())
b.hIerarchyNumber = 0
return
} else {
b.hIerarchyNumber = zz
log.Println("Success generating number: ", b.hIerarchyNumber)
}
b.hIerarchyNumber = rand.Int63()
log.Println("Initialized host number: ", b.hIerarchyNumber)
}

View File

@ -10,8 +10,6 @@ var MulticastEntity AbstractMulticast
var BstChannel = make(chan string, 1)
var ZoreideBridge AbstractBridge
const numberlenght = 18
func main() {
MulticastEntity.GetMulticastReady()

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net"
"regexp"
"slices"
"strconv"
"time"
@ -75,7 +76,12 @@ func (b *AbstractBridge) HierarchyReLocator(entity AbstractMulticast) {
log.Println("Inizializing Descalator")
entity.AddUniqueAndSort(b.hIerarchyNumber)
re := regexp.MustCompile("[0-9]+")
for bstNumber := range BstChannel {
bstNumber = re.FindAllString(bstNumber, -1)[0]
brdNumber, err := strconv.ParseInt(bstNumber, 10, 64)
if err != nil {
log.Println("Garbage received on multicast: ", bstNumber)
@ -117,8 +123,6 @@ 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())
@ -132,6 +136,8 @@ func (b *AbstractBridge) WaitAndClean(entity AbstractMulticast) {
if !isActive(string(brIp.String())) {
entity.HierarchyArray = entity.HierarchyArray[:0]
entity.HierarchyArray = slices.Clip(entity.HierarchyArray)
entity.AddUniqueAndSort(b.hIerarchyNumber)
}
}
}

View File

@ -2,7 +2,7 @@
"MulticastConfig": {
"MIpAddr": "239.0.0.19",
"MPort": "9898",
"MaxDatagramSize": 18
"MaxDatagramSize": 32
},
"InterfaceConfig": {
"ExistingInterface": "eth0",