mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Do the connection name fixing in a different way; always end up with a
QHostAddress.
This commit is contained in:
@@ -87,6 +87,8 @@ public:
|
|||||||
void setMsgProcessorModeOut( quint32 m ) { m_msgprocessor_out.setMode( m ); }
|
void setMsgProcessorModeOut( quint32 m ) { m_msgprocessor_out.setMode( m ); }
|
||||||
void setMsgProcessorModeIn( quint32 m ) { m_msgprocessor_in.setMode( m ); }
|
void setMsgProcessorModeIn( quint32 m ) { m_msgprocessor_in.setMode( m ); }
|
||||||
|
|
||||||
|
const QHostAddress peerIpAddress() const { return m_peerIpAddress; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ready();
|
void ready();
|
||||||
void failed();
|
void failed();
|
||||||
@@ -128,6 +130,7 @@ protected:
|
|||||||
bool m_outbound, m_ready, m_onceonly;
|
bool m_outbound, m_ready, m_onceonly;
|
||||||
msg_ptr m_firstmsg;
|
msg_ptr m_firstmsg;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
QHostAddress m_peerIpAddress;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleReadMsg();
|
void handleReadMsg();
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
ControlConnection::ControlConnection( Servent* parent )
|
ControlConnection::ControlConnection( Servent* parent, const QHostAddress &ha )
|
||||||
: Connection( parent )
|
: Connection( parent )
|
||||||
, m_dbsyncconn( 0 )
|
, m_dbsyncconn( 0 )
|
||||||
, m_registered( false )
|
, m_registered( false )
|
||||||
@@ -41,12 +41,44 @@ ControlConnection::ControlConnection( Servent* parent )
|
|||||||
{
|
{
|
||||||
qDebug() << "CTOR controlconnection";
|
qDebug() << "CTOR controlconnection";
|
||||||
setId("ControlConnection()");
|
setId("ControlConnection()");
|
||||||
|
|
||||||
// auto delete when connection closes:
|
// auto delete when connection closes:
|
||||||
connect( this, SIGNAL( finished() ), SLOT( deleteLater() ) );
|
connect( this, SIGNAL( finished() ), SLOT( deleteLater() ) );
|
||||||
|
|
||||||
this->setMsgProcessorModeIn( MsgProcessor::UNCOMPRESS_ALL | MsgProcessor::PARSE_JSON );
|
this->setMsgProcessorModeIn( MsgProcessor::UNCOMPRESS_ALL | MsgProcessor::PARSE_JSON );
|
||||||
this->setMsgProcessorModeOut( MsgProcessor::COMPRESS_IF_LARGE );
|
this->setMsgProcessorModeOut( MsgProcessor::COMPRESS_IF_LARGE );
|
||||||
|
|
||||||
|
m_peerIpAddress = ha;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ControlConnection::ControlConnection( Servent* parent, const QString &ha )
|
||||||
|
: Connection( parent )
|
||||||
|
, m_dbsyncconn( 0 )
|
||||||
|
, m_registered( false )
|
||||||
|
, m_pingtimer( 0 )
|
||||||
|
{
|
||||||
|
qDebug() << "CTOR controlconnection";
|
||||||
|
setId("ControlConnection()");
|
||||||
|
|
||||||
|
// auto delete when connection closes:
|
||||||
|
connect( this, SIGNAL( finished() ), SLOT( deleteLater() ) );
|
||||||
|
|
||||||
|
this->setMsgProcessorModeIn( MsgProcessor::UNCOMPRESS_ALL | MsgProcessor::PARSE_JSON );
|
||||||
|
this->setMsgProcessorModeOut( MsgProcessor::COMPRESS_IF_LARGE );
|
||||||
|
|
||||||
|
if ( !ha.isEmpty() )
|
||||||
|
{
|
||||||
|
QHostAddress qha( ha );
|
||||||
|
if ( !qha.isNull() )
|
||||||
|
m_peerIpAddress = qha;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QHostInfo qhi = QHostInfo::fromName( ha );
|
||||||
|
if ( !qhi.addresses().isEmpty() )
|
||||||
|
m_peerIpAddress = qhi.addresses().first();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,7 +104,7 @@ ControlConnection::source() const
|
|||||||
Connection*
|
Connection*
|
||||||
ControlConnection::clone()
|
ControlConnection::clone()
|
||||||
{
|
{
|
||||||
ControlConnection* clone = new ControlConnection( servent() );
|
ControlConnection* clone = new ControlConnection( servent(), m_peerIpAddress.toString() );
|
||||||
clone->setOnceOnly( onceOnly() );
|
clone->setOnceOnly( onceOnly() );
|
||||||
clone->setName( name() );
|
clone->setName( name() );
|
||||||
return clone;
|
return clone;
|
||||||
|
@@ -39,7 +39,8 @@ class DLLEXPORT ControlConnection : public Connection
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ControlConnection( Servent* parent = 0 );
|
explicit ControlConnection( Servent* parent = 0, const QHostAddress &ha = QHostAddress() );
|
||||||
|
explicit ControlConnection( Servent* parent = 0, const QString &ha = QString() );
|
||||||
~ControlConnection();
|
~ControlConnection();
|
||||||
Connection* clone();
|
Connection* clone();
|
||||||
|
|
||||||
|
@@ -142,6 +142,7 @@ DBSyncConnection::check()
|
|||||||
void
|
void
|
||||||
DBSyncConnection::gotUs( const QVariantMap& m )
|
DBSyncConnection::gotUs( const QVariantMap& m )
|
||||||
{
|
{
|
||||||
|
Q_UNUSED( m )
|
||||||
if ( !m_uscache.empty() )
|
if ( !m_uscache.empty() )
|
||||||
sendOps();
|
sendOps();
|
||||||
}
|
}
|
||||||
|
@@ -164,7 +164,7 @@ Servent::createConnectionKey( const QString& name, const QString &nodeid, const
|
|||||||
Q_ASSERT( this->thread() == QThread::currentThread() );
|
Q_ASSERT( this->thread() == QThread::currentThread() );
|
||||||
|
|
||||||
QString _key = ( key.isEmpty() ? uuid() : key );
|
QString _key = ( key.isEmpty() ? uuid() : key );
|
||||||
ControlConnection* cc = new ControlConnection( this );
|
ControlConnection* cc = new ControlConnection( this, name );
|
||||||
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 );
|
||||||
@@ -420,7 +420,7 @@ Servent::createParallelConnection( Connection* orig_conn, Connection* new_conn,
|
|||||||
// if we can connect to them directly:
|
// if we can connect to them directly:
|
||||||
if( orig_conn && orig_conn->outbound() )
|
if( orig_conn && orig_conn->outbound() )
|
||||||
{
|
{
|
||||||
connectToPeer( orig_conn->socket()->peerAddress().isNull() ? orig_conn->socket()->peerName() : orig_conn->socket()->peerAddress().toString(),
|
connectToPeer( orig_conn->socket()->peerAddress().toString(),
|
||||||
orig_conn->peerPort(),
|
orig_conn->peerPort(),
|
||||||
key,
|
key,
|
||||||
new_conn );
|
new_conn );
|
||||||
@@ -513,7 +513,7 @@ Servent::connectToPeer( const QString& ha, int port, const QString &key, const Q
|
|||||||
{
|
{
|
||||||
Q_ASSERT( this->thread() == QThread::currentThread() );
|
Q_ASSERT( this->thread() == QThread::currentThread() );
|
||||||
|
|
||||||
ControlConnection* conn = new ControlConnection( this );
|
ControlConnection* conn = new ControlConnection( this, ha );
|
||||||
QVariantMap m;
|
QVariantMap m;
|
||||||
m["conntype"] = "accept-offer";
|
m["conntype"] = "accept-offer";
|
||||||
m["key"] = key;
|
m["key"] = key;
|
||||||
@@ -565,7 +565,10 @@ Servent::connectToPeer( const QString& ha, int port, const QString &key, Connect
|
|||||||
connect( sock, SIGNAL( error( QAbstractSocket::SocketError ) ),
|
connect( sock, SIGNAL( error( QAbstractSocket::SocketError ) ),
|
||||||
SLOT( socketError( QAbstractSocket::SocketError ) ) );
|
SLOT( socketError( QAbstractSocket::SocketError ) ) );
|
||||||
|
|
||||||
sock->connectToHost( ha, port, QTcpSocket::ReadWrite );
|
if ( !conn->peerIpAddress().isNull() )
|
||||||
|
sock->connectToHost( conn->peerIpAddress(), port, QTcpSocket::ReadWrite );
|
||||||
|
else
|
||||||
|
sock->connectToHost( ha, port, QTcpSocket::ReadWrite );
|
||||||
sock->moveToThread( thread() );
|
sock->moveToThread( thread() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,7 +601,6 @@ Servent::reverseOfferRequest( ControlConnection* orig_conn, const QString& their
|
|||||||
Connection*
|
Connection*
|
||||||
Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString &key, const QHostAddress peer )
|
Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString &key, const QHostAddress peer )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << " peer is " << peer.toString();
|
|
||||||
bool noauth = qApp->arguments().contains( "--noauth" );
|
bool noauth = qApp->arguments().contains( "--noauth" );
|
||||||
|
|
||||||
// magic key for stream connections:
|
// magic key for stream connections:
|
||||||
@@ -633,7 +635,7 @@ Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString
|
|||||||
if( isIPWhitelisted( peer ) )
|
if( isIPWhitelisted( peer ) )
|
||||||
{
|
{
|
||||||
tDebug() << "Connection is from whitelisted IP range (LAN)";
|
tDebug() << "Connection is from whitelisted IP range (LAN)";
|
||||||
Connection* conn = new ControlConnection( this );
|
Connection* conn = new ControlConnection( this, peer.toString() );
|
||||||
conn->setName( peer.toString() );
|
conn->setName( peer.toString() );
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
@@ -679,7 +681,7 @@ Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString
|
|||||||
else if ( noauth )
|
else if ( noauth )
|
||||||
{
|
{
|
||||||
Connection* conn;
|
Connection* conn;
|
||||||
conn = new ControlConnection( this );
|
conn = new ControlConnection( this, peer );
|
||||||
conn->setName( key );
|
conn->setName( key );
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
@@ -475,7 +475,7 @@ SipHandler::onPeerOnline( const QString& jid )
|
|||||||
if( Servent::instance()->visibleExternally() )
|
if( Servent::instance()->visibleExternally() )
|
||||||
{
|
{
|
||||||
QString key = uuid();
|
QString key = uuid();
|
||||||
ControlConnection* conn = new ControlConnection( Servent::instance() );
|
ControlConnection* conn = new ControlConnection( Servent::instance(), QString() );
|
||||||
|
|
||||||
const QString& nodeid = Database::instance()->dbid();
|
const QString& nodeid = Database::instance()->dbid();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user