forked from cwtch.im/libcwtch-go
app event handler now turns app networking on/off based on ACN status
This commit is contained in:
parent
99a51ef19a
commit
61c7418252
|
@ -80,16 +80,39 @@ func (eh *EventHandler) GetNextEvent() string {
|
||||||
|
|
||||||
// handleAppBusEvent enriches AppBus events so they are usable with out further data fetches
|
// handleAppBusEvent enriches AppBus events so they are usable with out further data fetches
|
||||||
func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
|
acnStatus := -1
|
||||||
if eh.app != nil {
|
if eh.app != nil {
|
||||||
switch e.EventType {
|
switch e.EventType {
|
||||||
case event.ACNStatus:
|
case event.ACNStatus:
|
||||||
if e.Data[event.Progress] == "100" {
|
newAcnStatus, err := strconv.Atoi(e.Data[event.Progress])
|
||||||
for _, onion := range eh.app.ListProfiles() {
|
if err != nil {
|
||||||
// launch a listen thread (internally this does a check that the protocol engine is not listening)
|
break
|
||||||
// and as such is safe to call.
|
}
|
||||||
eh.app.GetPeer(onion).Listen()
|
if newAcnStatus == 100 {
|
||||||
|
if acnStatus != 100 {
|
||||||
|
// just came online
|
||||||
|
for _, onion := range eh.app.ListProfiles() {
|
||||||
|
eh.app.ActivePeerEngine(onion)
|
||||||
|
// launch a listen thread (internally this does a check that the protocol engine is not listening)
|
||||||
|
// and as such is safe to call.
|
||||||
|
profile := eh.app.GetPeer(onion)
|
||||||
|
profile.Listen()
|
||||||
|
profile.StartPeersConnections()
|
||||||
|
if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil {
|
||||||
|
profile.StartServerConnections()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if acnStatus == 100 {
|
||||||
|
// just fell offline
|
||||||
|
for _, onion := range eh.app.ListProfiles() {
|
||||||
|
eh.app.DeactivatePeerEngine(onion)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
acnStatus = newAcnStatus
|
||||||
|
|
||||||
case event.NewPeer:
|
case event.NewPeer:
|
||||||
onion := e.Data[event.Identity]
|
onion := e.Data[event.Identity]
|
||||||
profile := eh.app.GetPeer(e.Data[event.Identity])
|
profile := eh.app.GetPeer(e.Data[event.Identity])
|
||||||
|
@ -126,10 +149,12 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start up the Profile
|
// Start up the Profile
|
||||||
profile.Listen()
|
if acnStatus == 100 {
|
||||||
profile.StartPeersConnections()
|
profile.Listen()
|
||||||
if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil {
|
profile.StartPeersConnections()
|
||||||
profile.StartServerConnections()
|
if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil {
|
||||||
|
profile.StartServerConnections()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline)
|
online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline)
|
||||||
|
|
Loading…
Reference in New Issue