remove nodes not pingable
This commit is contained in:
@@ -20,9 +20,6 @@ archives:
|
||||
windows: Windows
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
files:
|
||||
- install-binary.sh
|
||||
- install-binary.bat
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
snapshot:
|
||||
|
||||
@@ -150,6 +150,15 @@ func UpdateIpTableListClient() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemoveOfflineNodes() error {
|
||||
// Ensure that the IP Table has Node pingable
|
||||
err := p2p.LocalSpeedTestIpTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendPostRequest Sends a file as a
|
||||
//POST request.
|
||||
// Reference (https://stackoverflow.com/questions/51234464/upload-a-file-with-post-request-golang)
|
||||
|
||||
@@ -170,6 +170,9 @@ func Server() (*gin.Engine, error) {
|
||||
// if not update current entry as proxy address
|
||||
// with appropriate port on IP Table
|
||||
if config.BehindNAT == "True" {
|
||||
// Remove nodes currently not pingable
|
||||
clientIPTable.RemoveOfflineNodes()
|
||||
|
||||
table, err := p2p.ReadIpTable()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -182,7 +185,7 @@ func Server() (*gin.Engine, error) {
|
||||
for i, _ := range table.IpAddress {
|
||||
// Checks if the ping is the lowest and if the following node is acting as a proxy
|
||||
//if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && table.IpAddress[i].ProxyPort != "" {
|
||||
if table.IpAddress[i].Latency.Milliseconds() < lowestLatency {
|
||||
if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && table.IpAddress[i].NAT != "" {
|
||||
lowestLatency = table.IpAddress[i].Latency.Milliseconds()
|
||||
lowestLatencyIpAddress = table.IpAddress[i]
|
||||
}
|
||||
@@ -212,9 +215,19 @@ func Server() (*gin.Engine, error) {
|
||||
// append the following to the ip table
|
||||
table.IpAddress = append(table.IpAddress, ProxyIpAddr)
|
||||
// write information back to the IP Table
|
||||
table.WriteIpTable()
|
||||
err = table.WriteIpTable()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// update ip table
|
||||
go clientIPTable.UpdateIpTableListClient()
|
||||
go func() error {
|
||||
err := clientIPTable.UpdateIpTableListClient()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user