예제 #1
0
BOOL CHostBrowser::ReadContent()
{
	CQuickLock oTransfersLock( Transfers.m_pSection );

	if ( m_nProtocol != PROTOCOL_ED2K && m_nProtocol != PROTOCOL_DC )
	{
		if ( m_nReceived < m_nLength )
		{
			CLockedBuffer pInput( GetInput() );

			DWORD nVolume = min( DWORD( m_nLength - m_nReceived ), pInput->m_nLength );
			m_nReceived += nVolume;

			if ( ! m_bDeflate )
			{
				m_pBuffer->AddBuffer( pInput, nVolume );
			}
			else if ( ! pInput->InflateStreamTo( *m_pBuffer, m_pInflate ) )		// Try to decompress the stream
			{
				Stop();			// Clean up
				return FALSE;	// Report failure
			}
		}
	}

	switch ( m_nProtocol )
	{
	case PROTOCOL_NULL:
		if ( ! StreamHTML() ) return FALSE;
		break;
	case PROTOCOL_G2:
		if ( ! StreamPacketsG2() ) return FALSE;
		break;
	case PROTOCOL_G1:
		if ( ! StreamPacketsG1() ) return FALSE;
		break;
	//case PROTOCOL_ED2K:
	//case PROTOCOL_DC:
	//	break;	// Skip
	//default:
	//	theApp.Message( MSG_ERROR, L"CHostBrowser::ReadContent(): Unknown Browse Protocol" );
	}

	if ( m_nReceived < m_nLength ) return TRUE;

	Stop( TRUE );

	return TRUE;
}
예제 #2
0
BOOL CEDClients::OnAccept(CConnection* pConnection)
{
	if ( ! Network.IsConnected() || ( Settings.Connection.RequireForTransfers && ! Settings.eDonkey.Enabled ) )
	{
		theApp.Message( MSG_ERROR, IDS_ED2K_CLIENT_DISABLED, (LPCTSTR)pConnection->m_sAddress );
		return FALSE;
	}

	CSingleLock oTransfersLock( &Transfers.m_pSection );
	if ( ! oTransfersLock.Lock( 250 ) )
	{
		theApp.Message( MSG_DEBUG, _T("Rejecting ed2k connection from %s, network core overloaded."),
			(LPCTSTR)pConnection->m_sAddress );			// protocolNames[ PROTOCOL_ED2K ]
		return FALSE;
	}

	CSingleLock oEDClientsLock( &m_pSection );
	if ( ! oEDClientsLock.Lock( 250 ) )
	{
		theApp.Message( MSG_DEBUG, _T("Rejecting ed2k connection from %s, network core overloaded."),
			(LPCTSTR)pConnection->m_sAddress );			// protocolNames[ PROTOCOL_ED2K ]
		return FALSE;
	}

	if ( IsFull() )
	{
		// Even if we're full, we still need to accept connections from clients we have queued, etc
		if ( ( GetByIP( &pConnection->m_pHost.sin_addr ) == NULL ) || ( IsOverloaded() ) )
		{
			theApp.Message( MSG_DEBUG, _T("Rejecting ed2k connection from %s, max client connections reached."),
				(LPCTSTR)pConnection->m_sAddress );		// protocolNames[ PROTOCOL_ED2K ]
			return FALSE;
		}
		else
		{
			theApp.Message( MSG_DEBUG, _T("Accepting ed2k connection from %s despite client connection limit."),
				(LPCTSTR)pConnection->m_sAddress );		// protocolNames[ PROTOCOL_ED2K ]
		}
	}

	if ( CEDClient* pClient = new CEDClient() )
	{
		pClient->AttachTo( pConnection );
		return TRUE;
	}

	return FALSE;
}
예제 #3
0
BOOL CHostBrowser::OnHeadersComplete()
{
	CQuickLock oTransfersLock( Transfers.m_pSection );

	if ( m_nState == hbsContent )
		return TRUE;

	if ( m_nProtocol == PROTOCOL_ANY || m_nLength == 0 )
	{
		theApp.Message( MSG_ERROR, IDS_BROWSE_BAD_RESPONSE, (LPCTSTR)m_sAddress );
		Stop();
		return FALSE;
	}

	m_nState		= hbsContent;
	m_nReceived		= 0ul;
	m_pBuffer->Clear();
	m_mInput.tLast	= GetTickCount();

	theApp.Message( MSG_INFO, IDS_BROWSE_DOWNLOADING_FROM,
		(LPCTSTR)m_sAddress, protocolNames[ m_nProtocol == PROTOCOL_NULL ? PROTOCOL_HTTP : m_nProtocol ]);

	return TRUE;
}
예제 #4
0
BOOL CHostBrowser::Browse()
{
	CQuickLock oTransfersLock( Transfers.m_pSection );

	m_sAddress = inet_ntoa( m_pAddress );
	m_sServer = protocolAbbr[ ( ( m_nProtocol == PROTOCOL_ANY ) ? PROTOCOL_NULL : m_nProtocol ) ];
	m_pVendor = VendorCache.Lookup( m_sServer );

	switch ( m_nProtocol )
	{
	case PROTOCOL_G2:
		Settings.Gnutella2.Enabled = true;
		break;
	case PROTOCOL_G1:
		Settings.Gnutella1.Enabled = true;
		break;
	case PROTOCOL_ED2K:
		Settings.eDonkey.Enabled = true;
		break;
	case PROTOCOL_DC:
		Settings.DC.Enabled = true;
		break;
	//default:
	}

	// ED2K Clients have their connection controlled by ED2KClient.
	// (One connection used for many things)
	if ( m_nProtocol == PROTOCOL_ED2K )
	{
		// Lock this object until we are finished with it
		CQuickLock oCEDClientsLock( EDClients.m_pSection );

		SOCKADDR_IN* pServer = NULL;	// ToDo: Add push connections
		CEDClient* pClient = EDClients.Connect( m_pAddress.s_addr, m_nPort,
			( pServer ? &pServer->sin_addr : NULL ),
			( pServer ? pServer->sin_port : 0 ), m_oClientID );

		if ( pClient && pClient->m_bConnected )
		{
			// Send browse request
			if ( CEDPacket* pPacket = CEDPacket::New( ED2K_C2C_ASKSHAREDDIRS ) )
				pClient->Send( pPacket );
		}
		else if ( ! pClient || ! pClient->Connect() )
		{
			theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress );
			return FALSE;
		}
	}
	else if ( m_nProtocol == PROTOCOL_DC )
	{
		CEnvyURL oURL;
		oURL.m_nProtocol		= PROTOCOL_DC;
		oURL.m_nAction			= CEnvyURL::uriDownload;
		oURL.m_pServerAddress	= m_pAddress;
		oURL.m_nServerPort		= m_nPort;
		oURL.m_sLogin			= m_sNick;
		oURL.m_sName.Format( L"Files of %s.xml.bz2", (LPCTSTR)SafeFilename( m_sNick ) );
		oURL.m_sURL.Format( L"dchub://%s@%s:%u/files.xml.bz2", (LPCTSTR)URLEncode( m_sNick ), (LPCTSTR)CString( inet_ntoa( m_pAddress ) ), m_nPort );

		return ( Downloads.Add( oURL ) != NULL );
	}
	else // G2/Gunetella
	{
		if ( IsValid() )
			return FALSE;

		if ( m_bMustPush )
		{
			if ( SendPush( FALSE ) )
			{
				theApp.Message( MSG_INFO, IDS_BROWSE_PUSHED_TO, (LPCTSTR)m_sAddress );
			}
			else
			{
				theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_PUSH_TO, (LPCTSTR)m_sAddress );
				return FALSE;
			}
		}
		else
		{
			if ( ConnectTo( &m_pAddress, m_nPort ) )
			{
				theApp.Message( MSG_INFO, IDS_BROWSE_CONNECTING_TO, (LPCTSTR)m_sAddress );
			}
			else
			{
				theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress );
				return FALSE;
			}
		}
	}

	m_nState = hbsConnecting;
	m_nHits  = 0;

	delete m_pProfile;
	m_pProfile = NULL;

	// Ensure window text is updated after state has been set to "connecting"
	m_pNotify->UpdateMessages();

	return TRUE;
}