mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-24 09:49:42 +01:00
* Fixed issue where Servent would never emit ready when UPnP returns an invalid ip.
This commit is contained in:
parent
9ec9fb9362
commit
48e3eb877d
@ -54,7 +54,7 @@ PortFwdThread::work()
|
||||
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
|
||||
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().contains( ":" ) ) continue; //ipv6
|
||||
@ -63,23 +63,23 @@ PortFwdThread::work()
|
||||
}
|
||||
|
||||
// try and pick an available port:
|
||||
if( m_portfwd->init( 2000 ) )
|
||||
if ( m_portfwd->init( 2000 ) )
|
||||
{
|
||||
int tryport = m_port;
|
||||
|
||||
// last.fm office firewall policy hack
|
||||
// (corp. firewall allows outgoing connections to this port,
|
||||
// so listen on this if you want lastfmers to connect to you)
|
||||
if( qApp->arguments().contains( "--porthack" ) )
|
||||
if ( qApp->arguments().contains( "--porthack" ) )
|
||||
{
|
||||
tryport = 3389;
|
||||
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;
|
||||
if( m_portfwd->add( tryport, m_port ) )
|
||||
if ( m_portfwd->add( tryport, m_port ) )
|
||||
{
|
||||
QString pubip = QString( m_portfwd->external_ip().c_str() );
|
||||
m_externalAddress = QHostAddress( pubip );
|
||||
@ -95,7 +95,7 @@ PortFwdThread::work()
|
||||
else
|
||||
qDebug() << "No UPNP Gateway device found?";
|
||||
|
||||
if( !m_externalPort )
|
||||
if ( !m_externalPort )
|
||||
qDebug() << "Could not setup fwd for port:" << m_port;
|
||||
|
||||
emit externalAddressDetected( m_externalAddress, m_externalPort );
|
||||
|
@ -136,26 +136,10 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
|
||||
if ( mode == TomahawkSettings::Upnp && !upnp )
|
||||
mode = TomahawkSettings::Lan;
|
||||
|
||||
switch( mode )
|
||||
switch ( mode )
|
||||
{
|
||||
case TomahawkSettings::Lan:
|
||||
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();
|
||||
QMetaObject::invokeMethod( this, "setExternalAddress", Qt::QueuedConnection, Q_ARG( QHostAddress, ha ), Q_ARG( unsigned int, m_port ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ready = true;
|
||||
emit ready();
|
||||
}
|
||||
break;
|
||||
}
|
||||
setInternalAddress();
|
||||
break;
|
||||
|
||||
case TomahawkSettings::Upnp:
|
||||
@ -179,7 +163,7 @@ Servent::createConnectionKey( const QString& name, const QString &nodeid, const
|
||||
QString _key = ( key.isEmpty() ? uuid() : key );
|
||||
ControlConnection* cc = new ControlConnection( this );
|
||||
cc->setName( name.isEmpty() ? QString( "KEY(%1)" ).arg( key ) : name );
|
||||
if( !nodeid.isEmpty() )
|
||||
if ( !nodeid.isEmpty() )
|
||||
cc->setId( nodeid );
|
||||
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
|
||||
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." ) )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << "Tried to set an invalid ip as external address!";
|
||||
setInternalAddress();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -134,6 +134,7 @@ protected:
|
||||
void incomingConnection( int sd );
|
||||
|
||||
public slots:
|
||||
void setInternalAddress();
|
||||
void setExternalAddress( QHostAddress ha, unsigned int port );
|
||||
|
||||
void socketError( QAbstractSocket::SocketError );
|
||||
|
Loading…
x
Reference in New Issue
Block a user