diff --git a/client/Iptable.go b/client/Iptable.go index ced9cd3..ebb38a7 100644 --- a/client/Iptable.go +++ b/client/Iptable.go @@ -47,14 +47,17 @@ func UpdateIpTable(IpAddress string) error { // Updates IP table based on information provided // by the server - err = ipStruct.SpeedTestUpdatedIPTable() - if err != nil { - return err + if len(ipStruct.IpAddress) > 0 { + err = ipStruct.SpeedTestUpdatedIPTable() + if err != nil { + return err + } } return nil } + // UpdateIpTableListClient updates IP tables (Default 3 hops) based on server information available //on the ip tables func UpdateIpTableListClient() error { diff --git a/p2p/50.bin b/p2p/50.bin index 1a20dba..7e656dd 100644 Binary files a/p2p/50.bin and b/p2p/50.bin differ diff --git a/p2p/ip_table.json b/p2p/ip_table.json index 78cf758..fc12812 100644 --- a/p2p/ip_table.json +++ b/p2p/ip_table.json @@ -2,15 +2,9 @@ "ip_address": [ { "ipv4": "145.40.90.151", - "latency": 144024138, - "download": 6.124989686501195, - "upload": 3863.649528583081 - }, - { - "ipv4": "86.99.70.106", - "latency": 7972645, - "download": 87.32677875720803, - "upload": 6006.624976985241 + "latency": 139109233, + "download": 6.383175565123993, + "upload": 896786.5894533413 } ] } \ No newline at end of file diff --git a/p2p/speedtest.go b/p2p/speedtest.go index 43dc8c1..94c3611 100644 --- a/p2p/speedtest.go +++ b/p2p/speedtest.go @@ -2,17 +2,38 @@ 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 + } + + var err error + if len(ip.IpAddress) == 1 { + i = 0 + } + // Ping Test - err := ip.IpAddress[i].PingTest() + err = ip.IpAddress[i].PingTest() + if err != nil { - // Remove IP address of element not pingable - ip.IpAddress = remove(ip.IpAddress,i) + ip.IpAddress = remove(ip.IpAddress,i) // Proceed to next element in the array continue } + //Upload Speed Test err = ip.IpAddress[i].UploadSpeed() if err != nil { @@ -23,6 +44,8 @@ func (ip *IpAddresses)SpeedTest() error{ if err != nil { return err } + + DoNotRead.IpAddress = append(DoNotRead.IpAddress, ip.IpAddress[i]) } err := ip.WriteIpTable()