diff --git a/client/Iptable.go b/client/Iptable.go index ebb38a7..7c150ef 100644 --- a/client/Iptable.go +++ b/client/Iptable.go @@ -121,6 +121,11 @@ func UpdateIpTableListClient() error { } } + // Removing duplicates in the IP table + if err := p2p.RemoveDuplicates(); err != nil { + return err + } + return nil } diff --git a/p2p/ip_table.json b/p2p/ip_table.json index bb16a07..ce8de32 100644 --- a/p2p/ip_table.json +++ b/p2p/ip_table.json @@ -1,22 +1,16 @@ { "ip_address": [ { - "ipv4": "145.40.90.151", - "latency": 136977360, - "download": 6.439557936207414, - "upload": 1247166.5933956294 + "ipv4": "147.75.100.225", + "latency": 1582411, + "download": 279180.07603469375, + "upload": 855366.1394760027 }, { "ipv4": "86.99.70.106", - "latency": 8933343, - "download": 201730.13853312942, - "upload": 2203225.5221644486 - }, - { - "ipv4": "86.99.70.106", - "latency": 0, - "download": 0, - "upload": 0 + "latency": 134446840, + "download": 1582.176490711659, + "upload": 597823.3252726822 } ] } \ No newline at end of file diff --git a/p2p/iptable.go b/p2p/iptable.go index a6ba6e0..7e164f5 100644 --- a/p2p/iptable.go +++ b/p2p/iptable.go @@ -86,5 +86,36 @@ func PrintIpTable() error { "-----------\n",table.IpAddress[i].Ipv4, table.IpAddress[i].Latency,table.IpAddress[i].Download,table.IpAddress[i].Upload) } + return nil +} + +// RemoveDuplicates This is a temporary fix current functions failing to remove +// Duplicate IP addresses from local IP table +func RemoveDuplicates() error { + table, err := ReadIpTable() + if err != nil { + return err + } + + var NoDuplicates IpAddresses + for i, _:= range table.IpAddress { + Exists := false + for k := range NoDuplicates.IpAddress { + if NoDuplicates.IpAddress[k].Ipv4 == table.IpAddress[i].Ipv4 { + Exists = true + break + } + } + + if Exists { + continue + } + NoDuplicates.IpAddress = append(NoDuplicates.IpAddress, table.IpAddress[i]) + } + + if err := NoDuplicates.WriteIpTable(); err != nil { + return nil + } + return nil } \ No newline at end of file diff --git a/p2p/speedtest.go b/p2p/speedtest.go index 090d940..79a9aaa 100644 --- a/p2p/speedtest.go +++ b/p2p/speedtest.go @@ -2,22 +2,8 @@ package p2p // SpeedTest Runs a speed test and does updates IP tables accordingly func (ip *IpAddresses)SpeedTest() error{ - // Remove Duplicate IP addresses - var DoNotRead IpAddresses - for i, _ := range ip.IpAddress { - - Exists := false - for k := range DoNotRead.IpAddress { - if DoNotRead.IpAddress[k].Ipv4 == ip.IpAddress[i].Ipv4 { - Exists = true - break - } - } - - if Exists { - continue - } + for i, value := range ip.IpAddress { var err error if len(ip.IpAddress) == 1 { @@ -25,27 +11,25 @@ func (ip *IpAddresses)SpeedTest() error{ } // Ping Test - err = ip.IpAddress[i].PingTest() + err = value.PingTest() if err != nil { - ip.IpAddress = remove(ip.IpAddress,i) + ip.IpAddress = append(ip.IpAddress[:i], ip.IpAddress[i+1:]...) // Proceed to next element in the array continue } - //Upload Speed Test - err = ip.IpAddress[i].UploadSpeed() + err = value.UploadSpeed() if err != nil { return err } - err = ip.IpAddress[i].DownloadSpeed() + err = value.DownloadSpeed() if err != nil { return err } - DoNotRead.IpAddress = append(DoNotRead.IpAddress, ip.IpAddress[i]) } err := ip.WriteIpTable() @@ -69,7 +53,7 @@ func (ip *IpAddresses)SpeedTestUpdatedIPTable() error{ // Appends all IP addresses for i, _ := range targets.IpAddress { - // To ensure that there are no duplicate IP addresses + // To ensure that there are no duplicate IP addresses Exists := false for k := range ip.IpAddress { if ip.IpAddress[k].Ipv4 == targets.IpAddress[i].Ipv4 {