1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 20:00:13 +02:00

* This should fix crashes / asserts in Servent.

This commit is contained in:
Christian Muehlhaeuser
2013-01-27 19:07:22 +01:00
parent 168c4f7ab7
commit 1fad16f9ee

View File

@@ -254,7 +254,9 @@ void
Servent::registerControlConnection( ControlConnection* conn ) Servent::registerControlConnection( ControlConnection* conn )
{ {
Q_ASSERT( conn ); Q_ASSERT( conn );
m_controlconnections.append( conn ); tLog( LOGVERBOSE ) << Q_FUNC_INFO << conn->name();
m_controlconnections << conn;
m_connectedNodes << conn->id();
} }
@@ -262,6 +264,7 @@ void
Servent::unregisterControlConnection( ControlConnection* conn ) Servent::unregisterControlConnection( ControlConnection* conn )
{ {
Q_ASSERT( conn ); Q_ASSERT( conn );
tLog( LOGVERBOSE ) << Q_FUNC_INFO << conn->name();
m_connectedNodes.removeAll( conn->id() ); m_connectedNodes.removeAll( conn->id() );
m_controlconnections.removeAll( conn ); m_controlconnections.removeAll( conn );
} }
@@ -481,8 +484,7 @@ Servent::readyRead()
foreach ( ControlConnection* con, m_controlconnections ) foreach ( ControlConnection* con, m_controlconnections )
{ {
if ( !con ) Q_ASSERT( con );
continue;
tLog() << "known connection:" << con->id(); tLog() << "known connection:" << con->id();
if ( con->id() == nodeid ) if ( con->id() == nodeid )
@@ -493,7 +495,7 @@ Servent::readyRead()
} }
// for zeroconf there might be no offer, that case is handled later // for zeroconf there might be no offer, that case is handled later
ControlConnection* ccMatch = qobject_cast< ControlConnection* >( m_offers.value( key ).data() ); ControlConnection* ccMatch = qobject_cast< ControlConnection* >( m_offers.value( key ).data() );
if ( dupe && ccMatch ) if ( dupe && ccMatch )
{ {
tLog() << "Duplicate control connection detected, dropping:" << nodeid << conntype; tLog() << "Duplicate control connection detected, dropping:" << nodeid << conntype;
@@ -517,7 +519,7 @@ Servent::readyRead()
tDebug() << "Add these peers now"; tDebug() << "Add these peers now";
foreach ( const peerinfo_ptr& currentPeerInfo, ccMatch->peerInfos() ) foreach ( const peerinfo_ptr& currentPeerInfo, ccMatch->peerInfos() )
{ {
tDebug() << "Adding " << currentPeerInfo->id(); tDebug() << "Adding" << currentPeerInfo->id();
keepConnection->addPeerInfo( currentPeerInfo ); keepConnection->addPeerInfo( currentPeerInfo );
} }
tDebug() << "Done adding."; tDebug() << "Done adding.";
@@ -529,7 +531,9 @@ Servent::readyRead()
foreach ( ControlConnection* con, m_controlconnections ) foreach ( ControlConnection* con, m_controlconnections )
{ {
if ( con && con->id() == controlid ) Q_ASSERT( con );
if ( con->id() == controlid )
{ {
cc = con; cc = con;
break; break;
@@ -540,7 +544,7 @@ Servent::readyRead()
if ( conntype == "accept-offer" || conntype == "push-offer" ) if ( conntype == "accept-offer" || conntype == "push-offer" )
{ {
sock.data()->_msg.clear(); sock.data()->_msg.clear();
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << key << nodeid << "socket peer address = " << sock.data()->peerAddress() << "socket peer name = " << sock.data()->peerName(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << key << nodeid << "socket peer address =" << sock.data()->peerAddress() << "socket peer name =" << sock.data()->peerName();
Connection* conn = claimOffer( cc, nodeid, key, sock.data()->peerAddress() ); Connection* conn = claimOffer( cc, nodeid, key, sock.data()->peerAddress() );
if ( !conn ) if ( !conn )
{ {
@@ -559,11 +563,11 @@ Servent::readyRead()
} }
tDebug( LOGVERBOSE ) << "claimOffer OK:" << key << nodeid; tDebug( LOGVERBOSE ) << "claimOffer OK:" << key << nodeid;
registerControlConnection( qobject_cast<ControlConnection*>(conn) );
m_connectedNodes << nodeid;
if ( !nodeid.isEmpty() ) if ( !nodeid.isEmpty() )
{
conn->setId( nodeid ); conn->setId( nodeid );
registerControlConnection( qobject_cast<ControlConnection*>(conn) );
}
handoverSocket( conn, sock.data() ); handoverSocket( conn, sock.data() );
return; return;
@@ -619,7 +623,7 @@ Servent::socketConnected()
{ {
QTcpSocketExtra* sock = (QTcpSocketExtra*)sender(); QTcpSocketExtra* sock = (QTcpSocketExtra*)sender();
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << thread() << "socket: " << sock << ", hostaddr: " << sock->peerAddress() << ", hostname: " << sock->peerName(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << thread() << "socket:" << sock << ", hostaddr:" << sock->peerAddress() << ", hostname:" << sock->peerName();
if ( sock->_conn.isNull() ) if ( sock->_conn.isNull() )
{ {
@@ -693,7 +697,7 @@ Servent::connectToPeer( const peerinfo_ptr& peerInfo )
SipInfo sipInfo = peerInfo->sipInfo(); SipInfo sipInfo = peerInfo->sipInfo();
peerInfoDebug( peerInfo ) << "connectToPeer: search for already established connections to the same nodeid: " << m_controlconnections.count() << "connections"; peerInfoDebug( peerInfo ) << "connectToPeer: search for already established connections to the same nodeid:" << m_controlconnections.count() << "connections";
bool isDupe = false; bool isDupe = false;
ControlConnection* conn = 0; ControlConnection* conn = 0;
@@ -749,20 +753,19 @@ Servent::connectToPeer( const peerinfo_ptr& peerInfo )
m["nodeid"] = Database::instance()->impl()->dbid(); m["nodeid"] = Database::instance()->impl()->dbid();
peerInfoDebug(peerInfo) << "No match found, creating a new ControlConnection..."; peerInfoDebug(peerInfo) << "No match found, creating a new ControlConnection...";
conn = new ControlConnection( this ); conn = new ControlConnection( this );
conn->addPeerInfo( peerInfo ); conn->addPeerInfo( peerInfo );
conn->setFirstMessage( m ); conn->setFirstMessage( m );
if ( peerInfo->id().length() ) if ( peerInfo->id().length() )
conn->setName( peerInfo->id() ); conn->setName( peerInfo->id() );
if ( sipInfo.uniqname().length() ) if ( sipInfo.uniqname().length() )
conn->setId( sipInfo.uniqname() ); conn->setId( sipInfo.uniqname() );
conn->setProperty( "nodeid", sipInfo.uniqname() ); conn->setProperty( "nodeid", sipInfo.uniqname() );
registerControlConnection( conn ); registerControlConnection( conn );
connectToPeer( sipInfo.host(), sipInfo.port(), sipInfo.key(), conn ); connectToPeer( sipInfo.host(), sipInfo.port(), sipInfo.key(), conn );
} }