@ -267,8 +267,10 @@ namespace i2p
void RouterContext : : UpdatePort ( int port )
void RouterContext : : UpdatePort ( int port )
{
{
auto addresses = m_RouterInfo . GetAddresses ( ) ;
if ( ! addresses ) return ;
bool updated = false ;
bool updated = false ;
for ( auto & address : m_RouterInfo . GetAddresses ( ) )
for ( auto & address : * addresses )
{
{
if ( address - > port ! = port & & address - > transportStyle = = i2p : : data : : RouterInfo : : eTransportSSU2 )
if ( address - > port ! = port & & address - > transportStyle = = i2p : : data : : RouterInfo : : eTransportSSU2 )
{
{
@ -283,8 +285,10 @@ namespace i2p
void RouterContext : : PublishNTCP2Address ( int port , bool publish , bool v4 , bool v6 , bool ygg )
void RouterContext : : PublishNTCP2Address ( int port , bool publish , bool v4 , bool v6 , bool ygg )
{
{
if ( ! m_NTCP2Keys ) return ;
if ( ! m_NTCP2Keys ) return ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
if ( ! addresses ) return ;
bool updated = false ;
bool updated = false ;
for ( auto & address : m_RouterInfo . GetAddresses ( ) )
for ( auto & address : * addresses )
{
{
if ( address - > IsNTCP2 ( ) & & ( address - > port ! = port | | address - > published ! = publish ) )
if ( address - > IsNTCP2 ( ) & & ( address - > port ! = port | | address - > published ! = publish ) )
{
{
@ -312,9 +316,10 @@ namespace i2p
void RouterContext : : UpdateNTCP2Address ( bool enable )
void RouterContext : : UpdateNTCP2Address ( bool enable )
{
{
auto & addresses = m_RouterInfo . GetAddresses ( ) ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
if ( ! addresses ) return ;
bool found = false , updated = false ;
bool found = false , updated = false ;
for ( auto it = addresses . begin ( ) ; it ! = addresses . end ( ) ; )
for ( auto it = addresses - > begin ( ) ; it ! = addresses - > end ( ) ; )
{
{
if ( ( * it ) - > IsNTCP2 ( ) )
if ( ( * it ) - > IsNTCP2 ( ) )
{
{
@ -326,7 +331,7 @@ namespace i2p
it + + ;
it + + ;
}
}
else
else
it = addresses . erase ( it ) ;
it = addresses - > erase ( it ) ;
updated = true ;
updated = true ;
}
}
else
else
@ -344,10 +349,12 @@ namespace i2p
void RouterContext : : PublishSSU2Address ( int port , bool publish , bool v4 , bool v6 )
void RouterContext : : PublishSSU2Address ( int port , bool publish , bool v4 , bool v6 )
{
{
if ( ! m_SSU2Keys ) return ;
if ( ! m_SSU2Keys ) return ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
if ( ! addresses ) return ;
int newPort = 0 ;
int newPort = 0 ;
if ( ! port )
if ( ! port )
{
{
for ( const auto & address : m_RouterInfo . GetAddresses ( ) )
for ( const auto & address : * addresses )
if ( address - > port )
if ( address - > port )
{
{
newPort = address - > port ;
newPort = address - > port ;
@ -356,7 +363,7 @@ namespace i2p
if ( ! newPort ) newPort = SelectRandomPort ( ) ;
if ( ! newPort ) newPort = SelectRandomPort ( ) ;
}
}
bool updated = false ;
bool updated = false ;
for ( auto & address : m_RouterInfo . GetAddresses ( ) )
for ( auto & address : * addresses )
{
{
if ( address - > IsSSU2 ( ) & & ( ! address - > port | | address - > port ! = port | | address - > published ! = publish ) & &
if ( address - > IsSSU2 ( ) & & ( ! address - > port | | address - > port ! = port | | address - > published ! = publish ) & &
( ( v4 & & address - > IsV4 ( ) ) | | ( v6 & & address - > IsV6 ( ) ) ) )
( ( v4 & & address - > IsV4 ( ) ) | | ( v6 & & address - > IsV6 ( ) ) ) )
@ -377,9 +384,10 @@ namespace i2p
void RouterContext : : UpdateSSU2Address ( bool enable )
void RouterContext : : UpdateSSU2Address ( bool enable )
{
{
auto & addresses = m_RouterInfo . GetAddresses ( ) ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
if ( ! addresses ) return ;
bool found = false , updated = false ;
bool found = false , updated = false ;
for ( auto it = addresses . begin ( ) ; it ! = addresses . end ( ) ; )
for ( auto it = addresses - > begin ( ) ; it ! = addresses - > end ( ) ; )
{
{
if ( ( * it ) - > IsSSU2 ( ) )
if ( ( * it ) - > IsSSU2 ( ) )
{
{
@ -391,7 +399,7 @@ namespace i2p
it + + ;
it + + ;
}
}
else
else
it = addresses . erase ( it ) ;
it = addresses - > erase ( it ) ;
updated = true ;
updated = true ;
}
}
else
else
@ -422,8 +430,10 @@ namespace i2p
void RouterContext : : UpdateAddress ( const boost : : asio : : ip : : address & host )
void RouterContext : : UpdateAddress ( const boost : : asio : : ip : : address & host )
{
{
auto addresses = m_RouterInfo . GetAddresses ( ) ;
if ( ! addresses ) return ;
bool updated = false ;
bool updated = false ;
for ( auto & address : m_RouterInfo . GetAddresses ( ) )
for ( auto & address : * addresses )
{
{
if ( address - > host ! = host & & address - > IsCompatible ( host ) & &
if ( address - > host ! = host & & address - > IsCompatible ( host ) & &
! i2p : : util : : net : : IsYggdrasilAddress ( address - > host ) )
! i2p : : util : : net : : IsYggdrasilAddress ( address - > host ) )
@ -472,9 +482,10 @@ namespace i2p
void RouterContext : : ClearSSU2Introducers ( bool v4 )
void RouterContext : : ClearSSU2Introducers ( bool v4 )
{
{
auto addresses = m_RouterInfo . GetAddresses ( ) ;
if ( ! addresses ) return ;
bool updated = false ;
bool updated = false ;
auto & addresses = m_RouterInfo . GetAddresses ( ) ;
for ( auto & addr : * addresses )
for ( auto & addr : addresses )
if ( addr - > IsSSU2 ( ) & & ( ( v4 & & addr - > IsV4 ( ) ) | | ( ! v4 & & addr - > IsV6 ( ) ) ) & &
if ( addr - > IsSSU2 ( ) & & ( ( v4 & & addr - > IsV4 ( ) ) | | ( ! v4 & & addr - > IsV6 ( ) ) ) & &
addr - > ssu & & ! addr - > ssu - > introducers . empty ( ) )
addr - > ssu & & ! addr - > ssu - > introducers . empty ( ) )
{
{
@ -597,15 +608,18 @@ namespace i2p
}
}
uint16_t port = 0 ;
uint16_t port = 0 ;
// delete previous introducers
// delete previous introducers
auto & addresses = m_RouterInfo . GetAddresses ( ) ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
for ( auto & addr : addresses )
if ( addresses )
if ( addr - > ssu & & ( ( v4 & & addr - > IsV4 ( ) ) | | ( v6 & & addr - > IsV6 ( ) ) ) )
{
{
for ( auto & addr : * addresses )
addr - > published = false ;
if ( addr - > ssu & & ( ( v4 & & addr - > IsV4 ( ) ) | | ( v6 & & addr - > IsV6 ( ) ) ) )
addr - > caps & = ~ i2p : : data : : RouterInfo : : eSSUIntroducer ; // can't be introducer
{
addr - > ssu - > introducers . clear ( ) ;
addr - > published = false ;
port = addr - > port ;
addr - > caps & = ~ i2p : : data : : RouterInfo : : eSSUIntroducer ; // can't be introducer
}
addr - > ssu - > introducers . clear ( ) ;
port = addr - > port ;
}
}
// unpublish NTCP2 addreeses
// unpublish NTCP2 addreeses
bool ntcp2 ; i2p : : config : : GetOption ( " ntcp2.enabled " , ntcp2 ) ;
bool ntcp2 ; i2p : : config : : GetOption ( " ntcp2.enabled " , ntcp2 ) ;
if ( ntcp2 )
if ( ntcp2 )
@ -630,15 +644,18 @@ namespace i2p
uint16_t port = 0 ;
uint16_t port = 0 ;
// delete previous introducers
// delete previous introducers
bool isSSU2Published ; i2p : : config : : GetOption ( " ssu2.published " , isSSU2Published ) ;
bool isSSU2Published ; i2p : : config : : GetOption ( " ssu2.published " , isSSU2Published ) ;
auto & addresses = m_RouterInfo . GetAddresses ( ) ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
for ( auto & addr : addresses )
if ( addresses )
if ( addr - > ssu & & isSSU2Published & & ( ( v4 & & addr - > IsV4 ( ) ) | | ( v6 & & addr - > IsV6 ( ) ) ) )
{
{
for ( auto & addr : * addresses )
addr - > published = true ;
if ( addr - > ssu & & isSSU2Published & & ( ( v4 & & addr - > IsV4 ( ) ) | | ( v6 & & addr - > IsV6 ( ) ) ) )
addr - > caps | = i2p : : data : : RouterInfo : : eSSUIntroducer ;
{
addr - > ssu - > introducers . clear ( ) ;
addr - > published = true ;
if ( addr - > port ) port = addr - > port ;
addr - > caps | = i2p : : data : : RouterInfo : : eSSUIntroducer ;
}
addr - > ssu - > introducers . clear ( ) ;
if ( addr - > port ) port = addr - > port ;
}
}
// publish NTCP2
// publish NTCP2
bool ntcp2 ; i2p : : config : : GetOption ( " ntcp2.enabled " , ntcp2 ) ;
bool ntcp2 ; i2p : : config : : GetOption ( " ntcp2.enabled " , ntcp2 ) ;
if ( ntcp2 )
if ( ntcp2 )
@ -663,23 +680,26 @@ namespace i2p
// insert v6 addresses if necessary
// insert v6 addresses if necessary
bool foundNTCP2 = false , foundSSU2 = false ;
bool foundNTCP2 = false , foundSSU2 = false ;
uint16_t port = 0 ;
uint16_t port = 0 ;
auto & addresses = m_RouterInfo . GetAddresses ( ) ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
for ( auto & addr : addresses )
i f ( addresses )
{
{
if ( addr - > IsV6 ( ) & & ! i2p : : util : : net : : IsYggdrasilAddress ( addr - > host ) )
for ( auto & addr : * addresses )
{
{
switch ( addr - > transportStyle )
if ( addr - > IsV6 ( ) & & ! i2p : : util : : net : : IsYggdrasilAddress ( addr - > host ) )
{
{
case i2p : : data : : RouterInfo : : eTransportNTCP2 :
switch ( addr - > transportStyle )
foundNTCP2 = true ;
{
break ;
case i2p : : data : : RouterInfo : : eTransportNTCP2 :
case i2p : : data : : RouterInfo : : eTransportSSU2 :
foundNTCP2 = true ;
foundSSU2 = true ;
break ;
break ;
case i2p : : data : : RouterInfo : : eTransportSSU2 :
default : ;
foundSSU2 = true ;
break ;
default : ;
}
}
}
port = addr - > port ;
}
}
port = addr - > port ;
}
}
if ( ! port )
if ( ! port )
{
{
@ -743,23 +763,26 @@ namespace i2p
bool foundNTCP2 = false , foundSSU2 = false ;
bool foundNTCP2 = false , foundSSU2 = false ;
std : : string host = " 127.0.0.1 " ;
std : : string host = " 127.0.0.1 " ;
uint16_t port = 0 ;
uint16_t port = 0 ;
auto & addresses = m_RouterInfo . GetAddresses ( ) ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
for ( auto & addr : addresses )
i f ( addresses )
{
{
if ( addr - > IsV4 ( ) )
for ( auto & addr : * addresses )
{
{
switch ( addr - > transportStyle )
if ( addr - > IsV4 ( ) )
{
{
case i2p : : data : : RouterInfo : : eTransportNTCP2 :
switch ( addr - > transportStyle )
foundNTCP2 = true ;
{
break ;
case i2p : : data : : RouterInfo : : eTransportNTCP2 :
case i2p : : data : : RouterInfo : : eTransportSSU2 :
foundNTCP2 = true ;
foundSSU2 = true ;
break ;
break ;
case i2p : : data : : RouterInfo : : eTransportSSU2 :
default : ;
foundSSU2 = true ;
break ;
default : ;
}
}
}
if ( addr - > port ) port = addr - > port ;
}
}
if ( addr - > port ) port = addr - > port ;
}
}
if ( ! port )
if ( ! port )
{
{
@ -816,14 +839,17 @@ namespace i2p
i2p : : config : : GetOption ( " ntcp2.port " , port ) ;
i2p : : config : : GetOption ( " ntcp2.port " , port ) ;
if ( ! port ) i2p : : config : : GetOption ( " port " , port ) ;
if ( ! port ) i2p : : config : : GetOption ( " port " , port ) ;
bool foundMesh = false ;
bool foundMesh = false ;
auto & addresses = m_RouterInfo . GetAddresses ( ) ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
for ( auto & addr : addresses )
i f ( addresses )
{
{
if ( ! port ) port = addr - > port ;
for ( auto & addr : * addresses )
if ( i2p : : util : : net : : IsYggdrasilAddress ( addr - > host ) )
{
{
foundMesh = true ;
if ( ! port ) port = addr - > port ;
break ;
if ( i2p : : util : : net : : IsYggdrasilAddress ( addr - > host ) )
{
foundMesh = true ;
break ;
}
}
}
}
}
if ( ! foundMesh )
if ( ! foundMesh )
@ -837,8 +863,9 @@ namespace i2p
void RouterContext : : SetMTU ( int mtu , bool v4 )
void RouterContext : : SetMTU ( int mtu , bool v4 )
{
{
if ( mtu < 1280 | | mtu > 1500 ) return ;
if ( mtu < 1280 | | mtu > 1500 ) return ;
auto & addresses = m_RouterInfo . GetAddresses ( ) ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
for ( auto & addr : addresses )
if ( ! addresses ) return ;
for ( auto & addr : * addresses )
{
{
if ( addr - > ssu & & ( ( v4 & & addr - > IsV4 ( ) ) | | ( ! v4 & & addr - > IsV6 ( ) ) ) )
if ( addr - > ssu & & ( ( v4 & & addr - > IsV4 ( ) ) | | ( ! v4 & & addr - > IsV6 ( ) ) ) )
{
{
@ -852,8 +879,9 @@ namespace i2p
{
{
bool isYgg = i2p : : util : : net : : IsYggdrasilAddress ( host ) ;
bool isYgg = i2p : : util : : net : : IsYggdrasilAddress ( host ) ;
bool updated = false ;
bool updated = false ;
auto & addresses = m_RouterInfo . GetAddresses ( ) ;
auto addresses = m_RouterInfo . GetAddresses ( ) ;
for ( auto & addr : addresses )
if ( ! addresses ) return ;
for ( auto & addr : * addresses )
{
{
if ( addr - > IsPublishedNTCP2 ( ) )
if ( addr - > IsPublishedNTCP2 ( ) )
{
{