From 8c708c6f1118758bd9e53163dc78ea539b405909 Mon Sep 17 00:00:00 2001 From: Akilan Date: Fri, 22 Dec 2023 00:13:57 +0000 Subject: [PATCH] added map port and baremetal mode --- client/MAPPort.go | 32 ++++++++++++++++++++++++++++++++ cmd/action.go | 12 ++++++++++++ cmd/flags.go | 9 ++++++++- server/server.go | 10 ++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 client/MAPPort.go diff --git a/client/MAPPort.go b/client/MAPPort.go new file mode 100644 index 0000000..851a213 --- /dev/null +++ b/client/MAPPort.go @@ -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 +} diff --git a/cmd/action.go b/cmd/action.go index c66b7ca..9f118d7 100644 --- a/cmd/action.go +++ b/cmd/action.go @@ -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 } diff --git a/cmd/flags.go b/cmd/flags.go index e46767f..1403e96 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -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{ diff --git a/server/server.go b/server/server.go index 088dd94..43fc27a 100644 --- a/server/server.go +++ b/server/server.go @@ -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" {