diff options
Diffstat (limited to 'bin/bbackupd/BackupDaemon.h')
-rw-r--r-- | bin/bbackupd/BackupDaemon.h | 148 |
1 files changed, 113 insertions, 35 deletions
diff --git a/bin/bbackupd/BackupDaemon.h b/bin/bbackupd/BackupDaemon.h index 62f9c393..0c864abd 100644 --- a/bin/bbackupd/BackupDaemon.h +++ b/bin/bbackupd/BackupDaemon.h @@ -14,16 +14,20 @@ #include <string> #include <memory> +#include "BackupClientContext.h" +#include "BackupClientDirectoryRecord.h" #include "BoxTime.h" #include "Daemon.h" -#include "BackupClientDirectoryRecord.h" +#include "Logging.h" #include "Socket.h" #include "SocketListen.h" #include "SocketStream.h" -#include "Logging.h" +#include "TLSContext.h" + #include "autogen_BackupProtocolClient.h" #ifdef WIN32 + #include "WinNamedPipeListener.h" #include "WinNamedPipeStream.h" #endif @@ -43,7 +47,8 @@ class Archive; // Created: 2003/10/08 // // -------------------------------------------------------------------------- -class BackupDaemon : public Daemon, ProgressNotifier +class BackupDaemon : public Daemon, ProgressNotifier, LocationResolver, +RunStatusProvider, SysadminNotifier { public: BackupDaemon(); @@ -52,10 +57,10 @@ public: private: // methods below do partial (specialized) serialization of // client state only - bool SerializeStoreObjectInfo(int64_t aClientStoreMarker, - box_time_t theLastSyncTime, box_time_t theNextSyncTime) const; - bool DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, - box_time_t & theLastSyncTime, box_time_t & theNextSyncTime); + bool SerializeStoreObjectInfo(box_time_t theLastSyncTime, + box_time_t theNextSyncTime) const; + bool DeserializeStoreObjectInfo(box_time_t & theLastSyncTime, + box_time_t & theNextSyncTime); bool DeleteStoreObjectInfo() const; BackupDaemon(const BackupDaemon &); @@ -65,6 +70,14 @@ public: std::string GetOptionString(); int ProcessOption(signed int option); int Main(const std::string &rConfigFileName); + + // This shouldn't be here, but apparently gcc on + // Windows has no idea about inherited methods... + virtual int Main(const char *DefaultConfigFile, int argc, + const char *argv[]) + { + return Daemon::Main(DefaultConfigFile, argc, argv); + } #endif void Run(); @@ -88,21 +101,22 @@ public: int GetState() {return mState;} // Allow other classes to call this too - enum - { - NotifyEvent_StoreFull = 0, - NotifyEvent_ReadError, - NotifyEvent_BackupError, - NotifyEvent_BackupStart, - NotifyEvent_BackupFinish, - NotifyEvent__MAX - // When adding notifications, remember to add strings to NotifySysadmin() - }; - void NotifySysadmin(int Event); + void NotifySysadmin(SysadminNotifier::EventCode Event); private: void Run2(); +public: + void InitCrypto(); + void RunSyncNowWithExceptionHandling(); + void RunSyncNow(); + void OnBackupStart(); + void OnBackupFinish(); + // TouchFileInWorkingDir is only here for use by Boxi. + // This does NOT constitute an API! + void TouchFileInWorkingDir(const char *Filename); + +private: void DeleteAllLocations(); void SetupLocations(BackupClientContext &rClientContext, const Configuration &rLocationsConf); @@ -126,8 +140,6 @@ private: void CloseCommandConnection(); void SendSyncStartOrFinish(bool SendStart); - void TouchFileInWorkingDir(const char *Filename); - void DeleteUnusedRootDirEntries(BackupClientContext &rContext); #ifdef PLATFORM_CANNOT_FIND_PEER_UID_OF_UNIX_SOCKET @@ -137,7 +149,7 @@ private: int UseScriptToSeeIfSyncAllowed(); -private: +public: class Location { public: @@ -157,7 +169,11 @@ private: ExcludeList *mpExcludeFiles; ExcludeList *mpExcludeDirs; }; - + + typedef const std::vector<Location *> Locations; + Locations GetLocations() { return mLocations; } + +private: int mState; // what the daemon is currently doing std::vector<Location *> mLocations; @@ -179,7 +195,8 @@ private: CommandSocketInfo &operator=(const CommandSocketInfo &); public: #ifdef WIN32 - WinNamedPipeStream mListeningSocket; + WinNamedPipeListener<1 /* listen backlog */> mListeningSocket; + std::auto_ptr<WinNamedPipeStream> mpConnectedSocket; #else SocketListen<SocketStream, 1 /* listen backlog */> mListeningSocket; std::auto_ptr<SocketStream> mpConnectedSocket; @@ -188,23 +205,51 @@ private: }; // Using a socket? - CommandSocketInfo *mpCommandSocketInfo; + std::auto_ptr<CommandSocketInfo> mapCommandSocketInfo; // Stop notifications being repeated. - bool mNotificationsSent[NotifyEvent__MAX]; + SysadminNotifier::EventCode mLastNotifiedEvent; // Unused entries in the root directory wait a while before being deleted box_time_t mDeleteUnusedRootDirEntriesAfter; // time to delete them std::vector<std::pair<int64_t,std::string> > mUnusedRootDirEntries; + int64_t mClientStoreMarker; + bool mStorageLimitExceeded; + bool mReadErrorsOnFilesystemObjects; + box_time_t mLastSyncTime, mNextSyncTime; + box_time_t mCurrentSyncStartTime, mUpdateStoreInterval; + TLSContext mTlsContext; + bool mDeleteStoreObjectInfoFile; + bool mDoSyncForcedByPreviousSyncError; + public: bool StopRun() { return this->Daemon::StopRun(); } + bool StorageLimitExceeded() { return mStorageLimitExceeded; } private: bool mLogAllFileAccess; +public: + ProgressNotifier* GetProgressNotifier() { return mpProgressNotifier; } + LocationResolver* GetLocationResolver() { return mpLocationResolver; } + RunStatusProvider* GetRunStatusProvider() { return mpRunStatusProvider; } + SysadminNotifier* GetSysadminNotifier() { return mpSysadminNotifier; } + void SetProgressNotifier (ProgressNotifier* p) { mpProgressNotifier = p; } + void SetLocationResolver (LocationResolver* p) { mpLocationResolver = p; } + void SetRunStatusProvider(RunStatusProvider* p) { mpRunStatusProvider = p; } + void SetSysadminNotifier (SysadminNotifier* p) { mpSysadminNotifier = p; } + +private: + ProgressNotifier* mpProgressNotifier; + LocationResolver* mpLocationResolver; + RunStatusProvider* mpRunStatusProvider; + SysadminNotifier* mpSysadminNotifier; + /* ProgressNotifier implementation */ public: + virtual void NotifyIDMapsSetup(BackupClientContext& rContext) { } + virtual void NotifyScanDirectory( const BackupClientDirectoryRecord* pDirRecord, const std::string& rLocalPath) @@ -387,7 +432,7 @@ public: { if (mLogAllFileAccess) { - BOX_INFO("Uploading complete file: " << rLocalPath); + BOX_NOTICE("Uploading complete file: " << rLocalPath); } } virtual void NotifyFileUploadingPatch( @@ -396,7 +441,7 @@ public: { if (mLogAllFileAccess) { - BOX_INFO("Uploading patch to file: " << rLocalPath); + BOX_NOTICE("Uploading patch to file: " << rLocalPath); } } virtual void NotifyFileUploaded( @@ -406,7 +451,7 @@ public: { if (mLogAllFileAccess) { - BOX_INFO("Uploaded file: " << rLocalPath); + BOX_NOTICE("Uploaded file: " << rLocalPath); } } virtual void NotifyFileSynchronised( @@ -419,18 +464,51 @@ public: BOX_INFO("Synchronised file: " << rLocalPath); } } + virtual void NotifyDirectoryDeleted( + int64_t ObjectID, + const std::string& rRemotePath) + { + if (mLogAllFileAccess) + { + BOX_NOTICE("Deleted directory: " << rRemotePath << + " (ID " << BOX_FORMAT_OBJECTID(ObjectID) << + ")"); + } + } + virtual void NotifyFileDeleted( + int64_t ObjectID, + const std::string& rRemotePath) + { + if (mLogAllFileAccess) + { + BOX_NOTICE("Deleted file: " << rRemotePath << + " (ID " << BOX_FORMAT_OBJECTID(ObjectID) << + ")"); + } + } + virtual void NotifyReadProgress(int64_t readSize, int64_t offset, + int64_t length, box_time_t elapsed, box_time_t finish) + { + BOX_TRACE("Read " << readSize << " bytes at " << offset << + ", " << (length - offset) << " remain, eta " << + BoxTimeToSeconds(finish - elapsed) << "s"); + } + virtual void NotifyReadProgress(int64_t readSize, int64_t offset, + int64_t length) + { + BOX_TRACE("Read " << readSize << " bytes at " << offset << + ", " << (length - offset) << " remain"); + } + virtual void NotifyReadProgress(int64_t readSize, int64_t offset) + { + BOX_TRACE("Read " << readSize << " bytes at " << offset << + ", unknown bytes remaining"); + } #ifdef WIN32 - public: - void RunHelperThread(void); - private: - bool mDoSyncFlagOut, mSyncIsForcedOut; bool mInstallService, mRemoveService, mRunAsService; std::string mServiceName; - HANDLE mhMessageToSendEvent, mhCommandReceivedEvent; - CRITICAL_SECTION mMessageQueueLock; - std::vector<std::string> mMessageList; #endif }; |