00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(AFX_ROUTECACHE_H__7FDD7D02_ABC8_4718_A985_C411BCE0D660__INCLUDED_)
00023 #define AFX_ROUTECACHE_H__7FDD7D02_ABC8_4718_A985_C411BCE0D660__INCLUDED_
00024
00025 #pragma once
00026
00027 class CNeighbour;
00028
00029
00030 class CRouteCacheItem
00031 {
00032
00033 public:
00034 CRouteCacheItem* m_pNext;
00035 DWORD m_tAdded;
00036 GGUID m_pGUID;
00037 const CNeighbour* m_pNeighbour;
00038 SOCKADDR_IN m_pEndpoint;
00039 };
00040
00041
00042 class CRouteCacheTable
00043 {
00044
00045 public:
00046 CRouteCacheTable();
00047 virtual ~CRouteCacheTable();
00048
00049
00050 protected:
00051 CRouteCacheItem* m_pHash[1024];
00052 CRouteCacheItem* m_pFree;
00053 CRouteCacheItem* m_pBuffer;
00054 DWORD m_nBuffer;
00055 DWORD m_nUsed;
00056 DWORD m_tFirst;
00057 DWORD m_tLast;
00058
00059
00060 public:
00061 CRouteCacheItem* Find(const GGUID* pGUID);
00062 CRouteCacheItem* Add(const GGUID* pGUID, const CNeighbour* pNeighbour, const SOCKADDR_IN* pEndpoint, DWORD nTime = 0);
00063 void Remove(CNeighbour* pNeighbour);
00064 void Resize(DWORD nSize);
00065 DWORD GetNextSize(DWORD nDesired);
00066 void Clear();
00067
00068 inline BOOL IsFull() const
00069 {
00070 return m_nUsed == m_nBuffer;
00071 }
00072 };
00073
00074
00075 class CRouteCache
00076 {
00077
00078 public:
00079 CRouteCache();
00080 virtual ~CRouteCache();
00081
00082
00083 protected:
00084 DWORD m_nSeconds;
00085 CRouteCacheTable m_pTable[2];
00086 CRouteCacheTable* m_pRecent;
00087 CRouteCacheTable* m_pHistory;
00088
00089
00090 public:
00091 void SetDuration(DWORD nSeconds);
00092 BOOL Add(const GGUID* pGUID, const CNeighbour* pNeighbour);
00093 BOOL Add(const GGUID* pGUID, const SOCKADDR_IN* pEndpoint);
00094 void Remove(CNeighbour* pNeighbour);
00095 void Clear();
00096 public:
00097 CRouteCacheItem* Add(const GGUID* pGUID, const CNeighbour* pNeighbour, const SOCKADDR_IN* pEndpoint, DWORD tAdded);
00098 CRouteCacheItem* Lookup(const GGUID* pGUID, CNeighbour** ppNeighbour = NULL, SOCKADDR_IN* pEndpoint = NULL);
00099
00100 };
00101
00102 #endif // !defined(AFX_ROUTECACHE_H__7FDD7D02_ABC8_4718_A985_C411BCE0D660__INCLUDED_)