コード例 #1
0
ファイル: SipHandler.cpp プロジェクト: mokerjoke/tomahawk
void
SipHandler::onSipInfo( const QString& peerId, const SipInfo& info )
{
    tDebug() << Q_FUNC_INFO << "SIP Message:" << peerId << info;

    QString barePeerId = peerId.left( peerId.indexOf( "/" ) );

    //FIXME: We should probably be using barePeerId in the connectToPeer call below.
    //But, verify this doesn't cause any problems (there is still a uniquename after all)

    /*
      If only one party is externally visible, connection is obvious
      If both are, peer with lowest IP address initiates the connection.
      This avoids dupe connections.
     */
    if ( info.isVisible() )
    {
        if( !Servent::instance()->visibleExternally() ||
            Servent::instance()->externalAddress() < info.host() ||
            ( Servent::instance()->externalAddress() == info.host() && Servent::instance()->externalPort() < info.port() ) )
        {
            tDebug() << "Initiate connection to" << peerId << "at" << info.host();
            Servent::instance()->connectToPeer( info.host(),
                                          info.port(),
                                          info.key(),
                                          peerId,
                                          info.uniqname() );
        }
        else
        {
            tDebug() << Q_FUNC_INFO << "They should be conecting to us...";
        }
    }
    else
    {
        tDebug() << Q_FUNC_INFO << "They are not visible, doing nothing atm";
    }

    m_peersSipInfos.insert( peerId, info );
}