fixed error for IP table in p2p module
This commit is contained in:
@@ -36,7 +36,7 @@ func UpdateIpTable(IpAddress string) error {
|
|||||||
return nil
|
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
|
//on the ip tables
|
||||||
func UpdateIpTableListClient() error {
|
func UpdateIpTableListClient() error {
|
||||||
// Ensure that the IP Table has Node pingable
|
// Ensure that the IP Table has Node pingable
|
||||||
@@ -89,7 +89,7 @@ func UpdateIpTableListClient() error {
|
|||||||
return nil
|
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)
|
// 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)
|
||||||
|
|||||||
BIN
p2p/50.bin
BIN
p2p/50.bin
Binary file not shown.
@@ -1,10 +1,7 @@
|
|||||||
{
|
{
|
||||||
"ip_address": [
|
"ip_address": [
|
||||||
{
|
{
|
||||||
"ipv4": "localhost",
|
"ipv4": "145.40.90.151"
|
||||||
"latency": 14981051,
|
|
||||||
"download": 8142.122540206258,
|
|
||||||
"upload": 3578.766512629995
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -22,15 +22,14 @@ type IpAddress struct {
|
|||||||
Upload float64 `json:"upload"`
|
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){
|
func ReadIpTable()(*IpAddresses ,error){
|
||||||
// Get Path from config
|
// Get Path from config
|
||||||
config, err := config.ConfigInit()
|
config, err := config.ConfigInit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil,err
|
||||||
}
|
}
|
||||||
|
jsonFile, err := os.Open(config.IPTable)
|
||||||
jsonFile, err := os.Open(config.SpeedTestFile)
|
|
||||||
// if we os.Open returns an error then handle it
|
// if we os.Open returns an error then handle it
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil,err
|
||||||
@@ -53,7 +52,7 @@ func ReadIpTable()(*IpAddresses ,error){
|
|||||||
return &ipAddresses, nil
|
return &ipAddresses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to IP table json file
|
// WriteIpTable Write to IP table json file
|
||||||
func (i *IpAddresses) WriteIpTable() error {
|
func (i *IpAddresses) WriteIpTable() error {
|
||||||
file, err := json.MarshalIndent(i, "", " ")
|
file, err := json.MarshalIndent(i, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -74,7 +73,7 @@ func (i *IpAddresses) WriteIpTable() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print Ip table data for Cli
|
// PrintIpTable Print Ip table data for Cli
|
||||||
func PrintIpTable() error {
|
func PrintIpTable() error {
|
||||||
table, err := ReadIpTable()
|
table, err := ReadIpTable()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package p2p
|
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{
|
func (ip *IpAddresses)SpeedTest() error{
|
||||||
|
|
||||||
for i, _ := range ip.IpAddress {
|
for i, _ := range ip.IpAddress {
|
||||||
@@ -33,7 +33,7 @@ func (ip *IpAddresses)SpeedTest() error{
|
|||||||
return nil
|
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{
|
func (ip *IpAddresses)SpeedTestUpdatedIPTable() error{
|
||||||
targets, err := ReadIpTable()
|
targets, err := ReadIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -71,7 +71,7 @@ func (ip *IpAddresses)SpeedTestUpdatedIPTable() error{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs speed test in iptables locally only
|
// LocalSpeedTestIpTable Runs speed test in iptables locally only
|
||||||
func LocalSpeedTestIpTable() error {
|
func LocalSpeedTestIpTable() error {
|
||||||
targets, err := ReadIpTable()
|
targets, err := ReadIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user