mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-21 00:12:06 +02:00
Add external-address-mode.
It's either Lan, DynDns or Upnp and can be configured only in the config file right now.
This commit is contained in:
parent
d007dbb477
commit
78a786e878
@ -18,6 +18,7 @@
|
||||
#include "sourcelist.h"
|
||||
|
||||
#include "portfwdthread.h"
|
||||
#include "tomahawksettings.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -82,30 +83,38 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
|
||||
}
|
||||
|
||||
// --lanhack means to advertise your LAN IP over jabber as if it were externallyVisible
|
||||
if( qApp->arguments().contains( "--lanhack" ) )
|
||||
switch( TomahawkSettings::instance()->externalAddressMode() )
|
||||
{
|
||||
QList<QHostAddress> ifs = QNetworkInterface::allAddresses();
|
||||
foreach( QHostAddress ha, ifs )
|
||||
{
|
||||
if( ha.toString() == "127.0.0.1" ) continue;
|
||||
if( ha.toString().contains( ":" ) ) continue; //ipv6
|
||||
case TomahawkSettings::Lan:
|
||||
foreach( QHostAddress ha, QNetworkInterface::allAddresses() )
|
||||
{
|
||||
if( ha.toString() == "127.0.0.1" ) continue;
|
||||
if( ha.toString().contains( ":" ) ) continue; //ipv6
|
||||
|
||||
m_externalAddress = ha;
|
||||
m_externalPort = m_port;
|
||||
qDebug() << "LANHACK: set external address to lan address" << ha.toString();
|
||||
m_externalAddress = ha;
|
||||
m_externalPort = m_port;
|
||||
qDebug() << "LANHACK: set external address to lan address" << ha.toString();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if( upnp )
|
||||
{
|
||||
// TODO check if we have a public/internet IP on this machine directly
|
||||
m_portfwd = new PortFwdThread( m_port );
|
||||
connect( m_portfwd, SIGNAL( externalAddressDetected( QHostAddress, unsigned int ) ),
|
||||
SLOT( setExternalAddress( QHostAddress, unsigned int ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
emit ready();
|
||||
|
||||
case TomahawkSettings::DynDns:
|
||||
qDebug() << "External address mode set to dyndns...";
|
||||
m_externalHostname = TomahawkSettings::instance()->externalHostname();
|
||||
m_externalPort = TomahawkSettings::instance()->externalPort();
|
||||
qDebug() << m_externalHostname << m_externalPort;
|
||||
break;
|
||||
|
||||
case TomahawkSettings::Upnp:
|
||||
// TODO check if we have a public/internet IP on this machine directly
|
||||
qDebug() << "External address mode set to upnp....";
|
||||
m_portfwd = new PortFwdThread( m_port );
|
||||
connect( m_portfwd, SIGNAL( externalAddressDetected( QHostAddress, unsigned int ) ),
|
||||
SLOT( setExternalAddress( QHostAddress, unsigned int ) ) );
|
||||
break;
|
||||
|
||||
default:
|
||||
emit ready();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -90,8 +90,8 @@ public:
|
||||
void connectToPeer( const QString& ha, int port, const QString &key, Connection* conn );
|
||||
void reverseOfferRequest( ControlConnection* orig_conn, const QString& key, const QString& theirkey );
|
||||
|
||||
bool visibleExternally() const { return m_externalPort > 0 && !m_externalAddress.isNull(); }
|
||||
QHostAddress externalAddress() const { return m_externalAddress; }
|
||||
bool visibleExternally() const { return !m_externalHostname.isNull() || (m_externalPort > 0 && !m_externalAddress.isNull()); }
|
||||
QString externalAddress() const { return !m_externalHostname.isNull() ? m_externalHostname : m_externalAddress.toString(); }
|
||||
int externalPort() const { return m_externalPort; }
|
||||
|
||||
QSharedPointer<QIODevice> remoteIODeviceFactory( const Tomahawk::result_ptr& );
|
||||
@ -142,6 +142,7 @@ private:
|
||||
QMap< QString, QPointer<Connection> > m_offers;
|
||||
int m_port, m_externalPort;
|
||||
QHostAddress m_externalAddress;
|
||||
QString m_externalHostname;
|
||||
|
||||
// currently active file transfers:
|
||||
QList< FileTransferConnection* > m_ftsessions;
|
||||
|
@ -297,17 +297,41 @@ TomahawkSettings::setJabberPassword( const QString& pw )
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TomahawkSettings::upnpEnabled() const
|
||||
TomahawkSettings::ExternalAddressMode
|
||||
TomahawkSettings::externalAddressMode() const
|
||||
{
|
||||
return value( "network/upnp", true ).toBool();
|
||||
return (TomahawkSettings::ExternalAddressMode) value( "network/external-address-mode", TomahawkSettings::Upnp ).toInt();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkSettings::setUPnPEnabled( bool enable )
|
||||
TomahawkSettings::setExternalAddressMode( ExternalAddressMode externalAddressMode )
|
||||
{
|
||||
setValue( "network/upnp", enable );
|
||||
setValue( "network/external-address-mode", externalAddressMode );
|
||||
}
|
||||
|
||||
QString
|
||||
TomahawkSettings::externalHostname() const
|
||||
{
|
||||
return value( "network/external-hostname" ).toString();
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkSettings::setExternalHostname(const QString& externalHostname)
|
||||
{
|
||||
setValue( "network/external-hostname", externalHostname );
|
||||
}
|
||||
|
||||
int
|
||||
TomahawkSettings::externalPort() const
|
||||
{
|
||||
return value( "network/external-port" ).toInt();
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkSettings::setExternalPort(int externalPort)
|
||||
{
|
||||
setValue( "network/external-port", externalPort);
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,11 +55,18 @@ public:
|
||||
void setJabberPort( int port );
|
||||
|
||||
/// Network settings
|
||||
enum ExternalAddressMode { Lan, DynDns, Upnp };
|
||||
ExternalAddressMode externalAddressMode() const;
|
||||
void setExternalAddressMode(ExternalAddressMode externalAddressMode);
|
||||
|
||||
bool httpEnabled() const; /// true by default
|
||||
void setHttpEnabled( bool enable );
|
||||
|
||||
bool upnpEnabled() const; /// true by default
|
||||
void setUPnPEnabled( bool enable );
|
||||
|
||||
QString externalHostname() const;
|
||||
void setExternalHostname( const QString& externalHostname );
|
||||
|
||||
int externalPort() const;
|
||||
void setExternalPort( int externalPort );
|
||||
|
||||
QString proxyHost() const;
|
||||
void setProxyHost( const QString &host );
|
||||
|
@ -39,7 +39,7 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
|
||||
ui->checkBoxHttp->setChecked( s->httpEnabled() );
|
||||
ui->checkBoxUpnp->setChecked( s->upnpEnabled() );
|
||||
ui->checkBoxUpnp->setChecked( s->externalAddressMode() == TomahawkSettings::Upnp );
|
||||
|
||||
// JABBER
|
||||
ui->checkBoxJabberAutoConnect->setChecked( s->jabberAutoConnect() );
|
||||
@ -99,7 +99,7 @@ SettingsDialog::~SettingsDialog()
|
||||
}
|
||||
|
||||
s->setHttpEnabled( ui->checkBoxHttp->checkState() == Qt::Checked );
|
||||
s->setUPnPEnabled( ui->checkBoxUpnp->checkState() == Qt::Checked );
|
||||
s->setExternalAddressMode(ui->checkBoxUpnp->checkState() == Qt::Checked ? TomahawkSettings::Upnp : TomahawkSettings::Lan);
|
||||
|
||||
s->setJabberAutoConnect( ui->checkBoxJabberAutoConnect->checkState() == Qt::Checked );
|
||||
s->setJabberUsername( ui->jabberUsername->text() );
|
||||
|
@ -129,7 +129,7 @@ SipHandler::onPeerOnline( const QString& jid )
|
||||
|
||||
Servent::instance()->registerOffer( key, conn );
|
||||
m["visible"] = true;
|
||||
m["ip"] = Servent::instance()->externalAddress().toString();
|
||||
m["ip"] = Servent::instance()->externalAddress();
|
||||
m["port"] = Servent::instance()->externalPort();
|
||||
m["key"] = key;
|
||||
m["uniqname"] = nodeid;
|
||||
@ -181,7 +181,7 @@ SipHandler::onMessage( const QString& from, const QString& msg )
|
||||
if ( m.value( "visible" ).toBool() )
|
||||
{
|
||||
if( !Servent::instance()->visibleExternally() ||
|
||||
Servent::instance()->externalAddress().toString() <= m.value( "ip" ).toString() )
|
||||
Servent::instance()->externalAddress() <= m.value( "ip" ).toString() )
|
||||
{
|
||||
qDebug() << "Initiate connection to" << from;
|
||||
Servent::instance()->connectToPeer( m.value( "ip" ).toString(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user