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/go.mod b/go.mod index c36ffc8..05fd87c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.openprivacy.ca/cwtch.im/libcwtch-go go 1.17 require ( - cwtch.im/cwtch v0.18.5 + cwtch.im/cwtch v0.18.6 git.openprivacy.ca/cwtch.im/server v1.4.5 git.openprivacy.ca/openprivacy/connectivity v1.8.6 git.openprivacy.ca/openprivacy/log v1.0.3 diff --git a/go.sum b/go.sum index dc621ab..1acb7b3 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ cwtch.im/cwtch v0.18.4 h1:Oht7rEDVJjVWDOKg0xqDgXvY/H059HMJlOPt/nBGqxk= cwtch.im/cwtch v0.18.4/go.mod h1:h8S7EgEM+8pE1k+XLB5jAFdIPlOzwoXEY0GH5mQye5A= cwtch.im/cwtch v0.18.5 h1:yqDns4flbowsbaWjMiUm7Em4IAlM8kkgm79CCcXV1GE= cwtch.im/cwtch v0.18.5/go.mod h1:h8S7EgEM+8pE1k+XLB5jAFdIPlOzwoXEY0GH5mQye5A= +cwtch.im/cwtch v0.18.6 h1:CRwoZ/H7y1rAp6jrYh6YCIILU+Sw59hJUvHaWqPgBjg= +cwtch.im/cwtch v0.18.6/go.mod h1:h8S7EgEM+8pE1k+XLB5jAFdIPlOzwoXEY0GH5mQye5A= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/lib.go b/lib.go index 20a7d37..5911262 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)) @@ -1111,6 +1133,8 @@ func SetProfileAttribute(profileOnion string, key string, value string) { // All other scopes and zones need to be added explicitly or handled by Cwtch. if zone == attr.ProfileZone && key == constants.Name { profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, value) + } else if zone == attr.ProfileZone && key == constants.PeerAutostart { + profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.PeerAutostart, value) } else { log.Errorf("attempted to set an attribute with an unknown zone: %v", key) } 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 {