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

@ -12,39 +12,39 @@ 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"`
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"`
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"`
ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
MTU int `json:"mtu" yaml:"mtu"`
PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`
MacAddress net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
TrafficKeyPublic []byte `json:"traffickeypublic" yaml:"trafficekeypublic"`
InternetGateway net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
Nodes []string `json:"nodes" yaml:"nodes"`
IsRelayed bool `json:"isrelayed" yaml:"isrelayed"`
RelayedBy string `json:"relayed_by" yaml:"relayed_by"`
IsRelay bool `json:"isrelay" yaml:"isrelay"`
RelayedHosts []string `json:"relay_hosts" yaml:"relay_hosts"`
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
IsDocker bool `json:"isdocker" yaml:"isdocker"`
IsK8S bool `json:"isk8s" yaml:"isk8s"`
IsStatic bool `json:"isstatic" yaml:"isstatic"`
IsDefault bool `json:"isdefault" yaml:"isdefault"`
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"`
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"`
LocalAddress net.IPNet `json:"localaddress" yaml:"localaddress"`
LocalRange net.IPNet `json:"localrange" yaml:"localrange"`
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"`
MacAddress net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
TrafficKeyPublic []byte `json:"traffickeypublic" yaml:"trafficekeypublic"`
InternetGateway net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
Nodes []string `json:"nodes" yaml:"nodes"`
IsRelayed bool `json:"isrelayed" yaml:"isrelayed"`
RelayedBy string `json:"relayed_by" yaml:"relayed_by"`
IsRelay bool `json:"isrelay" yaml:"isrelay"`
RelayedHosts []string `json:"relay_hosts" yaml:"relay_hosts"`
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
IsDocker bool `json:"isdocker" yaml:"isdocker"`
IsK8S bool `json:"isk8s" yaml:"isk8s"`
IsStatic bool `json:"isstatic" yaml:"isstatic"`
IsDefault bool `json:"isdefault" yaml:"isdefault"`
}
// FormatBool converts a boolean to a [yes|no] string

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