fixed error for IP table in p2p module

This commit is contained in:
2021-04-12 16:54:06 +04:00
parent 23b147cdd0
commit 823a65db5d
5 changed files with 10 additions and 14 deletions

View File

@@ -36,7 +36,7 @@ func UpdateIpTable(IpAddress string) error {
return nil
}
//updates IP tables (Default 3 hops) based on server information available
// UpdateIpTableListClient updates IP tables (Default 3 hops) based on server information available
//on the ip tables
func UpdateIpTableListClient() error {
// Ensure that the IP Table has Node pingable
@@ -89,7 +89,7 @@ func UpdateIpTableListClient() error {
return nil
}
// Sends a file as a POST request.
// SendPostRequest Sends a file as a POST request.
// Reference (https://stackoverflow.com/questions/51234464/upload-a-file-with-post-request-golang)
func SendPostRequest (url string, filename string, filetype string) ([]byte,error) {
file, err := os.Open(filename)

Binary file not shown.

View File

@@ -1,10 +1,7 @@
{
"ip_address": [
{
"ipv4": "localhost",
"latency": 14981051,
"download": 8142.122540206258,
"upload": 3578.766512629995
"ipv4": "145.40.90.151"
}
]
}

View File

@@ -22,15 +22,14 @@ type IpAddress struct {
Upload float64 `json:"upload"`
}
// Read data from Ip tables from json file
// ReadIpTable Read data from Ip tables from json file
func ReadIpTable()(*IpAddresses ,error){
// Get Path from config
config, err := config.ConfigInit()
if err != nil {
return nil,err
}
jsonFile, err := os.Open(config.SpeedTestFile)
jsonFile, err := os.Open(config.IPTable)
// if we os.Open returns an error then handle it
if err != nil {
return nil,err
@@ -53,7 +52,7 @@ func ReadIpTable()(*IpAddresses ,error){
return &ipAddresses, nil
}
// Write to IP table json file
// WriteIpTable Write to IP table json file
func (i *IpAddresses) WriteIpTable() error {
file, err := json.MarshalIndent(i, "", " ")
if err != nil {
@@ -74,7 +73,7 @@ func (i *IpAddresses) WriteIpTable() error {
return nil
}
// Print Ip table data for Cli
// PrintIpTable Print Ip table data for Cli
func PrintIpTable() error {
table, err := ReadIpTable()

View File

@@ -1,6 +1,6 @@
package p2p
// Runs a speed test and does updates IP tables accordingly
// SpeedTest Runs a speed test and does updates IP tables accordingly
func (ip *IpAddresses)SpeedTest() error{
for i, _ := range ip.IpAddress {
@@ -33,7 +33,7 @@ func (ip *IpAddresses)SpeedTest() error{
return nil
}
// Called when ip tables from client/server is also passed on
// SpeedTestUpdatedIPTable Called when ip tables from client/server is also passed on
func (ip *IpAddresses)SpeedTestUpdatedIPTable() error{
targets, err := ReadIpTable()
if err != nil {
@@ -71,7 +71,7 @@ func (ip *IpAddresses)SpeedTestUpdatedIPTable() error{
return nil
}
// Runs speed test in iptables locally only
// LocalSpeedTestIpTable Runs speed test in iptables locally only
func LocalSpeedTestIpTable() error {
targets, err := ReadIpTable()
if err != nil {