From fe84c6ac474c8036e7c9b041b84e450d83eb2c21 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 6 Apr 2021 14:56:01 -0700 Subject: [PATCH] Adding Block/Allow Unknown Contact Global Setting --- .../contact_functionality_addcontact_test.go | 8 ++++++++ go.mod | 2 +- go.sum | 2 ++ lib.go | 16 ++++++++++++++++ utils/eventHandler.go | 9 +++++++++ utils/settings.go | 2 ++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/features/contacts/contact_functionality_addcontact_test.go b/features/contacts/contact_functionality_addcontact_test.go index 2bf96ae..a460651 100644 --- a/features/contacts/contact_functionality_addcontact_test.go +++ b/features/contacts/contact_functionality_addcontact_test.go @@ -14,6 +14,14 @@ type MockPeer struct { peerRequest bool } +func (m MockPeer) BlockUnknownConnections() { + panic("should never be called") +} + +func (m MockPeer) AllowUnknownConnections() { + panic("should never be called") +} + func (m MockPeer) GetContacts() []string { panic("should never be called") } diff --git a/go.mod b/go.mod index ee7bd02..dcd2063 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.openprivacy.ca/flutter/libcwtch-go go 1.15 require ( - cwtch.im/cwtch v0.6.3 + cwtch.im/cwtch v0.6.4 git.openprivacy.ca/openprivacy/connectivity v1.3.3 git.openprivacy.ca/openprivacy/log v1.0.2 ) \ No newline at end of file diff --git a/go.sum b/go.sum index 8e2203d..b147a3d 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ cwtch.im/cwtch v0.6.2 h1:UqwVnxNXvhhG7yGpcY9aXyq0dy31XzjV708BWCHHIms= cwtch.im/cwtch v0.6.2/go.mod h1:snHZIZwRQPAZG2LRZsN5SpAIbeR597VJoDS+KHm7q9w= cwtch.im/cwtch v0.6.3 h1:AifcbxK60UTeOiOt0ur8PLQeDCuljQLhLqrAOO/8guA= cwtch.im/cwtch v0.6.3/go.mod h1:snHZIZwRQPAZG2LRZsN5SpAIbeR597VJoDS+KHm7q9w= +cwtch.im/cwtch v0.6.4 h1:7P7+c7pBw2/aGE1cVWWLlLWhkVrGwuhQomIRbWB840E= +cwtch.im/cwtch v0.6.4/go.mod h1:snHZIZwRQPAZG2LRZsN5SpAIbeR597VJoDS+KHm7q9w= cwtch.im/tapir v0.2.1 h1:t1YJB9q5sV1A9xwiiwL6WVfw3dwQWLoecunuzT1PQtw= cwtch.im/tapir v0.2.1/go.mod h1:xzzZ28adyUXNkYL1YodcHsAiTt3IJ8Loc29YVn9mIEQ= git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c= diff --git a/lib.go b/lib.go index 78c5e72..15b62d1 100644 --- a/lib.go +++ b/lib.go @@ -94,9 +94,12 @@ func StartCwtch(appDir string, torPath string) { settings := utils.ReadGlobalSettings() settingsJson, _ := json.Marshal(settings) + newApp.LoadProfiles("be gay do crime") application = newApp + + // Send global settings to the UI... application.GetPrimaryBus().Publish(event.NewEvent(utils.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)})) log.Infof("libcwtch-go application launched") @@ -142,6 +145,19 @@ func SendAppEvent(eventJson string) { } log.Debugf("New Settings %v", globalSettings) utils.WriteGlobalSettings(globalSettings) + + // Explicitly toggle blocking/unblocking of unknown connections for profiles + // that have been loaded. + if utils.ReadGlobalSettings().BlockUnknownConnections { + for onion := range application.ListPeers() { + application.GetPeer(onion).BlockUnknownConnections() + } + } else { + for onion := range application.ListPeers() { + application.GetPeer(onion).AllowUnknownConnections() + } + } + case utils.SetLoggingLevel: _, warn := new_event.Data[utils.Warn] _, error := new_event.Data[utils.Error] diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 05a0a53..0214465 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -68,6 +68,15 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { eh.app.AddPeerPlugin(onion, plugins.CONNECTIONRETRY) eh.app.AddPeerPlugin(onion, plugins.NETWORKCHECK) + // If the user has chosen to block unknown profiles + // then explicitly configure the protocol engine to do so.. + if ReadGlobalSettings().BlockUnknownConnections { + profile.BlockUnknownConnections() + } else { + // For completeness + profile.AllowUnknownConnections() + } + // Start up the Profile profile.Listen() profile.StartPeersConnections() diff --git a/utils/settings.go b/utils/settings.go index 76c548a..f60e4d8 100644 --- a/utils/settings.go +++ b/utils/settings.go @@ -26,6 +26,7 @@ type GlobalSettings struct { PreviousPid int64 ExperimentsEnabled bool Experiments map[string]bool + BlockUnknownConnections bool StateRootPane int FirstTime bool } @@ -38,6 +39,7 @@ var DefaultGlobalSettings = GlobalSettings{ Experiments: make(map[string]bool), StateRootPane: 0, FirstTime: true, + BlockUnknownConnections: false, } func InitGlobalSettingsFile(directory string, password string) error {