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