fixed configuration
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,3 +4,6 @@ remotegameplay
|
||||
room.json
|
||||
laplace
|
||||
scripts/
|
||||
server/
|
||||
client/
|
||||
p2p/
|
||||
|
||||
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
@@ -2,5 +2,6 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/server/docker/containers/docker-ubuntu-sshd" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
0
client/grouptrackcontainers.json
Normal file
0
client/grouptrackcontainers.json
Normal file
0
client/trackcontainers.json
Normal file
0
client/trackcontainers.json
Normal file
@@ -8,10 +8,7 @@ import (
|
||||
|
||||
var (
|
||||
defaultPath string
|
||||
defaults = map[string]interface{}{
|
||||
"SystemUsername": "",
|
||||
"BarrierHostName": "",
|
||||
}
|
||||
defaults = map[string]interface{}{}
|
||||
configName = "config"
|
||||
configType = "json"
|
||||
configFile = "config.json"
|
||||
@@ -64,7 +61,6 @@ func SetDefaults() error {
|
||||
defaults["SystemUsername"] = user.Username
|
||||
defaults["BarrierHostName"] = name
|
||||
defaults["Rooms"] = defaultPath + "room.json"
|
||||
defaults["IPAddress"] = "0.0.0.0"
|
||||
defaults["ScriptToExecute"] = ""
|
||||
defaults["SSHPassword"] = ""
|
||||
|
||||
@@ -110,6 +106,7 @@ func ConfigInit() (*Config, error) {
|
||||
for k, v := range defaults {
|
||||
viper.SetDefault(k, v)
|
||||
}
|
||||
|
||||
viper.SetConfigName(configName)
|
||||
viper.SetConfigFile(configFile)
|
||||
viper.SetConfigType(configType)
|
||||
@@ -145,22 +142,16 @@ func (c *Config) WriteConfig() error {
|
||||
defaults["NATEscapeServerPort"] = c.NATEscapeServerPort
|
||||
defaults["NATEscapeBarrierPort"] = c.NATEscapeBarrierPort
|
||||
|
||||
//Paths to search for config file
|
||||
configPaths = append(configPaths, defaultPath)
|
||||
|
||||
//Create rooms.json file
|
||||
os.Create(defaultPath + "room.json")
|
||||
|
||||
// If the config file exists remove and make a new one
|
||||
if fileExists(defaultPath + "config.json") {
|
||||
//if fileExists(defaultPath + "config.json") {
|
||||
err := os.Remove(defaultPath + "config.json")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
//Calling configuration file
|
||||
_, err := ConfigInit()
|
||||
_, err = ConfigInit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func TestConfigInit(t *testing.T) {
|
||||
_, err := ConfigInit()
|
||||
_, err := ConfigRead()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -1,138 +1,16 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"github.com/fatedier/frp/client"
|
||||
"github.com/fatedier/frp/pkg/config"
|
||||
"github.com/phayes/freeport"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/p2p/frp"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
address string
|
||||
port int
|
||||
}
|
||||
|
||||
// Client This struct stores
|
||||
// client information with server
|
||||
// proxy connected
|
||||
type Client struct {
|
||||
Name string
|
||||
Server *Server
|
||||
ClientMappings []ClientMapping
|
||||
}
|
||||
|
||||
// ClientMapping Stores client mapping ports
|
||||
// to proxy server
|
||||
type ClientMapping struct {
|
||||
LocalIP string
|
||||
LocalPort int
|
||||
RemotePort int
|
||||
}
|
||||
|
||||
// StartFRPClientForServer Starts Server using FRP server
|
||||
// returns back a port
|
||||
func StartFRPClientForServer(ipaddress string, serverport string, localport string) (string, error) {
|
||||
// Setup server information
|
||||
var s Server
|
||||
s.address = ipaddress
|
||||
// convert serverport to int
|
||||
portInt, err := strconv.Atoi(serverport)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
s.port = portInt
|
||||
|
||||
// Setup client information
|
||||
var c Client
|
||||
c.Name = "ServerPort"
|
||||
c.Server = &s
|
||||
|
||||
// converts localport to int
|
||||
portInt, err = strconv.Atoi(localport)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
//random serverport
|
||||
//randPort := rangeIn(10000, 99999)
|
||||
OpenPorts, err := freeport.GetFreePorts(1)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
c.ClientMappings = []ClientMapping{
|
||||
{
|
||||
LocalIP: "localhost",
|
||||
LocalPort: portInt,
|
||||
RemotePort: OpenPorts[0],
|
||||
},
|
||||
}
|
||||
|
||||
// Start client server
|
||||
go c.StartFRPClient()
|
||||
|
||||
return strconv.Itoa(OpenPorts[0]), nil
|
||||
|
||||
}
|
||||
|
||||
// StartFRPClient Starts FRP client
|
||||
func (c *Client) StartFRPClient() error {
|
||||
|
||||
cfg := config.GetDefaultClientConf()
|
||||
|
||||
var proxyConfs map[string]config.ProxyConf
|
||||
var visitorCfgs map[string]config.VisitorConf
|
||||
|
||||
proxyConfs = make(map[string]config.ProxyConf)
|
||||
|
||||
cfg.ServerAddr = c.Server.address
|
||||
cfg.ServerPort = c.Server.port
|
||||
|
||||
for i, _ := range c.ClientMappings {
|
||||
var tcpcnf config.TCPProxyConf
|
||||
tcpcnf.LocalIP = c.ClientMappings[i].LocalIP
|
||||
tcpcnf.LocalPort = c.ClientMappings[i].LocalPort
|
||||
tcpcnf.RemotePort = c.ClientMappings[i].RemotePort
|
||||
|
||||
proxyConfs[tcpcnf.ProxyName] = &tcpcnf
|
||||
}
|
||||
|
||||
cli, err := client.NewService(cfg, proxyConfs, visitorCfgs, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cli.Run()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetFRPServerPort(host string) (string, error) {
|
||||
resp, err := http.Get(host + "/FRPPort")
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
// EscapeNAT Func to escape NAT
|
||||
// - 1 port for server
|
||||
// - 2 port for barrierKVM
|
||||
func EscapeNAT(Port string) (ServerPort string, barrierKVMport string, err error) {
|
||||
// Get free port from P2PRC server node
|
||||
serverPort, err := GetFRPServerPort("http://64.227.168.102:8088")
|
||||
serverPort, err := frp.GetFRPServerPort("http://64.227.168.102:8088")
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
@@ -141,13 +19,13 @@ func EscapeNAT(Port string) (ServerPort string, barrierKVMport string, err error
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// port for the remote gameplay server
|
||||
ServerPort, err = StartFRPClientForServer("64.227.168.102", serverPort, Port)
|
||||
ServerPort, err = frp.StartFRPClientForServer("64.227.168.102", serverPort, Port)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Get free port from P2PRC server node
|
||||
serverPort, err = GetFRPServerPort("http://64.227.168.102:8088")
|
||||
serverPort, err = frp.GetFRPServerPort("http://64.227.168.102:8088")
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
@@ -156,7 +34,7 @@ func EscapeNAT(Port string) (ServerPort string, barrierKVMport string, err error
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
//port for the barrierKVM server
|
||||
barrierKVMport, err = StartFRPClientForServer("64.227.168.102", serverPort, "24800")
|
||||
barrierKVMport, err = frp.StartFRPClientForServer("64.227.168.102", serverPort, "24800")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEscapeNAT(t *testing.T) {
|
||||
nat, s, err := EscapeNAT("8090")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println(nat)
|
||||
fmt.Println(s)
|
||||
}
|
||||
7
go.mod
7
go.mod
@@ -2,9 +2,12 @@ module github.com/Akilan1999/remotegameplay
|
||||
|
||||
go 1.16
|
||||
|
||||
replace github.com/Akilan1999/p2p-rendering-computation => /Users/akilan/Documents/p2p-rendering-computation
|
||||
|
||||
require (
|
||||
github.com/fatedier/frp v0.47.0
|
||||
github.com/Akilan1999/p2p-rendering-computation v0.0.0-00010101000000-000000000000
|
||||
github.com/fatedier/frp v0.47.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
|
||||
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 // indirect
|
||||
github.com/spf13/viper v1.8.1
|
||||
)
|
||||
|
||||
22
main.go
22
main.go
@@ -17,7 +17,7 @@ func main() {
|
||||
addr := flag.String("addr", "localhost", "Listen address")
|
||||
port := flag.String("port", "8888", "port for running the server")
|
||||
tls := flag.Bool("tls", false, "Use TLS")
|
||||
setconfig := flag.Bool("setconfig", false, "Generates a config file")
|
||||
//setconfig := flag.Bool("setconfig", false, "Generates a config file")
|
||||
certFile := flag.String("certFile", "files/server.crt", "TLS cert file")
|
||||
keyFile := flag.String("keyFile", "files/server.key", "TLS key file")
|
||||
headless := flag.Bool("headless", false, "Creating screenshare using headless mode")
|
||||
@@ -28,15 +28,14 @@ func main() {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
// Action performed when the config file is called
|
||||
if *setconfig {
|
||||
config.SetDefaults()
|
||||
return
|
||||
}
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
server := core.GetHttp()
|
||||
|
||||
err := config.SetDefaults()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// running implementation to escape NAT
|
||||
Server, barrireKVM, err := core.EscapeNAT(*port)
|
||||
if err != nil {
|
||||
@@ -47,10 +46,13 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
Config.IPAddress = "64.227.168.102"
|
||||
Config.NATEscapeServerPort = Server
|
||||
Config.NATEscapeBarrierPort = barrireKVM
|
||||
|
||||
fmt.Println(Config)
|
||||
|
||||
err = Config.WriteConfig()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
@@ -142,6 +144,12 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Start P2PRC server
|
||||
//_, err = abstractions.Start()
|
||||
//if err != nil {
|
||||
// return
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
// PrettyPrint print the contents of the obj (
|
||||
|
||||
15
p2p/iptable/ip_table.json
Normal file
15
p2p/iptable/ip_table.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"ip_address": [
|
||||
{
|
||||
"Name": "Node1",
|
||||
"IPV4": "64.227.168.102",
|
||||
"IPV6": "",
|
||||
"Latency": 0,
|
||||
"Download": 0,
|
||||
"Upload": 0,
|
||||
"ServerPort": "8088",
|
||||
"NAT": "False",
|
||||
"EscapeImplementation": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
1
server/docker/containers/docker-ubuntu-sshd
Submodule
1
server/docker/containers/docker-ubuntu-sshd
Submodule
Submodule server/docker/containers/docker-ubuntu-sshd added at fbee2ad6a9
Reference in New Issue
Block a user