mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-04 13:17:34 +02:00
* Fixed issue where Servent would never emit ready when UPnP returns an invalid ip.
This commit is contained in:
@@ -54,7 +54,7 @@ PortFwdThread::work()
|
|||||||
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
|
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
|
||||||
m_portfwd = new Portfwd();
|
m_portfwd = new Portfwd();
|
||||||
|
|
||||||
foreach( QHostAddress ha, QNetworkInterface::allAddresses() )
|
foreach ( QHostAddress ha, QNetworkInterface::allAddresses() )
|
||||||
{
|
{
|
||||||
if( ha.toString() == "127.0.0.1" ) continue;
|
if( ha.toString() == "127.0.0.1" ) continue;
|
||||||
if( ha.toString().contains( ":" ) ) continue; //ipv6
|
if( ha.toString().contains( ":" ) ) continue; //ipv6
|
||||||
@@ -63,23 +63,23 @@ PortFwdThread::work()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// try and pick an available port:
|
// try and pick an available port:
|
||||||
if( m_portfwd->init( 2000 ) )
|
if ( m_portfwd->init( 2000 ) )
|
||||||
{
|
{
|
||||||
int tryport = m_port;
|
int tryport = m_port;
|
||||||
|
|
||||||
// last.fm office firewall policy hack
|
// last.fm office firewall policy hack
|
||||||
// (corp. firewall allows outgoing connections to this port,
|
// (corp. firewall allows outgoing connections to this port,
|
||||||
// so listen on this if you want lastfmers to connect to you)
|
// so listen on this if you want lastfmers to connect to you)
|
||||||
if( qApp->arguments().contains( "--porthack" ) )
|
if ( qApp->arguments().contains( "--porthack" ) )
|
||||||
{
|
{
|
||||||
tryport = 3389;
|
tryport = 3389;
|
||||||
m_portfwd->remove( tryport );
|
m_portfwd->remove( tryport );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int r = 0; r < 3; ++r )
|
for ( int r = 0; r < 3; ++r )
|
||||||
{
|
{
|
||||||
qDebug() << "Trying to setup portfwd on" << tryport;
|
qDebug() << "Trying to setup portfwd on" << tryport;
|
||||||
if( m_portfwd->add( tryport, m_port ) )
|
if ( m_portfwd->add( tryport, m_port ) )
|
||||||
{
|
{
|
||||||
QString pubip = QString( m_portfwd->external_ip().c_str() );
|
QString pubip = QString( m_portfwd->external_ip().c_str() );
|
||||||
m_externalAddress = QHostAddress( pubip );
|
m_externalAddress = QHostAddress( pubip );
|
||||||
@@ -95,7 +95,7 @@ PortFwdThread::work()
|
|||||||
else
|
else
|
||||||
qDebug() << "No UPNP Gateway device found?";
|
qDebug() << "No UPNP Gateway device found?";
|
||||||
|
|
||||||
if( !m_externalPort )
|
if ( !m_externalPort )
|
||||||
qDebug() << "Could not setup fwd for port:" << m_port;
|
qDebug() << "Could not setup fwd for port:" << m_port;
|
||||||
|
|
||||||
emit externalAddressDetected( m_externalAddress, m_externalPort );
|
emit externalAddressDetected( m_externalAddress, m_externalPort );
|
||||||
|
@@ -136,26 +136,10 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
|
|||||||
if ( mode == TomahawkSettings::Upnp && !upnp )
|
if ( mode == TomahawkSettings::Upnp && !upnp )
|
||||||
mode = TomahawkSettings::Lan;
|
mode = TomahawkSettings::Lan;
|
||||||
|
|
||||||
switch( mode )
|
switch ( mode )
|
||||||
{
|
{
|
||||||
case TomahawkSettings::Lan:
|
case TomahawkSettings::Lan:
|
||||||
foreach( QHostAddress ha, QNetworkInterface::allAddresses() )
|
setInternalAddress();
|
||||||
{
|
|
||||||
if( ha.toString() == "127.0.0.1" ) continue;
|
|
||||||
if( ha.toString().contains( ":" ) ) continue; //ipv6
|
|
||||||
|
|
||||||
if ( qApp->arguments().contains( "--lanhack" ) )
|
|
||||||
{
|
|
||||||
tLog() << "LANHACK: set external address to lan address" << ha.toString();
|
|
||||||
QMetaObject::invokeMethod( this, "setExternalAddress", Qt::QueuedConnection, Q_ARG( QHostAddress, ha ), Q_ARG( unsigned int, m_port ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_ready = true;
|
|
||||||
emit ready();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TomahawkSettings::Upnp:
|
case TomahawkSettings::Upnp:
|
||||||
@@ -179,7 +163,7 @@ Servent::createConnectionKey( const QString& name, const QString &nodeid, const
|
|||||||
QString _key = ( key.isEmpty() ? uuid() : key );
|
QString _key = ( key.isEmpty() ? uuid() : key );
|
||||||
ControlConnection* cc = new ControlConnection( this );
|
ControlConnection* cc = new ControlConnection( this );
|
||||||
cc->setName( name.isEmpty() ? QString( "KEY(%1)" ).arg( key ) : name );
|
cc->setName( name.isEmpty() ? QString( "KEY(%1)" ).arg( key ) : name );
|
||||||
if( !nodeid.isEmpty() )
|
if ( !nodeid.isEmpty() )
|
||||||
cc->setId( nodeid );
|
cc->setId( nodeid );
|
||||||
cc->setOnceOnly( onceOnly );
|
cc->setOnceOnly( onceOnly );
|
||||||
|
|
||||||
@@ -189,6 +173,31 @@ Servent::createConnectionKey( const QString& name, const QString &nodeid, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Servent::setInternalAddress()
|
||||||
|
{
|
||||||
|
foreach ( QHostAddress ha, QNetworkInterface::allAddresses() )
|
||||||
|
{
|
||||||
|
if ( ha.toString() == "127.0.0.1" )
|
||||||
|
continue;
|
||||||
|
if ( ha.toString().contains( ":" ) )
|
||||||
|
continue; //ipv6
|
||||||
|
|
||||||
|
if ( qApp->arguments().contains( "--lanhack" ) )
|
||||||
|
{
|
||||||
|
tLog() << "LANHACK: set external address to lan address" << ha.toString();
|
||||||
|
setExternalAddress( ha, m_port );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_ready = true;
|
||||||
|
emit ready();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Servent::setExternalAddress( QHostAddress ha, unsigned int port )
|
Servent::setExternalAddress( QHostAddress ha, unsigned int port )
|
||||||
{
|
{
|
||||||
@@ -198,6 +207,7 @@ Servent::setExternalAddress( QHostAddress ha, unsigned int port )
|
|||||||
if ( ip.startsWith( "10." ) || ip.startsWith( "172.16." ) || ip.startsWith( "192.168." ) )
|
if ( ip.startsWith( "10." ) || ip.startsWith( "172.16." ) || ip.startsWith( "192.168." ) )
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << "Tried to set an invalid ip as external address!";
|
tDebug() << Q_FUNC_INFO << "Tried to set an invalid ip as external address!";
|
||||||
|
setInternalAddress();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -134,6 +134,7 @@ protected:
|
|||||||
void incomingConnection( int sd );
|
void incomingConnection( int sd );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void setInternalAddress();
|
||||||
void setExternalAddress( QHostAddress ha, unsigned int port );
|
void setExternalAddress( QHostAddress ha, unsigned int port );
|
||||||
|
|
||||||
void socketError( QAbstractSocket::SocketError );
|
void socketError( QAbstractSocket::SocketError );
|
||||||
|
Reference in New Issue
Block a user