Delete Profile API #367
33
app/app.go
33
app/app.go
|
@ -44,7 +44,7 @@ type Application interface {
|
||||||
LoadProfiles(password string)
|
LoadProfiles(password string)
|
||||||
CreatePeer(name string, password string)
|
CreatePeer(name string, password string)
|
||||||
CreateTaggedPeer(name string, password string, tag string)
|
CreateTaggedPeer(name string, password string, tag string)
|
||||||
DeletePeer(onion string)
|
DeletePeer(onion string, currentPassword string)
|
||||||
AddPeerPlugin(onion string, pluginID plugins.PluginID)
|
AddPeerPlugin(onion string, pluginID plugins.PluginID)
|
||||||
ChangePeerPassword(onion, oldpass, newpass string)
|
ChangePeerPassword(onion, oldpass, newpass string)
|
||||||
LaunchPeers()
|
LaunchPeers()
|
||||||
|
@ -142,28 +142,33 @@ func (app *application) CreatePeer(name string, password string) {
|
||||||
app.CreateTaggedPeer(name, password, "")
|
app.CreateTaggedPeer(name, password, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) DeletePeer(onion string) {
|
func (app *application) DeletePeer(onion string, password string) {
|
||||||
log.Infof("DeletePeer called on %v\n", onion)
|
log.Infof("DeletePeer called on %v\n", onion)
|
||||||
app.appmutex.Lock()
|
app.appmutex.Lock()
|
||||||
defer app.appmutex.Unlock()
|
defer app.appmutex.Unlock()
|
||||||
|
|
||||||
app.appletPlugins.ShutdownPeer(onion)
|
if app.storage[onion].CheckPassword(password) {
|
||||||
app.plugins.Delete(onion)
|
app.appletPlugins.ShutdownPeer(onion)
|
||||||
|
app.plugins.Delete(onion)
|
||||||
|
|
||||||
app.peers[onion].Shutdown()
|
app.peers[onion].Shutdown()
|
||||||
delete(app.peers, onion)
|
delete(app.peers, onion)
|
||||||
|
|
||||||
app.engines[onion].Shutdown()
|
app.engines[onion].Shutdown()
|
||||||
delete(app.engines, onion)
|
delete(app.engines, onion)
|
||||||
|
|
||||||
app.storage[onion].Shutdown()
|
app.storage[onion].Shutdown()
|
||||||
app.storage[onion].Delete()
|
app.storage[onion].Delete()
|
||||||
delete(app.storage, onion)
|
delete(app.storage, onion)
|
||||||
|
|
||||||
app.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion))
|
app.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion))
|
||||||
|
|
||||||
app.applicationCore.DeletePeer(onion)
|
app.applicationCore.DeletePeer(onion)
|
||||||
log.Debugf("Delete peer for %v Done\n", onion)
|
log.Debugf("Delete peer for %v Done\n", onion)
|
||||||
|
app.appBus.Publish(event.NewEventList(event.PeerDeleted, event.Identity, onion))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.appBus.Publish(event.NewEventList(event.AppError, event.Error, event.PasswordMatchError, event.Identity, onion))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) ChangePeerPassword(onion, oldpass, newpass string) {
|
func (app *application) ChangePeerPassword(onion, oldpass, newpass string) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (ac *applicationClient) handleEvent(ev *event.Event) {
|
||||||
reload := ev.Data[event.Status] == event.StorageRunning
|
reload := ev.Data[event.Status] == event.StorageRunning
|
||||||
created := ev.Data[event.Created]
|
created := ev.Data[event.Created]
|
||||||
ac.newPeer(localID, key, salt, reload, created)
|
ac.newPeer(localID, key, salt, reload, created)
|
||||||
case event.DeletePeer:
|
case event.PeerDeleted:
|
||||||
onion := ev.Data[event.Identity]
|
onion := ev.Data[event.Identity]
|
||||||
ac.handleDeletedPeer(onion)
|
ac.handleDeletedPeer(onion)
|
||||||
case event.PeerError:
|
case event.PeerError:
|
||||||
|
@ -112,9 +112,9 @@ func (ac *applicationClient) CreateTaggedPeer(name, password, tag string) {
|
||||||
ac.bridge.Write(&message)
|
ac.bridge.Write(&message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePeer messages tehe service to delete a peer
|
// DeletePeer messages the service to delete a peer
|
||||||
func (ac *applicationClient) DeletePeer(onion string) {
|
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})}
|
message := event.IPCMessage{Dest: DestApp, Message: event.NewEvent(event.DeletePeer, map[event.Field]string{event.Identity: onion, event.Password: password})}
|
||||||
ac.bridge.Write(&message)
|
ac.bridge.Write(&message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +131,7 @@ func (ac *applicationClient) handleDeletedPeer(onion string) {
|
||||||
ac.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion))
|
ac.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion))
|
||||||
|
|
||||||
ac.applicationCore.DeletePeer(onion)
|
ac.applicationCore.DeletePeer(onion)
|
||||||
|
ac.appBus.Publish(event.NewEventList(event.PeerDeleted, event.Identity, onion))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ac *applicationClient) AddPeerPlugin(onion string, pluginID plugins.PluginID) {
|
func (ac *applicationClient) AddPeerPlugin(onion string, pluginID plugins.PluginID) {
|
||||||
|
|
|
@ -52,7 +52,8 @@ func (as *applicationService) handleEvent(ev *event.Event) {
|
||||||
as.createPeer(profileName, password, tag)
|
as.createPeer(profileName, password, tag)
|
||||||
case event.DeletePeer:
|
case event.DeletePeer:
|
||||||
onion := ev.Data[event.Identity]
|
onion := ev.Data[event.Identity]
|
||||||
as.deletePeer(onion)
|
password := ev.Data[event.Password]
|
||||||
|
as.deletePeer(onion, password)
|
||||||
|
|
||||||
message := event.IPCMessage{Dest: DestApp, Message: *ev}
|
message := event.IPCMessage{Dest: DestApp, Message: *ev}
|
||||||
as.bridge.Write(&message)
|
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()
|
as.asmutex.Lock()
|
||||||
defer as.asmutex.Unlock()
|
defer as.asmutex.Unlock()
|
||||||
|
|
||||||
as.appletPlugins.ShutdownPeer(onion)
|
if as.storage[onion].CheckPassword(password) {
|
||||||
as.plugins.Delete(onion)
|
as.appletPlugins.ShutdownPeer(onion)
|
||||||
|
as.plugins.Delete(onion)
|
||||||
|
|
||||||
as.engines[onion].Shutdown()
|
as.engines[onion].Shutdown()
|
||||||
delete(as.engines, onion)
|
delete(as.engines, onion)
|
||||||
|
|
||||||
as.storage[onion].Shutdown()
|
as.storage[onion].Shutdown()
|
||||||
as.storage[onion].Delete()
|
as.storage[onion].Delete()
|
||||||
delete(as.storage, onion)
|
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) {
|
func (as *applicationService) ShutdownPeer(onion string) {
|
||||||
|
|
|
@ -194,6 +194,8 @@ const (
|
||||||
|
|
||||||
// Identity(onion)
|
// Identity(onion)
|
||||||
DeletePeer = Type("DeletePeer")
|
DeletePeer = Type("DeletePeer")
|
||||||
|
// Identity(onion)
|
||||||
|
PeerDeleted = Type("PeerDeleted")
|
||||||
|
|
||||||
// Identity(onion), Data(pluginID)
|
// Identity(onion), Data(pluginID)
|
||||||
AddPeerPlugin = Type("AddPeerPlugin")
|
AddPeerPlugin = Type("AddPeerPlugin")
|
||||||
|
@ -312,6 +314,7 @@ const (
|
||||||
// Defining Common errors
|
// Defining Common errors
|
||||||
const (
|
const (
|
||||||
AppErrLoaded0 = "Loaded 0 profiles"
|
AppErrLoaded0 = "Loaded 0 profiles"
|
||||||
|
PasswordMatchError = "Password did not match"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Values to be suplied in event.NewPeer for Status
|
// Values to be suplied in event.NewPeer for Status
|
||||||
|
|
|
@ -22,6 +22,7 @@ type ProfileStore interface {
|
||||||
GetProfileCopy(timeline bool) *model.Profile
|
GetProfileCopy(timeline bool) *model.Profile
|
||||||
GetNewPeerMessage() *event.Event
|
GetNewPeerMessage() *event.Event
|
||||||
GetStatusMessages() []*event.Event
|
GetStatusMessages() []*event.Event
|
||||||
|
CheckPassword(string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateProfileWriterStore creates a profile store backed by a filestore listening for events and saving them
|
// CreateProfileWriterStore creates a profile store backed by a filestore listening for events and saving them
|
||||||
|
|
|
@ -33,6 +33,12 @@ type ProfileStoreV1 struct {
|
||||||
writer bool
|
writer bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckPassword returns true if the given password produces the same key as the current stored key, otherwise false.
|
||||||
|
func (ps *ProfileStoreV1) CheckPassword(checkpass string) bool {
|
||||||
|
oldkey := CreateKey(checkpass, ps.salt[:])
|
||||||
|
return oldkey == ps.key
|
||||||
|
}
|
||||||
|
|
||||||
func initV1Directory(directory, password string) ([32]byte, [128]byte, error) {
|
func initV1Directory(directory, password string) ([32]byte, [128]byte, error) {
|
||||||
key, salt, err := CreateKeySalt(password)
|
key, salt, err := CreateKeySalt(password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue