mirror of
https://github.com/netbirdio/netbird.git
synced 2025-05-20 00:11:00 +02:00
Add fqdn and address for notification listener (#757)
Extend the status notification listeners with FQDN and address changes. It is required for mobile services.
This commit is contained in:
parent
992cfe64e1
commit
71d24e59e6
@ -5,5 +5,6 @@ type Listener interface {
|
|||||||
OnConnected()
|
OnConnected()
|
||||||
OnDisconnected()
|
OnDisconnected()
|
||||||
OnConnecting()
|
OnConnecting()
|
||||||
|
OnAddressChanged(string, string)
|
||||||
OnPeersListChanged(int)
|
OnPeersListChanged(int)
|
||||||
}
|
}
|
||||||
|
@ -122,3 +122,12 @@ func (n *notifier) peerListChanged(numOfPeers int) {
|
|||||||
l.OnPeersListChanged(numOfPeers)
|
l.OnPeersListChanged(numOfPeers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *notifier) localAddressChanged(fqdn, address string) {
|
||||||
|
n.listenersLock.Lock()
|
||||||
|
defer n.listenersLock.Unlock()
|
||||||
|
|
||||||
|
for l := range n.listeners {
|
||||||
|
l.OnAddressChanged(fqdn, address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -190,6 +190,7 @@ func (d *Status) UpdateLocalPeerState(localPeerState LocalPeerState) {
|
|||||||
defer d.mux.Unlock()
|
defer d.mux.Unlock()
|
||||||
|
|
||||||
d.localPeer = localPeerState
|
d.localPeer = localPeerState
|
||||||
|
d.notifyAddressChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanLocalPeerState cleans local peer status
|
// CleanLocalPeerState cleans local peer status
|
||||||
@ -198,6 +199,7 @@ func (d *Status) CleanLocalPeerState() {
|
|||||||
defer d.mux.Unlock()
|
defer d.mux.Unlock()
|
||||||
|
|
||||||
d.localPeer = LocalPeerState{}
|
d.localPeer = LocalPeerState{}
|
||||||
|
d.notifyAddressChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkManagementDisconnected sets ManagementState to disconnected
|
// MarkManagementDisconnected sets ManagementState to disconnected
|
||||||
@ -215,7 +217,7 @@ func (d *Status) MarkManagementConnected() {
|
|||||||
defer d.mux.Unlock()
|
defer d.mux.Unlock()
|
||||||
defer d.onConnectionChanged()
|
defer d.onConnectionChanged()
|
||||||
|
|
||||||
d.managementState = true
|
d.managementState = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateSignalAddress update the address of the signal server
|
// UpdateSignalAddress update the address of the signal server
|
||||||
@ -238,7 +240,7 @@ func (d *Status) MarkSignalDisconnected() {
|
|||||||
defer d.mux.Unlock()
|
defer d.mux.Unlock()
|
||||||
defer d.onConnectionChanged()
|
defer d.onConnectionChanged()
|
||||||
|
|
||||||
d.signalState = false
|
d.signalState = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkSignalConnected sets SignalState to connected
|
// MarkSignalConnected sets SignalState to connected
|
||||||
@ -303,3 +305,7 @@ func (d *Status) onConnectionChanged() {
|
|||||||
func (d *Status) notifyPeerListChanged() {
|
func (d *Status) notifyPeerListChanged() {
|
||||||
d.notifier.peerListChanged(len(d.peers))
|
d.notifier.peerListChanged(len(d.peers))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Status) notifyAddressChanged() {
|
||||||
|
d.notifier.localAddressChanged(d.localPeer.FQDN, d.localPeer.IP)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user