downnload and upload speeds commented due to inaccruate results

This commit is contained in:
2021-05-03 04:24:03 +04:00
parent 336d88e36c
commit 9df89cb075
4 changed files with 66 additions and 59 deletions

View File

@@ -1,7 +1,6 @@
package client package client
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"git.sr.ht/~akilan1999/p2p-rendering-computation/config" "git.sr.ht/~akilan1999/p2p-rendering-computation/config"
@@ -11,7 +10,6 @@ import (
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"os" "os"
"path/filepath"
) )
type IP struct { type IP struct {
@@ -132,48 +130,48 @@ func UpdateIpTableListClient() error {
// 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)
func SendPostRequest (url string, filename string, filetype string) ([]byte,error) { //func SendPostRequest (url string, filename string, filetype string) ([]byte,error) {
file, err := os.Open(filename) // file, err := os.Open(filename)
if err != nil { // if err != nil {
return nil,err // return nil,err
} // }
defer file.Close() // defer file.Close()
//
//
body := &bytes.Buffer{} // body := &bytes.Buffer{}
writer := multipart.NewWriter(body) // writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile(filetype, filepath.Base(file.Name())) // part, err := writer.CreateFormFile(filetype, filepath.Base(file.Name()))
//
if err != nil { // if err != nil {
return nil,err // return nil,err
} // }
//
io.Copy(part, file) // io.Copy(part, file)
writer.Close() // writer.Close()
request, err := http.NewRequest("POST", url, body) // request, err := http.NewRequest("POST", url, body)
//
if err != nil { // if err != nil {
return nil,err // return nil,err
} // }
//
request.Header.Add("Content-Type", writer.FormDataContentType()) // request.Header.Add("Content-Type", writer.FormDataContentType())
client := &http.Client{} // client := &http.Client{}
//
response, err := client.Do(request) // response, err := client.Do(request)
//
if err != nil { // if err != nil {
return nil,err // return nil,err
} // }
defer response.Body.Close() // defer response.Body.Close()
//
content, err := ioutil.ReadAll(response.Body) // content, err := ioutil.ReadAll(response.Body)
//
if err != nil { // if err != nil {
return nil,err // return nil,err
} // }
//
return content, nil // return content, nil
} //}
func UploadMultipartFile(client http.Client, uri, key, path string) ([]byte, error) { func UploadMultipartFile(client http.Client, uri, key, path string) ([]byte, error) {
body, writer := io.Pipe() body, writer := io.Pipe()

View File

@@ -82,9 +82,9 @@ func PrintIpTable() error {
} }
for i := 0; i < len(table.IpAddress); i++ { for i := 0; i < len(table.IpAddress); i++ {
fmt.Printf("----------------------\nIP Address: %s\nLatency: %s\nDownload: %f\nUplaod: %f\n-----------" + fmt.Printf("\nIP Address: %s\nLatency: %s\n-----------" +
"-----------\n",table.IpAddress[i].Ipv4, "-----------------\n",table.IpAddress[i].Ipv4,
table.IpAddress[i].Latency,table.IpAddress[i].Download,table.IpAddress[i].Upload) table.IpAddress[i].Latency)
} }
return nil return nil
} }

View File

@@ -20,15 +20,18 @@ func (ip *IpAddresses)SpeedTest() error{
} }
//Upload Speed Test //Upload Speed Test
err = value.UploadSpeed() //err = value.UploadSpeed()
if err != nil { //if err != nil {
return err // return err
} //}
//
//err = value.DownloadSpeed()
//if err != nil {
// return err
//}
err = value.DownloadSpeed() //Set value to the list
if err != nil { ip.IpAddress[i] = value
return err
}
} }
@@ -95,7 +98,7 @@ func LocalSpeedTestIpTable() error {
} }
// Helper function to remove element from an array of a struct // Helper function to remove element from an array of a struct
func remove(s []IpAddress, i int) []IpAddress { //func remove(s []IpAddress, i int) []IpAddress {
s[len(s)-1], s[i] = s[i], s[len(s)-1] // s[len(s)-1], s[i] = s[i], s[len(s)-1]
return s[:len(s)-1] // return s[:len(s)-1]
} //}

View File

@@ -77,6 +77,12 @@ func Server() error{
c.String(http.StatusOK, fmt.Sprint(err)) c.String(http.StatusOK, fmt.Sprint(err))
} }
// Called step to remove duplicate IP addresses
err = p2p.RemoveDuplicates()
if err != nil {
c.String(http.StatusOK, fmt.Sprint(err))
}
// Reads IP addresses from ip table // Reads IP addresses from ip table
IpAddresses,err := p2p.ReadIpTable() IpAddresses,err := p2p.ReadIpTable()
if err != nil { if err != nil {