for update IPTable reduce logic

This commit is contained in:
2024-11-13 17:04:28 +00:00
parent eb0a7d6b34
commit 623d7b93e0

View File

@@ -2,6 +2,7 @@ package server
import ( import (
b64 "encoding/base64" b64 "encoding/base64"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable" "github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
@@ -10,6 +11,7 @@ import (
"github.com/Akilan1999/p2p-rendering-computation/p2p/frp" "github.com/Akilan1999/p2p-rendering-computation/p2p/frp"
"github.com/Akilan1999/p2p-rendering-computation/server/docker" "github.com/Akilan1999/p2p-rendering-computation/server/docker"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"io/ioutil"
"net/http" "net/http"
"os/user" "os/user"
"strconv" "strconv"
@@ -67,7 +69,7 @@ func Server() (*gin.Engine, error) {
//Gets Ip Table from server node //Gets Ip Table from server node
r.POST("/IpTable", func(c *gin.Context) { r.POST("/IpTable", func(c *gin.Context) {
//// Getting IPV4 address of client // Getting IPV4 address of client
//var ClientHost p2p.IpAddress //var ClientHost p2p.IpAddress
// //
//if p2p.Ip4or6(c.ClientIP()) == "version 6" { //if p2p.Ip4or6(c.ClientIP()) == "version 6" {
@@ -75,38 +77,38 @@ func Server() (*gin.Engine, error) {
//} else { //} else {
// ClientHost.Ipv4 = c.ClientIP() // ClientHost.Ipv4 = c.ClientIP()
//} //}
//
//// Variable to store IP table information // Variable to store IP table information
//var IPTable p2p.IpAddresses var IPTable p2p.IpAddresses
//
//// Receive file from POST request // Receive file from POST request
//body, err := c.FormFile("json") body, err := c.FormFile("json")
//if err != nil { if err != nil {
// c.String(http.StatusOK, fmt.Sprint(err)) c.String(http.StatusOK, fmt.Sprint(err))
//} }
//
//// Open file // Open file
//open, err := body.Open() open, err := body.Open()
//if err != nil { if err != nil {
// c.String(http.StatusOK, fmt.Sprint(err)) c.String(http.StatusOK, fmt.Sprint(err))
//} }
//
//// Open received file // Open received file
//file, err := ioutil.ReadAll(open) file, err := ioutil.ReadAll(open)
//if err != nil { if err != nil {
// c.String(http.StatusOK, fmt.Sprint(err)) c.String(http.StatusOK, fmt.Sprint(err))
//} }
//
//json.Unmarshal(file, &IPTable) json.Unmarshal(file, &IPTable)
//
////Add Client IP address to IPTable struct //Add Client IP address to IPTable struct
//IPTable.IpAddress = append(IPTable.IpAddress, ClientHost) //IPTable.IpAddress = append(IPTable.IpAddress, ClientHost)
//
//// Runs speed test to return only servers in the IP table pingable // Runs speed test to return only servers in the IP table pingable
//err = IPTable.SpeedTestUpdatedIPTable() err = IPTable.SpeedTestUpdatedIPTable()
//if err != nil { if err != nil {
// c.String(http.StatusOK, fmt.Sprint(err)) 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()