mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
Wait in ConnectMan for authentication until declaring a Connection as success
This commit is contained in:
@@ -331,12 +331,14 @@ Connection::checkACL()
|
|||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Not checking ACL, nodeid is empty";
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Not checking ACL, nodeid is empty";
|
||||||
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
||||||
|
emit authSuccessful();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( Servent::isIPWhitelisted( d_func()->peerIpAddress ) )
|
if ( Servent::isIPWhitelisted( d_func()->peerIpAddress ) )
|
||||||
{
|
{
|
||||||
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
||||||
|
emit authSuccessful();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,15 +360,19 @@ Connection::aclDecision( Tomahawk::ACLStatus::Type status )
|
|||||||
{
|
{
|
||||||
Q_D( Connection );
|
Q_D( Connection );
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "ACL decision for" << name() << ":" << status;
|
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "ACL decision for" << name() << ":" << status;
|
||||||
if ( status == Tomahawk::ACLStatus::Stream )
|
|
||||||
{
|
|
||||||
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We have a decision, free memory.
|
// We have a decision, free memory.
|
||||||
d->aclRequest->deleteLater();
|
d->aclRequest->deleteLater();
|
||||||
|
|
||||||
|
if ( status == Tomahawk::ACLStatus::Stream )
|
||||||
|
{
|
||||||
|
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
||||||
|
emit authSuccessful();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit authFailed();
|
||||||
|
|
||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,6 +385,8 @@ Connection::authCheckTimeout()
|
|||||||
if ( d->ready )
|
if ( d->ready )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
emit authTimeout();
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << "Closing connection, not authed in time.";
|
tDebug( LOGVERBOSE ) << "Closing connection, not authed in time.";
|
||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
|
@@ -87,6 +87,24 @@ public:
|
|||||||
|
|
||||||
QString bareName() const;
|
QString bareName() const;
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* Emitted if the authentication of this connection finally failed.
|
||||||
|
*/
|
||||||
|
void authFailed();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted if this connection was authenticated so that we can start talking to the other peer.
|
||||||
|
*/
|
||||||
|
void authSuccessful();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emiited if the authentication could not be processed in a given timespan.
|
||||||
|
*
|
||||||
|
* Though this does implicate a permanent problem in establishing a connection to the other peer,
|
||||||
|
* this connection will be shutdown. In most cases this signal is emitted because we are waiting
|
||||||
|
* for a user decision which has not yet be given.
|
||||||
|
*/
|
||||||
|
void authTimeout();
|
||||||
void ready();
|
void ready();
|
||||||
void failed();
|
void failed();
|
||||||
void finished();
|
void finished();
|
||||||
|
@@ -103,6 +103,39 @@ ConnectionManager::setWeakRef( QWeakPointer<ConnectionManager> weakRef )
|
|||||||
d_func()->ownRef = weakRef;
|
d_func()->ownRef = weakRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ConnectionManager::authSuccessful()
|
||||||
|
{
|
||||||
|
Q_D( ConnectionManager );
|
||||||
|
|
||||||
|
// We have successfully connected to the other peer, we're done.
|
||||||
|
disconnect( d->controlConnection.data(), SIGNAL( authSuccessful() ), this, SLOT( authSuccessful() ) );
|
||||||
|
disconnect( d->controlConnection.data(), SIGNAL( authFailed() ), this , SLOT( authFailed() ) );
|
||||||
|
disconnect( d->controlConnection.data(), SIGNAL( authTimeout() ), this, SLOT( authFailed() ) );
|
||||||
|
|
||||||
|
d->currentPeerInfo.clear();
|
||||||
|
deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ConnectionManager::authFailed()
|
||||||
|
{
|
||||||
|
Q_D( ConnectionManager );
|
||||||
|
|
||||||
|
// We could not auth with the peer on the other side, maybe this is the wrong one?
|
||||||
|
disconnect( d->controlConnection.data(), SIGNAL( authSuccessful() ), this, SLOT( authSuccessful() ) );
|
||||||
|
disconnect( d->controlConnection.data(), SIGNAL( authFailed() ), this, SLOT( authFailed() ) );
|
||||||
|
disconnect( d->controlConnection.data(), SIGNAL( authTimeout() ), this, SLOT( authFailed() ) );
|
||||||
|
|
||||||
|
// If auth failed, we need to setup a new controlconnection as the old will be destroyed.
|
||||||
|
newControlConnection( d->currentPeerInfo );
|
||||||
|
// Try to connect with the next available SipInfo.
|
||||||
|
tryConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ConnectionManager::handleSipInfoPrivate( const Tomahawk::peerinfo_ptr &peerInfo )
|
ConnectionManager::handleSipInfoPrivate( const Tomahawk::peerinfo_ptr &peerInfo )
|
||||||
{
|
{
|
||||||
@@ -142,6 +175,32 @@ ConnectionManager::handleSipInfoPrivate( const Tomahawk::peerinfo_ptr &peerInfo
|
|||||||
deactivate();
|
deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ConnectionManager::newControlConnection( const Tomahawk::peerinfo_ptr& peerInfo )
|
||||||
|
{
|
||||||
|
Q_D( ConnectionManager );
|
||||||
|
QVariantMap m;
|
||||||
|
m["conntype"] = "accept-offer";
|
||||||
|
m["key"] = peerInfo->key();
|
||||||
|
m["nodeid"] = Tomahawk::Database::instance()->impl()->dbid();
|
||||||
|
|
||||||
|
d->controlConnection = QPointer<ControlConnection>( new ControlConnection( Servent::instance() ) );
|
||||||
|
d->controlConnection->setShutdownOnEmptyPeerInfos( false );
|
||||||
|
d->controlConnection->addPeerInfo( peerInfo );
|
||||||
|
d->controlConnection->setFirstMessage( m );
|
||||||
|
|
||||||
|
if ( peerInfo->id().length() )
|
||||||
|
d->controlConnection->setName( peerInfo->contactId() );
|
||||||
|
if ( peerInfo->nodeId().length() )
|
||||||
|
d->controlConnection->setId( peerInfo->nodeId() );
|
||||||
|
|
||||||
|
d->controlConnection->setNodeId( peerInfo->nodeId() );
|
||||||
|
|
||||||
|
Servent::instance()->registerControlConnection( d->controlConnection.data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ConnectionManager::connectToPeer( const Tomahawk::peerinfo_ptr &peerInfo, bool lock )
|
ConnectionManager::connectToPeer( const Tomahawk::peerinfo_ptr &peerInfo, bool lock )
|
||||||
{
|
{
|
||||||
@@ -234,24 +293,7 @@ ConnectionManager::connectToPeer( const Tomahawk::peerinfo_ptr &peerInfo, bool l
|
|||||||
d_func()->sipCandidates.append( privateIPv6 );
|
d_func()->sipCandidates.append( privateIPv6 );
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap m;
|
newControlConnection( peerInfo );
|
||||||
m["conntype"] = "accept-offer";
|
|
||||||
m["key"] = peerInfo->key();
|
|
||||||
m["nodeid"] = Tomahawk::Database::instance()->impl()->dbid();
|
|
||||||
|
|
||||||
d_func()->controlConnection = QPointer<ControlConnection>( new ControlConnection( Servent::instance() ) );
|
|
||||||
d_func()->controlConnection->setShutdownOnEmptyPeerInfos( false );
|
|
||||||
d_func()->controlConnection->addPeerInfo( peerInfo );
|
|
||||||
d_func()->controlConnection->setFirstMessage( m );
|
|
||||||
|
|
||||||
if ( peerInfo->id().length() )
|
|
||||||
d_func()->controlConnection->setName( peerInfo->contactId() );
|
|
||||||
if ( peerInfo->nodeId().length() )
|
|
||||||
d_func()->controlConnection->setId( peerInfo->nodeId() );
|
|
||||||
|
|
||||||
d_func()->controlConnection->setNodeId( peerInfo->nodeId() );
|
|
||||||
|
|
||||||
Servent::instance()->registerControlConnection( d_func()->controlConnection.data() );
|
|
||||||
tryConnect();
|
tryConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,15 +399,19 @@ ConnectionManager::deactivate()
|
|||||||
void
|
void
|
||||||
ConnectionManager::socketConnected()
|
ConnectionManager::socketConnected()
|
||||||
{
|
{
|
||||||
|
Q_D( ConnectionManager );
|
||||||
QTcpSocketExtra* sock = (QTcpSocketExtra*)sender();
|
QTcpSocketExtra* sock = (QTcpSocketExtra*)sender();
|
||||||
|
|
||||||
peerInfoDebug( d_func()->currentPeerInfo ) << Q_FUNC_INFO << "Connected to hostaddr: " << sock->peerAddress() << ", hostname:" << sock->peerName();
|
peerInfoDebug( d->currentPeerInfo ) << Q_FUNC_INFO << "Connected to hostaddr: " << sock->peerAddress() << ", hostname:" << sock->peerName();
|
||||||
|
|
||||||
Q_ASSERT( !sock->_conn.isNull() );
|
Q_ASSERT( !sock->_conn.isNull() );
|
||||||
|
|
||||||
handoverSocket( sock );
|
handoverSocket( sock );
|
||||||
d_func()->currentPeerInfo.clear();
|
|
||||||
deactivate();
|
// Connect signal to wait for authentication result.
|
||||||
|
connect( d->controlConnection.data(), SIGNAL( authSuccessful() ), SLOT( authSuccessful() ) );
|
||||||
|
connect( d->controlConnection.data(), SIGNAL( authFailed()) , SLOT( authFailed() ) );
|
||||||
|
connect( d->controlConnection.data(), SIGNAL( authTimeout() ), SLOT( authFailed() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -60,6 +60,8 @@ public:
|
|||||||
void setWeakRef( QWeakPointer< ConnectionManager > weakRef );
|
void setWeakRef( QWeakPointer< ConnectionManager > weakRef );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void authSuccessful();
|
||||||
|
void authFailed();
|
||||||
void socketConnected();
|
void socketConnected();
|
||||||
void socketError( QAbstractSocket::SocketError error );
|
void socketError( QAbstractSocket::SocketError error );
|
||||||
|
|
||||||
@@ -74,6 +76,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
ConnectionManager( const QString& nodeid );
|
ConnectionManager( const QString& nodeid );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ControlConnection for talking to a peer.
|
||||||
|
*/
|
||||||
|
void newControlConnection(const Tomahawk::peerinfo_ptr &peerInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy handleSipInfoPrivate to hand over a strong reference to the connectionManager
|
* Proxy handleSipInfoPrivate to hand over a strong reference to the connectionManager
|
||||||
* so that the refcount is >0 while transferring the context of operation to another thread.
|
* so that the refcount is >0 while transferring the context of operation to another thread.
|
||||||
|
Reference in New Issue
Block a user