1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 13:47:26 +02:00

* Store PeerInfos in a temporary ControlConnection while the SIP is pending, so they don't get deleted again immediately.

This commit is contained in:
Christian Muehlhaeuser
2013-04-16 09:39:31 +02:00
parent 59a30573ee
commit d7c03e03ce
5 changed files with 41 additions and 34 deletions

View File

@@ -880,7 +880,7 @@ XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
handlePeerStatus( jid, Jreen::Presence::Available ); handlePeerStatus( jid, Jreen::Presence::Available );
} }
} }
else if ( context == RequestVersion) else if ( context == RequestVersion )
{ {
Jreen::SoftwareVersion::Ptr softwareVersion = iq.payload<Jreen::SoftwareVersion>(); Jreen::SoftwareVersion::Ptr softwareVersion = iq.payload<Jreen::SoftwareVersion>();
if ( softwareVersion ) if ( softwareVersion )
@@ -932,7 +932,7 @@ XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
Tomahawk::peerinfo_ptr peerInfo = PeerInfo::get( this, iq.from().full() ); Tomahawk::peerinfo_ptr peerInfo = PeerInfo::get( this, iq.from().full() );
if ( peerInfo.isNull() ) if ( peerInfo.isNull() )
{ {
tDebug() << Q_FUNC_INFO << "no valid peerInfo for " << iq.from().full(); tDebug() << Q_FUNC_INFO << "no valid peerInfo for" << iq.from().full();
return; return;
} }
peerInfo->setSipInfo( info ); peerInfo->setSipInfo( info );

View File

@@ -311,7 +311,7 @@ Servent::registerPeer( const Tomahawk::peerinfo_ptr& peerInfo )
if ( peerInfo->type() == Tomahawk::PeerInfo::Local ) if ( peerInfo->type() == Tomahawk::PeerInfo::Local )
{ {
peerInfoDebug(peerInfo) << "YAY, we need to establish the connection now.. thinking"; peerInfoDebug(peerInfo) << "we need to establish the connection now... thinking";
if ( !connectedToSession( peerInfo->sipInfo().nodeId() ) ) if ( !connectedToSession( peerInfo->sipInfo().nodeId() ) )
{ {
connectToPeer( peerInfo ); connectToPeer( peerInfo );
@@ -336,8 +336,6 @@ Servent::registerPeer( const Tomahawk::peerinfo_ptr& peerInfo )
else else
{ {
SipInfo info; SipInfo info;
if ( visibleExternally() )
{
QString peerId = peerInfo->id(); QString peerId = peerInfo->id();
QString key = uuid(); QString key = uuid();
ControlConnection* conn = new ControlConnection( this ); ControlConnection* conn = new ControlConnection( this );
@@ -347,6 +345,8 @@ Servent::registerPeer( const Tomahawk::peerinfo_ptr& peerInfo )
conn->setId( nodeid ); conn->setId( nodeid );
conn->addPeerInfo( peerInfo ); conn->addPeerInfo( peerInfo );
if ( visibleExternally() )
{
registerOffer( key, conn ); registerOffer( key, conn );
info.setVisible( true ); info.setVisible( true );
info.setHost( externalAddress() ); info.setHost( externalAddress() );
@@ -414,6 +414,8 @@ void Servent::handleSipInfo( const Tomahawk::peerinfo_ptr& peerInfo )
else else
{ {
tDebug() << Q_FUNC_INFO << "They are not visible, doing nothing atm"; tDebug() << Q_FUNC_INFO << "They are not visible, doing nothing atm";
if ( peerInfo->controlConnection() )
delete peerInfo->controlConnection();
} }
} }
@@ -714,10 +716,13 @@ Servent::connectToPeer( const peerinfo_ptr& peerInfo )
SipInfo sipInfo = peerInfo->sipInfo(); SipInfo sipInfo = peerInfo->sipInfo();
peerInfoDebug( peerInfo ) << "connectToPeer: search for already established connections to the same nodeid:" << m_controlconnections.count() << "connections"; peerInfoDebug( peerInfo ) << "connectToPeer: search for already established connections to the same nodeid:" << m_controlconnections.count() << "connections";
if ( peerInfo->controlConnection() )
delete peerInfo->controlConnection();
bool isDupe = false; bool isDupe = false;
ControlConnection* conn = 0; ControlConnection* conn = 0;
// try to find a ControlConnection with the same SipInfo, then we dont need to try to connect again // try to find a ControlConnection with the same SipInfo, then we dont need to try to connect again
foreach ( ControlConnection* c, m_controlconnections ) foreach ( ControlConnection* c, m_controlconnections )
{ {
Q_ASSERT( c ); Q_ASSERT( c );
@@ -769,7 +774,6 @@ Servent::connectToPeer( const peerinfo_ptr& peerInfo )
m["nodeid"] = Database::instance()->impl()->dbid(); m["nodeid"] = Database::instance()->impl()->dbid();
peerInfoDebug(peerInfo) << "No match found, creating a new ControlConnection..."; peerInfoDebug(peerInfo) << "No match found, creating a new ControlConnection...";
conn = new ControlConnection( this ); conn = new ControlConnection( this );
conn->addPeerInfo( peerInfo ); conn->addPeerInfo( peerInfo );
conn->setFirstMessage( m ); conn->setFirstMessage( m );
@@ -787,7 +791,7 @@ Servent::connectToPeer( const peerinfo_ptr& peerInfo )
void void
Servent::connectToPeer( const QString& ha, int port, const QString &key, Connection* conn ) Servent::connectToPeer( const QString& ha, int port, const QString& key, Connection* conn )
{ {
tDebug( LOGVERBOSE ) << "Servent::connectToPeer:" << ha << ":" << port tDebug( LOGVERBOSE ) << "Servent::connectToPeer:" << ha << ":" << port
<< thread() << QThread::currentThread(); << thread() << QThread::currentThread();

View File

@@ -118,8 +118,8 @@ public slots:
public: public:
void connectToPeer( const Tomahawk::peerinfo_ptr& ha ); void connectToPeer( const Tomahawk::peerinfo_ptr& ha );
void connectToPeer( const QString& ha, int port, const QString &key, Connection* conn ); void connectToPeer( const QString& ha, int port, const QString& key, Connection* conn );
void reverseOfferRequest( ControlConnection* orig_conn, const QString &theirdbid, const QString& key, const QString& theirkey ); void reverseOfferRequest( ControlConnection* orig_conn, const QString& theirdbid, const QString& key, const QString& theirkey );
bool visibleExternally() const { return !m_externalHostname.isNull() || (m_externalPort > 0 && !m_externalAddress.isNull()); } 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(); } QString externalAddress() const { return !m_externalHostname.isNull() ? m_externalHostname : m_externalAddress.toString(); }

View File

@@ -263,7 +263,7 @@ PeerInfo::setSipInfo( const SipInfo& sipInfo )
m_sipInfo = sipInfo; m_sipInfo = sipInfo;
tLog() << "id: " << id() << " info changed" << sipInfo; tLog() << "id:" << id() << "info changed" << sipInfo;
emit sipInfoChanged(); emit sipInfoChanged();
} }

View File

@@ -35,12 +35,13 @@ public:
{ {
} }
SipInfoPrivate( const SipInfoPrivate& other ) : QSharedData( other ), SipInfoPrivate( const SipInfoPrivate& other )
visible(other.visible), : QSharedData( other )
host(other.host), , visible( other.visible )
port(other.port), , host( other.host )
nodeId(other.nodeId), , port( other.port )
key(other.key) , nodeId( other.nodeId )
, key( other.key )
{ {
} }
~SipInfoPrivate() { } ~SipInfoPrivate() { }
@@ -93,10 +94,10 @@ SipInfo::clear()
bool bool
SipInfo::isValid() const SipInfo::isValid() const
{ {
// qDebug() << Q_FUNC_INFO << d->visible << d->host.hostName() << d->port << d->nodeId << d->key; // tDebug() << Q_FUNC_INFO << d->visible << d->host << d->port << d->nodeId << d->key;
if( !d->visible.isNull() ) if ( !d->visible.isNull() )
{ {
if( if (
// visible and all data available // visible and all data available
( d->visible.toBool() && !d->host.isEmpty() && ( d->port > 0 ) && !d->nodeId.isNull() && !d->key.isNull() ) ( d->visible.toBool() && !d->host.isEmpty() && ( d->port > 0 ) && !d->nodeId.isNull() && !d->key.isNull() )
// invisible and no data available // invisible and no data available
@@ -112,7 +113,7 @@ SipInfo::isValid() const
void void
SipInfo::setVisible( bool visible ) SipInfo::setVisible( bool visible )
{ {
d->visible.setValue(visible); d->visible.setValue( visible );
} }
@@ -195,7 +196,7 @@ SipInfo::toJson() const
// build variant map // build variant map
QVariantMap m; QVariantMap m;
m["visible"] = isVisible(); m["visible"] = isVisible();
if( isVisible() ) if ( isVisible() )
{ {
m["ip"] = host(); m["ip"] = host();
m["port"] = port(); m["port"] = port();
@@ -227,7 +228,7 @@ SipInfo::fromJson( QString json )
QVariantMap m = v.toMap(); QVariantMap m = v.toMap();
info.setVisible( m["visible"].toBool() ); info.setVisible( m["visible"].toBool() );
if( m["visible"].toBool() ) if ( m["visible"].toBool() )
{ {
info.setHost( m["host"].toString() ); info.setHost( m["host"].toString() );
info.setPort( m["port"].toInt() ); info.setPort( m["port"].toInt() );
@@ -242,7 +243,7 @@ SipInfo::fromJson( QString json )
QDebug QDebug
operator<< ( QDebug dbg, const SipInfo& info ) operator<< ( QDebug dbg, const SipInfo& info )
{ {
if( !info.isValid() ) if ( !info.isValid() )
dbg.nospace() << "info is invalid"; dbg.nospace() << "info is invalid";
else else
dbg.nospace() << info.toJson(); dbg.nospace() << info.toJson();
@@ -250,7 +251,9 @@ operator<< ( QDebug dbg, const SipInfo& info )
return dbg.maybeSpace(); return dbg.maybeSpace();
} }
bool operator==( const SipInfo& one, const SipInfo& two )
bool
operator==( const SipInfo& one, const SipInfo& two )
{ {
// check valid/invalid combinations first, so we don't try to access any invalid sipInfos (->assert) // check valid/invalid combinations first, so we don't try to access any invalid sipInfos (->assert)
if ( ( one.isValid() && !two.isValid() ) || ( !one.isValid() && two.isValid() ) ) if ( ( one.isValid() && !two.isValid() ) || ( !one.isValid() && two.isValid() ) )
@@ -272,6 +275,7 @@ bool operator==( const SipInfo& one, const SipInfo& two )
return false; return false;
} }
const QString const QString
SipInfo::debugString() const SipInfo::debugString() const
{ {
@@ -281,6 +285,5 @@ SipInfo::debugString() const
.arg( d->port ) .arg( d->port )
.arg( d->nodeId ) .arg( d->nodeId )
.arg( d->key ); .arg( d->key );
} }