void UT_CIceConnectionHandler::UT_CNATFWConnectionHandler_STUNBindingEventOccurredLL()
    {
    // not ready case
    EUNIT_ASSERT_LEAVE( iConnectionHandler->STUNBindingEventOccurredL( 
        MSTUNClientObserver::EPublicAddressResolved, 
        reinterpret_cast<const CBinding&>( *this ) ) );
    EUNIT_ASSERT( !iCheckCompletedCalled );
    
    // ready cases
    TInetAddr peerAddr( KRemoteAddr, KRemotePort );
    peerAddr.SetFamily( KAfInet );
    const_cast<CNATFWCandidate&>
        ( iPairs[0]->RemoteCandidate() ).SetTransportAddrL( peerAddr );
    
    TUint stunConnection = iConnectionHandler->CreateConnectionL( *iPairs[0] );
    
    iConnectionHandler->PerformConnCheckL( 
        iStreamId, stunConnection, 0, 0, 0, peerAddr, *this );
    
    EUNIT_ASSERT_NO_LEAVE( iConnectionHandler->STUNBindingEventOccurredL( 
        MSTUNClientObserver::EPublicAddressResolved, 
        *( iConnectionHandler->iBindings[0].iBinding ) ) );
    EUNIT_ASSERT( iCheckCompletedCalled );
    
    EUNIT_ASSERT_NO_LEAVE( iConnectionHandler->STUNBindingEventOccurredL( 
        MSTUNClientObserver::ECredentialsRejected, 
        *( iConnectionHandler->iBindings[0].iBinding ) ) );
    EUNIT_ASSERT( iCheckCompletedCalled );
    
    // UNKNOWN EVENT
    EUNIT_ASSERT_PANIC( 
        iConnectionHandler->STUNBindingEventOccurredL( 
            MSTUNClientObserver::EActiveDestinationSet, 
            *( iConnectionHandler->iBindings[0].iBinding ) ), "USER", 0 );
    }
void UT_CIceConnectionHandler::UT_CNATFWConnectionHandler_IncomingMessageLL(  )
    {
    TInetAddr localAddr( KLocalAddr );
    TInetAddr fromAddr( KRemoteAddr );
    TInetAddr peerAddr( KRemoteAddr );
    
    _LIT8( KDummyContent, "dummycontent" );
    TBool consumed( EFalse );
    
    // no connection
    EUNIT_ASSERT_LEAVE( iConnectionHandler->IncomingMessageL( 
        iStreamId, KDummyContent, localAddr, fromAddr, peerAddr, consumed ) );
    
    TUint stunConnection = iConnectionHandler->CreateConnectionL( *iPairs[0] );
    
    // unknown sream
    EUNIT_ASSERT_NO_LEAVE( iConnectionHandler->IncomingMessageL( 
        iStreamId + 1, KDummyContent, 
        localAddr, fromAddr, peerAddr, consumed ) );
    EUNIT_ASSERT( !consumed );
    
    // known stream
    TUint stunConnection2 = iConnectionHandler->CreateConnectionL( *iPairs[0] );
    EUNIT_ASSERT_NO_LEAVE( iConnectionHandler->IncomingMessageL( 
        iStreamId, KDummyContent, localAddr, fromAddr, peerAddr, consumed ) );
    
    iConnectionHandler->RemoveConnection( iStreamId, stunConnection );
    iConnectionHandler->RemoveConnection( iStreamId, stunConnection2 );
    }
Beispiel #3
0
void Acceptor::handleRead() {
	m_pEventLoop->AssertInLoopThread();
	InetAddress peerAddr(0);
	int nConnFd = m_AccpetSocket.Accpet(&peerAddr);
	if (nConnFd >= 0) {
		if (m_NewConCallBack) {
			m_NewConCallBack(nConnFd, peerAddr);
		} else {
			Sockets::Close(nConnFd);
		}
	}
}
void UT_CIceConnectionHandler::UT_CNATFWConnectionHandler_STUNBindingErrorOccurredL()
    {
    // ready cases
    TInetAddr peerAddr( iPairs[0]->RemoteCandidate().TransportAddr() );
    TUint stunConnection = iConnectionHandler->CreateConnectionL( *iPairs[0] );
    
    iConnectionHandler->PerformConnCheckL( 
        iStreamId, stunConnection, 0, 0, 0, peerAddr, *this );
    
    iConnectionHandler->STUNBindingErrorOccurred( 
        *( iConnectionHandler->iBindings[0].iBinding ), KErrNotReady );
    EUNIT_ASSERT( iCheckCompletedCalled );
    iConnectionHandler->RemoveConnection( iStreamId, stunConnection );
    
    // not ready case
    EUNIT_ASSERT_PANIC(
        iConnectionHandler->STUNBindingErrorOccurred( 
            reinterpret_cast<const CBinding&>( *this ), KErrNotReady ), 
            "USER", 0 );
    EUNIT_ASSERT( !iCheckCompletedCalled );
    }
Beispiel #5
0
void ADC::HubSession::EventSearchReply(QuickDC::Share::SearchReply* reply)
{
	QuickDC::Share::SearchRequest* req = reply->getRequest();
	const QuickDC::User* user = reply->getRequest()->getUser();
	QuickDC::Share::File* file = reply->getFile();
	
	if (user->getAddressIPv4() && user->getPortIPv4() && QuickDC::Core::getInstance()->server)
	{
		/* Send UDP packet */
		
		ADC::Command cmd(FOURCC('U','R','E','S'), ADC::CID::getInstance()->getCID());
		cmd.addArgument("FN", file->getPublicName());
		cmd.addArgument("SI", quickdc_ulltoa(file->getSize()));
		cmd.addArgument("TR", file->getTTH());
		cmd.addArgument("TD", "0");
		cmd.addArgument("TO", req->getToken());
		// cmd.addArgument("SL", "3"); // FIXME: implement me
		
		Samurai::IO::Buffer buffer;
		cmd.write(&buffer);
		Samurai::IO::Net::DatagramPacket packet(&buffer);
		Samurai::IO::Net::InetSocketAddress peerAddr(user->getAddressIPv4(), user->getPortIPv4(), Samurai::IO::Net::InetAddress::IPv4);
		packet.setAddress(&peerAddr);
		QuickDC::Core::getInstance()->server->send(&packet);
	
	}
	else
	{
		/* Send result via server */
		ADC::Command* cmd = new ADC::Command(FOURCC('D','R','E','S'), sid, user->getID());
		cmd->addArgument("FN", file->getPublicName());
		cmd->addArgument("SI", quickdc_ulltoa(file->getSize()));
		cmd->addArgument("TR", file->getTTH());
		cmd->addArgument("TD", "0");
		cmd->addArgument("TO", req->getToken());
		// cmd.addArgument("SL", "3"); // FIXME: implement me
		
		send(cmd);
	}
}
Beispiel #6
0
Connector* NetFactory::connect(const string& ip, int port, INetReactor &netReactor, const char* remoteHostName)
{
	NetAddress peerAddr(ip, port);

	// ´´½¨Ò»¸öÍøÂçÁ¬½ÓÆ÷£¬¸ÃÍøÂç¼àÌýÆ÷½«±»×¢²áµ½ÍøÂçÖÐ
	Connector* connector = new Connector(peerAddr, &netReactor, nextNet(), remoteHostName, this);
	if (NULL == connector) {
		LOG_SYSTEM_ERR << "connect to <" << ip << ": " << port << "> failed, not enough memory";
		return NULL;
	}

	if (!connector->open()) {
		LOG_SYSTEM_ERR << "connect to <" << ip << ": " << port << "> failed, open failed";
		delete connector;
		return NULL;
	}

	connector->connect();

	m_connectors.push_back(connector);
	return connector;
}
void UT_CIceConnectionHandler::UT_CNATFWConnectionHandler_PerformConnCheckLL(  )
    {
    TInetAddr peerAddr( iPairs[0]->RemoteCandidate().TransportAddr() );
    TUint connection = iConnectionHandler->CreateConnectionL( *iPairs[0] );
    
    if ( TIceTestUtils::AllocTestEnabled() )
        {
        iConnectionHandler->PerformConnCheckL( 
            iStreamId, connection, 0, EFalse, 0, peerAddr, *this );
        }
    else
        {
        // SUCCESFULL RESPONSE
        EUNIT_ASSERT_NO_LEAVE( iConnectionHandler->PerformConnCheckL( 
            iStreamId, connection, 0, EFalse, 0, peerAddr, *this ) );
        TInetAddr localAddr;
        TInetAddr fromAddr = peerAddr;
        _LIT8( Kdummycontent, "dummycontent" );
        TBool consumed( EFalse );
        EUNIT_ASSERT_NO_LEAVE( iConnectionHandler->IncomingMessageL( 
            iStreamId, Kdummycontent, localAddr, fromAddr, peerAddr, consumed ) );
        EUNIT_ASSERT_NO_LEAVE( iConnectionHandler->STUNBindingEventOccurredL( 
            MSTUNClientObserver::EPublicAddressResolved, 
            *( iConnectionHandler->iBindings[0].iBinding ) ) );
        
        // CREDENTIALS REJECTED
        EUNIT_ASSERT_NO_LEAVE( iConnectionHandler->PerformConnCheckL( 
            iStreamId, connection, 0, EFalse, 0, peerAddr, *this ) );
        EUNIT_ASSERT_NO_LEAVE( iConnectionHandler->IncomingMessageL( 
            iStreamId, Kdummycontent, localAddr, fromAddr, peerAddr, consumed ) );
        
        EUNIT_ASSERT_NO_LEAVE( iConnectionHandler->STUNBindingEventOccurredL( 
            MSTUNClientObserver::ECredentialsRejected, 
            *( iConnectionHandler->iBindings[0].iBinding ) ) );
        }
    
    iConnectionHandler->RemoveConnection( iStreamId, connection );
    }
void UT_CIceConnectionHandler::UT_CNATFWConnectionHandler_CancelCheckL()
    {
    TInetAddr peerAddr( iPairs[0]->RemoteCandidate().TransportAddr() );
    TUint connection = iConnectionHandler->CreateConnectionL( *iPairs[0] );
    
    // cancel before mux connection activation
    iConnectionHandler->PerformConnCheckL( 
        iStreamId, connection, 0, EFalse, 0, peerAddr, *this );
    iConnectionHandler->CancelCheck( iStreamId, connection, peerAddr );
    
    // cancel after mux connection activation
    iConnectionHandler->PerformConnCheckL( 
        iStreamId, connection, 0, EFalse, 0, peerAddr, *this );
    iConnectionHandler->ConnectionNotify( iStreamId, connection, 
        MNcmConnectionObserver::EReceivingActivated, KErrNone );
    iConnectionHandler->ConnectionNotify( iStreamId, connection, 
        MNcmConnectionObserver::ESendingActivated, KErrNone );
    iConnectionHandler->CancelCheck( iStreamId, connection, peerAddr );
    iConnectionHandler->RemoveConnection( iStreamId, connection );
    
    EUNIT_ASSERT_PANIC( 
        iConnectionHandler->CancelCheck( iStreamId, 5, peerAddr ), "USER", 0 );
    }
void UT_CIceConnectionHandler::UT_CNATFWConnectionHandler_ConnectionNotifyL()
    {
    TInetAddr peerAddr( iPairs[0]->RemoteCandidate().TransportAddr() );
    TUint stunConnection = iConnectionHandler->CreateConnectionL( *iPairs[0] );
    
    // unknown connection
    const TUint KUnknownStream( 10 );
    const TUint KUnknownConnection( 10 );
    iConnectionHandler->ConnectionNotify( KUnknownStream, KUnknownConnection,
        MNcmConnectionObserver::EConnectionRemoved, KErrNone );
    EUNIT_ASSERT( 0 != iConnectionHandler->iBindings.Count() );
    
    // known connection
    // MNcmConnectionObserver::EReceivingActivated
    iConnectionHandler->ConnectionNotify( iStreamId, stunConnection,
        MNcmConnectionObserver::EReceivingActivated, KErrNone );
    EUNIT_ASSERT( EStreamingStatePassive 
        == iConnectionHandler->iBindings[0].iStreamingStatus );
    
    // MNcmConnectionObserver::EReceivingDeactivated
    iConnectionHandler->ConnectionNotify( iStreamId, stunConnection,
        MNcmConnectionObserver::EReceivingDeactivated, KErrNone );
    EUNIT_ASSERT( EStreamingStatePassive 
        == iConnectionHandler->iBindings[0].iStreamingStatus );
    
    // MNcmConnectionObserver::ESendingActivated
    iConnectionHandler->ConnectionNotify( iStreamId, stunConnection,
        MNcmConnectionObserver::ESendingActivated, KErrNone );
    EUNIT_ASSERT( EStreamingStateActive 
        == iConnectionHandler->iBindings[0].iStreamingStatus );
    
    // MNcmConnectionObserver::EConnectionRemoved
    iConnectionHandler->ConnectionNotify( iStreamId, stunConnection,
        MNcmConnectionObserver::EConnectionRemoved, KErrNone );
    EUNIT_ASSERT( 0 == iConnectionHandler->iBindings.Count() );
    
    // MNcmConnectionObserver::EConnectionError
    stunConnection = iConnectionHandler->CreateConnectionL( *iPairs[0] );
    iConnectionHandler->ConnectionNotify( iStreamId, stunConnection,
        MNcmConnectionObserver::EConnectionError, KErrUnknown );
    EUNIT_ASSERT( 0 == iConnectionHandler->iBindings.Count() );
    
    // events for relay connections must be discarded
    for ( TInt i = 0; i < iPairs.Count(); ++i )
        {
        if ( CNATFWCandidate::ERelay == iPairs[i]->LocalCandidate().Type() )
            {
            TUint relayConnection 
                = iConnectionHandler->CreateConnectionL( *iPairs[i] );
            iConnectionHandler->ConnectionNotify( iStreamId, relayConnection,
                MNcmConnectionObserver::EConnectionRemoved, KErrNone );
            EUNIT_ASSERT( 0 != iConnectionHandler->iBindings.Count() );
            }
        }
    
    // unknown event
    stunConnection = iConnectionHandler->CreateConnectionL( *iPairs[0] );
    EUNIT_ASSERT_PANIC(
        iConnectionHandler->ConnectionNotify( iStreamId, stunConnection,
            static_cast<MNcmConnectionObserver::TConnectionNotifyType>( -1 ), 
            KErrNone ), "USER", 0 );
    }