added optmized approach to update IPTable
This commit is contained in:
@@ -31,7 +31,7 @@ func AddCustomInformationToIPTable(text string) error {
|
|||||||
if found {
|
if found {
|
||||||
table.WriteIpTable()
|
table.WriteIpTable()
|
||||||
// update IPTable after modified entry
|
// update IPTable after modified entry
|
||||||
UpdateIpTableListClient()
|
go UpdateIpTableListClient()
|
||||||
} else {
|
} else {
|
||||||
return errors.New("start server with p2prc -s as the server is currently not running")
|
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()
|
// Not required to update IP table as speed test updates the IP Table
|
||||||
if err != nil {
|
//err = ipStruct.WriteIpTable()
|
||||||
return err
|
//if err != nil {
|
||||||
}
|
// return err
|
||||||
|
//}
|
||||||
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ type Config struct {
|
|||||||
PrivateKeyFile string
|
PrivateKeyFile string
|
||||||
PemFile string
|
PemFile string
|
||||||
KeyFile string
|
KeyFile string
|
||||||
BareMetal string
|
BareMetal bool
|
||||||
|
UnsafeMode bool
|
||||||
CustomConfig interface{}
|
CustomConfig interface{}
|
||||||
//NetworkInterface string
|
//NetworkInterface string
|
||||||
//NetworkInterfaceIPV6Index int
|
//NetworkInterfaceIPV6Index int
|
||||||
|
|||||||
@@ -93,7 +93,8 @@ func SetDefaults(envName string, forceDefault bool, CustomConfig interface{}, No
|
|||||||
// Generate Public and private keys and set path
|
// Generate Public and private keys and set path
|
||||||
Defaults.PublicKeyFile = defaultPath + "p2prc.PublicKeyBareMetal"
|
Defaults.PublicKeyFile = defaultPath + "p2prc.PublicKeyBareMetal"
|
||||||
Defaults.PrivateKeyFile = defaultPath + "p2prc.privateKey"
|
Defaults.PrivateKeyFile = defaultPath + "p2prc.privateKey"
|
||||||
Defaults.BareMetal = "False"
|
Defaults.BareMetal = false
|
||||||
|
Defaults.UnsafeMode = false
|
||||||
|
|
||||||
// Generate certificate files for SSL
|
// Generate certificate files for SSL
|
||||||
err = GenerateCertificate()
|
err = GenerateCertificate()
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ type IpAddresses struct {
|
|||||||
|
|
||||||
type IpAddress struct {
|
type IpAddress struct {
|
||||||
Name string `json:"Name"`
|
Name string `json:"Name"`
|
||||||
|
MachineUsername string `json:"MachineUsername"`
|
||||||
Ipv4 string `json:"IPV4"`
|
Ipv4 string `json:"IPV4"`
|
||||||
Ipv6 string `json:"IPV6"`
|
Ipv6 string `json:"IPV6"`
|
||||||
Latency time.Duration `json:"Latency"`
|
Latency time.Duration `json:"Latency"`
|
||||||
@@ -31,6 +32,8 @@ type IpAddress struct {
|
|||||||
NAT string `json:"NAT"`
|
NAT string `json:"NAT"`
|
||||||
EscapeImplementation string `json:"EscapeImplementation"`
|
EscapeImplementation string `json:"EscapeImplementation"`
|
||||||
ProxyServer string `json:"ProxyServer"`
|
ProxyServer string `json:"ProxyServer"`
|
||||||
|
UnSafeMode bool `json:"UnSafeMode"`
|
||||||
|
PublicKey string `json:"PublicKey"`
|
||||||
CustomInformation string `json:"CustomInformation"`
|
CustomInformation string `json:"CustomInformation"`
|
||||||
//CustomInformationKey []byte `json:"CustomInformationKey"`
|
//CustomInformationKey []byte `json:"CustomInformationKey"`
|
||||||
}
|
}
|
||||||
|
|||||||
116
server/server.go
116
server/server.go
@@ -2,7 +2,6 @@ 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"
|
||||||
@@ -11,8 +10,8 @@ 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"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -69,45 +68,45 @@ 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" {
|
||||||
ClientHost.Ipv6 = c.ClientIP()
|
// ClientHost.Ipv6 = c.ClientIP()
|
||||||
} 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()
|
||||||
@@ -294,7 +293,7 @@ func Server() (*gin.Engine, error) {
|
|||||||
ProxyIpAddr.ProxyServer = "False"
|
ProxyIpAddr.ProxyServer = "False"
|
||||||
ProxyIpAddr.EscapeImplementation = "FRP"
|
ProxyIpAddr.EscapeImplementation = "FRP"
|
||||||
|
|
||||||
if config.BareMetal == "True" {
|
if config.BareMetal {
|
||||||
_, SSHPort, err := MapPort("22", "")
|
_, SSHPort, err := MapPort("22", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -303,9 +302,6 @@ func Server() (*gin.Engine, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//ProxyIpAddr.CustomInformationKey = p2p.GenerateHashSHA256(config.IPTableKey)
|
//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
|
// write information back to the IP Table
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,14 +317,34 @@ func Server() (*gin.Engine, error) {
|
|||||||
ProxyIpAddr.ProxyServer = "True"
|
ProxyIpAddr.ProxyServer = "True"
|
||||||
}
|
}
|
||||||
ProxyIpAddr.EscapeImplementation = ""
|
ProxyIpAddr.EscapeImplementation = ""
|
||||||
if config.BareMetal == "True" {
|
if config.BareMetal {
|
||||||
ProxyIpAddr.BareMetalSSHPort = "22"
|
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
|
// Writing results to the IPTable
|
||||||
err = table.WriteIpTable()
|
err = table.WriteIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -406,11 +422,8 @@ func MapPort(port string, domainName string) (string, string, error) {
|
|||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(domainName)
|
|
||||||
|
|
||||||
// Doing the proxy mapping for the domain name
|
// Doing the proxy mapping for the domain name
|
||||||
if domainName != "" {
|
if domainName != "" {
|
||||||
fmt.Println("called --------------------------------")
|
|
||||||
fmt.Println("http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort + "/AddProxy?port=" + proxyPort + "&domain_name=" + domainName + "&ip_address=" + lowestLatencyIpAddress.Ipv4)
|
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
|
URL := "http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort + "/AddProxy?port=" + proxyPort + "&domain_name=" + domainName + "&ip_address=" + lowestLatencyIpAddress.Ipv4
|
||||||
//} else {
|
//} else {
|
||||||
@@ -426,6 +439,7 @@ func MapPort(port string, domainName string) (string, string, error) {
|
|||||||
ProxyIpAddr.Name = config.MachineName
|
ProxyIpAddr.Name = config.MachineName
|
||||||
ProxyIpAddr.NAT = "False"
|
ProxyIpAddr.NAT = "False"
|
||||||
ProxyIpAddr.EscapeImplementation = "FRP"
|
ProxyIpAddr.EscapeImplementation = "FRP"
|
||||||
|
|
||||||
//ProxyIpAddr.CustomInformationKey = p2p.GenerateHashSHA256(config.IPTableKey)
|
//ProxyIpAddr.CustomInformationKey = p2p.GenerateHashSHA256(config.IPTableKey)
|
||||||
} else {
|
} else {
|
||||||
return "", "", errors.New("proxy IP not found")
|
return "", "", errors.New("proxy IP not found")
|
||||||
|
|||||||
Reference in New Issue
Block a user