00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00055
00056 void CNeighboursWithG1::Connect()
00057 {
00058 CNeighboursBase::Connect();
00059 m_pPingRoute->SetDuration( Settings.Gnutella.RouteCache );
00060 }
00061
00063
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
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
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 }