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

NeighboursWithG1.cpp

Go to the documentation of this file.
00001 //
00002 // NeighboursWithG1.cpp
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 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "Network.h"
00026 #include "NeighboursWithG1.h"
00027 #include "G1Neighbour.h"
00028 #include "RouteCache.h"
00029 #include "PongCache.h"
00030 
00031 #ifdef _DEBUG
00032 #undef THIS_FILE
00033 static char THIS_FILE[]=__FILE__;
00034 #define new DEBUG_NEW
00035 #endif
00036 
00037 
00039 // CNeighboursWithG1 construction
00040 
00041 CNeighboursWithG1::CNeighboursWithG1()
00042 {
00043         m_pPingRoute    = new CRouteCache();
00044         m_pPongCache    = new CPongCache();
00045 }
00046 
00047 CNeighboursWithG1::~CNeighboursWithG1()
00048 {
00049         delete m_pPongCache;
00050         delete m_pPingRoute;
00051 }
00052 
00054 // CNeighboursWithG1 connect
00055 
00056 void CNeighboursWithG1::Connect()
00057 {
00058         CNeighboursBase::Connect();
00059         m_pPingRoute->SetDuration( Settings.Gnutella.RouteCache );
00060 }
00061 
00063 // CNeighboursWithG1 close
00064 
00065 void CNeighboursWithG1::Close()
00066 {
00067         CNeighboursBase::Close();
00068 
00069         m_pPingRoute->Clear();
00070         m_pPongCache->Clear();
00071 }
00072 
00073 void CNeighboursWithG1::Remove(CNeighbour* pNeighbour)
00074 {
00075         m_pPingRoute->Remove( pNeighbour );
00076         CNeighboursBase::Remove( pNeighbour );
00077 }
00078 
00080 // CNeighboursWithG1 G1 ping handler
00081 
00082 void CNeighboursWithG1::OnG1Ping()
00083 {
00084         if ( m_pPongCache->ClearIfOld() )
00085         {
00086                 DWORD dwNow = GetTickCount();
00087                 GGUID pGUID;
00088 
00089                 Network.CreateID( pGUID );
00090 
00091                 for ( POSITION pos = GetIterator() ; pos ; )
00092                 {
00093                         CG1Neighbour* pNeighbour = (CG1Neighbour*)GetNext( pos );
00094 
00095                         if ( pNeighbour->m_nProtocol == PROTOCOL_G1 && pNeighbour->m_bPongCaching )
00096                         {
00097                                 pNeighbour->SendPing( dwNow, &pGUID );
00098                         }
00099                 }
00100         }
00101 }
00102 
00104 // CNeighboursWithG1 G1 pong handler
00105 
00106 void CNeighboursWithG1::OnG1Pong(CG1Neighbour* pFrom, IN_ADDR* pAddress, WORD nPort, BYTE nHops, DWORD nFiles, DWORD nVolume)
00107 {
00108         CPongItem* pPongCache = m_pPongCache->Add( pFrom, pAddress, nPort, nHops, nFiles, nVolume );
00109 
00110         if ( pPongCache == NULL ) return;
00111 
00112         for ( POSITION pos = GetIterator() ; pos ; )
00113         {
00114                 CG1Neighbour* pNeighbour = (CG1Neighbour*)GetNext( pos );
00115 
00116                 if ( pNeighbour->m_nProtocol == PROTOCOL_G1 && pNeighbour != pFrom )
00117                 {
00118                         pNeighbour->OnNewPong( pPongCache );
00119                 }
00120         }
00121 }

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