mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-19 23:41:51 +02:00
Add a function to clean host addreses for sending to other peers.
This commit is contained in:
parent
0b4bee77e6
commit
0d08826ac3
@ -143,21 +143,10 @@ Servent::startListening( QHostAddress ha, bool upnp, int port, Tomahawk::Network
|
||||
if ( ha == QHostAddress::Any || ha == QHostAddress::AnyIPv6 )
|
||||
{
|
||||
// We are listening on all available addresses, so we should send a SipInfo for all of them.
|
||||
foreach ( QHostAddress addr, QNetworkInterface::allAddresses() )
|
||||
{
|
||||
if ( addr.toString() == "127.0.0.1" )
|
||||
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->externalAddresses = QNetworkInterface::allAddresses();
|
||||
cleanAddresses( d->externalAddresses );
|
||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Listening to" << d->externalAddresses;
|
||||
d->externalListenAll = true;
|
||||
}
|
||||
else if ( ( ha.toString() != "127.0.0.1" ) && ( ha.toString() != "::1" ) && ( ha.toString() != "::7F00:1" ) )
|
||||
{
|
||||
@ -420,6 +409,7 @@ Servent::getLocalSipInfos( const QString& nodeid, const QString& key )
|
||||
if ( d->externalListenAll )
|
||||
{
|
||||
addresses = QNetworkInterface::allAddresses();
|
||||
cleanAddresses( addresses );
|
||||
}
|
||||
|
||||
foreach ( QHostAddress ha, addresses )
|
||||
@ -1088,7 +1078,9 @@ Servent::addresses() const
|
||||
|
||||
if ( d->externalListenAll )
|
||||
{
|
||||
return QNetworkInterface::allAddresses();
|
||||
QList<QHostAddress> addresses( QNetworkInterface::allAddresses() );
|
||||
cleanAddresses( addresses );
|
||||
return addresses;
|
||||
}
|
||||
|
||||
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
|
||||
Servent::isIPWhitelisted( QHostAddress ip )
|
||||
{
|
||||
|
@ -196,6 +196,14 @@ private:
|
||||
void cleanupSocket( QTcpSocketExtra* sock );
|
||||
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;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user