Change Persist Thread to a 30 Second delayed, run once on changes.

This commit is contained in:
Jim Norman 2005-10-27 19:24:13 +00:00
parent bb67a93ec8
commit 2483c16c08
7 changed files with 55 additions and 16 deletions

View File

@ -501,6 +501,13 @@ namespace sscs.cache
return false; return false;
} }
internal void UpdatePersistentStore()
{
if (lss != null)
lss.PersistStoreWithDelay();
}
/* This function would need to do any storage/cleanup required /* This function would need to do any storage/cleanup required
* before removing a user session. * before removing a user session.
*/ */

View File

@ -48,8 +48,6 @@ namespace sscs.lss
m_baGeneratedKey = baMasterPasscode; m_baGeneratedKey = baMasterPasscode;
LoadPersistentStore(); LoadPersistentStore();
userStore.DumpSecretstore(); userStore.DumpSecretstore();
persistThread = new Thread(new ThreadStart(PersistStoreThreadFn));
persistThread.Start();
} }
~LocalStorage() ~LocalStorage()
{ {
@ -68,22 +66,29 @@ namespace sscs.lss
m_baGeneratedKey = baMasterPasscode; m_baGeneratedKey = baMasterPasscode;
LoadPersistentStore(); LoadPersistentStore();
userStore.DumpSecretstore(); userStore.DumpSecretstore();
persistThread = new Thread(new ThreadStart(PersistStoreThreadFn));
persistThread.Start();
} }
public void StorePersistentData(string sDataID, byte[] baData) private void StorePersistentData(string sDataID, byte[] baData)
{ {
} }
public byte[] RetrievePersistentData(string sDataID) private byte[] RetrievePersistentData(string sDataID)
{ {
return null; return null;
} }
public void PersistStoreWithDelay()
{
if (persistThread == null)
{
persistThread = new Thread(new ThreadStart(PersistStoreDelayThreadFn));
persistThread.Start();
}
}
public bool StopPersistence() public bool StopPersistence()
{ {
if(persistThread != null) if(persistThread != null)
@ -246,6 +251,13 @@ namespace sscs.lss
return true; return true;
} }
private void PersistStoreDelayThreadFn()
{
Thread.Sleep(30000);
PersistStore();
persistThread = null;
}
private void PersistStoreThreadFn() private void PersistStoreThreadFn()
{ {
while(true) while(true)
@ -264,12 +276,6 @@ namespace sscs.lss
// userStore.DumpSecretstore(); // userStore.DumpSecretstore();
try try
{ {
string fileName = userStore.GetPersistenceFilePath();
if(File.Exists(fileName))
{
File.Delete(fileName);
}
MemoryStream ms1 = new MemoryStream(); MemoryStream ms1 = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(ms1,null); XmlTextWriter writer = new XmlTextWriter(ms1,null);
@ -384,8 +390,24 @@ namespace sscs.lss
writer.Flush(); writer.Flush();
writer.Close(); writer.Close();
byte[] key = CASACrypto.GetKeySetFromFile(CASACrypto.GetMasterPasscode(userStore.GetDesktopPasswd(),userStore.GetPasscodeByDesktopFilePath()),userStore.GetKeyFilePath()); //byte[] key = CASACrypto.GetKeySetFromFile(CASACrypto.GetMasterPasscode(userStore.GetDesktopPasswd(),userStore.GetPasscodeByDesktopFilePath()),userStore.GetKeyFilePath());
byte[] key = CASACrypto.GetKeySetFromFile(m_baGeneratedKey, userStore.GetKeyFilePath());
string fileName = userStore.GetPersistenceFilePath();
// rename existing file
if(File.Exists(fileName))
{
File.Move(fileName, fileName+".tmp");
}
CASACrypto.EncryptDataAndWriteToFile(ms1.ToArray(),key,fileName); CASACrypto.EncryptDataAndWriteToFile(ms1.ToArray(),key,fileName);
//remove temp
if(File.Exists(fileName+".tmp"))
{
File.Delete(fileName+".tmp");
}
} }
catch(Exception e) catch(Exception e)
{ {

View File

@ -300,7 +300,7 @@
/> />
<File <File
RelPath = "init\ProjectInstaller.cs" RelPath = "init\ProjectInstaller.cs"
SubType = "Code" SubType = "Component"
BuildAction = "Compile" BuildAction = "Compile"
/> />
<File <File
@ -310,7 +310,7 @@
/> />
<File <File
RelPath = "init\WinSecretStoreClientService.cs" RelPath = "init\WinSecretStoreClientService.cs"
SubType = "Code" SubType = "Component"
BuildAction = "Compile" BuildAction = "Compile"
/> />
<File <File

View File

@ -208,7 +208,9 @@ namespace sscs.verbs
{ {
KeyChain kc = ssStore.GetKeyChain(sKeyChainID); KeyChain kc = ssStore.GetKeyChain(sKeyChainID);
kc.RemoveAllSecrets(); kc.RemoveAllSecrets();
ssStore.UpdatePersistentStore();
} }
return wo; return wo;
} }
@ -243,7 +245,8 @@ namespace sscs.verbs
{ {
secret = keyChain.GetSecret(secretID); secret = keyChain.GetSecret(secretID);
secret.RemoveKeyValue(keyID); secret.RemoveKeyValue(keyID);
wo.SetError(constants.RetCodes.SUCCESS, null); wo.SetError(constants.RetCodes.SUCCESS, null);
ssStore.UpdatePersistentStore();
} }
} }
catch (Exception e) catch (Exception e)
@ -348,6 +351,7 @@ namespace sscs.verbs
ChangeLinkedKeys(keyChain, secret, keyID, sValue); ChangeLinkedKeys(keyChain, secret, keyID, sValue);
wo.SetError(constants.RetCodes.SUCCESS, null); wo.SetError(constants.RetCodes.SUCCESS, null);
ssStore.UpdatePersistentStore();
} }
else else
wo.SetError(constants.RetCodes.FAILURE, null); wo.SetError(constants.RetCodes.FAILURE, null);
@ -392,6 +396,7 @@ namespace sscs.verbs
// now call the traget to change it's linked ones // now call the traget to change it's linked ones
ChangeLinkedKeys(keyChain, targetSecret, key, valStr); ChangeLinkedKeys(keyChain, targetSecret, key, valStr);
} }
} }
} }
@ -613,6 +618,7 @@ namespace sscs.verbs
Secret targetSecret = keyChain.GetSecret(lki.GetLinkedSecretID()); Secret targetSecret = keyChain.GetSecret(lki.GetLinkedSecretID());
KeyValue targetkv = targetSecret.GetKeyValue(lki.GetLinkedKeyID()); KeyValue targetkv = targetSecret.GetKeyValue(lki.GetLinkedKeyID());
targetkv.RemoveLink(secretID+":"+keyID); targetkv.RemoveLink(secretID+":"+keyID);
ssStore.UpdatePersistentStore();
return wo; return wo;
} }
@ -638,6 +644,7 @@ namespace sscs.verbs
Secret target = keyChain.GetSecret(lki.GetLinkedSecretID()); Secret target = keyChain.GetSecret(lki.GetLinkedSecretID());
KeyValue targetkv = target.GetKeyValue(lki.GetLinkedKeyID()); KeyValue targetkv = target.GetKeyValue(lki.GetLinkedKeyID());
targetkv.AddLink(new LinkedKeyInfo(secretID, keyID)); targetkv.AddLink(new LinkedKeyInfo(secretID, keyID));
ssStore.UpdatePersistentStore();
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -87,6 +87,7 @@ namespace sscs.verbs
{ {
// TODO: get the secret and remove linked keys // TODO: get the secret and remove linked keys
keyChain.RemoveSecret(secretId); keyChain.RemoveSecret(secretId);
ssStore.UpdatePersistentStore();
} }
} }
else else

View File

@ -187,6 +187,7 @@ namespace sscs.verbs
// Now change all values for linked keys // Now change all values for linked keys
ChangeLinkedKeys(keyChain, secret, key, valStr); ChangeLinkedKeys(keyChain, secret, key, valStr);
ssStore.UpdatePersistentStore();
} }
else else

View File

@ -172,6 +172,7 @@ namespace sscs.verbs
} }
} }
ssStore.StartPersistenceByDesktopPasswd(passwd); ssStore.StartPersistenceByDesktopPasswd(passwd);
ssStore.UpdatePersistentStore();
} }
} }
else else