1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 06:07:37 +02:00

Reconnect if ACL decision took too long

This commit is contained in:
Uwe L. Korn
2013-06-09 11:47:00 +02:00
parent 0b453df15c
commit 1d3dd67bf3
7 changed files with 74 additions and 5 deletions

View File

@@ -207,23 +207,27 @@ Connection::checkACL()
} }
QString nodeid = property( "nodeid" ).toString(); QString nodeid = property( "nodeid" ).toString();
QString bareName = name().contains( '/' ) ? name().left( name().indexOf( "/" ) ) : name();
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Checking ACL for" << name(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Checking ACL for" << name();
connect( ACLRegistry::instance(), SIGNAL( aclResult( QString, QString, ACLRegistry::ACL ) ), this, SLOT( checkACLResult( QString, QString, ACLRegistry::ACL ) ), Qt::QueuedConnection ); connect( ACLRegistry::instance(), SIGNAL( aclResult( QString, QString, ACLRegistry::ACL ) ), this, SLOT( checkACLResult( QString, QString, ACLRegistry::ACL ) ), Qt::QueuedConnection );
QMetaObject::invokeMethod( ACLRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, nodeid ), Q_ARG( QString, bareName ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ) ); QMetaObject::invokeMethod( ACLRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, nodeid ), Q_ARG( QString, bareName() ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ) );
} }
QString
Connection::bareName() const
{
return name().contains( '/' ) ? name().left( name().indexOf( "/" ) ) : name();
}
void void
Connection::checkACLResult( const QString &nodeid, const QString &username, ACLRegistry::ACL peerStatus ) Connection::checkACLResult( const QString &nodeid, const QString &username, ACLRegistry::ACL peerStatus )
{ {
QString bareName = name().contains( '/' ) ? name().left( name().indexOf( "/" ) ) : name();
if ( nodeid != property( "nodeid" ).toString() ) if ( nodeid != property( "nodeid" ).toString() )
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << QString( "nodeid (%1) not ours (%2) for user %3" ).arg( nodeid ).arg( property( "nodeid" ).toString() ).arg( username ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << QString( "nodeid (%1) not ours (%2) for user %3" ).arg( nodeid ).arg( property( "nodeid" ).toString() ).arg( username );
return; return;
} }
if ( username != bareName ) if ( username != bareName() )
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "username not our barename"; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "username not our barename";
return; return;

View File

@@ -92,6 +92,7 @@ public:
const QHostAddress peerIpAddress() const { return m_peerIpAddress; } const QHostAddress peerIpAddress() const { return m_peerIpAddress; }
QString bareName() const;
signals: signals:
void ready(); void ready();
void failed(); void failed();
@@ -105,6 +106,7 @@ protected:
protected slots: protected slots:
virtual void handleMsg( msg_ptr msg ) = 0; virtual void handleMsg( msg_ptr msg ) = 0;
virtual void authCheckTimeout();
public slots: public slots:
virtual void start( QTcpSocket* sock ); virtual void start( QTcpSocket* sock );
@@ -122,7 +124,6 @@ private slots:
void doSetup(); void doSetup();
void checkACL(); void checkACL();
void checkACLResult( const QString &nodeid, const QString &username, ACLRegistry::ACL peerStatus ); void checkACLResult( const QString &nodeid, const QString &username, ACLRegistry::ACL peerStatus );
void authCheckTimeout();
void bytesWritten( qint64 ); void bytesWritten( qint64 );
void calcStats(); void calcStats();

View File

@@ -273,6 +273,18 @@ ControlConnection::handleMsg( msg_ptr msg )
tDebug() << id() << "Invalid msg:" << QString::fromLatin1( msg->payload() ); tDebug() << id() << "Invalid msg:" << QString::fromLatin1( msg->payload() );
} }
void
ControlConnection::authCheckTimeout()
{
if ( m_ready )
return;
Servent::instance()->queueForAclResult( bareName(), m_peerInfos );
tDebug( LOGVERBOSE ) << "Closing connection, not authed in time.";
shutdown();
}
void void
ControlConnection::onPingTimer() ControlConnection::onPingTimer()

View File

@@ -58,6 +58,7 @@ protected:
protected slots: protected slots:
virtual void handleMsg( msg_ptr msg ); virtual void handleMsg( msg_ptr msg );
virtual void authCheckTimeout();
private slots: private slots:
void dbSyncConnFinished( QObject* c ); void dbSyncConnFinished( QObject* c );

View File

@@ -210,6 +210,8 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
break; break;
} }
connect( ACLRegistry::instance(), SIGNAL( aclResult( QString, QString, ACLRegistry::ACL ) ), this, SLOT( checkACLResult( QString, QString, ACLRegistry::ACL ) ), Qt::QueuedConnection );
return true; return true;
} }
@@ -421,6 +423,22 @@ Servent::getLocalSipInfos( const QString& nodeid, const QString& key )
return sipInfos; return sipInfos;
} }
void
Servent::queueForAclResult( const QString& username, const QSet<peerinfo_ptr>& peerInfos )
{
if ( peerInfos.isEmpty() )
{
// If all peerInfos disappeared, do not queue.
return;
}
if ( !d_func()->queuedForACLResult.contains( username ) )
{
d_func()->queuedForACLResult[username] = QMap<QString, QSet<Tomahawk::peerinfo_ptr> >();
}
d_func()->queuedForACLResult[username][ (*peerInfos.begin())->nodeId() ] = QSet<Tomahawk::peerinfo_ptr>( peerInfos );
}
SipInfo SipInfo
Servent::getSipInfoForOldVersions( const QList<SipInfo>& sipInfos ) Servent::getSipInfoForOldVersions( const QList<SipInfo>& sipInfos )
{ {
@@ -880,6 +898,33 @@ Servent::socketError( QAbstractSocket::SocketError e )
} }
} }
void
Servent::checkACLResult( const QString& nodeid, const QString& username, ACLRegistry::ACL peerStatus )
{
if ( !d_func()->queuedForACLResult.contains( username ) )
{
return;
}
if ( !d_func()->queuedForACLResult.value( username ).contains( nodeid ) )
{
return;
}
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << QString( "ACL status for user %1 is" ).arg( username ) << peerStatus;
QSet<Tomahawk::peerinfo_ptr> peerInfos = d_func()->queuedForACLResult.value( username ).value( nodeid );
if ( peerStatus == ACLRegistry::Stream )
{
foreach ( Tomahawk::peerinfo_ptr peerInfo, peerInfos )
{
registerPeer( peerInfo );
}
}
// We have a result, so remove from queue
d_func()->queuedForACLResult[username].remove( nodeid );
}
void void
Servent::reverseOfferRequest( ControlConnection* orig_conn, const QString& theirdbid, const QString& key, const QString& theirkey ) Servent::reverseOfferRequest( ControlConnection* orig_conn, const QString& theirdbid, const QString& key, const QString& theirkey )
{ {

View File

@@ -36,6 +36,7 @@
#include "Typedefs.h" #include "Typedefs.h"
#include "Msg.h" #include "Msg.h"
#include "AclRegistry.h"
#include "DllMacro.h" #include "DllMacro.h"
@@ -134,6 +135,8 @@ public:
bool isReady() const; bool isReady() const;
QList<SipInfo> getLocalSipInfos(const QString& nodeid, const QString &key); QList<SipInfo> getLocalSipInfos(const QString& nodeid, const QString &key);
void queueForAclResult( const QString& username, const QSet<Tomahawk::peerinfo_ptr>& peerInfos );
signals: signals:
void dbSyncTriggered(); void dbSyncTriggered();
void streamStarted( StreamConnection* ); void streamStarted( StreamConnection* );
@@ -158,6 +161,7 @@ private slots:
void deleteLazyOffer( const QString& key ); void deleteLazyOffer( const QString& key );
void readyRead(); void readyRead();
void socketError( QAbstractSocket::SocketError e ); void socketError( QAbstractSocket::SocketError e );
void checkACLResult( const QString &nodeid, const QString &username, ACLRegistry::ACL peerStatus );
Connection* claimOffer( ControlConnection* cc, const QString &nodeid, const QString &key, const QHostAddress peer = QHostAddress::Any ); Connection* claimOffer( ControlConnection* cc, const QString &nodeid, const QString &key, const QHostAddress peer = QHostAddress::Any );

View File

@@ -83,6 +83,8 @@ private:
// currently active file transfers: // currently active file transfers:
QList< StreamConnection* > scsessions; QList< StreamConnection* > scsessions;
QMutex ftsession_mut; QMutex ftsession_mut;
// username -> nodeid -> PeerInfos
QMap<QString, QMap<QString, QSet<Tomahawk::peerinfo_ptr> > > queuedForACLResult;
QPointer< PortFwdThread > portfwd; QPointer< PortFwdThread > portfwd;
}; };