added optmized approach to update IPTable
This commit is contained in:
@@ -31,7 +31,7 @@ func AddCustomInformationToIPTable(text string) error {
|
||||
if found {
|
||||
table.WriteIpTable()
|
||||
// update IPTable after modified entry
|
||||
UpdateIpTableListClient()
|
||||
go UpdateIpTableListClient()
|
||||
} else {
|
||||
return errors.New("start server with p2prc -s as the server is currently not running")
|
||||
}
|
||||
|
||||
@@ -64,10 +64,11 @@ func UpdateIpTable(IpAddress string, serverPort string, wg *sync.WaitGroup) erro
|
||||
}
|
||||
}
|
||||
|
||||
err = ipStruct.WriteIpTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Not required to update IP table as speed test updates the IP Table
|
||||
//err = ipStruct.WriteIpTable()
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
|
||||
wg.Done()
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ type Config struct {
|
||||
PrivateKeyFile string
|
||||
PemFile string
|
||||
KeyFile string
|
||||
BareMetal string
|
||||
BareMetal bool
|
||||
UnsafeMode bool
|
||||
CustomConfig interface{}
|
||||
//NetworkInterface string
|
||||
//NetworkInterfaceIPV6Index int
|
||||
|
||||
@@ -93,7 +93,8 @@ func SetDefaults(envName string, forceDefault bool, CustomConfig interface{}, No
|
||||
// Generate Public and private keys and set path
|
||||
Defaults.PublicKeyFile = defaultPath + "p2prc.PublicKeyBareMetal"
|
||||
Defaults.PrivateKeyFile = defaultPath + "p2prc.privateKey"
|
||||
Defaults.BareMetal = "False"
|
||||
Defaults.BareMetal = false
|
||||
Defaults.UnsafeMode = false
|
||||
|
||||
// Generate certificate files for SSL
|
||||
err = GenerateCertificate()
|
||||
|
||||
@@ -21,6 +21,7 @@ type IpAddresses struct {
|
||||
|
||||
type IpAddress struct {
|
||||
Name string `json:"Name"`
|
||||
MachineUsername string `json:"MachineUsername"`
|
||||
Ipv4 string `json:"IPV4"`
|
||||
Ipv6 string `json:"IPV6"`
|
||||
Latency time.Duration `json:"Latency"`
|
||||
@@ -31,6 +32,8 @@ type IpAddress struct {
|
||||
NAT string `json:"NAT"`
|
||||
EscapeImplementation string `json:"EscapeImplementation"`
|
||||
ProxyServer string `json:"ProxyServer"`
|
||||
UnSafeMode bool `json:"UnSafeMode"`
|
||||
PublicKey string `json:"PublicKey"`
|
||||
CustomInformation string `json:"CustomInformation"`
|
||||
//CustomInformationKey []byte `json:"CustomInformationKey"`
|
||||
}
|
||||
|
||||
116
server/server.go
116
server/server.go
@@ -2,7 +2,6 @@ package server
|
||||
|
||||
import (
|
||||
b64 "encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
|
||||
@@ -11,8 +10,8 @@ import (
|
||||
"github.com/Akilan1999/p2p-rendering-computation/p2p/frp"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/server/docker"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
@@ -69,45 +68,45 @@ func Server() (*gin.Engine, error) {
|
||||
//Gets Ip Table from server node
|
||||
r.POST("/IpTable", func(c *gin.Context) {
|
||||
// Getting IPV4 address of client
|
||||
var ClientHost p2p.IpAddress
|
||||
|
||||
if p2p.Ip4or6(c.ClientIP()) == "version 6" {
|
||||
ClientHost.Ipv6 = c.ClientIP()
|
||||
} else {
|
||||
ClientHost.Ipv4 = c.ClientIP()
|
||||
}
|
||||
|
||||
// Variable to store IP table information
|
||||
var IPTable p2p.IpAddresses
|
||||
|
||||
// Receive file from POST request
|
||||
body, err := c.FormFile("json")
|
||||
if err != nil {
|
||||
c.String(http.StatusOK, fmt.Sprint(err))
|
||||
}
|
||||
|
||||
// Open file
|
||||
open, err := body.Open()
|
||||
if err != nil {
|
||||
c.String(http.StatusOK, fmt.Sprint(err))
|
||||
}
|
||||
|
||||
// Open received file
|
||||
file, err := ioutil.ReadAll(open)
|
||||
if err != nil {
|
||||
c.String(http.StatusOK, fmt.Sprint(err))
|
||||
}
|
||||
|
||||
json.Unmarshal(file, &IPTable)
|
||||
|
||||
//Add Client IP address to IPTable struct
|
||||
IPTable.IpAddress = append(IPTable.IpAddress, ClientHost)
|
||||
|
||||
// Runs speed test to return only servers in the IP table pingable
|
||||
err = IPTable.SpeedTestUpdatedIPTable()
|
||||
if err != nil {
|
||||
c.String(http.StatusOK, fmt.Sprint(err))
|
||||
}
|
||||
//var ClientHost p2p.IpAddress
|
||||
//
|
||||
//if p2p.Ip4or6(c.ClientIP()) == "version 6" {
|
||||
// ClientHost.Ipv6 = c.ClientIP()
|
||||
//} else {
|
||||
// ClientHost.Ipv4 = c.ClientIP()
|
||||
//}
|
||||
//
|
||||
//// Variable to store IP table information
|
||||
//var IPTable p2p.IpAddresses
|
||||
//
|
||||
//// Receive file from POST request
|
||||
//body, err := c.FormFile("json")
|
||||
//if err != nil {
|
||||
// c.String(http.StatusOK, fmt.Sprint(err))
|
||||
//}
|
||||
//
|
||||
//// Open file
|
||||
//open, err := body.Open()
|
||||
//if err != nil {
|
||||
// c.String(http.StatusOK, fmt.Sprint(err))
|
||||
//}
|
||||
//
|
||||
//// Open received file
|
||||
//file, err := ioutil.ReadAll(open)
|
||||
//if err != nil {
|
||||
// c.String(http.StatusOK, fmt.Sprint(err))
|
||||
//}
|
||||
//
|
||||
//json.Unmarshal(file, &IPTable)
|
||||
//
|
||||
////Add Client IP address to IPTable struct
|
||||
//IPTable.IpAddress = append(IPTable.IpAddress, ClientHost)
|
||||
//
|
||||
//// Runs speed test to return only servers in the IP table pingable
|
||||
//err = IPTable.SpeedTestUpdatedIPTable()
|
||||
//if err != nil {
|
||||
// c.String(http.StatusOK, fmt.Sprint(err))
|
||||
//}
|
||||
|
||||
// Reads IP addresses from ip table
|
||||
IpAddresses, err := p2p.ReadIpTable()
|
||||
@@ -294,7 +293,7 @@ func Server() (*gin.Engine, error) {
|
||||
ProxyIpAddr.ProxyServer = "False"
|
||||
ProxyIpAddr.EscapeImplementation = "FRP"
|
||||
|
||||
if config.BareMetal == "True" {
|
||||
if config.BareMetal {
|
||||
_, SSHPort, err := MapPort("22", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -303,9 +302,6 @@ func Server() (*gin.Engine, error) {
|
||||
}
|
||||
|
||||
//ProxyIpAddr.CustomInformationKey = p2p.GenerateHashSHA256(config.IPTableKey)
|
||||
|
||||
// append the following to the ip table
|
||||
table.IpAddress = append(table.IpAddress, ProxyIpAddr)
|
||||
// write information back to the IP Table
|
||||
}
|
||||
|
||||
@@ -321,14 +317,34 @@ func Server() (*gin.Engine, error) {
|
||||
ProxyIpAddr.ProxyServer = "True"
|
||||
}
|
||||
ProxyIpAddr.EscapeImplementation = ""
|
||||
if config.BareMetal == "True" {
|
||||
if config.BareMetal {
|
||||
ProxyIpAddr.BareMetalSSHPort = "22"
|
||||
}
|
||||
|
||||
table.IpAddress = append(table.IpAddress, ProxyIpAddr)
|
||||
|
||||
}
|
||||
|
||||
// Get machine username
|
||||
currentUser, err := user.Current()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Add username p2prc binary is being run under
|
||||
ProxyIpAddr.MachineUsername = currentUser.Username
|
||||
ProxyIpAddr.UnSafeMode = config.UnsafeMode
|
||||
// Adds the public key information to the IPTable
|
||||
// improving transmission of IPTables without the
|
||||
// entire public key is future work to be improved
|
||||
// in the P2PRC protocol level (Improving by adding
|
||||
// UDP with TCP reliability layer).
|
||||
ProxyIpAddr.PublicKey, err = config.GetPublicKey()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// append the following to the ip table
|
||||
table.IpAddress = append(table.IpAddress, ProxyIpAddr)
|
||||
|
||||
// Writing results to the IPTable
|
||||
err = table.WriteIpTable()
|
||||
if err != nil {
|
||||
@@ -406,11 +422,8 @@ func MapPort(port string, domainName string) (string, string, error) {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
fmt.Println(domainName)
|
||||
|
||||
// Doing the proxy mapping for the domain name
|
||||
if domainName != "" {
|
||||
fmt.Println("called --------------------------------")
|
||||
fmt.Println("http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort + "/AddProxy?port=" + proxyPort + "&domain_name=" + domainName + "&ip_address=" + lowestLatencyIpAddress.Ipv4)
|
||||
URL := "http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort + "/AddProxy?port=" + proxyPort + "&domain_name=" + domainName + "&ip_address=" + lowestLatencyIpAddress.Ipv4
|
||||
//} else {
|
||||
@@ -426,6 +439,7 @@ func MapPort(port string, domainName string) (string, string, error) {
|
||||
ProxyIpAddr.Name = config.MachineName
|
||||
ProxyIpAddr.NAT = "False"
|
||||
ProxyIpAddr.EscapeImplementation = "FRP"
|
||||
|
||||
//ProxyIpAddr.CustomInformationKey = p2p.GenerateHashSHA256(config.IPTableKey)
|
||||
} else {
|
||||
return "", "", errors.New("proxy IP not found")
|
||||
|
||||
Reference in New Issue
Block a user