From 848d5971b6d9045edbc5675c1d3a3588a36eec04 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 27 Feb 2023 13:31:32 -0800 Subject: [PATCH] Consolidating Profile Setup Logic --- app/app.go | 54 +++++++++++++++---------- extensions/profile_value.go | 2 +- peer/cwtch_peer.go | 4 ++ peer/profile_interface.go | 1 + protocol/files/filesharing_subsystem.go | 2 +- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/app/app.go b/app/app.go index cfb3367..08dfb4f 100644 --- a/app/app.go +++ b/app/app.go @@ -113,6 +113,14 @@ func (app *application) UpdateSettings(settings GlobalSettings) { defer app.peerLock.Unlock() for _, profile := range app.peers { profile.UpdateExperiments(settings.ExperimentsEnabled, settings.Experiments) + + // Explicitly toggle blocking/unblocking of unknown connections for profiles + // that have been loaded. + if settings.BlockUnknownConnections { + profile.BlockUnknownConnections() + } else { + profile.AllowUnknownConnections() + } } } @@ -183,6 +191,24 @@ func (app *application) CreateTaggedPeer(name string, password string, tag strin app.CreatePeer(name, password, map[attr.ZonedPath]string{attr.ProfileZone.ConstructZonedPath(constants.Tag): tag}) } +func (app *application) setupPeer(profile peer.CwtchPeer) { + eventBus := event.NewEventManager() + app.eventBuses[profile.GetOnion()] = eventBus + + // Initialize the Peer with the Given Event Bus + app.peers[profile.GetOnion()] = profile + profile.Init(app.eventBuses[profile.GetOnion()]) + + // Update the Peer with the Most Recent Experiment State... + settings := app.settings.ReadGlobalSettings() + profile.UpdateExperiments(settings.ExperimentsEnabled, settings.Experiments) + app.registerHooks(profile) + + // Register the Peer With Application Plugins.. + app.AddPeerPlugin(profile.GetOnion(), plugins.CONNECTIONRETRY) // Now Mandatory + +} + func (app *application) CreatePeer(name string, password string, attributes map[attr.ZonedPath]string) { app.appmutex.Lock() defer app.appmutex.Unlock() @@ -196,18 +222,13 @@ func (app *application) CreatePeer(name string, password string, attributes map[ return } - eventBus := event.NewEventManager() - app.eventBuses[profile.GetOnion()] = eventBus - profile.Init(app.eventBuses[profile.GetOnion()]) - app.registerHooks(profile) - app.peers[profile.GetOnion()] = profile + app.setupPeer(profile) for zp, val := range attributes { zone, key := attr.ParseZone(zp.ToString()) profile.SetScopedZonedAttribute(attr.LocalScope, zone, key, val) } - app.AddPeerPlugin(profile.GetOnion(), plugins.CONNECTIONRETRY) // Now Mandatory app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.GetOnion(), event.Created: event.True})) } @@ -216,6 +237,11 @@ func (app *application) DeleteProfile(onion string, password string) { app.appmutex.Lock() defer app.appmutex.Unlock() + // allow a blank password to delete "unencrypted" accounts... + if password == "" { + password = DefactoPasswordForUnencryptedProfiles + } + if app.peers[onion].CheckPassword(password) { // soft-shutdown app.peers[onion].Shutdown() @@ -310,21 +336,7 @@ func (app *application) installProfile(profile peer.CwtchPeer) bool { // Only attempt to finalize the profile if we don't have one loaded... if app.peers[profile.GetOnion()] == nil { - eventBus := event.NewEventManager() - app.eventBuses[profile.GetOnion()] = eventBus - - // Initialize the Peer with the Given Event Bus - app.peers[profile.GetOnion()] = profile - profile.Init(app.eventBuses[profile.GetOnion()]) - - // Update the Peer with the Most Recent Experiment State... - settings := app.settings.ReadGlobalSettings() - profile.UpdateExperiments(settings.ExperimentsEnabled, settings.Experiments) - app.registerHooks(profile) - - // Register the Peer With Application Plugins.. - app.AddPeerPlugin(profile.GetOnion(), plugins.CONNECTIONRETRY) // Now Mandatory - + app.setupPeer(profile) // Finalize the Creation of Peer / Notify any Interfaces.. app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.GetOnion(), event.Created: event.False})) return true diff --git a/extensions/profile_value.go b/extensions/profile_value.go index 3855807..5c4dddc 100644 --- a/extensions/profile_value.go +++ b/extensions/profile_value.go @@ -41,7 +41,7 @@ func (pne ProfileValueExtension) OnContactReceiveValue(profile peer.CwtchPeer, c // OnContactRequestValue for ProfileValueExtension handles returning Public Profile Values func (pne ProfileValueExtension) OnContactRequestValue(profile peer.CwtchPeer, conversation model.Conversation, eventID string, szp attr.ScopedZonedPath) { scope, zone, zpath := szp.GetScopeZonePath() - log.Debugf("Looking up public | conversation scope/zone %v", szp.ToString()) + log.Infof("Looking up public | conversation scope/zone %v", szp.ToString()) if scope.IsPublic() || scope.IsConversation() { val, exists := profile.GetScopedZonedAttribute(scope, zone, zpath) diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 8375d41..560c4fe 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -75,6 +75,10 @@ type cwtchPeer struct { experimentsLock sync.Mutex } +func (cp *cwtchPeer) EnhancedImportBundle(importString string) string { + return cp.ImportBundle(importString).Error() +} + func (cp *cwtchPeer) EnhancedGetMessages(conversation int, index int, count int) string { var emessages []EnhancedMessage = make([]EnhancedMessage, count) diff --git a/peer/profile_interface.go b/peer/profile_interface.go index 4a22052..2954dfa 100644 --- a/peer/profile_interface.go +++ b/peer/profile_interface.go @@ -105,6 +105,7 @@ type CwtchPeer interface { // Import Bundle ImportBundle(string) error + EnhancedImportBundle(string) string // New Unified Conversation Interfaces NewContactConversation(handle string, acl model.AccessControl, accepted bool) (int, error) diff --git a/protocol/files/filesharing_subsystem.go b/protocol/files/filesharing_subsystem.go index 2d63b81..011d015 100644 --- a/protocol/files/filesharing_subsystem.go +++ b/protocol/files/filesharing_subsystem.go @@ -34,7 +34,7 @@ func (fsss *FileSharingSubSystem) ShareFile(fileKey string, serializedManifest s log.Errorf("could not share file %v", err) return } - log.Debugf("sharing file: %v %v", fileKey, serializedManifest) + log.Infof("sharing file: %v %v", fileKey, serializedManifest) fsss.activeShares.Store(fileKey, &manifest) }