1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

Speed up connecting by sorting the SipInfos

This commit is contained in:
Uwe L. Korn 2013-06-10 14:40:33 +02:00
parent 051edb079c
commit f805b267fd
3 changed files with 84 additions and 1 deletions

View File

@ -164,7 +164,69 @@ ConnectionManager::connectToPeer( const Tomahawk::peerinfo_ptr &peerInfo, bool l
// If we are not connected, try to connect
d_func()->currentPeerInfo = peerInfo;
peerInfoDebug( peerInfo ) << "No existing connection found, trying to connect.";
d_func()->sipCandidates.append( peerInfo->sipInfos() );
// Sort SipInfos
QList< SipInfo > anyOther;
QList< SipInfo > publicIPv4;
QList< SipInfo > publicIPv6;
QList< SipInfo > privateIPv4;
QList< SipInfo > privateIPv6;
foreach ( SipInfo sipInfo, peerInfo->sipInfos() )
{
if ( !sipInfo.isVisible() )
{
continue;
}
QHostAddress ha;
if ( ha.setAddress( sipInfo.host() ) )
{
if ( Servent::isValidExternalIP( ha ) )
{
if ( ha.protocol() == QAbstractSocket::IPv6Protocol )
{
publicIPv6.append( sipInfo );
}
else
{
publicIPv4.append( sipInfo );
}
}
else
{
if ( ha.protocol() == QAbstractSocket::IPv6Protocol )
{
privateIPv6.append( sipInfo );
}
else
{
privateIPv4.append( sipInfo );
}
}
}
else
{
anyOther.append( sipInfo );
}
}
if ( Servent::instance()->ipv6ConnectivityLikely() && !publicIPv6.isEmpty() )
{
// Prefer IPv6 over IPv4
d_func()->sipCandidates.append( anyOther );
d_func()->sipCandidates.append( publicIPv6 );
d_func()->sipCandidates.append( publicIPv4 );
d_func()->sipCandidates.append( privateIPv6 );
d_func()->sipCandidates.append( privateIPv4 );
}
else
{
// First try all IPv4 before trying IPv6
d_func()->sipCandidates.append( anyOther );
d_func()->sipCandidates.append( publicIPv4 );
d_func()->sipCandidates.append( privateIPv4 );
d_func()->sipCandidates.append( publicIPv6 );
d_func()->sipCandidates.append( privateIPv6 );
}
QVariantMap m;
m["conntype"] = "accept-offer";

View File

@ -953,6 +953,20 @@ Servent::visibleExternally() const
return (!d_func()->externalHostname.isNull()) || (d_func()->externalAddresses.length() > 0);
}
bool
Servent::ipv6ConnectivityLikely() const
{
foreach ( QHostAddress ha, d_func()->externalAddresses )
{
if ( ha.protocol() == QAbstractSocket::IPv6Protocol && Servent::isValidExternalIP( ha ) )
{
return true;
}
}
return false;
}
int
Servent::port() const
{

View File

@ -99,6 +99,13 @@ public:
bool visibleExternally() const;
/**
* Is the probality that this host supports IPv6 high?
*
* Though we cannot fully test for IPv6 connectivity, some guesses based on non-localhost addresses are done.
*/
bool ipv6ConnectivityLikely() const;
/**
* The port this Peer listens directly (per default)
*/