diff --git a/src/libtomahawk/network/Servent.cpp b/src/libtomahawk/network/Servent.cpp index 8a4112062..239318f38 100644 --- a/src/libtomahawk/network/Servent.cpp +++ b/src/libtomahawk/network/Servent.cpp @@ -347,6 +347,44 @@ Servent::lookupControlConnection( const SipInfo& sipInfo ) } +QList +Servent::getLocalSipInfos( const QString& nodeid, QString key ) +{ + QList sipInfos = QList(); + foreach ( QHostAddress ha, m_externalAddresses ) + { + SipInfo info = SipInfo(); + info.setHost( ha.toString() ); + info.setPort( m_port ); + info.setKey( key ); + info.setVisible( true ); + info.setNodeId( nodeid ); + sipInfos.append( info ); + } + if ( m_externalHostname.length() > 0) + { + SipInfo info = SipInfo(); + info.setHost( m_externalHostname ); + info.setPort( m_externalPort ); + info.setKey( key ); + info.setVisible( true ); + info.setNodeId( nodeid ); + sipInfos.append( info ); + } + + if ( sipInfos.isEmpty() ) + { + // We are not visible via any IP, send a dummy SipInfo + SipInfo info = SipInfo(); + info.setVisible( false ); + info.setKey( key ); + info.setNodeId( nodeid ); + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Only accepting connections, no usable IP to listen to found."; + } + + return sipInfos; +} + void Servent::registerPeer( const Tomahawk::peerinfo_ptr& peerInfo ) { @@ -398,37 +436,7 @@ Servent::registerPeer( const Tomahawk::peerinfo_ptr& peerInfo ) conn->addPeerInfo( peerInfo ); registerOffer( key, conn ); - QList sipInfos = QList(); - foreach ( QHostAddress ha, m_externalAddresses ) - { - SipInfo info = SipInfo(); - info.setHost( ha.toString() ); - info.setPort( m_port ); - info.setKey( key ); - info.setVisible( true ); - info.setNodeId( nodeid ); - sipInfos.append( info ); - } - if ( m_externalHostname.length() > 0) - { - SipInfo info = SipInfo(); - info.setHost( m_externalHostname ); - info.setPort( m_externalPort ); - info.setKey( key ); - info.setVisible( true ); - info.setNodeId( nodeid ); - sipInfos.append( info ); - } - - if ( sipInfos.isEmpty() ) - { - // We are not visible via any IP, send a dummy SipInfo - SipInfo info = SipInfo(); - info.setVisible( false ); - info.setKey( key ); - info.setNodeId( nodeid ); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Only accepting connections, no usable IP to listen to found."; - } + QList sipInfos = getLocalSipInfos( nodeid, key ); peerInfo->sendLocalSipInfos( sipInfos ); diff --git a/src/libtomahawk/network/Servent.h b/src/libtomahawk/network/Servent.h index 27aabd710..cce7cb388 100644 --- a/src/libtomahawk/network/Servent.h +++ b/src/libtomahawk/network/Servent.h @@ -130,6 +130,7 @@ public: bool isReady() const { return m_ready; } + QList getLocalSipInfos(const QString& nodeid, QString key); signals: void dbSyncTriggered(); void streamStarted( StreamConnection* );