diff --git a/constants/attributes.go b/constants/attributes.go index 8f7e458..a50d7b5 100644 --- a/constants/attributes.go +++ b/constants/attributes.go @@ -16,6 +16,8 @@ const ProfileTypeV1Password = "v1-userPassword" // PeerOnline stores state on if the peer believes it is online const PeerOnline = "peer-online" +const PeerAutostart = "autostart" + // Description is used on server contacts, const Description = "description" diff --git a/lib.go b/lib.go index 20a7d37..a3beec0 100644 --- a/lib.go +++ b/lib.go @@ -520,6 +520,28 @@ func GetAppBusEvent() string { return json } +//export c_ActivatePeerEngine +func c_ActivatePeerEngine(onion_ptr *C.char, onion_len C.int) { + ActivatePeerEngine(C.GoStringN(onion_ptr, onion_len)) +} + +func ActivatePeerEngine(profile string) { + doServers := false + if _, err := groups.ExperimentGate(utils.ReadGlobalSettings().Experiments); err == nil { + doServers = true + } + application.ActivatePeerEngine(profile, true, true, doServers) +} + +//export c_DeactivatePeerEngine +func c_DeactivatePeerEngine(onion_ptr *C.char, onion_len C.int) { + DeactivatePeerEngine(C.GoStringN(onion_ptr, onion_len)) +} + +func DeactivatePeerEngine(profile string) { + application.DeactivatePeerEngine(profile) +} + //export c_CreateProfile func c_CreateProfile(nick_ptr *C.char, nick_len C.int, pass_ptr *C.char, pass_len C.int) { CreateProfile(C.GoStringN(nick_ptr, nick_len), C.GoStringN(pass_ptr, pass_len)) diff --git a/utils/eventHandler.go b/utils/eventHandler.go index b2269f9..2ca2830 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -104,7 +104,14 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { doServers = true } - eh.app.ActivateEngines(true, true, doServers) + + for _, onion := range eh.app.ListProfiles() { + profile := eh.app.GetPeer(onion) + autostart, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerAutostart) + if !exists || autostart == "true" { + eh.app.ActivatePeerEngine(onion, true, true, doServers) + } + } eh.api.LaunchServers() } } else { @@ -156,14 +163,26 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { // Start up the Profile if acnStatus == 100 { - doServers := false - if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { - doServers = true + autostart, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerAutostart) + if !exists || autostart == "true" { + doServers := false + if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { + doServers = true + } + eh.app.ActivatePeerEngine(onion, true, true, doServers) } - eh.app.ActivatePeerEngine(onion, true, true, doServers) } online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) + e.Data["Online"] = online + + autostart, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerAutostart) + // legacy profiles should autostart by default + if !exists { + autostart = "true" + } + e.Data["autostart"] = autostart + // Name always exists e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion) @@ -183,8 +202,6 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { // Resolve the profile image of the profile. - e.Data["Online"] = online - // If file sharing is enabled then reshare all active files... fsf, err := filesharing.FunctionalityGate(settings.Experiments) if err == nil {