mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 09:47:49 +02:00
Add OnDisconnecting service callback (#767)
Add OnDisconnecting service callback for mobile
This commit is contained in:
parent
488d338ce8
commit
8ebd6ce963
@ -164,6 +164,7 @@ func RunClient(ctx context.Context, config *Config, statusRecorder *peer.Status,
|
|||||||
state.Set(StatusConnected)
|
state.Set(StatusConnected)
|
||||||
|
|
||||||
<-engineCtx.Done()
|
<-engineCtx.Done()
|
||||||
|
statusRecorder.ClientTeardown()
|
||||||
|
|
||||||
backOff.Reset()
|
backOff.Reset()
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ type Listener interface {
|
|||||||
OnConnected()
|
OnConnected()
|
||||||
OnDisconnected()
|
OnDisconnected()
|
||||||
OnConnecting()
|
OnConnecting()
|
||||||
|
OnDisconnecting()
|
||||||
OnAddressChanged(string, string)
|
OnAddressChanged(string, string)
|
||||||
OnPeersListChanged(int)
|
OnPeersListChanged(int)
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ const (
|
|||||||
stateDisconnected = iota
|
stateDisconnected = iota
|
||||||
stateConnected
|
stateConnected
|
||||||
stateConnecting
|
stateConnecting
|
||||||
|
stateDisconnecting
|
||||||
)
|
)
|
||||||
|
|
||||||
type notifier struct {
|
type notifier struct {
|
||||||
@ -57,8 +58,12 @@ func (n *notifier) updateServerStates(mgmState bool, signalState bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
n.currentServerState = newState
|
n.currentServerState = newState
|
||||||
n.lastNotification = n.calculateState(newState, n.currentClientState)
|
|
||||||
|
|
||||||
|
if n.lastNotification == stateDisconnecting {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
n.lastNotification = n.calculateState(newState, n.currentClientState)
|
||||||
go n.notifyAll(n.lastNotification)
|
go n.notifyAll(n.lastNotification)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +83,14 @@ func (n *notifier) clientStop() {
|
|||||||
go n.notifyAll(n.lastNotification)
|
go n.notifyAll(n.lastNotification)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *notifier) clientTearDown() {
|
||||||
|
n.serverStateLock.Lock()
|
||||||
|
defer n.serverStateLock.Unlock()
|
||||||
|
n.currentClientState = false
|
||||||
|
n.lastNotification = stateDisconnecting
|
||||||
|
go n.notifyAll(n.lastNotification)
|
||||||
|
}
|
||||||
|
|
||||||
func (n *notifier) isServerStateChanged(newState bool) bool {
|
func (n *notifier) isServerStateChanged(newState bool) bool {
|
||||||
return n.currentServerState != newState
|
return n.currentServerState != newState
|
||||||
}
|
}
|
||||||
@ -99,6 +112,8 @@ func (n *notifier) notifyListener(l Listener, state int) {
|
|||||||
l.OnConnected()
|
l.OnConnected()
|
||||||
case stateConnecting:
|
case stateConnecting:
|
||||||
l.OnConnecting()
|
l.OnConnecting()
|
||||||
|
case stateDisconnecting:
|
||||||
|
l.OnDisconnecting()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,6 +288,11 @@ func (d *Status) ClientStop() {
|
|||||||
d.notifier.clientStop()
|
d.notifier.clientStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientTeardown will notify all listeners about the service is under teardown
|
||||||
|
func (d *Status) ClientTeardown() {
|
||||||
|
d.notifier.clientTearDown()
|
||||||
|
}
|
||||||
|
|
||||||
// AddConnectionListener add a listener to the notifier
|
// AddConnectionListener add a listener to the notifier
|
||||||
func (d *Status) AddConnectionListener(listener Listener) {
|
func (d *Status) AddConnectionListener(listener Listener) {
|
||||||
d.notifier.addListener(listener)
|
d.notifier.addListener(listener)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user