void CNeighbourTipCtrl::OnTimer(UINT_PTR nIDEvent)
{
	CCoolTipCtrl::OnTimer( nIDEvent );

	if ( m_pGraph == NULL ) return;

	CSingleLock pLock( &Network.m_pSection );
	if ( ! pLock.Lock( 100 ) ) return;

	CNeighbour* pNeighbour = Neighbours.Get( m_nNeighbour );
	if ( pNeighbour == NULL ) return;

	pNeighbour->Measure();

	const DWORD nIn  = pNeighbour->m_mInput.nMeasure;
	const DWORD nOut = pNeighbour->m_mOutput.nMeasure;

	m_pItemIn->Add( nIn );
	m_pItemOut->Add( nOut );

	m_pGraph->m_nMaximum = max( m_pGraph->m_nMaximum, nIn );
	m_pGraph->m_nMaximum = max( m_pGraph->m_nMaximum, nOut );
	m_pGraph->m_nUpdates++;

	CRect rcWndTip;
	SystemParametersInfo( SPI_GETWORKAREA, 0, rcWndTip, 0 );
	rcWndTip.top += 90;
	InvalidateRect( &rcWndTip );
}
void CNeighboursWithConnect::MaintainNodeStatus()
{
	BOOL  bG2Leaf		= FALSE;
	BOOL  bG2Hub		= FALSE;
	BOOL  bG1Leaf		= FALSE;
	BOOL  bG1Ultrapeer	= FALSE;
	DWORD tEstablish	= GetTickCount() - 1500;
	DWORD nStableCount	= 0;
	DWORD nBandwidthIn	= 0;
	DWORD nBandwidthOut	= 0;

	for ( POSITION pos = GetIterator() ; pos ; )
	{
		CNeighbour* pNeighbour = GetNext( pos );

		// We're done with the handshake with this neighbour
		if ( pNeighbour->m_nState == nrsConnected )
		{
			pNeighbour->Measure();
			nBandwidthIn += pNeighbour->m_mInput.nMeasure;
			nBandwidthOut += pNeighbour->m_mOutput.nMeasure;

			if ( pNeighbour->m_tConnected < tEstablish )
				nStableCount++;

			// We're connected to this neighbour and exchanging Gnutella or Gnutella2 packets
			if ( pNeighbour->m_nProtocol == PROTOCOL_G2 )
			{
				// If our connection to this remote computer is up to a hub, we are a leaf, if it's down to a leaf, we are a hub
				if ( pNeighbour->m_nNodeType == ntHub )
					bG2Leaf = TRUE;
				else
					bG2Hub  = TRUE;
			}
			else if ( pNeighbour->m_nProtocol == PROTOCOL_G1 )
			{
				// If our connection to this remote computer is up to a hub, we are a leaf, if it's down to a leaf, we are an ultrapeer
				if ( pNeighbour->m_nNodeType == ntHub )
					bG1Leaf = TRUE;
				else
					bG1Ultrapeer = TRUE;
			}
		}
	}

	m_bG2Leaf		= bG2Leaf;
	m_bG2Hub		= bG2Hub;
	m_bG1Leaf		= bG1Leaf;
	m_bG1Ultrapeer	= bG1Ultrapeer;
	m_nStableCount	= nStableCount;
	m_nBandwidthIn	= nBandwidthIn;
	m_nBandwidthOut	= nBandwidthOut;
}
Exemple #3
0
void CRemote::PageNetworkNetwork(int nID, bool* pbConnect, LPCTSTR pszName)
{
	CSingleLock pLock( &Network.m_pSection );

	CString str;
	str.Format( L"%i", nID );

	if ( GetKey( L"connect" ) == str )
	{
		*pbConnect = TRUE;
		Network.Connect( TRUE );
	}
	else if ( GetKey( L"disconnect" ) == str )
	{
		*pbConnect = FALSE;

		if ( SafeLock( pLock ) )
		{
			for ( POSITION pos = Neighbours.GetIterator(); pos != NULL; )
			{
				CNeighbour* pNeighbour = Neighbours.GetNext( pos );
				if ( pNeighbour->m_nProtocol == PROTOCOL_NULL ||
					 pNeighbour->m_nProtocol == nID )
					pNeighbour->Close( IDS_CONNECTION_CLOSED );
			}
			pLock.Unlock();
		}
	}

	Add( L"network_id", str );
	Add( L"network_caption", pszName );
	if ( *pbConnect ) Add( L"network_connected", L"true" );
	Output( L"networkNetStart" );

	pLock.Lock();

	for ( POSITION pos = Neighbours.GetIterator(); pos != NULL; )
	{
		CNeighbour* pNeighbour = Neighbours.GetNext( pos );
		if ( pNeighbour->m_nProtocol != nID ) continue;
		pNeighbour->Measure();

		str.Format( L"%p", pNeighbour );
		Add( L"row_id", str );
		Add( L"row_address", pNeighbour->m_sAddress );
	//	Add( L"row_mode", Neighbours.GetName( pNeighbour ) );	// ToDo
		Add( L"row_agent", pNeighbour->m_sUserAgent );
	//	Add( L"row_nick", Neighbours.GetNick( pNeighbour ) );	// ToDo
		str.Format( L"%u -/- %u", pNeighbour->m_nInputCount, pNeighbour->m_nOutputCount );
		Add( L"row_packets", str );
		str.Format( L"%s -/- %s",
			(LPCTSTR)Settings.SmartSpeed( pNeighbour->m_mInput.nMeasure ),
			(LPCTSTR)Settings.SmartSpeed( pNeighbour->m_mOutput.nMeasure ) );
		Add( L"row_bandwidth", str );
		str.Format( L"%s -/- %s",
			(LPCTSTR)Settings.SmartVolume( pNeighbour->m_mInput.nTotal ),
			(LPCTSTR)Settings.SmartVolume( pNeighbour->m_mOutput.nTotal ) );
		Add( L"row_total", str );

		switch ( pNeighbour->m_nState )
		{
		case nrsConnecting:
			LoadString( str, IDS_NEIGHBOUR_CONNECTING );
			break;
		case nrsHandshake1:
		case nrsHandshake2:
		case nrsHandshake3:
			LoadString( str, IDS_NEIGHBOUR_HANDSHAKING );
			break;
		case nrsRejected:
			LoadString( str, IDS_NEIGHBOUR_REJECTED );
			break;
		case nrsClosing:
			LoadString( str, IDS_NEIGHBOUR_CLOSING );
			break;
		case nrsConnected:
			{
				const DWORD tNow = ( GetTickCount() - pNeighbour->m_tConnected ) / 1000;	// Seconds
				if ( tNow > 86400 )
					str.Format( L"%u:%.2u:%.2u:%.2u", tNow / 86400, ( tNow / 3600 ) % 24, ( tNow / 60 ) % 60, tNow % 60 );
				else
					str.Format( L"%u:%.2u:%.2u", tNow / 3600, ( tNow / 60 ) % 60, tNow % 60 );
			}
			break;
		case nrsNull:
		default:
			LoadString( str, IDS_NEIGHBOUR_UNKNOWN );
			break;
		}
		Add( L"row_time", str );

		if ( pNeighbour->GetUserCount() )
		{
			if ( pNeighbour->GetUserLimit() )
				str.Format( L"%u/%u", pNeighbour->GetUserCount(), pNeighbour->GetUserLimit() );
			else
				str.Format( L"%u", pNeighbour->GetUserCount() );
			Add( L"row_leaves", str );
		}

		if ( pNeighbour->m_nProtocol == PROTOCOL_G1 )
		{
		//	CG1Neighbour* pG1 = reinterpret_cast<CG1Neighbour*>(pNeighbour);

			switch ( pNeighbour->m_nNodeType )
			{
			case ntNode:
				LoadString( str, IDS_NEIGHBOUR_G1PEER );
				break;
			case ntHub:
				LoadString( str, IDS_NEIGHBOUR_G1ULTRA );
				break;
			case ntLeaf:
				LoadString( str, IDS_NEIGHBOUR_G1LEAF );
				break;
			}

			Add( L"row_mode", str );
			str.Empty();
		}
		else if ( pNeighbour->m_nProtocol == PROTOCOL_G2 )
		{
			CG2Neighbour* pG2 = static_cast<CG2Neighbour*>(pNeighbour);

			switch ( pNeighbour->m_nNodeType )
			{
			case ntNode:
				LoadString( str, IDS_NEIGHBOUR_G2PEER );
				break;
			case ntHub:
				LoadString( str, IDS_NEIGHBOUR_G2HUB );
				break;
			case ntLeaf:
				LoadString( str, IDS_NEIGHBOUR_G2LEAF );
				break;
			}

			Add( L"row_mode", str );
			str.Empty();

			if ( pG2->m_pProfile )
				str = pG2->m_pProfile->GetNick();
		}
		else if ( pNeighbour->m_nProtocol == PROTOCOL_ED2K )
		{
			CEDNeighbour* pED2K = static_cast<CEDNeighbour*>(pNeighbour);

			if ( pED2K->m_nClientID > 0 )
				LoadString( str, CEDPacket::IsLowID( pED2K->m_nClientID ) ? IDS_NEIGHBOUR_ED2K_LOWID : IDS_NEIGHBOUR_ED2K_HIGHID );
			else
				str = L"eDonkey2000";

			Add( L"row_mode", str );

			str = pED2K->m_sServerName;
		}
		else if ( pNeighbour->m_nProtocol == PROTOCOL_DC )
		{
			str = pNeighbour->m_sServerName;
		}

		Add( L"row_nick", str );
		str = pNeighbour->m_sAddress + L" - " + str;
		Add( L"row_caption", str );

		Output( L"networkRow" );
		Prepare( L"row_" );
	}

	Output( L"networkNetEnd" );
	Prepare( L"network_" );
}