Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

RouteCache.h

Go to the documentation of this file.
00001 //
00002 // RouteCache.h
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 // Attributes
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 // Construction
00045 public:
00046         CRouteCacheTable();
00047         virtual ~CRouteCacheTable();
00048 
00049 // Attributes
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 // Operations
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 // Construction
00078 public:
00079         CRouteCache();
00080         virtual ~CRouteCache();
00081 
00082 // Attributes
00083 protected:
00084         DWORD                           m_nSeconds;
00085         CRouteCacheTable        m_pTable[2];
00086         CRouteCacheTable*       m_pRecent;
00087         CRouteCacheTable*       m_pHistory;
00088 
00089 // Operations
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_)

Generated on Thu Dec 15 10:39:47 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2