mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 22:56:42 +02:00
Add a function to clean host addreses for sending to other peers.
This commit is contained in:
@@ -143,22 +143,11 @@ Servent::startListening( QHostAddress ha, bool upnp, int port, Tomahawk::Network
|
|||||||
if ( ha == QHostAddress::Any || ha == QHostAddress::AnyIPv6 )
|
if ( ha == QHostAddress::Any || ha == QHostAddress::AnyIPv6 )
|
||||||
{
|
{
|
||||||
// We are listening on all available addresses, so we should send a SipInfo for all of them.
|
// We are listening on all available addresses, so we should send a SipInfo for all of them.
|
||||||
foreach ( QHostAddress addr, QNetworkInterface::allAddresses() )
|
d->externalAddresses = QNetworkInterface::allAddresses();
|
||||||
{
|
cleanAddresses( d->externalAddresses );
|
||||||
if ( addr.toString() == "127.0.0.1" )
|
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Listening to" << d->externalAddresses;
|
||||||
continue; // IPv4 localhost
|
|
||||||
if ( addr.toString() == "::1" )
|
|
||||||
continue; // IPv6 localhost
|
|
||||||
if ( addr.toString() == "::7F00:1" )
|
|
||||||
continue; // IPv4 localhost as IPv6 address
|
|
||||||
if ( addr.isInSubnet( QHostAddress::parseSubnet( "fe80::/10" ) ) )
|
|
||||||
continue; // Skip link local addresses
|
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Listening to" << addr.toString();
|
|
||||||
d->externalAddresses.append( addr );
|
|
||||||
d->externalListenAll = true;
|
d->externalListenAll = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
else if ( ( ha.toString() != "127.0.0.1" ) && ( ha.toString() != "::1" ) && ( ha.toString() != "::7F00:1" ) )
|
else if ( ( ha.toString() != "127.0.0.1" ) && ( ha.toString() != "::1" ) && ( ha.toString() != "::7F00:1" ) )
|
||||||
{
|
{
|
||||||
// We listen only to one specific Address, only announce this.
|
// We listen only to one specific Address, only announce this.
|
||||||
@@ -420,6 +409,7 @@ Servent::getLocalSipInfos( const QString& nodeid, const QString& key )
|
|||||||
if ( d->externalListenAll )
|
if ( d->externalListenAll )
|
||||||
{
|
{
|
||||||
addresses = QNetworkInterface::allAddresses();
|
addresses = QNetworkInterface::allAddresses();
|
||||||
|
cleanAddresses( addresses );
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( QHostAddress ha, addresses )
|
foreach ( QHostAddress ha, addresses )
|
||||||
@@ -1088,7 +1078,9 @@ Servent::addresses() const
|
|||||||
|
|
||||||
if ( d->externalListenAll )
|
if ( d->externalListenAll )
|
||||||
{
|
{
|
||||||
return QNetworkInterface::allAddresses();
|
QList<QHostAddress> addresses( QNetworkInterface::allAddresses() );
|
||||||
|
cleanAddresses( addresses );
|
||||||
|
return addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
return d->externalAddresses;
|
return d->externalAddresses;
|
||||||
@@ -1319,6 +1311,37 @@ Servent::printCurrentTransfers()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Servent::cleanAddresses( QList<QHostAddress>& addresses ) const
|
||||||
|
{
|
||||||
|
QList<QHostAddress>::iterator iter = addresses.begin();
|
||||||
|
while ( iter != addresses.end() )
|
||||||
|
{
|
||||||
|
QString hostString = iter->toString();
|
||||||
|
if ( hostString.startsWith( QLatin1String( "127.0.0." ) ) //< IPv4 localhost
|
||||||
|
// IPv6 localhost
|
||||||
|
|| hostString == "::1"
|
||||||
|
// IPv4 localhost as IPv6 address
|
||||||
|
|| hostString == "::7F00:1" )
|
||||||
|
{
|
||||||
|
iter = addresses.erase( iter );
|
||||||
|
// Always continue if we changed iter as we might have reached the end
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove IPv6 link local addresses
|
||||||
|
if ( iter->isInSubnet( QHostAddress::parseSubnet( "fe80::/10" ) ) )
|
||||||
|
{
|
||||||
|
iter = addresses.erase( iter );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Advance to next element
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Servent::isIPWhitelisted( QHostAddress ip )
|
Servent::isIPWhitelisted( QHostAddress ip )
|
||||||
{
|
{
|
||||||
|
@@ -196,6 +196,14 @@ private:
|
|||||||
void cleanupSocket( QTcpSocketExtra* sock );
|
void cleanupSocket( QTcpSocketExtra* sock );
|
||||||
void printCurrentTransfers();
|
void printCurrentTransfers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove addresses from the list that we shall not use in Tomahawk (e.g.
|
||||||
|
* for sending to other peers).
|
||||||
|
*
|
||||||
|
* @param addresses The list that shall be cleanded.
|
||||||
|
*/
|
||||||
|
void cleanAddresses( QList<QHostAddress>& addresses ) const;
|
||||||
|
|
||||||
static Servent* s_instance;
|
static Servent* s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user