change public listen port field

This commit is contained in:
Abhishek Kondur 2023-01-18 12:00:26 +05:30
parent e290994021
commit 10f724310c
3 changed files with 41 additions and 37 deletions

View file

@ -433,8 +433,8 @@ func GetPeerUpdateForHost(host *models.Host) (models.HostPeerUpdate, error) {
func getPeerListenPort(host *models.Host) int {
peerPort := host.ListenPort
if host.ProxyEnabled {
if host.ProxyPublicListenPort != 0 {
peerPort = host.ProxyPublicListenPort
if host.PublicListenPort != 0 {
peerPort = host.PublicListenPort
} else if host.ProxyListenPort != 0 {
peerPort = host.ProxyListenPort
}
@ -633,7 +633,7 @@ func GetPeerUpdateLegacy(node *models.Node) (models.PeerUpdate, error) {
if node.LocalAddress.String() != peer.LocalAddress.String() && peer.LocalAddress.IP != nil {
peerHost.EndpointIP = peer.LocalAddress.IP
if peerHost.ListenPort != 0 {
peerHost.ListenPort = peerHost.ListenPort
peerHost.ListenPort = getPeerListenPort(peerHost)
}
} else {
continue
@ -666,7 +666,7 @@ func GetPeerUpdateLegacy(node *models.Node) (models.PeerUpdate, error) {
// or, if port is for some reason zero use the LocalListenPort
// but only do this if LocalListenPort is not zero
if ((!setUDPPort) || peerHost.ListenPort == 0) && peerHost.ListenPort != 0 {
peerHost.ListenPort = peerHost.ListenPort
peerHost.ListenPort = getPeerListenPort(peerHost)
}
endpoint := peerHost.EndpointIP.String() + ":" + strconv.FormatInt(int64(peerHost.ListenPort), 10)

View file

@ -26,7 +26,7 @@ type Host struct {
ListenPort int `json:"listenport" yaml:"listenport"`
LocalAddress net.IPNet `json:"localaddress" yaml:"localaddress"`
LocalRange net.IPNet `json:"localrange" yaml:"localrange"`
ProxyPublicListenPort int `json:"proxy_public_listen_port" yaml:"proxy_public_listen_port"`
PublicListenPort int `json:"proxy_public_listen_port" yaml:"proxy_public_listen_port"`
ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
MTU int `json:"mtu" yaml:"mtu"`
PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`

View file

@ -188,6 +188,10 @@ func updateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
currHost.ProxyListenPort = newHost.ProxyListenPort
sendPeerUpdate = true
}
if newHost.PublicListenPort != 0 && currHost.PublicListenPort != newHost.PublicListenPort {
currHost.PublicListenPort = newHost.PublicListenPort
sendPeerUpdate = true
}
if currHost.ProxyEnabled != newHost.ProxyEnabled {
currHost.ProxyEnabled = newHost.ProxyEnabled
sendPeerUpdate = true