From d82194bae0785a9d7dababd7b46afa9f47ec7f09 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 14 Jun 2021 16:50:35 -0700 Subject: [PATCH] revert DeletePeer having a return value; match other app apis with message returns; full app client/service support --- app/app.go | 9 +++++---- app/appClient.go | 7 +++---- app/appService.go | 32 ++++++++++++++++++++++---------- event/common.go | 3 +++ 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/app/app.go b/app/app.go index 5845065..9aba3741 100644 --- a/app/app.go +++ b/app/app.go @@ -44,7 +44,7 @@ type Application interface { LoadProfiles(password string) CreatePeer(name string, password string) CreateTaggedPeer(name string, password string, tag string) - DeletePeer(onion string, currentPassword string) bool + DeletePeer(onion string, currentPassword string) AddPeerPlugin(onion string, pluginID plugins.PluginID) ChangePeerPassword(onion, oldpass, newpass string) LaunchPeers() @@ -142,7 +142,7 @@ func (app *application) CreatePeer(name string, password string) { app.CreateTaggedPeer(name, password, "") } -func (app *application) DeletePeer(onion string, password string) bool { +func (app *application) DeletePeer(onion string, password string) { log.Infof("DeletePeer called on %v\n", onion) app.appmutex.Lock() defer app.appmutex.Unlock() @@ -165,9 +165,10 @@ func (app *application) DeletePeer(onion string, password string) bool { app.applicationCore.DeletePeer(onion) log.Debugf("Delete peer for %v Done\n", onion) - return true + app.appBus.Publish(event.NewEventList(event.PeerDeleted, event.Identity, onion)) + return } - return false + app.appBus.Publish(event.NewEventList(event.AppError, event.Error, event.PasswordMatchError, event.Identity, onion)) } func (app *application) ChangePeerPassword(onion, oldpass, newpass string) { diff --git a/app/appClient.go b/app/appClient.go index 184ce63..9dd5c1b 100644 --- a/app/appClient.go +++ b/app/appClient.go @@ -47,7 +47,7 @@ func (ac *applicationClient) handleEvent(ev *event.Event) { reload := ev.Data[event.Status] == event.StorageRunning created := ev.Data[event.Created] ac.newPeer(localID, key, salt, reload, created) - case event.DeletePeer: + case event.PeerDeleted: onion := ev.Data[event.Identity] ac.handleDeletedPeer(onion) case event.PeerError: @@ -113,11 +113,9 @@ func (ac *applicationClient) CreateTaggedPeer(name, password, tag string) { } // DeletePeer messages the service to delete a peer -func (ac *applicationClient) DeletePeer(onion string, password string) bool { +func (ac *applicationClient) DeletePeer(onion string, password string) { message := event.IPCMessage{Dest: DestApp, Message: event.NewEvent(event.DeletePeer, map[event.Field]string{event.Identity: onion, event.Password: password})} ac.bridge.Write(&message) - // This return value is a lie... - return true } func (ac *applicationClient) ChangePeerPassword(onion, oldpass, newpass string) { @@ -133,6 +131,7 @@ func (ac *applicationClient) handleDeletedPeer(onion string) { ac.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion)) ac.applicationCore.DeletePeer(onion) + ac.appBus.Publish(event.NewEventList(event.PeerDeleted, event.Identity, onion)) } func (ac *applicationClient) AddPeerPlugin(onion string, pluginID plugins.PluginID) { diff --git a/app/appService.go b/app/appService.go index 7cbf4dc..7d0bf21 100644 --- a/app/appService.go +++ b/app/appService.go @@ -52,7 +52,8 @@ func (as *applicationService) handleEvent(ev *event.Event) { as.createPeer(profileName, password, tag) case event.DeletePeer: onion := ev.Data[event.Identity] - as.deletePeer(onion) + password := ev.Data[event.Password] + as.deletePeer(onion, password) message := event.IPCMessage{Dest: DestApp, Message: *ev} as.bridge.Write(&message) @@ -164,21 +165,32 @@ func (as *applicationService) getACNStatusHandler() func(int, string) { } } -func (as *applicationService) deletePeer(onion string) { +func (as *applicationService) deletePeer(onion, password string) { as.asmutex.Lock() defer as.asmutex.Unlock() - as.appletPlugins.ShutdownPeer(onion) - as.plugins.Delete(onion) + if as.storage[onion].CheckPassword(password) { + as.appletPlugins.ShutdownPeer(onion) + as.plugins.Delete(onion) - as.engines[onion].Shutdown() - delete(as.engines, onion) + as.engines[onion].Shutdown() + delete(as.engines, onion) - as.storage[onion].Shutdown() - as.storage[onion].Delete() - delete(as.storage, onion) + as.storage[onion].Shutdown() + as.storage[onion].Delete() + delete(as.storage, onion) - as.applicationCore.DeletePeer(onion) + as.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion)) + + as.applicationCore.DeletePeer(onion) + log.Debugf("Delete peer for %v Done\n", onion) + + message := event.IPCMessage{Dest: DestApp, Message: event.NewEventList(event.PeerDeleted, event.Identity, onion)} + as.bridge.Write(&message) + return + } + message := event.IPCMessage{Dest: DestApp, Message: event.NewEventList(event.AppError, event.Error, event.PasswordMatchError, event.Identity, onion)} + as.bridge.Write(&message) } func (as *applicationService) ShutdownPeer(onion string) { diff --git a/event/common.go b/event/common.go index 7e75f43..37d11ca 100644 --- a/event/common.go +++ b/event/common.go @@ -194,6 +194,8 @@ const ( // Identity(onion) DeletePeer = Type("DeletePeer") + // Identity(onion) + PeerDeleted = Type("PeerDeleted") // Identity(onion), Data(pluginID) AddPeerPlugin = Type("AddPeerPlugin") @@ -312,6 +314,7 @@ const ( // Defining Common errors const ( AppErrLoaded0 = "Loaded 0 profiles" + PasswordMatchError = "Password did not match" ) // Values to be suplied in event.NewPeer for Status