added fix for reverse proxy
This commit is contained in:
@@ -3,7 +3,6 @@ package client
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/p2p"
|
|
||||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/server"
|
"git.sr.ht/~akilan1999/p2p-rendering-computation/server"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -12,30 +11,30 @@ import (
|
|||||||
// GetSpecs Gets Specs from the server such CPU, GPU usage
|
// GetSpecs Gets Specs from the server such CPU, GPU usage
|
||||||
// and other basic information which helps set a
|
// and other basic information which helps set a
|
||||||
// cluster of computer
|
// cluster of computer
|
||||||
func GetSpecs(IP string)(*server.SysInfo,error) {
|
func GetSpecs(IP string) (*server.SysInfo, error) {
|
||||||
var URL string
|
var URL string
|
||||||
version := p2p.Ip4or6(IP)
|
//version := p2p.Ip4or6(IP)
|
||||||
|
|
||||||
//Get port number of the server
|
//Get port number of the server
|
||||||
serverPort, err := GetServerPort(IP)
|
//serverPort, err := GetServerPort(IP)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
//}
|
||||||
|
|
||||||
if version == "version 6" {
|
//if version == "version 6" {
|
||||||
URL = "http://[" + IP + "]:" + serverPort + "/server_info"
|
URL = "http://" + IP + "/server_info"
|
||||||
} else {
|
//} else {
|
||||||
URL = "http://" + IP + ":" + serverPort + "/server_info"
|
// URL = "http://" + IP + ":" + serverPort + "/server_info"
|
||||||
}
|
//}
|
||||||
resp, err := http.Get(URL)
|
resp, err := http.Get(URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert response to byte value
|
// Convert response to byte value
|
||||||
byteValue, err := ioutil.ReadAll(resp.Body)
|
byteValue, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create variable for result response type
|
// Create variable for result response type
|
||||||
@@ -44,7 +43,7 @@ func GetSpecs(IP string)(*server.SysInfo,error) {
|
|||||||
// Adds byte value to docker.DockerVM struct
|
// Adds byte value to docker.DockerVM struct
|
||||||
json.Unmarshal(byteValue, &serverSpecsResult)
|
json.Unmarshal(byteValue, &serverSpecsResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &serverSpecsResult, nil
|
return &serverSpecsResult, nil
|
||||||
@@ -61,4 +60,4 @@ func PrettyPrint(data interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("%s \n", p)
|
fmt.Printf("%s \n", p)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,39 +12,39 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
serverPort = "8088"
|
serverPort = "8088"
|
||||||
client = http.Client{}
|
client = http.Client{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// StartContainer Start container using REST api Implementation
|
// StartContainer Start container using REST api Implementation
|
||||||
// From the selected server IP address
|
// From the selected server IP address
|
||||||
// TODO: Test cases for this function
|
// TODO: Test cases for this function
|
||||||
//Calls URL ex: http://0.0.0.0:8088/startcontainer?ports=0&GPU=false&ContainerName=docker-ubuntu-sshd
|
// Calls URL ex: http://0.0.0.0:8088/startcontainer?ports=0&GPU=false&ContainerName=docker-ubuntu-sshd
|
||||||
func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string) (*docker.DockerVM ,error) {
|
func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string) (*docker.DockerVM, error) {
|
||||||
// Passes URL with number of TCP ports to allocated and to give GPU access to the docker container
|
// Passes URL with number of TCP ports to allocated and to give GPU access to the docker container
|
||||||
var URL string
|
var URL string
|
||||||
version := p2p.Ip4or6(IP)
|
//version := p2p.Ip4or6(IP)
|
||||||
|
//
|
||||||
|
////Get port number of the server
|
||||||
|
//serverPort, err := GetServerPort(IP)
|
||||||
|
//if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
//}
|
||||||
|
|
||||||
//Get port number of the server
|
//if version == "version 6" {
|
||||||
serverPort, err := GetServerPort(IP)
|
// URL = "http://[" + IP + "]:" + serverPort + "/startcontainer?ports=" + fmt.Sprint(NumPorts) + "&GPU=" + strconv.FormatBool(GPU) + "&ContainerName=" + ContainerName
|
||||||
if err != nil {
|
//} else {
|
||||||
return nil, err
|
URL = "http://" + IP + "/startcontainer?ports=" + fmt.Sprint(NumPorts) + "&GPU=" + strconv.FormatBool(GPU) + "&ContainerName=" + ContainerName
|
||||||
}
|
//}
|
||||||
|
|
||||||
if version == "version 6" {
|
|
||||||
URL = "http://[" + IP + "]:" + serverPort + "/startcontainer?ports=" + fmt.Sprint(NumPorts) + "&GPU=" + strconv.FormatBool(GPU) + "&ContainerName=" + ContainerName
|
|
||||||
} else {
|
|
||||||
URL = "http://" + IP + ":" + serverPort + "/startcontainer?ports=" + fmt.Sprint(NumPorts) + "&GPU=" + strconv.FormatBool(GPU) + "&ContainerName=" + ContainerName
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := http.Get(URL)
|
resp, err := http.Get(URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert response to byte value
|
// Convert response to byte value
|
||||||
byteValue, err := ioutil.ReadAll(resp.Body)
|
byteValue, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create variable for result response type
|
// Create variable for result response type
|
||||||
@@ -53,7 +53,7 @@ func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string) (*d
|
|||||||
// Adds byte value to docker.DockerVM struct
|
// Adds byte value to docker.DockerVM struct
|
||||||
json.Unmarshal(byteValue, &dockerResult)
|
json.Unmarshal(byteValue, &dockerResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds the container to the tracked list
|
// Adds the container to the tracked list
|
||||||
@@ -66,21 +66,21 @@ func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string) (*d
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveContianer Stops and removes container from the server
|
// RemoveContianer Stops and removes container from the server
|
||||||
func RemoveContianer(IP string,ID string) error {
|
func RemoveContianer(IP string, ID string) error {
|
||||||
var URL string
|
var URL string
|
||||||
version := p2p.Ip4or6(IP)
|
//version := p2p.Ip4or6(IP)
|
||||||
|
//
|
||||||
|
////Get port number of the server
|
||||||
|
//serverPort, err := GetServerPort(IP)
|
||||||
|
//if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
|
||||||
//Get port number of the server
|
//if version == "version 6" {
|
||||||
serverPort, err := GetServerPort(IP)
|
// URL = "http://[" + IP + "]:" + serverPort + "/RemoveContainer?id=" + ID
|
||||||
if err != nil {
|
//} else {
|
||||||
return err
|
URL = "http://" + IP + "/RemoveContainer?id=" + ID
|
||||||
}
|
//}
|
||||||
|
|
||||||
if version == "version 6" {
|
|
||||||
URL = "http://[" + IP + "]:" + serverPort + "/RemoveContainer?id=" + ID
|
|
||||||
} else {
|
|
||||||
URL = "http://" + IP + ":" + serverPort + "/RemoveContainer?id=" + ID
|
|
||||||
}
|
|
||||||
resp, err := http.Get(URL)
|
resp, err := http.Get(URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -102,7 +102,7 @@ func RemoveContianer(IP string,ID string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Remove container created from the tracked list
|
// Remove container created from the tracked list
|
||||||
err = RemoveTrackedContainer(ID)
|
err = RemoveTrackedContainer(ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -112,31 +112,31 @@ func RemoveContianer(IP string,ID string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ViewContainers This function displays all containers available on server side
|
// ViewContainers This function displays all containers available on server side
|
||||||
func ViewContainers(IP string)(*docker.DockerContainers, error){
|
func ViewContainers(IP string) (*docker.DockerContainers, error) {
|
||||||
// Passes URL with route /ShowImages
|
// Passes URL with route /ShowImages
|
||||||
var URL string
|
var URL string
|
||||||
version := p2p.Ip4or6(IP)
|
//version := p2p.Ip4or6(IP)
|
||||||
|
//
|
||||||
|
////Get port number of the server
|
||||||
|
//serverPort, err := GetServerPort(IP)
|
||||||
|
//if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
//}
|
||||||
|
|
||||||
//Get port number of the server
|
//if version == "version 6" {
|
||||||
serverPort, err := GetServerPort(IP)
|
// URL = "http://[" + IP + "]:" + serverPort + "/ShowImages"
|
||||||
if err != nil {
|
//} else {
|
||||||
return nil, err
|
URL = "http://" + IP + "/ShowImages"
|
||||||
}
|
//}
|
||||||
|
|
||||||
if version == "version 6" {
|
|
||||||
URL = "http://[" + IP + "]:" + serverPort + "/ShowImages"
|
|
||||||
} else {
|
|
||||||
URL = "http://" + IP + ":" + serverPort + "/ShowImages"
|
|
||||||
}
|
|
||||||
resp, err := http.Get(URL)
|
resp, err := http.Get(URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert response to byte value
|
// Convert response to byte value
|
||||||
byteValue, err := ioutil.ReadAll(resp.Body)
|
byteValue, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create variable for result response type
|
// Create variable for result response type
|
||||||
@@ -145,18 +145,18 @@ func ViewContainers(IP string)(*docker.DockerContainers, error){
|
|||||||
// Adds byte value to docker.DockerContainers struct
|
// Adds byte value to docker.DockerContainers struct
|
||||||
json.Unmarshal(byteValue, &Result)
|
json.Unmarshal(byteValue, &Result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Result, nil
|
return &Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetServerPort Helper function to do find out server port information
|
// GetServerPort Helper function to do find out server port information
|
||||||
func GetServerPort(IpAddress string) (string,error) {
|
func GetServerPort(IpAddress string) (string, error) {
|
||||||
// Getting information from the clients ip table
|
// Getting information from the clients ip table
|
||||||
ipTable, err := p2p.ReadIpTable()
|
ipTable, err := p2p.ReadIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "",err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate thorough ip table struct and find
|
// Iterate thorough ip table struct and find
|
||||||
@@ -170,7 +170,7 @@ func GetServerPort(IpAddress string) (string,error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We return default port
|
// We return default port
|
||||||
return "8088",nil
|
return "8088", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintStartContainer Prints results Generated container
|
// PrintStartContainer Prints results Generated container
|
||||||
@@ -187,7 +187,6 @@ func GetServerPort(IpAddress string) (string,error) {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
// TODO implementation using RPC calls
|
// TODO implementation using RPC calls
|
||||||
//func StartContainer(Ip string) (*docker.DockerVM,error){
|
//func StartContainer(Ip string) (*docker.DockerVM,error){
|
||||||
// client, err := rpc.DialHTTP("tcp",Ip + ":" + serverPort)
|
// client, err := rpc.DialHTTP("tcp",Ip + ":" + serverPort)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/server/docker"
|
"git.sr.ht/~akilan1999/p2p-rendering-computation/server/docker"
|
||||||
"github.com/fatedier/frp/client"
|
"github.com/fatedier/frp/client"
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
|
"github.com/phayes/freeport"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@@ -50,19 +51,23 @@ func StartFRPClientForServer(ipaddress string, port string, localport string) (s
|
|||||||
}
|
}
|
||||||
|
|
||||||
//random port
|
//random port
|
||||||
randPort := rangeIn(10000, 99999)
|
//randPort := rangeIn(10000, 99999)
|
||||||
|
OpenPorts, err := freeport.GetFreePorts(1)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
c.ClientMappings = []ClientMapping{
|
c.ClientMappings = []ClientMapping{
|
||||||
{
|
{
|
||||||
LocalIP: ipaddress,
|
LocalIP: "localhost",
|
||||||
LocalPort: portInt,
|
LocalPort: portInt,
|
||||||
RemotePort: randPort,
|
RemotePort: OpenPorts[0],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start client server
|
// Start client server
|
||||||
go c.StartFRPClient()
|
go c.StartFRPClient()
|
||||||
|
|
||||||
return strconv.Itoa(randPort), nil
|
return strconv.Itoa(OpenPorts[0]), nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +93,7 @@ func StartFRPCDockerContainer(ipaddress string, port string, docker *docker.Dock
|
|||||||
// Set client mapping
|
// Set client mapping
|
||||||
var clientMapping ClientMapping
|
var clientMapping ClientMapping
|
||||||
portMap := docker.Ports.PortSet[i].ExternalPort
|
portMap := docker.Ports.PortSet[i].ExternalPort
|
||||||
|
clientMapping.LocalIP = "localhost"
|
||||||
clientMapping.LocalPort = portMap
|
clientMapping.LocalPort = portMap
|
||||||
clientMapping.RemotePort = portMap
|
clientMapping.RemotePort = portMap
|
||||||
// Append to array
|
// Append to array
|
||||||
|
|||||||
@@ -183,6 +183,8 @@ func Server() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(proxyPort)
|
||||||
|
|
||||||
// updating with the current proxy address
|
// updating with the current proxy address
|
||||||
ProxyIpAddr.Ipv4 = lowestLatencyIpAddress.Ipv4
|
ProxyIpAddr.Ipv4 = lowestLatencyIpAddress.Ipv4
|
||||||
ProxyIpAddr.ServerPort = proxyPort
|
ProxyIpAddr.ServerPort = proxyPort
|
||||||
|
|||||||
Reference in New Issue
Block a user