Closing Down Database + Delete Peer
This commit is contained in:
parent
cb8960f893
commit
f1caca3adf
29
app/app.go
29
app/app.go
|
@ -121,23 +121,24 @@ func (app *application) DeletePeer(onion string, password string) {
|
|||
app.appmutex.Lock()
|
||||
defer app.appmutex.Unlock()
|
||||
|
||||
//if app.storage[onion].CheckPassword(password) {
|
||||
app.appletPlugins.ShutdownPeer(onion)
|
||||
app.plugins.Delete(onion)
|
||||
if app.peers[onion].CheckPassword(password) {
|
||||
app.appletPlugins.ShutdownPeer(onion)
|
||||
app.plugins.Delete(onion)
|
||||
|
||||
app.peers[onion].Shutdown()
|
||||
delete(app.peers, onion)
|
||||
// Shutdown and Remove the Engine
|
||||
app.engines[onion].Shutdown()
|
||||
delete(app.engines, onion)
|
||||
|
||||
app.engines[onion].Shutdown()
|
||||
delete(app.engines, onion)
|
||||
app.peers[onion].Shutdown()
|
||||
app.peers[onion].Delete()
|
||||
delete(app.peers, onion)
|
||||
app.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion))
|
||||
app.applicationCore.DeletePeer(onion)
|
||||
|
||||
app.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion))
|
||||
|
||||
app.applicationCore.DeletePeer(onion)
|
||||
log.Debugf("Delete peer for %v Done\n", onion)
|
||||
app.appBus.Publish(event.NewEventList(event.PeerDeleted, event.Identity, onion))
|
||||
return
|
||||
//}
|
||||
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))
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,23 @@ type cwtchPeer struct {
|
|||
eventBus event.Manager
|
||||
}
|
||||
|
||||
func (cp *cwtchPeer) Delete() {
|
||||
cp.mutex.Lock()
|
||||
defer cp.mutex.Unlock()
|
||||
cp.storage.Delete()
|
||||
}
|
||||
|
||||
func (cp *cwtchPeer) CheckPassword(password string) bool {
|
||||
cp.mutex.Lock()
|
||||
defer cp.mutex.Unlock()
|
||||
db, err := openEncryptedDatabase(cp.storage.ProfileDirectory, password, false)
|
||||
if db == nil || err != nil {
|
||||
return false
|
||||
}
|
||||
db.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
// GenerateProtocolEngine
|
||||
// Status: New in 1.5
|
||||
func (cp *cwtchPeer) GenerateProtocolEngine(acn connectivity.ACN, bus event.Manager) (connections.Engine, error) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// StorageKeyType is an interface wrapper around storage key types
|
||||
|
@ -50,8 +51,8 @@ type CwtchProfileStorage struct {
|
|||
channelGetCountStmts map[ChannelID]*sql.Stmt
|
||||
channelGetMostRecentMessagesStmts map[ChannelID]*sql.Stmt
|
||||
channelGetMessageByContentHashStmts map[ChannelID]*sql.Stmt
|
||||
|
||||
db *sql.DB
|
||||
ProfileDirectory string
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
// ChannelID encapsulates the data necessary to reference a channel structure.
|
||||
|
@ -98,7 +99,7 @@ const getMostRecentMessagesSQLStmt = `select ID, Body, Attributes, Signature, Co
|
|||
|
||||
// NewCwtchProfileStorage constructs a new CwtchProfileStorage from a database. It is also responsible for
|
||||
// Preparing commonly used SQL Statements
|
||||
func NewCwtchProfileStorage(db *sql.DB) (*CwtchProfileStorage, error) {
|
||||
func NewCwtchProfileStorage(db *sql.DB, profileDirectory string) (*CwtchProfileStorage, error) {
|
||||
|
||||
if db == nil {
|
||||
return nil, errors.New("cannot construct cwtch profile storage with a nil database")
|
||||
|
@ -165,6 +166,7 @@ func NewCwtchProfileStorage(db *sql.DB) (*CwtchProfileStorage, error) {
|
|||
}
|
||||
|
||||
return &CwtchProfileStorage{db: db,
|
||||
ProfileDirectory: profileDirectory,
|
||||
insertProfileKeyValueStmt: insertProfileKeyValueStmt,
|
||||
selectProfileKeyValueStmt: selectProfileKeyStmt,
|
||||
fetchAllConversationsStmt: fetchAllConversationsStmt,
|
||||
|
@ -635,6 +637,47 @@ func (cps *CwtchProfileStorage) Close() {
|
|||
if cps.db != nil {
|
||||
cps.insertProfileKeyValueStmt.Close()
|
||||
cps.selectProfileKeyValueStmt.Close()
|
||||
|
||||
cps.insertConversationStmt.Close()
|
||||
cps.fetchAllConversationsStmt.Close()
|
||||
cps.selectConversationStmt.Close()
|
||||
cps.selectConversationByHandleStmt.Close()
|
||||
cps.acceptConversationStmt.Close()
|
||||
cps.deleteConversationStmt.Close()
|
||||
cps.setConversationAttributesStmt.Close()
|
||||
cps.setConversationACLStmt.Close()
|
||||
|
||||
for _, v := range cps.channelInsertStmts {
|
||||
v.Close()
|
||||
}
|
||||
for _, v := range cps.channelUpdateMessageStmts {
|
||||
v.Close()
|
||||
}
|
||||
for _, v := range cps.channelGetMessageStmts {
|
||||
v.Close()
|
||||
}
|
||||
for _, v := range cps.channelGetMessageBySignatureStmts {
|
||||
v.Close()
|
||||
}
|
||||
for _, v := range cps.channelGetCountStmts {
|
||||
v.Close()
|
||||
}
|
||||
for _, v := range cps.channelGetMostRecentMessagesStmts {
|
||||
v.Close()
|
||||
}
|
||||
for _, v := range cps.channelGetMessageByContentHashStmts {
|
||||
v.Close()
|
||||
}
|
||||
|
||||
cps.db.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// Delete unconditionally destroys the profile directory associated with the store.
|
||||
// This is unrecoverable.
|
||||
func (cps *CwtchProfileStorage) Delete() {
|
||||
err := os.RemoveAll(cps.ProfileDirectory)
|
||||
if err != nil {
|
||||
log.Errorf("error deleting profile directory", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,4 +118,6 @@ type CwtchPeer interface {
|
|||
GetMostRecentMessages(conversation int, channel int, offset int, limit int) ([]model.ConversationMessage, error)
|
||||
|
||||
ShareFile(fileKey string, serializedManifest string)
|
||||
CheckPassword(password string) bool
|
||||
Delete()
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ func CreateEncryptedStorePeer(profileDirectory string, name string, password str
|
|||
|
||||
log.Debugf("Creating Cwtch Profile Backed By Encrypted Database")
|
||||
|
||||
cps, err := NewCwtchProfileStorage(db)
|
||||
cps, err := NewCwtchProfileStorage(db, profileDirectory)
|
||||
if err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
|
@ -140,7 +140,7 @@ func CreateEncryptedStore(profileDirectory string, password string) (*CwtchProfi
|
|||
|
||||
log.Debugf("Creating Cwtch Profile Backed By Encrypted Database")
|
||||
|
||||
cps, err := NewCwtchProfileStorage(db)
|
||||
cps, err := NewCwtchProfileStorage(db, profileDirectory)
|
||||
if err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
|
@ -158,7 +158,7 @@ func FromEncryptedDatabase(profileDirectory string, password string) (CwtchPeer,
|
|||
}
|
||||
|
||||
log.Debugf("Initializing Profile from Encrypted Storage")
|
||||
cps, err := NewCwtchProfileStorage(db)
|
||||
cps, err := NewCwtchProfileStorage(db, profileDirectory)
|
||||
if err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue