Browse Source

use public ip func from netmaker

Abhishek Kondur 2 years ago
parent
commit
09a5b0ff62

+ 2 - 2
compose/docker-compose.yml

@@ -87,8 +87,8 @@ services:
     volumes:
       - turn_server:/etc/config
     environment:
-      DEBUG_MODE: "on"
-      VERBOSITY: "4"
+      DEBUG_MODE: "off"
+      VERBOSITY: "1"
       TURN_PORT: "3479"
       TURN_API_PORT: "8089"
       CORS_ALLOWED_ORIGIN: "*"

+ 8 - 2
docker/Caddyfile

@@ -36,12 +36,18 @@ https://stun.NETMAKER_BASE_DOMAIN {
 }
 
 # TURN
-https://stun.NETMAKER_BASE_DOMAIN {
-	reverse_proxy netmaker:3479
+https://turn.NETMAKER_BASE_DOMAIN {
+	reverse_proxy turn:3479
+}
+
+#TURN API
+https://turnapi.NETMAKER_BASE_DOMAIN {
+        reverse_proxy http://turn:8089
 }
 
 
 
+
 # MQ
 wss://broker.NETMAKER_BASE_DOMAIN {
         reverse_proxy ws://mq:8883 # For EMQX websockets use `reverse_proxy ws://mq:8083`

+ 0 - 1
turnserver/internal/utils/response.go

@@ -7,7 +7,6 @@ import (
 	"github.com/gravitl/netmaker/models"
 )
 
-// ReturnSuccessResponse - success api response
 // ReturnSuccessResponse - success api response
 func ReturnSuccessResponse(c *gin.Context, message string, responseBody interface{}) {
 	var httpResponse models.SuccessResponse

+ 0 - 46
turnserver/internal/utils/utils.go

@@ -1,46 +0,0 @@
-package utils
-
-import (
-	"errors"
-	"io"
-	"net/http"
-	"time"
-)
-
-// GetPublicIP - gets public ip
-func GetPublicIP() (string, error) {
-
-	iplist := []string{"https://ip.client.gravitl.com", "https://ifconfig.me", "https://api.ipify.org", "https://ipinfo.io/ip"}
-
-	//for network, ipService := range global_settings.PublicIPServices {
-	//logger.Log(3, "User provided public IP service defined for network", network, "is", ipService)
-
-	// prepend the user-specified service so it's checked first
-	//		iplist = append([]string{ipService}, iplist...)
-	//}
-
-	endpoint := ""
-	var err error
-	for _, ipserver := range iplist {
-		client := &http.Client{
-			Timeout: time.Second * 10,
-		}
-		resp, err := client.Get(ipserver)
-		if err != nil {
-			continue
-		}
-		defer resp.Body.Close()
-		if resp.StatusCode == http.StatusOK {
-			bodyBytes, err := io.ReadAll(resp.Body)
-			if err != nil {
-				continue
-			}
-			endpoint = string(bodyBytes)
-			break
-		}
-	}
-	if err == nil && endpoint == "" {
-		err = errors.New("public address not found")
-	}
-	return endpoint, err
-}

+ 1 - 1
turnserver/src/routes/routes.go

@@ -30,5 +30,5 @@ func registerRoutes(r *gin.RouterGroup) {
 func status(c *gin.Context) {
 	c.JSON(http.StatusOK, struct {
 		Msg string `json:"msg"`
-	}{Msg: "hello"})
+	}{Msg: "active"})
 }

+ 2 - 2
turnserver/src/turn/server.go

@@ -11,9 +11,9 @@ import (
 	"time"
 
 	"github.com/gravitl/netmaker/logger"
+	"github.com/gravitl/netmaker/servercfg"
 	"github.com/gravitl/netmaker/turnserver/config"
 	"github.com/gravitl/netmaker/turnserver/internal/auth"
-	"github.com/gravitl/netmaker/turnserver/internal/utils"
 	"github.com/pion/turn/v2"
 	"golang.org/x/sys/unix"
 )
@@ -28,7 +28,7 @@ func Start(ctx context.Context, wg *sync.WaitGroup) {
 	if err != nil {
 		log.Fatalf("Failed to parse server address: %s", err)
 	}
-	publicIP, err := utils.GetPublicIP()
+	publicIP, err := servercfg.GetPublicIP()
 	if err != nil {
 		logger.FatalLog("failed to get public ip: ", err.Error())
 	}