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:
Zoltan Papp 2023-03-24 18:51:35 +01:00 committed by GitHub
parent 992cfe64e1
commit 71d24e59e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -5,5 +5,6 @@ type Listener interface {
OnConnected()
OnDisconnected()
OnConnecting()
OnAddressChanged(string, string)
OnPeersListChanged(int)
}

View File

@ -122,3 +122,12 @@ func (n *notifier) peerListChanged(numOfPeers int) {
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)
}
}

View File

@ -190,6 +190,7 @@ func (d *Status) UpdateLocalPeerState(localPeerState LocalPeerState) {
defer d.mux.Unlock()
d.localPeer = localPeerState
d.notifyAddressChanged()
}
// CleanLocalPeerState cleans local peer status
@ -198,6 +199,7 @@ func (d *Status) CleanLocalPeerState() {
defer d.mux.Unlock()
d.localPeer = LocalPeerState{}
d.notifyAddressChanged()
}
// MarkManagementDisconnected sets ManagementState to disconnected
@ -215,7 +217,7 @@ func (d *Status) MarkManagementConnected() {
defer d.mux.Unlock()
defer d.onConnectionChanged()
d.managementState = true
d.managementState = true
}
// UpdateSignalAddress update the address of the signal server
@ -238,7 +240,7 @@ func (d *Status) MarkSignalDisconnected() {
defer d.mux.Unlock()
defer d.onConnectionChanged()
d.signalState = false
d.signalState = false
}
// MarkSignalConnected sets SignalState to connected
@ -303,3 +305,7 @@ func (d *Status) onConnectionChanged() {
func (d *Status) notifyPeerListChanged() {
d.notifier.peerListChanged(len(d.peers))
}
func (d *Status) notifyAddressChanged() {
d.notifier.localAddressChanged(d.localPeer.FQDN, d.localPeer.IP)
}