added minor fixed to reverse proxy
This commit is contained in:
@@ -138,8 +138,10 @@ func (table *IpAddresses) RemoveDuplicates() error {
|
||||
Exists := false
|
||||
for k := range NoDuplicates.IpAddress {
|
||||
if (NoDuplicates.IpAddress[k].Ipv4 != "" && NoDuplicates.IpAddress[k].Ipv4 == table.IpAddress[i].Ipv4) || (NoDuplicates.IpAddress[k].Ipv6 != "" && NoDuplicates.IpAddress[k].Ipv6 == table.IpAddress[i].Ipv6) {
|
||||
Exists = true
|
||||
break
|
||||
if NoDuplicates.IpAddress[k].ProxyPort == "0" {
|
||||
Exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if Exists {
|
||||
|
||||
149
p2p/speedtest.go
149
p2p/speedtest.go
@@ -1,111 +1,110 @@
|
||||
package p2p
|
||||
|
||||
// SpeedTest Runs a speed test and does updates IP tables accordingly
|
||||
func (ip *IpAddresses)SpeedTest() error{
|
||||
func (ip *IpAddresses) SpeedTest() error {
|
||||
|
||||
//temp variable to store elements IP addresses and other information
|
||||
// of IP addresses that are pingable
|
||||
var ActiveIP IpAddresses
|
||||
|
||||
// Index to remove from struct
|
||||
for _, value := range ip.IpAddress {
|
||||
//temp variable to store elements IP addresses and other information
|
||||
// of IP addresses that are pingable
|
||||
var ActiveIP IpAddresses
|
||||
|
||||
var err error
|
||||
//if len(ip.IpAddress) == 1 {
|
||||
// i = 0
|
||||
//}
|
||||
// Index to remove from struct
|
||||
for _, value := range ip.IpAddress {
|
||||
|
||||
// Ping Test
|
||||
err = value.PingTest()
|
||||
var err error
|
||||
//if len(ip.IpAddress) == 1 {
|
||||
// i = 0
|
||||
//}
|
||||
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// Ping Test
|
||||
err = value.PingTest()
|
||||
|
||||
//Upload Speed Test
|
||||
//err = value.UploadSpeed()
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
//
|
||||
//err = value.DownloadSpeed()
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
//Set value to the list
|
||||
//Upload Speed Test
|
||||
//err = value.UploadSpeed()
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
//
|
||||
//err = value.DownloadSpeed()
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
|
||||
ActiveIP.IpAddress = append(ActiveIP.IpAddress, value)
|
||||
//Set value to the list
|
||||
|
||||
}
|
||||
ActiveIP.IpAddress = append(ActiveIP.IpAddress, value)
|
||||
|
||||
ip.IpAddress = ActiveIP.IpAddress
|
||||
}
|
||||
|
||||
err := ip.WriteIpTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ip.IpAddress = ActiveIP.IpAddress
|
||||
|
||||
return nil
|
||||
err := ip.WriteIpTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SpeedTestUpdatedIPTable Called when ip tables from httpclient/server is also passed on
|
||||
func (ip *IpAddresses)SpeedTestUpdatedIPTable() error{
|
||||
targets, err := ReadIpTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (ip *IpAddresses) SpeedTestUpdatedIPTable() error {
|
||||
targets, err := ReadIpTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// To ensure struct has no duplicates IP addresses
|
||||
//DoNotRead := targets
|
||||
// To ensure struct has no duplicates IP addresses
|
||||
//DoNotRead := targets
|
||||
|
||||
// Appends all IP addresses
|
||||
for i, _ := range targets.IpAddress {
|
||||
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
|
||||
//}
|
||||
// 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
|
||||
//}
|
||||
|
||||
ip.IpAddress = append(ip.IpAddress, targets.IpAddress[i])
|
||||
}
|
||||
ip.IpAddress = append(ip.IpAddress, targets.IpAddress[i])
|
||||
}
|
||||
|
||||
err = ip.SpeedTest()
|
||||
err = ip.SpeedTest()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// LocalSpeedTestIpTable Runs speed test in iptables locally only
|
||||
func LocalSpeedTestIpTable() error {
|
||||
targets, err := ReadIpTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
targets, err := ReadIpTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = targets.SpeedTest()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = targets.SpeedTest()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// Helper function to remove element from an array of a struct
|
||||
//func remove(s []IpAddress, i int) []IpAddress {
|
||||
// s[len(s)-1], s[i] = s[i], s[len(s)-1]
|
||||
|
||||
Reference in New Issue
Block a user