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.MIpAddr = a.MulticastConfig.MIPAddr
MulticastEntity.MPort = a.MulticastConfig.MPort MulticastEntity.MPort = a.MulticastConfig.MPort
MulticastEntity.MaxDatagramSize = numberlenght MulticastEntity.MaxDatagramSize = a.MulticastConfig.MaxDatagramSize
ZoreideBridge.BridgeIpCIDR = a.InterfaceConfig.BridgeIPCIDR ZoreideBridge.BridgeIpCIDR = a.InterfaceConfig.BridgeIPCIDR
ZoreideBridge.ExistingInterface = a.InterfaceConfig.ExistingInterface ZoreideBridge.ExistingInterface = a.InterfaceConfig.ExistingInterface

View File

@ -5,7 +5,6 @@ import (
"log" "log"
"math/rand" "math/rand"
"net" "net"
"strconv"
"time" "time"
"github.com/go-ping/ping" "github.com/go-ping/ping"
@ -46,22 +45,8 @@ func (b *AbstractBridge) RefreshArp() {
func (b *AbstractBridge) initializeHierarchy() { func (b *AbstractBridge) initializeHierarchy() {
var letterRunes = []rune("123456789") b.hIerarchyNumber = rand.Int63()
log.Println("Initialized host number: ", b.hIerarchyNumber)
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)
}
} }

View File

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

View File

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

View File

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