Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals | Related Pages

HashTreeNode.h

Go to the documentation of this file.
00001 
00019 #pragma once
00020 #include "stdafx.h"
00021 #include "types.h"
00022 #include "hashcontainer.h"
00023 
00029 #define CHashTreeNodeTA     hashClass, CSBase, CSBuildup, CSDepth
00030 
00033 #define CHashTreeNodeTTA    class hashClass, uint8 CSBase, uint8 CSBuildup, uint8 CSDepth
00034 
00038 template<CHashTreeNodeTTA>
00039 class CHashTreeNode : public CHashContainer<hashClass>
00040 {
00041 public:
00042     CHashTreeNode   (CHashTreeNode<CHashTreeNodeTA> &cTree, CHashTreeNode<CHashTreeNodeTA> *pParent = NULL);
00043     CHashTreeNode   (uint64 nLength, uint8 nLevel = 0);
00044     CHashTreeNode   (CFile &cFile, uint64 nPath = 0, uint8 nLevel = 0, CHashTreeNode<CHashTreeNodeTA> *pParent = NULL);
00045     CHashTreeNode   (uint8 *pData, uint32 nData, uint8 nLevel = 0, CHashTreeNode<CHashTreeNodeTA> *pParent = NULL);
00046     CHashTreeNode   (CHashTreeNode<CHashTreeNodeTA> *pParent = NULL);
00047     ~CHashTreeNode  (void);     // Modders: To delete anything less than a whole tree, Prune() the node to delete and delete that.
00048     void Init       (void);
00049 
00050     CHashTreeNode<CHashTreeNodeTA>  *FindNodeTop        (void);
00051     CHashTreeNode<CHashTreeNodeTA>  *FindNodePath       (uint64 nPath, uint8 nLevel, bool nCreate = false);
00052     CHashTreeNode<CHashTreeNodeTA>  *FindNodeNum        (uint64 nodeID);
00053     CHashTreeNode<CHashTreeNodeTA>  *DeleteNodePath     (uint64 nPath, uint8 nLevel);
00054     CHashTreeNode<CHashTreeNodeTA>  *DeleteNodeNum      (uint64 nodeID);
00055 
00056     uint32                          GetHashTreeList     (uint64 nPath, uint8 levelTop, uint8 levelBottom, uint32 *pList);
00057     uint32                          GetHashStripList    (uint64 nPath, uint8 nLevel, uint16 nHashes, uint32 *pList);
00058     uint32                          GetHashListList     (uint16 nHashes, uint64 *pIDList, uint32 *pList);
00059     uint32                          GetHashDiffList     (uint16 nHashes, uint64 *pIDList, uint8 *pDiff, uint32 *pList);
00060 
00061     uint32                          GetHashTreeHash     (CHashContainer<hashClass> &Hash, uint64 nPath, uint8 levelTop, uint8 levelBottom);
00062     uint32                          GetHashStripHash    (CHashContainer<hashClass> &Hash, uint16 nHashes, uint64 nPath, uint8 nLevel);
00063     uint32                          GetHashListHash     (CHashContainer<hashClass> &Hash, uint16 nHashes, uint64 *pIDList);
00064 
00065     void                            SaveTree            (CFile &cFile);
00066     uint8                           Verify              (uint64 nPath, uint8 nLevel, uint8 nSecured);
00067 
00068     uint32                          InsertTree          (uint64 nPath, CHashTreeNode<CHashTreeNodeTA> &cTree);
00069     bool                            Graft               (uint64 nPath, CHashTreeNode<CHashTreeNodeTA> *pTree);
00070     CHashTreeNode<CHashTreeNodeTA>  *Prune              (uint64 nPath, uint8 nLevel);
00071     bool                            Trim                (uint8 nLevel);
00072 
00073     CHashTreeNode<CHashTreeNodeTA>  &operator =			(CHashTreeNode<CHashTreeNodeTA> &cTree);
00074 
00076     static uint8    SetIOLevel(uint8 nIOLevel)      {if (nIOLevel >= CSBuildup) BlockIOLevel = nIOLevel; return BlockIOLevel;}
00078     static uint8    GetIOLevel(void)                {return BlockIOLevel;}
00080     static uint8    SetKeepLevel(uint8 nKeep)       {if (nKeep >= CSBase) KeepLevel = nKeep; return KeepLevel;}
00082     static uint8    GetKeepLevel(void)              {return KeepLevel;}
00083 
00084 protected:
00085     uint32      HashBlock       (uint8 *pData, uint32 nData);
00086     uint32      HashFile        (CFile &cFile, uint64 nPath);
00087     void        SetNodeFlags    (uint16 flagSet, uint16 flagReset, uint8 levelTop, uint8 levelBottom);
00088     void        SetNodeFlags    (uint16 flagSet, uint16 flagReset, uint8 levelTarget);
00089 
00091     CHashTreeNode<CHashTreeNodeTA>      *nodePtr[2];
00092 
00094     CHashTreeNode<CHashTreeNodeTA>      *nodeParent;
00095 
00099     uint8           nodeLevel;
00100 
00102     enum NODE_Status {  
00104         NODE_Undefined = 0x00,
00106         NODE_Valid = 0x01,
00108         NODE_Complete = 0x02,
00110         NODE_OnDisk = 0x04,
00112         NODE_Changed = 0x08,
00114         NODE_ICHKeep = 0x10,
00116         NODE_Singleton = 0x20,
00118         NODE_Verified = 0x40,
00120         NODE_Secured = 0x80,
00122         NODE_Flags = NODE_Verified | NODE_ICHKeep | NODE_Singleton | NODE_Secured
00123     };
00124 
00126     uint16          nodeFlags;
00127 
00129 
00133     static uint8 KeepLevel;
00134 
00136     
00140     static  uint8   BlockIOLevel;
00141 
00142 private:
00146     struct STHListStruc {
00148         uint16  Count;
00150         bool    Complete;
00152         uint32  *DataPtr;
00154         uint32  Data[((2 << CSDepth) - 2) * DIGESTSIZE32];
00156         uint8   levelSecure;
00158         uint8   levelVerify;
00159     };
00160 
00161     bool    GSTHList    (STHListStruc *STHListuint8, uint8 nDepth = 0);
00162     bool    GSTHHash    (CHashContainer<hashClass> *cHash, uint8 *pData = NULL, uint32 nData = 0);
00164     bool    GSTHHash    (uint8 *pData = NULL, uint32 nData = 0) {return GSTHHash(this, pData, nData);}
00165 
00167     static const CString CLASSNAME;
00168 
00169 };
00170 
00171 template <CHashTreeNodeTTA>
00172 const   CString CHashTreeNode<CHashTreeNodeTA>::CLASSNAME = CString("CHashTreeNode/") + StaticAlgorithmName();
00173 
00174 template <CHashTreeNodeTTA>
00175 uint8   CHashTreeNode<CHashTreeNodeTA>::KeepLevel = CSBase;
00176 
00177 template <CHashTreeNodeTTA>
00178 uint8   CHashTreeNode<CHashTreeNodeTA>::BlockIOLevel = CSBuildup + 1;
00179 
00180 #include "HashTreeNode.cpp"

Generated on Mon Nov 3 21:39:46 2003 for Moonlight's eMule Tweaks Documentation by doxygen 1.3.4