fix: correctly set the country code when no flag is passed:

- And send uuid in node info
This commit is contained in:
HeshamTB 2024-03-28 22:58:20 +03:00
parent f0018bbd2f
commit 9836ce6725
2 changed files with 6 additions and 2 deletions

View File

@ -14,9 +14,10 @@ import (
"strings" "strings"
"time" "time"
"github.com/biter777/countries"
"github.com/google/uuid"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"github.com/biter777/countries"
hvpnnode3 "gitea.hbanafa.com/HeshamTB/hvpn-node3" hvpnnode3 "gitea.hbanafa.com/HeshamTB/hvpn-node3"
) )
@ -35,6 +36,7 @@ var WgPort int
var wgLink *hvpnnode3.WGLink var wgLink *hvpnnode3.WGLink
var Country countries.CountryCode var Country countries.CountryCode
var UUID uuid.UUID
var httpPort int var httpPort int
var TLS_ENABLED bool var TLS_ENABLED bool
@ -211,7 +213,6 @@ func createCliApp() *cli.App {
if c == countries.Unknown { if c == countries.Unknown {
return errors.New(fmt.Sprintf("Country code %s is unknown", s)) return errors.New(fmt.Sprintf("Country code %s is unknown", s))
} }
Country = c
return nil return nil
}, },
EnvVars: []string{ "HVPN_COUNTRY" }, EnvVars: []string{ "HVPN_COUNTRY" },
@ -287,6 +288,8 @@ func setup(ctx *cli.Context) error {
os.Exit(-1) os.Exit(-1)
} }
slog.Info("Node UUID: " + uuid.String()) slog.Info("Node UUID: " + uuid.String())
UUID = *uuid
Country = countries.ByName(string(ctx.String("country")))
var privateKey wgtypes.Key var privateKey wgtypes.Key
createPrivKey := func() error { createPrivKey := func() error {

View File

@ -3,6 +3,7 @@ package proto
import "time" import "time"
type NodePublicInfo struct { type NodePublicInfo struct {
UUID string `json:"uuid"`
PublicKey string `json:"public_key"` PublicKey string `json:"public_key"`
UDPPort int `json:"udp_port"` UDPPort int `json:"udp_port"`
Endpoint string `json:"endpoint"` Endpoint string `json:"endpoint"`