[Box Backup-commit] COMMIT r1191 - in box/chris/merge: bin/bbackupd lib/backupclient

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sun Dec 3 10:40:26 GMT 2006


Author: chris
Date: 2006-12-03 10:40:26 +0000 (Sun, 03 Dec 2006)
New Revision: 1191

Modified:
   box/chris/merge/bin/bbackupd/BackupClientContext.cpp
   box/chris/merge/bin/bbackupd/BackupClientContext.h
   box/chris/merge/bin/bbackupd/BackupDaemon.cpp
   box/chris/merge/lib/backupclient/BackupStoreFile.h
   box/chris/merge/lib/backupclient/BackupStoreFileDiff.cpp
Log:
Moved KeepAlive timer to BackupClientContext object.

Made timeout initialisation non-static, and a property of the context 
object. (perhaps should be in rParams, I know).

(refs #3, refs #9)


Modified: box/chris/merge/bin/bbackupd/BackupClientContext.cpp
===================================================================
--- box/chris/merge/bin/bbackupd/BackupClientContext.cpp	2006-12-03 10:33:42 UTC (rev 1190)
+++ box/chris/merge/bin/bbackupd/BackupClientContext.cpp	2006-12-03 10:40:26 UTC (rev 1191)
@@ -67,6 +67,7 @@
 	  mStorageLimitExceeded(false),
 	  mpExcludeFiles(0),
 	  mpExcludeDirs(0),
+	  mKeepAliveTimer(0),
 	  mbIsManaged(false)
 {
 }
@@ -495,21 +496,17 @@
 	return true;
 }
 
-// maximum time to spend diffing
-static int sMaximumDiffTime = 600;
-// maximum time of SSL inactivity (keep-alive interval)
-static int sKeepAliveTime = 0;
-
 void BackupClientContext::SetMaximumDiffingTime(int iSeconds)
 {
-	sMaximumDiffTime = iSeconds < 0 ? 0 : iSeconds;
-	TRACE1("Set maximum diffing time to %d seconds\n", sMaximumDiffTime);
+	mMaximumDiffingTime = iSeconds < 0 ? 0 : iSeconds;
+	TRACE1("Set maximum diffing time to %d seconds\n", mMaximumDiffingTime);
 }
 
 void BackupClientContext::SetKeepAliveTime(int iSeconds)
 {
-	sKeepAliveTime = iSeconds < 0 ? 0 : iSeconds;
-	TRACE1("Set keep-alive time to %d seconds\n", sKeepAliveTime);
+	mKeepAliveTime = iSeconds < 0 ? 0 : iSeconds;
+	TRACE1("Set keep-alive time to %d seconds\n", mKeepAliveTime);
+	mKeepAliveTimer = Timer(mKeepAliveTime);
 }
 
 // --------------------------------------------------------------------------
@@ -544,7 +541,8 @@
 //
 // Function
 //		Name:    BackupClientContext::DoKeepAlive()
-//		Purpose: Does something inconsequential over the SSL link to keep it up
+//		Purpose: Check whether it's time to send a KeepAlive
+//			 message over the SSL link, and if so, send it.
 //		Created: 04/19/2005
 //
 // --------------------------------------------------------------------------
@@ -552,19 +550,26 @@
 {
 	if (!mpConnection)
 	{
-		::syslog(LOG_ERR, "DoKeepAlive() called with no connection!");
 		return;
 	}
+	
+	if (mKeepAliveTime == 0)
+	{
+		return;
+	}
 
+	if (!mKeepAliveTimer.HasExpired())
+	{
+		return;
+	}
+	
+	TRACE0("KeepAliveTime reached, sending keep-alive message\n");
 	mpConnection->QueryGetIsAlive();
+	
+	mKeepAliveTimer = Timer(mKeepAliveTime);
 }
 
 int BackupClientContext::GetMaximumDiffingTime() 
 {
-	return sMaximumDiffTime;
+	return mMaximumDiffingTime;
 }
-
-int BackupClientContext::GetKeepAliveTime() 
-{
-	return sKeepAliveTime;
-}

Modified: box/chris/merge/bin/bbackupd/BackupClientContext.h
===================================================================
--- box/chris/merge/bin/bbackupd/BackupClientContext.h	2006-12-03 10:33:42 UTC (rev 1190)
+++ box/chris/merge/bin/bbackupd/BackupClientContext.h	2006-12-03 10:40:26 UTC (rev 1191)
@@ -14,6 +14,7 @@
 #include "BackupClientDeleteList.h"
 #include "BackupStoreFile.h"
 #include "ExcludeList.h"
+#include "Timer.h"
 
 class TLSContext;
 class BackupProtocolClient;
@@ -151,7 +152,7 @@
 	//		Created: 04/19/2005
 	//
 	// --------------------------------------------------------------------------
-	static void SetMaximumDiffingTime(int iSeconds);
+	void SetMaximumDiffingTime(int iSeconds);
 
 	// --------------------------------------------------------------------------
 	//
@@ -161,7 +162,7 @@
 	//		Created: 04/19/2005
 	//
 	// --------------------------------------------------------------------------
-	static void SetKeepAliveTime(int iSeconds);
+	void SetKeepAliveTime(int iSeconds);
 
 	// --------------------------------------------------------------------------
 	//
@@ -183,18 +184,17 @@
 	// --------------------------------------------------------------------------
 	void UnManageDiffProcess();
 
-	// --------------------------------------------------------------------------
+	// -------------------------------------------------------------------
 	//
 	// Function
 	//		Name:    BackupClientContext::DoKeepAlive()
-	//		Purpose: Does something inconsequential over the SSL link to 
-	//				 keep it up, implements DiffTimer interface
+	//		Purpose: Check whether it's time to send a KeepAlive
+	//			 message over the SSL link, and if so, send it.
 	//		Created: 04/19/2005
 	//
-	// --------------------------------------------------------------------------
+	// -------------------------------------------------------------------
 	virtual void   DoKeepAlive();
 	virtual int    GetMaximumDiffingTime();
-	virtual int    GetKeepAliveTime();
 	virtual bool   IsManaged() { return mbIsManaged; }
 	
 private:
@@ -215,8 +215,10 @@
 	bool mStorageLimitExceeded;
 	ExcludeList *mpExcludeFiles;
 	ExcludeList *mpExcludeDirs;
-
+	Timer mKeepAliveTimer;
 	bool mbIsManaged;
+	int mKeepAliveTime;
+	int mMaximumDiffingTime;
 };
 
 #endif // BACKUPCLIENTCONTEXT__H

Modified: box/chris/merge/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/merge/bin/bbackupd/BackupDaemon.cpp	2006-12-03 10:33:42 UTC (rev 1190)
+++ box/chris/merge/bin/bbackupd/BackupDaemon.cpp	2006-12-03 10:40:26 UTC (rev 1191)
@@ -523,18 +523,20 @@
 	// Set up the keys for various things
 	BackupClientCryptoKeys_Setup(conf.GetKeyValue("KeysFile").c_str());
 
+	// Setup various timings
+	int maximumDiffingTime = 600;
+	int keepAliveTime = 60;
+
 	// max diffing time, keep-alive time
 	if(conf.KeyExists("MaximumDiffingTime"))
 	{
-		BackupClientContext::SetMaximumDiffingTime(conf.GetKeyValueInt("MaximumDiffingTime"));
+		maximumDiffingTime = conf.GetKeyValueInt("MaximumDiffingTime");
 	}
 	if(conf.KeyExists("KeepAliveTime"))
 	{
-		BackupClientContext::SetKeepAliveTime(conf.GetKeyValueInt("KeepAliveTime"));
+		keepAliveTime = conf.GetKeyValueInt("KeepAliveTime");
 	}
 
-	// Setup various timings
-	
 	// How often to connect to the store (approximate)
 	box_time_t updateStoreInterval = SecondsToBoxTime(conf.GetKeyValueInt("UpdateStoreInterval"));
 
@@ -725,6 +727,9 @@
 				params.mFileTrackingSizeThreshold = conf.GetKeyValueInt("FileTrackingSizeThreshold");
 				params.mDiffingUploadSizeThreshold = conf.GetKeyValueInt("DiffingUploadSizeThreshold");
 				params.mMaxFileTimeInFuture = SecondsToBoxTime(conf.GetKeyValueInt("MaxFileTimeInFuture"));
+
+				clientContext.SetMaximumDiffingTime(maximumDiffingTime);
+				clientContext.SetKeepAliveTime(keepAliveTime);
 				
 				// Set store marker
 				clientContext.SetClientStoreMarker(clientStoreMarker);

Modified: box/chris/merge/lib/backupclient/BackupStoreFile.h
===================================================================
--- box/chris/merge/lib/backupclient/BackupStoreFile.h	2006-12-03 10:33:42 UTC (rev 1190)
+++ box/chris/merge/lib/backupclient/BackupStoreFile.h	2006-12-03 10:40:26 UTC (rev 1191)
@@ -50,10 +50,9 @@
 	DiffTimer();
 	virtual ~DiffTimer();
 public:
-	virtual void   DoKeepAlive() = 0;
-	virtual int    GetMaximumDiffingTime() = 0;
-	virtual int    GetKeepAliveTime() = 0;
-	virtual bool   IsManaged() = 0;
+	virtual void DoKeepAlive() = 0;
+	virtual int  GetMaximumDiffingTime() = 0;
+	virtual bool IsManaged() = 0;
 };
 
 // --------------------------------------------------------------------------

Modified: box/chris/merge/lib/backupclient/BackupStoreFileDiff.cpp
===================================================================
--- box/chris/merge/lib/backupclient/BackupStoreFileDiff.cpp	2006-12-03 10:33:42 UTC (rev 1190)
+++ box/chris/merge/lib/backupclient/BackupStoreFileDiff.cpp	2006-12-03 10:40:26 UTC (rev 1191)
@@ -460,12 +460,10 @@
 	int32_t Sizes[BACKUP_FILE_DIFF_MAX_BLOCK_SIZES], DiffTimer *pDiffTimer)
 {
 	Timer maximumDiffingTime(0);
-	Timer keepAliveTime(0);
 
-	if (pDiffTimer && pDiffTimer->IsManaged())
+	if(pDiffTimer && pDiffTimer->IsManaged())
 	{
 		maximumDiffingTime = Timer(pDiffTimer->GetMaximumDiffingTime());
-		keepAliveTime      = Timer(pDiffTimer->GetKeepAliveTime());
 	}
 	
 	std::map<int64_t, int32_t> goodnessOfFit;
@@ -560,16 +558,11 @@
 					break;
 				}
 				
-				if(keepAliveTime.HasExpired())
+				if(pDiffTimer)
 				{
-					ASSERT(pDiffTimer != NULL);
-					TRACE0("KeepAliveTime reached - "
-						"initiating keep-alive\n");
 					pDiffTimer->DoKeepAlive();
-					keepAliveTime = Timer(
-						pDiffTimer->GetKeepAliveTime());
 				}
-
+				
 				// Load in another block of data, and record how big it is
 				int bytesInEndings = rFile.Read(endings, Sizes[s]);
 				int tmp;




More information about the Boxbackup-commit mailing list