fix ipv6 bugs
This commit is contained in:
@@ -3,21 +3,7 @@
|
||||
{
|
||||
"ipv4": "86.99.25.74",
|
||||
"ipv6": "2001:8f8:172d:ee93:7588:ad57:c351:3309",
|
||||
"latency": 428261,
|
||||
"download": 0,
|
||||
"upload": 0
|
||||
},
|
||||
{
|
||||
"ipv4": "86.99.25.74",
|
||||
"ipv6": "2001:8f8:172d:ee93:7588:ad57:c351:3309",
|
||||
"latency": 374920,
|
||||
"download": 0,
|
||||
"upload": 0
|
||||
},
|
||||
{
|
||||
"ipv4": "86.99.25.74",
|
||||
"ipv6": "2001:8f8:172d:ee93:7588:ad57:c351:3309",
|
||||
"latency": 341720,
|
||||
"latency": 403227,
|
||||
"download": 0,
|
||||
"upload": 0
|
||||
}
|
||||
|
||||
@@ -126,13 +126,13 @@ func PrintIpTable() error {
|
||||
|
||||
// RemoveDuplicates This is a temporary fix current functions failing to remove
|
||||
// Duplicate IP addresses from local IP table
|
||||
func (table IpAddresses)RemoveDuplicates() error {
|
||||
func (table *IpAddresses)RemoveDuplicates() error {
|
||||
|
||||
var NoDuplicates IpAddresses
|
||||
for i, _:= range table.IpAddress {
|
||||
Exists := false
|
||||
for k := range NoDuplicates.IpAddress {
|
||||
if NoDuplicates.IpAddress[k].Ipv4 == table.IpAddress[i].Ipv4 || (NoDuplicates.IpAddress[k].Ipv6 != "" && NoDuplicates.IpAddress[k].Ipv6 == table.IpAddress[i].Ipv6){
|
||||
if NoDuplicates.IpAddress[k].Ipv4 == table.IpAddress[i].Ipv4 || (NoDuplicates.IpAddress[k].Ipv6 != "" && NoDuplicates.IpAddress[k].Ipv6 == table.IpAddress[i].Ipv6){
|
||||
Exists = true
|
||||
break
|
||||
}
|
||||
@@ -144,6 +144,8 @@ func (table IpAddresses)RemoveDuplicates() error {
|
||||
NoDuplicates.IpAddress = append(NoDuplicates.IpAddress, table.IpAddress[i])
|
||||
}
|
||||
|
||||
table.IpAddress = NoDuplicates.IpAddress
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -21,4 +22,39 @@ func TestReadIpTable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Testing is a IPV6 address is returned
|
||||
func TestGetCurrentIPV6(t *testing.T) {
|
||||
res, err := GetCurrentIPV6()
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
fmt.Println(res)
|
||||
}
|
||||
|
||||
// This test ensures that the duplicate function works as intended
|
||||
func TestIpAddresses_RemoveDuplicates(t *testing.T) {
|
||||
var testduplicates IpAddresses
|
||||
var duplicateaddress1 IpAddress
|
||||
var duplicateaddress2 IpAddress
|
||||
|
||||
duplicateaddress1.Ipv6="2001:8f8:172d:ee93:7588:ad57:c351:3309"
|
||||
duplicateaddress1.Ipv4="0.0.0.0"
|
||||
|
||||
duplicateaddress2.Ipv6="2001:8f8:172d:ee93:7588:ad57:c351:3309"
|
||||
duplicateaddress2.Ipv4="0.0.0.0"
|
||||
|
||||
testduplicates.IpAddress = append(testduplicates.IpAddress, duplicateaddress1)
|
||||
testduplicates.IpAddress = append(testduplicates.IpAddress, duplicateaddress2)
|
||||
|
||||
err := testduplicates.RemoveDuplicates()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(testduplicates.IpAddress) == 2 {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,20 +63,20 @@ func (ip *IpAddresses)SpeedTestUpdatedIPTable() error{
|
||||
for i, _ := range targets.IpAddress {
|
||||
|
||||
// To ensure that there are no duplicate IP addresses
|
||||
Exists := false
|
||||
for k := range ip.IpAddress {
|
||||
// Checks if both the IPV4 addresses are the same or the IPV6 address is not
|
||||
// an empty string and IPV6 address are the same
|
||||
if ip.IpAddress[k].Ipv4 == targets.IpAddress[i].Ipv4 || (targets.IpAddress[i].Ipv6 != "" && ip.IpAddress[k].Ipv6 == targets.IpAddress[i].Ipv6) {
|
||||
Exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If the struct exists then continues
|
||||
if Exists {
|
||||
continue
|
||||
}
|
||||
//Exists := false
|
||||
//for k := range ip.IpAddress {
|
||||
// // Checks if both the IPV4 addresses are the same or the IPV6 address is not
|
||||
// // an empty string and IPV6 address are the same
|
||||
// if ip.IpAddress[k].Ipv4 == targets.IpAddress[i].Ipv4 || (targets.IpAddress[i].Ipv6 != "" && ip.IpAddress[k].Ipv6 == targets.IpAddress[i].Ipv6) {
|
||||
// Exists = true
|
||||
// break
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//// If the struct exists then continues
|
||||
//if Exists {
|
||||
// continue
|
||||
//}
|
||||
|
||||
ip.IpAddress = append(ip.IpAddress, targets.IpAddress[i])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user