diff --git a/src/libtomahawk/network/Servent.cpp b/src/libtomahawk/network/Servent.cpp index 0d5c3c0ed..47757a3e9 100644 --- a/src/libtomahawk/network/Servent.cpp +++ b/src/libtomahawk/network/Servent.cpp @@ -57,6 +57,7 @@ Q_DECLARE_METATYPE( sipConnectionPair ) Q_DECLARE_METATYPE( QList< SipInfo > ) Q_DECLARE_METATYPE( Connection* ) Q_DECLARE_METATYPE( QTcpSocketExtra* ) +Q_DECLARE_METATYPE( Tomahawk::peerinfo_ptr ) using namespace Tomahawk; @@ -678,7 +679,7 @@ Servent::createParallelConnection( Connection* orig_conn, Connection* new_conn, info.setPort( orig_conn->peerPort() ); Q_ASSERT( info.isValid() ); sipInfo.append( info ); - connectToPeer( sipInfo, new_conn ); + connectToPeer( peerinfo_ptr(), sipInfo, new_conn ); } else // ask them to connect to us: { @@ -841,16 +842,22 @@ Servent::connectToPeer( const peerinfo_ptr& peerInfo ) conn->setProperty( "nodeid", peerInfo->nodeId() ); registerControlConnection( conn ); - connectToPeer( peerInfo->sipInfo(), conn ); + connectToPeer( peerInfo, peerInfo->sipInfo(), conn ); } void -Servent::connectToPeer(const QList& sipInfoList, Connection* conn ) +Servent::connectToPeer(const peerinfo_ptr& peerInfo, const QList& sipInfoList, Connection* conn ) { if ( sipInfoList.isEmpty() ) { tLog( LOGVERBOSE ) << Q_FUNC_INFO << "No more possible SIP endpoints for " << conn->name() << " skipping."; + // If a peerinfo was supplied and has a ControlConnection which should be destroyed, than use this + if ( !peerInfo.isNull() && peerInfo->controlConnection() ) + delete peerInfo->controlConnection(); + else + // Connecting failed, so destroy this connection. + delete conn; return; } QList sipInfo = QList(sipInfoList); @@ -859,7 +866,7 @@ Servent::connectToPeer(const QList& sipInfoList, Connection* conn ) if ( !info.isVisible() ) { // Try next SipInfo, we can't connect to this one - connectToPeer( sipInfo, conn ); + connectToPeer( peerInfo, sipInfo, conn ); return; } @@ -874,14 +881,14 @@ Servent::connectToPeer(const QList& sipInfoList, Connection* conn ) if ( QHostAddress( info.host() ) == ha) { tDebug() << "Tomahawk won't try to connect to" << info.host() << ":" << info.port() << ": same IP as ourselves."; - connectToPeer( sipInfo, conn ); + connectToPeer( peerInfo, sipInfo, conn ); return; } } if ( info.host() == m_externalHostname ) { tDebug() << "Tomahawk won't try to connect to" << info.host() << ":" << info.port() << ": same IP as ourselves."; - connectToPeer( sipInfo, conn ); + connectToPeer( peerInfo, sipInfo, conn ); return; } @@ -902,8 +909,8 @@ Servent::connectToPeer(const QList& sipInfoList, Connection* conn ) connect( sock, SIGNAL( connected() ), SLOT( socketConnected() ) ); NewClosure( sock, SIGNAL( error( QAbstractSocket::SocketError ) ), - this, SLOT( connectToPeerFailed( QList, Connection*, QTcpSocketExtra* ) ), - sipInfo, conn, sock ); + this, SLOT( connectToPeerFailed( Tomahawk::peerinfo_ptr, QList, Connection*, QTcpSocketExtra* ) ), + peerInfo, sipInfo, conn, sock ); if ( !conn->peerIpAddress().isNull() ) sock->connectToHost( conn->peerIpAddress(), info.port(), QTcpSocket::ReadWrite ); @@ -913,12 +920,12 @@ Servent::connectToPeer(const QList& sipInfoList, Connection* conn ) } void -Servent::connectToPeerFailed( QList sipInfo, Connection* conn, QTcpSocketExtra* socket ) +Servent::connectToPeerFailed( const peerinfo_ptr& peerInfo, QList sipInfo, Connection* conn, QTcpSocketExtra* socket ) { cleanupSocket( socket ); // Try next SipInfo - connectToPeer( sipInfo, conn ); + connectToPeer( peerInfo, sipInfo, conn ); } void diff --git a/src/libtomahawk/network/Servent.h b/src/libtomahawk/network/Servent.h index 61f070039..2243d6a92 100644 --- a/src/libtomahawk/network/Servent.h +++ b/src/libtomahawk/network/Servent.h @@ -90,7 +90,7 @@ public slots: public: void connectToPeer( const Tomahawk::peerinfo_ptr& ha ); - void connectToPeer( const QList& sipInfoList, Connection* conn ); + void connectToPeer(const Tomahawk::peerinfo_ptr &peerInfo, const QList& sipInfoList, Connection* conn ); void reverseOfferRequest( ControlConnection* orig_conn, const QString &theirdbid, const QString& key, const QString& theirkey ); bool visibleExternally() const { return (!m_externalHostname.isNull()) || (m_externalAddresses.length() > 0); } @@ -142,7 +142,7 @@ protected: public slots: void setExternalAddress( QHostAddress ha, unsigned int port ); - void connectToPeerFailed(QList sipInfo, Connection* conn , QTcpSocketExtra *socket); + void connectToPeerFailed( const Tomahawk::peerinfo_ptr& peerInfo, QList sipInfo, Connection* conn , QTcpSocketExtra *socket ); void socketError( QAbstractSocket::SocketError e ); void createParallelConnection( Connection* orig_conn, Connection* new_conn, const QString& key );