1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Do the connection name fixing in a different way; always end up with a

QHostAddress.
This commit is contained in:
Jeff Mitchell 2011-11-18 18:18:19 -05:00
parent ed11593b16
commit 46793bbf99
6 changed files with 51 additions and 12 deletions

View File

@ -87,6 +87,8 @@ public:
void setMsgProcessorModeOut( quint32 m ) { m_msgprocessor_out.setMode( m ); }
void setMsgProcessorModeIn( quint32 m ) { m_msgprocessor_in.setMode( m ); }
const QHostAddress peerIpAddress() const { return m_peerIpAddress; }
signals:
void ready();
void failed();
@ -128,6 +130,7 @@ protected:
bool m_outbound, m_ready, m_onceonly;
msg_ptr m_firstmsg;
QString m_name;
QHostAddress m_peerIpAddress;
private:
void handleReadMsg();

View File

@ -33,7 +33,7 @@
using namespace Tomahawk;
ControlConnection::ControlConnection( Servent* parent )
ControlConnection::ControlConnection( Servent* parent, const QHostAddress &ha )
: Connection( parent )
, m_dbsyncconn( 0 )
, m_registered( false )
@ -41,12 +41,44 @@ ControlConnection::ControlConnection( Servent* parent )
{
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 );
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*
ControlConnection::clone()
{
ControlConnection* clone = new ControlConnection( servent() );
ControlConnection* clone = new ControlConnection( servent(), m_peerIpAddress.toString() );
clone->setOnceOnly( onceOnly() );
clone->setName( name() );
return clone;

View File

@ -39,7 +39,8 @@ class DLLEXPORT ControlConnection : public Connection
Q_OBJECT
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();
Connection* clone();

View File

@ -142,6 +142,7 @@ DBSyncConnection::check()
void
DBSyncConnection::gotUs( const QVariantMap& m )
{
Q_UNUSED( m )
if ( !m_uscache.empty() )
sendOps();
}

View File

@ -164,7 +164,7 @@ Servent::createConnectionKey( const QString& name, const QString &nodeid, const
Q_ASSERT( this->thread() == QThread::currentThread() );
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 );
if ( !nodeid.isEmpty() )
cc->setId( nodeid );
@ -420,7 +420,7 @@ Servent::createParallelConnection( Connection* orig_conn, Connection* new_conn,
// if we can connect to them directly:
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(),
key,
new_conn );
@ -513,7 +513,7 @@ Servent::connectToPeer( const QString& ha, int port, const QString &key, const Q
{
Q_ASSERT( this->thread() == QThread::currentThread() );
ControlConnection* conn = new ControlConnection( this );
ControlConnection* conn = new ControlConnection( this, ha );
QVariantMap m;
m["conntype"] = "accept-offer";
m["key"] = key;
@ -565,7 +565,10 @@ Servent::connectToPeer( const QString& ha, int port, const QString &key, Connect
connect( sock, SIGNAL( error( 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() );
}
@ -598,7 +601,6 @@ Servent::reverseOfferRequest( ControlConnection* orig_conn, const QString& their
Connection*
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" );
// magic key for stream connections:
@ -633,7 +635,7 @@ Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString
if( isIPWhitelisted( peer ) )
{
tDebug() << "Connection is from whitelisted IP range (LAN)";
Connection* conn = new ControlConnection( this );
Connection* conn = new ControlConnection( this, peer.toString() );
conn->setName( peer.toString() );
return conn;
}
@ -679,7 +681,7 @@ Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString
else if ( noauth )
{
Connection* conn;
conn = new ControlConnection( this );
conn = new ControlConnection( this, peer );
conn->setName( key );
return conn;
}

View File

@ -475,7 +475,7 @@ SipHandler::onPeerOnline( const QString& jid )
if( Servent::instance()->visibleExternally() )
{
QString key = uuid();
ControlConnection* conn = new ControlConnection( Servent::instance() );
ControlConnection* conn = new ControlConnection( Servent::instance(), QString() );
const QString& nodeid = Database::instance()->dbid();