@ -346,7 +346,6 @@ namespace llarp
itr - > second . inbound = inbound ;
itr - > second . inbound = inbound ;
itr - > second . remote = info ;
itr - > second . remote = info ;
}
}
itr - > second . lastUsed = Now ( ) ;
}
}
size_t
size_t
@ -383,7 +382,6 @@ namespace llarp
{
{
auto & s = Sessions ( ) [ tag ] ;
auto & s = Sessions ( ) [ tag ] ;
s . intro = intro ;
s . intro = intro ;
s . lastUsed = Now ( ) ;
}
}
bool
bool
@ -405,7 +403,6 @@ namespace llarp
return ;
return ;
}
}
itr - > second . replyIntro = intro ;
itr - > second . replyIntro = intro ;
itr - > second . lastUsed = Now ( ) ;
}
}
bool
bool
@ -443,17 +440,18 @@ namespace llarp
itr = Sessions ( ) . emplace ( tag , Session { } ) . first ;
itr = Sessions ( ) . emplace ( tag , Session { } ) . first ;
}
}
itr - > second . sharedKey = k ;
itr - > second . sharedKey = k ;
itr - > second . lastUsed = Now ( ) ;
}
}
void
void
Endpoint : : MarkConvoTagActive ( const ConvoTag & tag )
Endpoint : : ConvoTagTX ( const ConvoTag & tag )
{
{
auto itr = Sessions ( ) . find ( tag ) ;
Sessions ( ) [ tag ] . TX ( ) ;
if ( itr ! = Sessions ( ) . end ( ) )
}
{
itr - > second . lastUsed = Now ( ) ;
void
}
Endpoint : : ConvoTagRX ( const ConvoTag & tag )
{
Sessions ( ) [ tag ] . RX ( ) ;
}
}
bool
bool
@ -1012,10 +1010,35 @@ namespace llarp
return false ;
return false ;
}
}
std: : string
EndpointBase: : AddressVariant_t
Endpoint : : LocalAddress ( ) const
Endpoint : : LocalAddress ( ) const
{
{
return m_Identity . pub . Addr ( ) . ToString ( ) ;
return m_Identity . pub . Addr ( ) ;
}
inline void
AccumulateStats ( const Session & session , EndpointBase : : SendStat & stats )
{ }
inline void
AccumulateStats (
const std : : shared_ptr < exit : : BaseSession > & session , EndpointBase : : SendStat & stats )
{ }
std : : unordered_map < EndpointBase : : AddressVariant_t , EndpointBase : : SendStat >
Endpoint : : GetStatistics ( ) const
{
std : : unordered_map < AddressVariant_t , SendStat > stats ;
for ( const auto & item : Sessions ( ) )
{
Address addr = item . second . remote . Addr ( ) ;
AccumulateStats ( item . second , stats [ addr ] ) ;
}
for ( const auto & item : m_state - > m_SNodeSessions )
{
AccumulateStats ( item . second . first , stats [ item . first ] ) ;
}
return stats ;
}
}
bool
bool
@ -1372,13 +1395,16 @@ namespace llarp
{
{
if ( * ptr = = m_Identity . pub . Addr ( ) )
if ( * ptr = = m_Identity . pub . Addr ( ) )
{
{
ConvoTagTX ( tag ) ;
Loop ( ) - > wakeup ( ) ;
Loop ( ) - > wakeup ( ) ;
return HandleInboundPacket ( tag , pkt , t , 0 ) ;
if ( not HandleInboundPacket ( tag , pkt , t , 0 ) )
return false ;
ConvoTagRX ( tag ) ;
return true ;
}
}
}
}
if ( not SendToOrQueue ( * maybe , pkt , t ) )
if ( not SendToOrQueue ( * maybe , pkt , t ) )
return false ;
return false ;
MarkConvoTagActive ( tag ) ;
Loop ( ) - > wakeup ( ) ;
Loop ( ) - > wakeup ( ) ;
return true ;
return true ;
}
}
@ -1393,11 +1419,13 @@ namespace llarp
auto pkt = std : : make_shared < net : : IPPacket > ( ) ;
auto pkt = std : : make_shared < net : : IPPacket > ( ) ;
if ( ! pkt - > Load ( buf ) )
if ( ! pkt - > Load ( buf ) )
return false ;
return false ;
EnsurePathToSNode (
EnsurePathToSNode ( addr , [ = ] ( RouterID , exit : : BaseSession_ptr s , ConvoTag tag ) {
addr , [ pkt , t ] ( RouterID , exit : : BaseSession_ptr s , [[maybe_unused]] ConvoTag tag ) {
if ( s )
if ( s )
{
s - > SendPacketToRemote ( pkt - > ConstBuffer ( ) , t ) ;
ConvoTagTX ( tag ) ;
} ) ;
s - > SendPacketToRemote ( pkt - > ConstBuffer ( ) , t ) ;
}
} ) ;
return true ;
return true ;
}
}
@ -1428,7 +1456,7 @@ namespace llarp
msg . seqno ) ;
msg . seqno ) ;
if ( HandleInboundPacket ( msg . tag , msg . payload , msg . proto , msg . seqno ) )
if ( HandleInboundPacket ( msg . tag , msg . payload , msg . proto , msg . seqno ) )
{
{
MarkConvoTagActive ( msg . tag ) ;
ConvoTagRX ( msg . tag ) ;
}
}
else
else
{
{
@ -1451,7 +1479,7 @@ namespace llarp
SendEvent_t item = m_SendQueue . popFront ( ) ;
SendEvent_t item = m_SendQueue . popFront ( ) ;
item . first - > S = item . second - > NextSeqNo ( ) ;
item . first - > S = item . second - > NextSeqNo ( ) ;
if ( item . second - > SendRoutingMessage ( * item . first , router ) )
if ( item . second - > SendRoutingMessage ( * item . first , router ) )
MarkConvoTagActive ( item . first - > T . T ) ;
ConvoTagTX ( item . first - > T . T ) ;
}
}
UpstreamFlush ( router ) ;
UpstreamFlush ( router ) ;
@ -1542,7 +1570,7 @@ namespace llarp
else
else
tag . Randomize ( ) ;
tag . Randomize ( ) ;
PutSenderFor ( tag , m_Identity . pub , true ) ;
PutSenderFor ( tag , m_Identity . pub , true ) ;
MarkConvoTagActive ( tag ) ;
ConvoTagTX ( tag ) ;
Sessions ( ) [ tag ] . forever = true ;
Sessions ( ) [ tag ] . forever = true ;
Loop ( ) - > call_soon ( [ tag , hook ] ( ) { hook ( tag ) ; } ) ;
Loop ( ) - > call_soon ( [ tag , hook ] ( ) { hook ( tag ) ; } ) ;
return true ;
return true ;
@ -1648,10 +1676,14 @@ namespace llarp
m - > introReply = p - > intro ;
m - > introReply = p - > intro ;
PutReplyIntroFor ( f . T , m - > introReply ) ;
PutReplyIntroFor ( f . T , m - > introReply ) ;
m - > sender = m_Identity . pub ;
m - > sender = m_Identity . pub ;
m - > seqno = GetSeqNoForConvo ( f . T ) ;
if ( auto maybe = GetSeqNoForConvo ( f . T ) )
if ( m - > seqno = = 0 )
{
m - > seqno = * maybe ;
}
else
{
{
LogWarn ( Name ( ) , " no session T= " , f . T ) ;
LogWarn ( Name ( ) , " no session T= " , f . T ) ;
return false ;
}
}
f . S = m - > seqno ;
f . S = m - > seqno ;
f . F = m - > introReply . pathID ;
f . F = m - > introReply . pathID ;
@ -1680,45 +1712,45 @@ namespace llarp
}
}
// Failed to find a suitable inbound convo, look for outbound
// Failed to find a suitable inbound convo, look for outbound
LogTrace ( " Not an inbound convo " ) ;
LogTrace ( " Not an inbound convo " ) ;
auto & sessions = m_state - > m_RemoteSessions ;
auto & sessions = m_state - > m_RemoteSessions ;
auto range = sessions . equal_range ( remote ) ;
auto range = sessions . equal_range ( remote ) ;
for ( auto itr = range . first ; itr ! = range . second ; + + itr )
for ( auto itr = range . first ; itr ! = range . second ; + + itr )
{
if ( itr - > second - > ReadyToSend ( ) )
{
{
if ( itr - > second - > ReadyToSend ( ) )
LogTrace ( " Found an outbound session to use to reach " , remote ) ;
{
itr - > second - > AsyncEncryptAndSendTo ( data , t ) ;
LogTrace ( " Found an outbound session to use to reach " , remote ) ;
return true ;
itr - > second - > AsyncEncryptAndSendTo ( data , t ) ;
return true ;
}
}
}
// if we want to make an outbound session
}
if ( WantsOutboundSession ( remote ) )
// if we want to make an outbound session
{
if ( WantsOutboundSession ( remote ) )
LogTrace ( " Making an outbound session and queuing the data " ) ;
{
// add pending traffic
LogTrace ( " Making an outbound session and queuing the data " ) ;
auto & traffic = m_state - > m_PendingTraffic ;
// add pending traffic
traffic [ remote ] . emplace_back ( data , t ) ;
auto & traffic = m_state - > m_PendingTraffic ;
EnsurePathToService (
traffic [ remote ] . emplace_back ( data , t ) ;
remote ,
EnsurePathToService (
[ self = this ] ( Address addr , OutboundContext * ctx ) {
remote ,
if ( ctx )
[ self = this ] ( Address addr , OutboundContext * ctx ) {
{
if ( ctx )
for ( auto & pending : self - > m_state - > m_PendingTraffic [ addr ] )
{
{
for ( auto & pending : self - > m_state - > m_PendingTraffic [ addr ] )
ctx - > AsyncEncryptAndSendTo ( pending . Buffer ( ) , pending . protocol ) ;
}
}
else
{
{
LogWarn( " no path made to " , addr ) ;
ctx - > AsyncEncryptAndSendTo ( pending . Buffer ( ) , pending . protocol ) ;
}
}
self - > m_state - > m_PendingTraffic . erase ( addr ) ;
}
} ,
else
1500 ms ) ;
{
return true ;
LogWarn ( " no path made to " , addr ) ;
}
}
LogDebug ( " SendOrQueue failed: no inbound/outbound sessions " ) ;
self - > m_state - > m_PendingTraffic . erase ( addr ) ;
} ,
1500 ms ) ;
return true ;
}
LogDebug ( " SendOrQueue failed: no inbound/outbound sessions " ) ;
return false ;
return false ;
}
}
@ -1735,14 +1767,13 @@ namespace llarp
return Sessions ( ) . find ( t ) ! = Sessions ( ) . end ( ) ;
return Sessions ( ) . find ( t ) ! = Sessions ( ) . end ( ) ;
}
}
uint64_t
std : : optional < uint64_t >
Endpoint : : GetSeqNoForConvo ( const ConvoTag & tag )
Endpoint : : GetSeqNoForConvo ( const ConvoTag & tag )
{
{
auto itr = Sessions ( ) . find ( tag ) ;
auto itr = Sessions ( ) . find ( tag ) ;
if ( itr = = Sessions ( ) . end ( ) )
if ( itr = = Sessions ( ) . end ( ) )
return 0 ;
return std : : nullopt ;
itr - > second . seqno + = 1 ;
return itr - > second . seqno + + ;
return itr - > second . seqno ;
}
}
bool
bool