added map port and baremetal mode
This commit is contained in:
32
client/MAPPort.go
Normal file
32
client/MAPPort.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func MAPPort(port string) (string, error) {
|
||||
Config, err := config.ConfigInit(nil, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
//if version == "version 6" {
|
||||
URL := "http://0.0.0.0:" + Config.ServerPort + "/MAPPort?port=" + port
|
||||
//} else {
|
||||
// URL = "http://" + IP + ":" + serverPort + "/server_info"
|
||||
//}
|
||||
resp, err := http.Get(URL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Convert response to byte value
|
||||
byteValue, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(byteValue), nil
|
||||
}
|
||||
@@ -282,5 +282,17 @@ var CliAction = func(ctx *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
if MAPPort != "" {
|
||||
address, err := client.MAPPort(MAPPort)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(address)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ var (
|
||||
UpdateServerList bool
|
||||
ServerList bool
|
||||
SetDefaultConfig bool
|
||||
BareMetalPublicKey string
|
||||
NetworkInterface bool
|
||||
ViewPlugin bool
|
||||
TrackedContainers bool
|
||||
@@ -30,6 +29,7 @@ var (
|
||||
Groups bool
|
||||
RemoveContainerGroup bool
|
||||
RemoveGroup string
|
||||
MAPPort string
|
||||
//FRPProxy bool
|
||||
// Generate only allowed in dev release
|
||||
// -- REMOVE ON REGULAR RELEASE --
|
||||
@@ -205,6 +205,13 @@ var AppConfigFlags = []cli.Flag{
|
||||
EnvVars: []string{"REMOVE_GROUP"},
|
||||
Destination: &RemoveGroup,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "MAPPort",
|
||||
Aliases: []string{"mp"},
|
||||
Usage: "Maps port for a specific port provided as the parameter",
|
||||
EnvVars: []string{"MAPPORT"},
|
||||
Destination: &MAPPort,
|
||||
},
|
||||
// Generate only allowed in dev release
|
||||
// -- REMOVE ON REGULAR RELEASE --
|
||||
&cli.StringFlag{
|
||||
|
||||
@@ -173,6 +173,16 @@ func Server() (*gin.Engine, error) {
|
||||
c.String(http.StatusOK, strconv.Itoa(port))
|
||||
})
|
||||
|
||||
r.GET("/MAPPort", func(c *gin.Context) {
|
||||
Ports := c.DefaultQuery("port", "0")
|
||||
url, _, err := MapPort(Ports)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||
}
|
||||
|
||||
c.String(http.StatusOK, url)
|
||||
})
|
||||
|
||||
// If there is a proxy port specified
|
||||
// then starts the FRP server
|
||||
//if config.FRPServerPort != "0" {
|
||||
|
||||
Reference in New Issue
Block a user