@ -47,28 +47,36 @@ namespace llarp
void
void
LookupIntroSetRelayed (
LookupIntroSetRelayed (
const Key_t & target , const Key_t & whoasked , uint64_t whoaskedTX ,
const Key_t & target ,
const Key_t & askpeer , uint64_t relayOrder ,
const Key_t & whoasked ,
uint64_t whoaskedTX ,
const Key_t & askpeer ,
uint64_t relayOrder ,
service : : EncryptedIntroSetLookupHandler result = nullptr ) override ;
service : : EncryptedIntroSetLookupHandler result = nullptr ) override ;
void
void
LookupIntroSetDirect (
LookupIntroSetDirect (
const Key_t & target , const Key_t & whoasked , uint64_t whoaskedTX ,
const Key_t & target ,
const Key_t & whoasked ,
uint64_t whoaskedTX ,
const Key_t & askpeer ,
const Key_t & askpeer ,
service : : EncryptedIntroSetLookupHandler result = nullptr ) override ;
service : : EncryptedIntroSetLookupHandler result = nullptr ) override ;
/// on behalf of whoasked request router with public key target from dht
/// on behalf of whoasked request router with public key target from dht
/// router with key askpeer
/// router with key askpeer
void
void
LookupRouterRecursive ( const RouterID & target , const Key_t & whoasked ,
LookupRouterRecursive (
uint64_t whoaskedTX , const Key_t & askpeer ,
const RouterID & target ,
RouterLookupHandler result = nullptr ) override ;
const Key_t & whoasked ,
uint64_t whoaskedTX ,
const Key_t & askpeer ,
RouterLookupHandler result = nullptr ) override ;
bool
bool
LookupRouter ( const RouterID & target , RouterLookupHandler result ) override
LookupRouter ( const RouterID & target , RouterLookupHandler result ) override
{
{
Key_t askpeer ;
Key_t askpeer ;
if ( ! _nodes - > FindClosest ( Key_t ( target ) , askpeer ) )
if ( ! _nodes - > FindClosest ( Key_t ( target ) , askpeer ) )
{
{
return false ;
return false ;
}
}
@ -84,58 +92,72 @@ namespace llarp
/// issue dht lookup for router via askpeer and send reply to local path
/// issue dht lookup for router via askpeer and send reply to local path
void
void
LookupRouterForPath ( const RouterID & target , uint64_t txid ,
LookupRouterForPath (
const PathID_t & path , const Key_t & askpeer ) override ;
const RouterID & target ,
uint64_t txid ,
const PathID_t & path ,
const Key_t & askpeer ) override ;
/// issue dht lookup for introset for addr via askpeer and send reply to
/// issue dht lookup for introset for addr via askpeer and send reply to
/// local path
/// local path
void
void
LookupIntroSetForPath ( const Key_t & addr , uint64_t txid ,
LookupIntroSetForPath (
const llarp : : PathID_t & path , const Key_t & askpeer ,
const Key_t & addr ,
uint64_t relayOrder ) override ;
uint64_t txid ,
const llarp : : PathID_t & path ,
const Key_t & askpeer ,
uint64_t relayOrder ) override ;
/// send a dht message to peer, if keepalive is true then keep the session
/// send a dht message to peer, if keepalive is true then keep the session
/// with that peer alive for 10 seconds
/// with that peer alive for 10 seconds
void
void
DHTSendTo ( const RouterID & peer , IMessage * msg ,
DHTSendTo ( const RouterID & peer , IMessage * msg , bool keepalive = true ) override ;
bool keepalive = true ) override ;
/// get routers closest to target excluding requester
/// get routers closest to target excluding requester
bool
bool
HandleExploritoryRouterLookup (
HandleExploritoryRouterLookup (
const Key_t & requester , uint64_t txid , const RouterID & target ,
const Key_t & requester ,
std : : vector < std : : unique_ptr < IMessage > > & reply ) override ;
uint64_t txid ,
const RouterID & target ,
std : : vector < std : : unique_ptr < IMessage > > & reply ) override ;
/// handle rc lookup from requester for target
/// handle rc lookup from requester for target
void
void
LookupRouterRelayed (
LookupRouterRelayed (
const Key_t & requester , uint64_t txid , const Key_t & target ,
const Key_t & requester ,
uint64_t txid ,
const Key_t & target ,
bool recursive ,
bool recursive ,
std : : vector < std : : unique_ptr < IMessage > > & replies ) override ;
std : : vector < std : : unique_ptr < IMessage > > & replies ) override ;
/// relay a dht message from a local path to the main network
/// relay a dht message from a local path to the main network
bool
bool
RelayRequestForPath ( const llarp : : PathID_t & localPath ,
RelayRequestForPath ( const llarp : : PathID_t & localPath , const IMessage & msg ) override ;
const IMessage & msg ) override ;
/// send introset to peer as R/S
/// send introset to peer as R/S
void
void
PropagateLocalIntroSet ( const PathID_t & from , uint64_t txid ,
PropagateLocalIntroSet (
const service : : EncryptedIntroSet & introset ,
const PathID_t & from ,
const Key_t & tellpeer , uint64_t relayOrder ) ;
uint64_t txid ,
const service : : EncryptedIntroSet & introset ,
const Key_t & tellpeer ,
uint64_t relayOrder ) ;
/// send introset to peer from source with S counter and excluding peers
/// send introset to peer from source with S counter and excluding peers
void
void
PropagateIntroSetTo ( const Key_t & from , uint64_t txid ,
PropagateIntroSetTo (
const service : : EncryptedIntroSet & introset ,
const Key_t & from ,
const Key_t & tellpeer , uint64_t relayOrder ) ;
uint64_t txid ,
const service : : EncryptedIntroSet & introset ,
const Key_t & tellpeer ,
uint64_t relayOrder ) ;
/// initialize dht context and explore every exploreInterval milliseconds
/// initialize dht context and explore every exploreInterval milliseconds
void
void
Init ( const Key_t & us , AbstractRouter * router ) override ;
Init ( const Key_t & us , AbstractRouter * router ) override ;
/// get localally stored introset by service address
/// get localally stored introset by service address
nonstd : : optional < llarp : : service : : EncryptedIntroSet >
nonstd : : optional < llarp : : service : : EncryptedIntroSet >
GetIntroSetByLocation ( const Key_t & location ) const override ;
GetIntroSetByLocation ( const Key_t & location ) const override ;
void
void
@ -147,12 +169,12 @@ namespace llarp
llarp : : AbstractRouter * router { nullptr } ;
llarp : : AbstractRouter * router { nullptr } ;
// for router contacts
// for router contacts
std : : unique_ptr < Bucket < RCNode > > _nodes ;
std : : unique_ptr < Bucket < RCNode > > _nodes ;
// for introduction sets
// for introduction sets
std : : unique_ptr < Bucket < ISNode > > _services ;
std : : unique_ptr < Bucket < ISNode > > _services ;
Bucket < ISNode > *
Bucket < ISNode > *
services ( ) override
services ( ) override
{
{
return _services . get ( ) ;
return _services . get ( ) ;
@ -171,7 +193,7 @@ namespace llarp
return allowTransit ;
return allowTransit ;
}
}
Bucket < RCNode > *
Bucket < RCNode > *
Nodes ( ) const override
Nodes ( ) const override
{
{
return _nodes . get ( ) ;
return _nodes . get ( ) ;
@ -180,14 +202,14 @@ namespace llarp
void
void
PutRCNodeAsync ( const RCNode & val ) override
PutRCNodeAsync ( const RCNode & val ) override
{
{
auto func = std : : bind ( & Bucket < RCNode > : : PutNode , Nodes ( ) , val ) ;
auto func = std : : bind ( & Bucket < RCNode > : : PutNode , Nodes ( ) , val ) ;
LogicCall ( router - > logic ( ) , func ) ;
LogicCall ( router - > logic ( ) , func ) ;
}
}
void
void
DelRCNodeAsync ( const Key_t & val ) override
DelRCNodeAsync ( const Key_t & val ) override
{
{
auto func = std : : bind ( & Bucket < RCNode > : : DelNode , Nodes ( ) , val ) ;
auto func = std : : bind ( & Bucket < RCNode > : : DelNode , Nodes ( ) , val ) ;
LogicCall ( router - > logic ( ) , func ) ;
LogicCall ( router - > logic ( ) , func ) ;
}
}
@ -283,16 +305,15 @@ namespace llarp
{
{
// ask N random peers for new routers
// ask N random peers for new routers
llarp : : LogDebug ( " Exploring network via " , N , " peers " ) ;
llarp : : LogDebug ( " Exploring network via " , N , " peers " ) ;
std : : set < Key_t > peers ;
std : : set < Key_t > peers ;
if ( _nodes - > GetManyRandom ( peers , N ) )
if ( _nodes - > GetManyRandom ( peers , N ) )
{
{
for ( const auto & peer : peers )
for ( const auto & peer : peers )
ExploreNetworkVia ( peer ) ;
ExploreNetworkVia ( peer ) ;
}
}
else
else
llarp : : LogError ( " failed to select " , N ,
llarp : : LogError ( " failed to select " , N , " random nodes for exploration " ) ;
" random nodes for exploration " ) ;
}
}
void
void
@ -313,14 +334,14 @@ namespace llarp
CleanupTX ( ) ;
CleanupTX ( ) ;
const llarp_time_t now = Now ( ) ;
const llarp_time_t now = Now ( ) ;
if ( _services )
if ( _services )
{
{
// expire intro sets
// expire intro sets
auto & nodes = _services - > nodes ;
auto & nodes = _services - > nodes ;
auto itr = nodes . begin ( ) ;
auto itr = nodes . begin ( ) ;
while ( itr ! = nodes . end ( ) )
while ( itr ! = nodes . end ( ) )
{
{
if ( itr - > second . introset . IsExpired ( now ) )
if ( itr - > second . introset . IsExpired ( now ) )
{
{
itr = nodes . erase ( itr ) ;
itr = nodes . erase ( itr ) ;
}
}
@ -333,17 +354,19 @@ namespace llarp
void
void
Context : : LookupRouterRelayed (
Context : : LookupRouterRelayed (
const Key_t & requester , uint64_t txid , const Key_t & target ,
const Key_t & requester ,
bool recursive , std : : vector < std : : unique_ptr < IMessage > > & replies )
uint64_t txid ,
const Key_t & target ,
bool recursive ,
std : : vector < std : : unique_ptr < IMessage > > & replies )
{
{
if ( target = = ourKey )
if ( target = = ourKey )
{
{
// we are the target, give them our RC
// we are the target, give them our RC
replies . emplace_back (
replies . emplace_back ( new GotRouterMessage ( requester , txid , { router - > rc ( ) } , false ) ) ;
new GotRouterMessage ( requester , txid , { router - > rc ( ) } , false ) ) ;
return ;
return ;
}
}
if ( not GetRouter ( ) - > ConnectionToRouterAllowed ( target . as_array ( ) ) )
if ( not GetRouter ( ) - > ConnectionToRouterAllowed ( target . as_array ( ) ) )
{
{
// explicitly not allowed
// explicitly not allowed
replies . emplace_back ( new GotRouterMessage ( requester , txid , { } , false ) ) ;
replies . emplace_back ( new GotRouterMessage ( requester , txid , { } , false ) ) ;
@ -352,10 +375,10 @@ namespace llarp
const auto rc = GetRouter ( ) - > nodedb ( ) - > FindClosestTo ( target ) ;
const auto rc = GetRouter ( ) - > nodedb ( ) - > FindClosestTo ( target ) ;
const Key_t next ( rc . pubkey ) ;
const Key_t next ( rc . pubkey ) ;
{
{
if ( next = = target )
if ( next = = target )
{
{
// we know the target
// we know the target
if ( rc . ExpiresSoon ( llarp : : time_now_ms ( ) ) )
if ( rc . ExpiresSoon ( llarp : : time_now_ms ( ) ) )
{
{
// ask target for their rc to keep it updated
// ask target for their rc to keep it updated
LookupRouterRecursive ( target . as_array ( ) , requester , txid , next ) ;
LookupRouterRecursive ( target . as_array ( ) , requester , txid , next ) ;
@ -363,14 +386,13 @@ namespace llarp
else
else
{
{
// send reply with rc we know of
// send reply with rc we know of
replies . emplace_back (
replies . emplace_back ( new GotRouterMessage ( requester , txid , { rc } , false ) ) ;
new GotRouterMessage ( requester , txid , { rc } , false ) ) ;
}
}
}
}
else if ( recursive ) // are we doing a recursive lookup?
else if ( recursive ) // are we doing a recursive lookup?
{
{
// is the next peer we ask closer to the target than us?
// is the next peer we ask closer to the target than us?
if ( ( next ^ target ) < ( ourKey ^ target ) )
if ( ( next ^ target ) < ( ourKey ^ target ) )
{
{
// yes it is closer, ask neighbour recursively
// yes it is closer, ask neighbour recursively
LookupRouterRecursive ( target . as_array ( ) , requester , txid , next ) ;
LookupRouterRecursive ( target . as_array ( ) , requester , txid , next ) ;
@ -379,24 +401,22 @@ namespace llarp
{
{
// no we are closer to the target so tell requester it's not there
// no we are closer to the target so tell requester it's not there
// so they switch to iterative lookup
// so they switch to iterative lookup
replies . emplace_back (
replies . emplace_back ( new GotRouterMessage ( requester , txid , { } , false ) ) ;
new GotRouterMessage ( requester , txid , { } , false ) ) ;
}
}
}
}
else
else
{
{
// iterative lookup and we don't have it tell them who is closer
// iterative lookup and we don't have it tell them who is closer
replies . emplace_back (
replies . emplace_back ( new GotRouterMessage ( requester , next , txid , false ) ) ;
new GotRouterMessage ( requester , next , txid , false ) ) ;
}
}
}
}
}
}
nonstd : : optional < llarp : : service : : EncryptedIntroSet >
nonstd : : optional < llarp : : service : : EncryptedIntroSet >
Context : : GetIntroSetByLocation ( const Key_t & key ) const
Context : : GetIntroSetByLocation ( const Key_t & key ) const
{
{
auto itr = _services - > nodes . find ( key ) ;
auto itr = _services - > nodes . find ( key ) ;
if ( itr = = _services - > nodes . end ( ) )
if ( itr = = _services - > nodes . end ( ) )
return { } ;
return { } ;
return itr - > second . introset ;
return itr - > second . introset ;
}
}
@ -415,23 +435,22 @@ namespace llarp
util : : StatusObject
util : : StatusObject
Context : : ExtractStatus ( ) const
Context : : ExtractStatus ( ) const
{
{
util : : StatusObject obj {
util : : StatusObject obj { { " pendingRouterLookups " , pendingRouterLookups ( ) . ExtractStatus ( ) } ,
{ " pendingRouterLookups " , pendingRouterLookups ( ) . ExtractStatus ( ) } ,
{ " pendingIntrosetLookups " , _pendingIntrosetLookups . ExtractStatus ( ) } ,
{ " pendingIntrosetLookups " , _pendingIntrosetLookups . ExtractStatus ( ) } ,
{ " pendingExploreLookups " , pendingExploreLookups ( ) . ExtractStatus ( ) } ,
{ " pendingExploreLookups " , pendingExploreLookups ( ) . ExtractStatus ( ) } ,
{ " nodes " , _nodes - > ExtractStatus ( ) } ,
{ " nodes " , _nodes - > ExtractStatus ( ) } ,
{ " services " , _services - > ExtractStatus ( ) } ,
{ " services " , _services - > ExtractStatus ( ) } ,
{ " ourKey " , ourKey . ToHex ( ) } } ;
{ " ourKey " , ourKey . ToHex ( ) } } ;
return obj ;
return obj ;
}
}
void
void
Context : : Init ( const Key_t & us , AbstractRouter * r )
Context : : Init ( const Key_t & us , AbstractRouter * r )
{
{
router = r ;
router = r ;
ourKey = us ;
ourKey = us ;
_nodes = std : : make_unique < Bucket < RCNode > > ( ourKey , llarp : : randint ) ;
_nodes = std : : make_unique < Bucket < RCNode > > ( ourKey , llarp : : randint ) ;
_services = std : : make_unique < Bucket < ISNode > > ( ourKey , llarp : : randint ) ;
_services = std : : make_unique < Bucket < ISNode > > ( ourKey , llarp : : randint ) ;
llarp : : LogDebug ( " initialize dht with key " , ourKey ) ;
llarp : : LogDebug ( " initialize dht with key " , ourKey ) ;
// start cleanup timer
// start cleanup timer
ScheduleCleanupTimer ( ) ;
ScheduleCleanupTimer ( ) ;
@ -441,8 +460,7 @@ namespace llarp
Context : : ScheduleCleanupTimer ( )
Context : : ScheduleCleanupTimer ( )
{
{
router - > logic ( ) - > call_later (
router - > logic ( ) - > call_later (
1 s ,
1 s , std : : bind ( & llarp : : dht : : Context : : handle_cleaner_timer , this , 1000 ) ) ;
std : : bind ( & llarp : : dht : : Context : : handle_cleaner_timer , this , 1000 ) ) ;
}
}
void
void
@ -451,7 +469,7 @@ namespace llarp
llarp : : DHTImmediateMessage m ;
llarp : : DHTImmediateMessage m ;
m . msgs . emplace_back ( msg ) ;
m . msgs . emplace_back ( msg ) ;
router - > SendToOrQueue ( peer , & m , [ ] ( SendStatus status ) {
router - > SendToOrQueue ( peer , & m , [ ] ( SendStatus status ) {
if ( status ! = SendStatus : : Success )
if ( status ! = SendStatus : : Success )
LogInfo ( " DHTSendTo unsuccessful, status: " , ( int ) status ) ;
LogInfo ( " DHTSendTo unsuccessful, status: " , ( int ) status ) ;
} ) ;
} ) ;
auto now = Now ( ) ;
auto now = Now ( ) ;
@ -466,9 +484,9 @@ namespace llarp
Context : : RelayRequestForPath ( const llarp : : PathID_t & id , const IMessage & msg )
Context : : RelayRequestForPath ( const llarp : : PathID_t & id , const IMessage & msg )
{
{
llarp : : routing : : DHTMessage reply ;
llarp : : routing : : DHTMessage reply ;
if ( ! msg . HandleMessage ( router - > dht ( ) , reply . M ) )
if ( ! msg . HandleMessage ( router - > dht ( ) , reply . M ) )
return false ;
return false ;
if ( not reply . M . empty ( ) )
if ( not reply . M . empty ( ) )
{
{
auto path = router - > pathContext ( ) . GetByUpstream ( router - > pubkey ( ) , id ) ;
auto path = router - > pathContext ( ) . GetByUpstream ( router - > pubkey ( ) , id ) ;
return path & & path - > SendRoutingMessage ( reply , router ) ;
return path & & path - > SendRoutingMessage ( reply , router ) ;
@ -477,106 +495,120 @@ namespace llarp
}
}
void
void
Context : : LookupIntroSetForPath ( const Key_t & addr , uint64_t txid ,
Context : : LookupIntroSetForPath (
const llarp : : PathID_t & path ,
const Key_t & addr ,
const Key_t & askpeer , uint64_t relayOrder )
uint64_t txid ,
const llarp : : PathID_t & path ,
const Key_t & askpeer ,
uint64_t relayOrder )
{
{
const TXOwner asker ( OurKey ( ) , txid ) ;
const TXOwner asker ( OurKey ( ) , txid ) ;
const TXOwner peer ( askpeer , + + ids ) ;
const TXOwner peer ( askpeer , + + ids ) ;
_pendingIntrosetLookups . NewTX (
_pendingIntrosetLookups . NewTX (
peer , asker , asker ,
peer ,
new LocalServiceAddressLookup ( path , txid , relayOrder , addr , this ,
asker ,
askpeer ) ) ;
asker ,
new LocalServiceAddressLookup ( path , txid , relayOrder , addr , this , askpeer ) ) ;
}
}
void
void
Context : : PropagateIntroSetTo ( const Key_t & from , uint64_t txid ,
Context : : PropagateIntroSetTo (
const service : : EncryptedIntroSet & introset ,
const Key_t & from ,
const Key_t & tellpeer , uint64_t relayOrder )
uint64_t txid ,
const service : : EncryptedIntroSet & introset ,
const Key_t & tellpeer ,
uint64_t relayOrder )
{
{
const TXOwner asker ( from , txid ) ;
const TXOwner asker ( from , txid ) ;
const TXOwner peer ( tellpeer , + + ids ) ;
const TXOwner peer ( tellpeer , + + ids ) ;
_pendingIntrosetLookups . NewTX (
_pendingIntrosetLookups . NewTX (
peer , asker , asker ,
peer , asker , asker , new PublishServiceJob ( asker , introset , this , relayOrder ) ) ;
new PublishServiceJob ( asker , introset , this , relayOrder ) ) ;
}
}
void
void
Context : : PropagateLocalIntroSet ( const PathID_t & from , uint64_t txid ,
Context : : PropagateLocalIntroSet (
const service : : EncryptedIntroSet & introset ,
const PathID_t & from ,
const Key_t & tellpeer , uint64_t relayOrder )
uint64_t txid ,
const service : : EncryptedIntroSet & introset ,
const Key_t & tellpeer ,
uint64_t relayOrder )
{
{
const TXOwner asker ( OurKey ( ) , txid ) ;
const TXOwner asker ( OurKey ( ) , txid ) ;
const TXOwner peer ( tellpeer , + + ids ) ;
const TXOwner peer ( tellpeer , + + ids ) ;
_pendingIntrosetLookups . NewTX (
_pendingIntrosetLookups . NewTX (
peer , asker , peer ,
peer ,
new LocalPublishServiceJob ( peer , from , txid , introset , this ,
asker ,
relayOrder ) ) ;
peer ,
new LocalPublishServiceJob ( peer , from , txid , introset , this , relayOrder ) ) ;
}
}
void
void
Context : : LookupIntroSetRelayed (
Context : : LookupIntroSetRelayed (
const Key_t & addr , const Key_t & whoasked , uint64_t txid ,
const Key_t & addr ,
const Key_t & askpeer , uint64_t relayOrder ,
const Key_t & whoasked ,
uint64_t txid ,
const Key_t & askpeer ,
uint64_t relayOrder ,
service : : EncryptedIntroSetLookupHandler handler )
service : : EncryptedIntroSetLookupHandler handler )
{
{
const TXOwner asker ( whoasked , txid ) ;
const TXOwner asker ( whoasked , txid ) ;
const TXOwner peer ( askpeer , + + ids ) ;
const TXOwner peer ( askpeer , + + ids ) ;
_pendingIntrosetLookups . NewTX (
_pendingIntrosetLookups . NewTX (
peer , asker , asker ,
peer , asker , asker , new ServiceAddressLookup ( asker , addr , this , relayOrder , handler ) ) ;
new ServiceAddressLookup ( asker , addr , this , relayOrder , handler ) ) ;
}
}
void
void
Context : : LookupIntroSetDirect (
Context : : LookupIntroSetDirect (
const Key_t & addr , const Key_t & whoasked , uint64_t txid ,
const Key_t & addr ,
const Key_t & askpeer , service : : EncryptedIntroSetLookupHandler handler )
const Key_t & whoasked ,
uint64_t txid ,
const Key_t & askpeer ,
service : : EncryptedIntroSetLookupHandler handler )
{
{
const TXOwner asker ( whoasked , txid ) ;
const TXOwner asker ( whoasked , txid ) ;
const TXOwner peer ( askpeer , + + ids ) ;
const TXOwner peer ( askpeer , + + ids ) ;
_pendingIntrosetLookups . NewTX (
_pendingIntrosetLookups . NewTX (
peer , asker , asker ,
peer , asker , asker , new ServiceAddressLookup ( asker , addr , this , 0 , handler ) , 1 s ) ;
new ServiceAddressLookup ( asker , addr , this , 0 , handler ) , 1 s ) ;
}
}
bool
bool
Context : : HandleExploritoryRouterLookup (
Context : : HandleExploritoryRouterLookup (
const Key_t & requester , uint64_t txid , const RouterID & target ,
const Key_t & requester ,
std : : vector < std : : unique_ptr < IMessage > > & reply )
uint64_t txid ,
const RouterID & target ,
std : : vector < std : : unique_ptr < IMessage > > & reply )
{
{
std : : vector < RouterID > closer ;
std : : vector < RouterID > closer ;
const Key_t t ( target . as_array ( ) ) ;
const Key_t t ( target . as_array ( ) ) ;
std : : set < Key_t > foundRouters ;
std : : set < Key_t > foundRouters ;
if ( ! _nodes )
if ( ! _nodes )
return false ;
return false ;
const size_t nodeCount = _nodes - > size ( ) ;
const size_t nodeCount = _nodes - > size ( ) ;
if ( nodeCount = = 0 )
if ( nodeCount = = 0 )
{
{
llarp : : LogError (
llarp : : LogError ( " cannot handle exploritory router lookup, no dht peers " ) ;
" cannot handle exploritory router lookup, no dht peers " ) ;
return false ;
return false ;
}
}
llarp : : LogDebug ( " We have " , _nodes - > size ( ) ,
llarp : : LogDebug ( " We have " , _nodes - > size ( ) , " connected nodes into the DHT " ) ;
" connected nodes into the DHT " ) ;
// ourKey should never be in the connected list
// ourKey should never be in the connected list
// requester is likely in the connected list
// requester is likely in the connected list
// 4 or connection nodes (minus a potential requestor), whatever is less
// 4 or connection nodes (minus a potential requestor), whatever is less
if ( ! _nodes - > GetManyNearExcluding ( t , foundRouters ,
if ( ! _nodes - > GetManyNearExcluding (
std : : min ( nodeCount , size_t { 4 } ) ,
t , foundRouters , std : : min ( nodeCount , size_t { 4 } ) , std : : set < Key_t > { ourKey , requester } ) )
std : : set < Key_t > { ourKey , requester } ) )
{
{
llarp : : LogError (
llarp : : LogError (
" not enough dht nodes to handle exploritory router lookup, "
" not enough dht nodes to handle exploritory router lookup, "
" have " ,
" have " ,
nodeCount , " dht peers " ) ;
nodeCount ,
" dht peers " ) ;
return false ;
return false ;
}
}
for ( const auto & f : foundRouters )
for ( const auto & f : foundRouters )
{
{
const RouterID id = f . as_array ( ) ;
const RouterID id = f . as_array ( ) ;
// discard shit routers
// discard shit routers
if ( router - > routerProfiling ( ) . IsBadForConnect ( id ) )
if ( router - > routerProfiling ( ) . IsBadForConnect ( id ) )
continue ;
continue ;
closer . emplace_back ( id ) ;
closer . emplace_back ( id ) ;
}
}
@ -586,29 +618,28 @@ namespace llarp
}
}
void
void
Context : : LookupRouterForPath ( const RouterID & target , uint64_t txid ,
Context : : LookupRouterForPath (
const llarp : : PathID_t & path ,
const RouterID & target , uint64_t txid , const llarp : : PathID_t & path , const Key_t & askpeer )
const Key_t & askpeer )
{
{
const TXOwner peer ( askpeer , + + ids ) ;
const TXOwner peer ( askpeer , + + ids ) ;
const TXOwner whoasked ( OurKey ( ) , txid ) ;
const TXOwner whoasked ( OurKey ( ) , txid ) ;
_pendingRouterLookups . NewTX (
_pendingRouterLookups . NewTX (
peer , whoasked , target ,
peer , whoasked , target , new LocalRouterLookup ( path , txid , target , this ) ) ;
new LocalRouterLookup ( path , txid , target , this ) ) ;
}
}
void
void
Context : : LookupRouterRecursive ( const RouterID & target ,
Context : : LookupRouterRecursive (
const Key_t & whoasked , uint64_t txid ,
const RouterID & target ,
const Key_t & askpeer ,
const Key_t & whoasked ,
RouterLookupHandler handler )
uint64_t txid ,
const Key_t & askpeer ,
RouterLookupHandler handler )
{
{
const TXOwner asker ( whoasked , txid ) ;
const TXOwner asker ( whoasked , txid ) ;
const TXOwner peer ( askpeer , + + ids ) ;
const TXOwner peer ( askpeer , + + ids ) ;
_pendingRouterLookups . NewTX (
_pendingRouterLookups . NewTX (
peer , asker , target ,
peer , asker , target , new RecursiveRouterLookup ( asker , target , this , handler ) ) ;
new RecursiveRouterLookup ( asker , target , this , handler ) ) ;
}
}
llarp_time_t
llarp_time_t
@ -617,10 +648,10 @@ namespace llarp
return router - > Now ( ) ;
return router - > Now ( ) ;
}
}
std : : unique_ptr < AbstractContext >
std : : unique_ptr < AbstractContext >
makeContext ( )
makeContext ( )
{
{
return std : : make_unique < Context > ( ) ;
return std : : make_unique < Context > ( ) ;
}
}
} // namespace dht
} // namespace dht