From b3d3464e1e6b7d1bda02c94b765cc422ad6d329c Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Wed, 3 Nov 2021 18:19:30 -0700 Subject: [PATCH] support to delete a server --- constants/globals.go | 9 +++++++++ features/servers/servers_functionality.go | 1 + go.mod | 2 +- go.sum | 2 ++ lib.go | 9 +++++++-- utils/eventHandler.go | 1 + 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/constants/globals.go b/constants/globals.go index 88c80f3..f71e3a4 100644 --- a/constants/globals.go +++ b/constants/globals.go @@ -2,4 +2,13 @@ package constants // We offer "un-passworded" profiles but our storage encrypts everything with a password. We need an agreed upon // password to use in that case, that the app case use behind the scenes to password and unlock with +// https://docs.openprivacy.ca/cwtch-security-handbook/profile_encryption_and_storage.html const DefactoPasswordForUnencryptedProfiles = "be gay do crime" + +const ( + // StatusSuccess is an event response for event.Status signifying a call succeeded + StatusSuccess = "success" + // StatusError is an event response for event.Status signifying a call failed in error, ideally accompanied by a event.Error + StatusError = "error" +) + diff --git a/features/servers/servers_functionality.go b/features/servers/servers_functionality.go index f2026cf..4dd0c62 100644 --- a/features/servers/servers_functionality.go +++ b/features/servers/servers_functionality.go @@ -16,6 +16,7 @@ const ( ZeroServersLoaded = event.Type("ZeroServersLoaded") NewServer = event.Type("NewServer") ServerIntentUpdate = event.Type("ServerIntentUpdate") + ServerDeleted = event.Type("ServerDeleted") ) const ( diff --git a/go.mod b/go.mod index ea51191..0944f6e 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( cwtch.im/cwtch v0.13.1 - git.openprivacy.ca/cwtch.im/server v1.3.1 + git.openprivacy.ca/cwtch.im/server v1.3.2 git.openprivacy.ca/openprivacy/connectivity v1.5.0 git.openprivacy.ca/openprivacy/log v1.0.3 golang.org/x/mobile v0.0.0-20210716004757-34ab1303b554 // indirect diff --git a/go.sum b/go.sum index a7ac3c9..a7e4e42 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmG filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= git.openprivacy.ca/cwtch.im/server v1.3.1 h1:Kt4TnlGxGPk1KTjvs1cXtnFWDx+hYqu8w+2eIaqt+F4= git.openprivacy.ca/cwtch.im/server v1.3.1/go.mod h1:gps6glXDt/ra66Do491csrm0TwatAc2lMLOAKCkh5Vw= +git.openprivacy.ca/cwtch.im/server v1.3.2 h1:dUNMM88IWER6cmgCfhekahkef7laH597hqTp9CE2tYg= +git.openprivacy.ca/cwtch.im/server v1.3.2/go.mod h1:gps6glXDt/ra66Do491csrm0TwatAc2lMLOAKCkh5Vw= git.openprivacy.ca/cwtch.im/tapir v0.4.9 h1:LXonlztwvI1F1++0IyomIcDH1/Bxzo+oN8YjGonNvjM= git.openprivacy.ca/cwtch.im/tapir v0.4.9/go.mod h1:p4bHo3DAO8wwimU6JAeZXbfPQ4jnoA2bV+4YvknWTNQ= git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c= diff --git a/lib.go b/lib.go index 1156871..956becc 100644 --- a/lib.go +++ b/lib.go @@ -1048,8 +1048,13 @@ func DeleteServer(onion string, currentPassword string) { if err == nil { serversHandler.StopServer(onion) application.GetPrimaryBus().Publish(event.NewEventList(servers.ServerIntentUpdate, event.Identity, onion, servers.Intent, servers.IntentStopped)) - serversHandler.DeleteServer(onion, currentPassword) - // TODO HANDLE err from DeleteServer? + + err := serversHandler.DeleteServer(onion, currentPassword) + if err == nil { + application.GetPrimaryBus().Publish(event.NewEventList(servers.ServerDeleted, event.Status, constants.StatusSuccess, event.Identity, onion)) + } else { + application.GetPrimaryBus().Publish(event.NewEventList(servers.ServerDeleted, event.Status, constants.StatusError, event.Error, err.Error(), event.Identity, onion)) + } } } diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 8657202..99921a8 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -52,6 +52,7 @@ func (eh *EventHandler) HandleApp(application app.Application) { application.GetPrimaryBus().Subscribe(CwtchStarted, eh.appBusQueue) application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue) application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue) } func (eh *EventHandler) GetNextEvent() string {