Explorar el Código

fetch public listen of wg if present

Abhishek Kondur hace 2 años
padre
commit
f1c32f4f74
Se han modificado 2 ficheros con 30 adiciones y 15 borrados
  1. 14 1
      logic/peers.go
  2. 16 14
      models/host.go

+ 14 - 1
logic/peers.go

@@ -220,11 +220,12 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
 				}
 				peerConfig.Endpoint = &net.UDPAddr{
 					IP:   peerHost.EndpointIP,
-					Port: peerHost.ListenPort,
+					Port: getPeerWgListenPort(peerHost),
 				}
 
 				if uselocal {
 					peerConfig.Endpoint.IP = peer.LocalAddress.IP
+					peerConfig.Endpoint.Port = peerHost.ListenPort
 				}
 				allowedips := GetAllowedIPs(&node, &peer, nil)
 				if peer.IsIngressGateway {
@@ -425,9 +426,21 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
 	return hostPeerUpdate, nil
 }
 
+// getPeerWgListenPort - fetches the wg listen port for the host
+func getPeerWgListenPort(host *models.Host) int {
+	peerPort := host.ListenPort
+	if host.WgPublicListenPort != 0 {
+		peerPort = host.WgPublicListenPort
+	}
+	return peerPort
+}
+
 // GetPeerListenPort - given a host, retrieve it's appropriate listening port
 func GetPeerListenPort(host *models.Host) int {
 	peerPort := host.ListenPort
+	if host.WgPublicListenPort != 0 {
+		peerPort = host.WgPublicListenPort
+	}
 	if host.ProxyEnabled {
 		if host.PublicListenPort != 0 {
 			peerPort = host.PublicListenPort

+ 16 - 14
models/host.go

@@ -41,20 +41,22 @@ const WIREGUARD_INTERFACE = "netmaker"
 
 // Host - represents a host on the network
 type Host struct {
-	ID               uuid.UUID        `json:"id" yaml:"id"`
-	Verbosity        int              `json:"verbosity" yaml:"verbosity"`
-	FirewallInUse    string           `json:"firewallinuse" yaml:"firewallinuse"`
-	Version          string           `json:"version" yaml:"version"`
-	IPForwarding     bool             `json:"ipforwarding" yaml:"ipforwarding"`
-	DaemonInstalled  bool             `json:"daemoninstalled" yaml:"daemoninstalled"`
-	AutoUpdate       bool             `json:"autoupdate" yaml:"autoupdate"`
-	HostPass         string           `json:"hostpass" yaml:"hostpass"`
-	Name             string           `json:"name" yaml:"name"`
-	OS               string           `json:"os" yaml:"os"`
-	Interface        string           `json:"interface" yaml:"interface"`
-	Debug            bool             `json:"debug" yaml:"debug"`
-	ListenPort       int              `json:"listenport" yaml:"listenport"`
-	PublicListenPort int              `json:"public_listen_port" yaml:"public_listen_port"`
+	ID                 uuid.UUID `json:"id" yaml:"id"`
+	Verbosity          int       `json:"verbosity" yaml:"verbosity"`
+	FirewallInUse      string    `json:"firewallinuse" yaml:"firewallinuse"`
+	Version            string    `json:"version" yaml:"version"`
+	IPForwarding       bool      `json:"ipforwarding" yaml:"ipforwarding"`
+	DaemonInstalled    bool      `json:"daemoninstalled" yaml:"daemoninstalled"`
+	AutoUpdate         bool      `json:"autoupdate" yaml:"autoupdate"`
+	HostPass           string    `json:"hostpass" yaml:"hostpass"`
+	Name               string    `json:"name" yaml:"name"`
+	OS                 string    `json:"os" yaml:"os"`
+	Interface          string    `json:"interface" yaml:"interface"`
+	Debug              bool      `json:"debug" yaml:"debug"`
+	ListenPort         int       `json:"listenport" yaml:"listenport"`
+	PublicListenPort   int       `json:"public_listen_port" yaml:"public_listen_port"`
+	WgPublicListenPort int       `json:"wg_public_listen_port" yaml:"wg_public_listen_port"` /* will be using existing `public_listen_port` \
+	once proxy is disabled for regular comms */
 	ProxyListenPort  int              `json:"proxy_listen_port" yaml:"proxy_listen_port"`
 	MTU              int              `json:"mtu" yaml:"mtu"`
 	PublicKey        wgtypes.Key      `json:"publickey" yaml:"publickey"`