Merge remote-tracking branch 'origin/staging' into staging

pull/320/head
Jeff Becker 5 years ago
commit ef13ec7499
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -11,7 +11,7 @@ build:linux:
- linux
stage: build
before_script:
- apk add --update g++ make cmake linux-headers libcap-dev
- apk add --update g++ make cmake linux-headers libcap-dev rapidjson
script:
- make
artifacts:

@ -5,7 +5,6 @@ set(PROJECT_NAME lokinet)
project(${PROJECT_NAME} C CXX ASM)
# Core options
option(USE_LIBABYSS "enable libabyss" )
option(USE_AVX2 "enable avx2 code" )
option(USE_NETNS "enable networking namespace support. Linux only" )
option(AMD_RYZEN_HACK "hack for AMD Ryzen FPU bug (support FMA3 and FMA4 in FPU, but does not show in CPUID)" )
@ -21,6 +20,7 @@ option(WITH_COVERAGE "generate coverage data")
# Basic definitions
get_filename_component(CORE_INCLUDE include ABSOLUTE)
get_filename_component(ABYSS_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/${ABYSS}/include" ABSOLUTE CACHE)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
@ -30,6 +30,7 @@ endif()
if(WIN32)
set(CMAKE_CXX_STANDARD 17)
ENABLE_LANGUAGE(RC)
add_compile_options(-Wno-format)
else()
set(CMAKE_CXX_STANDARD 14)
endif(WIN32)
@ -310,39 +311,33 @@ function(add_log_tag target)
endforeach(F)
endfunction()
if(USE_LIBABYSS)
add_definitions(-DUSE_ABYSS=1)
set(ABYSS_SRC
${ABYSS}/src/http.cpp
${ABYSS}/src/client.cpp
${ABYSS}/src/server.cpp)
add_library(${ABYSS_LIB} STATIC ${ABYSS_SRC})
endif(USE_LIBABYSS)
set(ABYSS_SRC
${ABYSS}/src/http.cpp
${ABYSS}/src/client.cpp
${ABYSS}/src/server.cpp)
add_library(${ABYSS_LIB} STATIC ${ABYSS_SRC})
add_subdirectory(crypto)
add_subdirectory(libutp)
add_subdirectory(llarp)
if(USE_LIBABYSS)
target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB})
target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB})
if (NOT WIN32)
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} Threads::Threads)
else()
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp llarp/win32/abyss.rc)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32)
endif(NOT WIN32)
target_include_directories(${ABYSS_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include")
target_include_directories(${ABYSS_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include")
# for freebsd
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_include_directories(${ABYSS_LIB} /usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
add_log_tag(${ABYSS_EXE})
add_log_tag(${ABYSS_LIB})
endif(USE_LIBABYSS)
if (NOT WIN32)
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} Threads::Threads)
else()
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp llarp/win32/abyss.rc)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32)
endif(NOT WIN32)
target_include_directories(${ABYSS_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include")
target_include_directories(${ABYSS_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include")
# for freebsd
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_include_directories(${ABYSS_LIB} /usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
add_log_tag(${ABYSS_EXE})
add_log_tag(${ABYSS_LIB})
if(SHADOW)
add_shadow_plugin(shadow-plugin-${SHARED_LIB} ${EXE_SRC} ${LIB_SRC} ${UTP_SRC} ${LIB_PLATFORM_SRC} ${CPP_BACKPORT_SRC} ${ABYSS_SRC} ${CRYPTOGRAPHY_SRC})

@ -18,7 +18,7 @@ namespace llarp
struct Config;
struct Crypto;
class Logic;
struct Router;
struct AbstractRouter;
struct RouterContact;
struct Context
@ -28,7 +28,7 @@ namespace llarp
int num_nethreads = 1;
bool singleThreaded = false;
std::unique_ptr< llarp::Crypto > crypto;
std::unique_ptr< llarp::Router > router;
std::unique_ptr< llarp::AbstractRouter > router;
std::unique_ptr< llarp_threadpool > worker;
std::unique_ptr< llarp::Logic > logic;
std::unique_ptr< llarp::Config > config;

@ -202,12 +202,7 @@ set(LIB_SRC
)
add_library(${STATIC_LIB} STATIC ${LIB_SRC})
target_link_libraries(${STATIC_LIB} PUBLIC ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOGRAPHY_LIB} libutp ${LIBS})
if(USE_LIBABYSS)
add_definitions(-DUSE_ABYSS=1)
target_link_libraries(${STATIC_LIB} PUBLIC ${ABYSS_LIB})
endif()
target_link_libraries(${STATIC_LIB} PUBLIC ${ABYSS_LIB} ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOGRAPHY_LIB} libutp ${LIBS})
if(TESTNET)
target_sources(${STATIC_LIB} PUBLIC testnet.c)
@ -215,18 +210,10 @@ endif()
if(WITH_SHARED)
add_library(${SHARED_LIB} SHARED ${LIB_SRC})
target_link_libraries(${SHARED_LIB} PUBLIC ${ABYSS_LIB} ${CRYPTOGRAPHY_LIB} ${LIBS} ${UTIL_LIB} ${PLATFORM_LIB} Threads::Threads)
if (WIN32)
if(USE_LIBABYSS)
target_link_libraries(${SHARED_LIB} ${ABYSS_LIB} ${CRYPTOGRAPHY_LIB} ${LIBS} ${UTIL_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi Threads::Threads)
else()
target_link_libraries(${SHARED_LIB} ${CRYPTOGRAPHY_LIB} ${LIBS} ${UTIL_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi Threads::Threads)
endif()
target_link_libraries(${SHARED_LIB} PUBLIC ws2_32 iphlpapi)
else()
if(USE_LIBABYSS)
target_link_libraries(${SHARED_LIB} ${ABYSS_LIB} ${CRYPTOGRAPHY_LIB} ${LIBS} ${UTIL_LIB} libutp ${PLATFORM_LIB} Threads::Threads)
else()
target_link_libraries(${SHARED_LIB} ${CRYPTOGRAPHY_LIB} ${LIBS} ${UTIL_LIB} libutp ${PLATFORM_LIB} Threads::Threads)
endif()
install(TARGETS ${SHARED_LIB} LIBRARY DESTINATION lib)
endif()
add_log_tag(${SHARED_LIB})

@ -97,7 +97,8 @@ namespace llarp
Context::LoadDatabase()
{
crypto = std::make_unique< sodium::CryptoLibSodium >();
nodedb = std::make_unique< llarp_nodedb >(crypto.get(), router->disk);
nodedb =
std::make_unique< llarp_nodedb >(crypto.get(), router->diskworker());
if(!llarp_nodedb::ensure_dir(nodedb_dir.c_str()))
{
@ -360,7 +361,7 @@ extern "C"
llarp_main_inject_vpn_fd(struct llarp_main *ptr, int fd)
{
llarp::handlers::TunEndpoint *tun =
ptr->ctx->router->hiddenServiceContext.getFirstTun();
ptr->ctx->router->hiddenServiceContext().getFirstTun();
if(!tun)
return;
if(!tun->Promise)
@ -467,8 +468,9 @@ extern "C"
// llarp::Info("checkOnline - DHT nodes ",
// request->ptr->ctx->router->dht->impl.nodes->nodes.size());
request->online = false;
request->nodes = request->ptr->ctx->router->dht()->impl.nodes->nodes.size();
if(request->ptr->ctx->router->dht()->impl.nodes->nodes.size())
request->nodes =
request->ptr->ctx->router->dht()->impl->Nodes()->nodes.size();
if(request->ptr->ctx->router->dht()->impl->Nodes()->nodes.size())
{
// llarp::Info("checkOnline - Going to say we're online");
request->online = true;
@ -506,15 +508,15 @@ extern "C"
main_router_prefetch(struct llarp_main *ptr,
const llarp::service::Address &addr)
{
auto *endpoint = &ptr->ctx->router->hiddenServiceContext;
return endpoint->Prefetch(addr);
auto &endpoint = ptr->ctx->router->hiddenServiceContext();
return endpoint.Prefetch(addr);
}
llarp::handlers::TunEndpoint *
main_router_getFirstTunEndpoint(struct llarp_main *ptr)
{
if(ptr && ptr->ctx && ptr->ctx->router)
return ptr->ctx->router->hiddenServiceContext.getFirstTun();
return ptr->ctx->router->hiddenServiceContext().getFirstTun();
return nullptr;
}
@ -522,15 +524,13 @@ extern "C"
main_router_endpoint_iterator(
struct llarp_main *ptr, struct llarp::service::Context::endpoint_iter &i)
{
auto *context = &ptr->ctx->router->hiddenServiceContext;
return context->iterate(i);
return ptr->ctx->router->hiddenServiceContext().iterate(i);
}
llarp_tun_io *
main_router_getRange(struct llarp_main *ptr)
{
auto *context = &ptr->ctx->router->hiddenServiceContext;
return context->getRange();
return ptr->ctx->router->hiddenServiceContext().getRange();
}
const char *

@ -29,9 +29,264 @@ namespace llarp
{
}
struct Context final : public AbstractContext
{
Context();
~Context()
{
}
util::StatusObject
ExtractStatus() const override;
llarp::Crypto*
Crypto() const override;
/// on behalf of whoasked request introset for target from dht router with
/// key askpeer
void
LookupIntroSetRecursive(
const service::Address& target, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer, uint64_t R,
service::IntroSetLookupHandler result = nullptr) override;
void
LookupIntroSetIterative(
const service::Address& target, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer,
service::IntroSetLookupHandler result = nullptr) override;
/// on behalf of whoasked request router with public key target from dht
/// router with key askpeer
void
LookupRouterRecursive(const RouterID& target, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer,
RouterLookupHandler result = nullptr);
bool
LookupRouter(const RouterID& target, RouterLookupHandler result) override
{
Key_t askpeer;
if(!nodes->FindClosest(Key_t(target), askpeer))
{
return false;
}
LookupRouterRecursive(target, OurKey(), 0, askpeer, result);
return true;
}
bool
HasRouterLookup(const RouterID& target) const override
{
return pendingRouterLookups().HasLookupFor(target);
}
/// on behalf of whoasked request introsets with tag from dht router with
/// key askpeer with Recursion depth R
void
LookupTagRecursive(const service::Tag& tag, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer,
uint64_t R) override;
/// issue dht lookup for tag via askpeer and send reply to local path
void
LookupTagForPath(const service::Tag& tag, uint64_t txid,
const llarp::PathID_t& path,
const Key_t& askpeer) override;
/// issue dht lookup for router via askpeer and send reply to local path
void
LookupRouterForPath(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
/// local path
void
LookupIntroSetForPath(const service::Address& addr, uint64_t txid,
const llarp::PathID_t& path,
const Key_t& askpeer) override;
/// send a dht message to peer, if keepalive is true then keep the session
/// with that peer alive for 10 seconds
void
DHTSendTo(const RouterID& peer, IMessage* msg,
bool keepalive = true) override;
/// get routers closest to target excluding requester
bool
HandleExploritoryRouterLookup(
const Key_t& requester, uint64_t txid, const RouterID& target,
std::vector< std::unique_ptr< IMessage > >& reply) override;
std::set< service::IntroSet >
FindRandomIntroSetsWithTagExcluding(
const service::Tag& tag, size_t max = 2,
const std::set< service::IntroSet >& excludes = {}) override;
/// handle rc lookup from requester for target
void
LookupRouterRelayed(
const Key_t& requester, uint64_t txid, const Key_t& target,
bool recursive,
std::vector< std::unique_ptr< IMessage > >& replies) override;
/// relay a dht message from a local path to the main network
bool
RelayRequestForPath(const llarp::PathID_t& localPath,
const IMessage* msg) override;
/// send introset to peer from source with S counter and excluding peers
void
PropagateIntroSetTo(const Key_t& source, uint64_t sourceTX,
const service::IntroSet& introset, const Key_t& peer,
uint64_t S,
const std::set< Key_t >& exclude) override;
/// initialize dht context and explore every exploreInterval milliseconds
void
Init(const Key_t& us, AbstractRouter* router,
llarp_time_t exploreInterval) override;
/// get localally stored introset by service address
const llarp::service::IntroSet*
GetIntroSetByServiceAddress(
const llarp::service::Address& addr) const override;
static void
handle_cleaner_timer(void* user, uint64_t orig, uint64_t left);
static void
handle_explore_timer(void* user, uint64_t orig, uint64_t left);
/// explore dht for new routers
void
Explore(size_t N = 3);
llarp::AbstractRouter* router;
// for router contacts
std::unique_ptr< Bucket< RCNode > > nodes;
// for introduction sets
std::unique_ptr< Bucket< ISNode > > _services;
Bucket< ISNode >*
services() override
{
return _services.get();
}
bool allowTransit;
bool&
AllowTransit() override
{
return allowTransit;
}
const bool&
AllowTransit() const override
{
return allowTransit;
}
Bucket< RCNode >*
Nodes() const override
{
return nodes.get();
}
const Key_t&
OurKey() const override
{
return ourKey;
}
llarp::AbstractRouter*
GetRouter() const override
{
return router;
}
PendingIntrosetLookups _pendingIntrosetLookups;
PendingTagLookups _pendingTagLookups;
PendingRouterLookups _pendingRouterLookups;
PendingExploreLookups _pendingExploreLookups;
PendingIntrosetLookups&
pendingIntrosetLookups() override
{
return _pendingIntrosetLookups;
}
const PendingIntrosetLookups&
pendingIntrosetLookups() const override
{
return _pendingIntrosetLookups;
}
PendingTagLookups&
pendingTagLookups() override
{
return _pendingTagLookups;
}
const PendingTagLookups&
pendingTagLookups() const override
{
return _pendingTagLookups;
}
PendingRouterLookups&
pendingRouterLookups() override
{
return _pendingRouterLookups;
}
const PendingRouterLookups&
pendingRouterLookups() const override
{
return _pendingRouterLookups;
}
PendingExploreLookups&
pendingExploreLookups() override
{
return _pendingExploreLookups;
}
const PendingExploreLookups&
pendingExploreLookups() const override
{
return _pendingExploreLookups;
}
uint64_t
NextID()
{
return ++ids;
}
llarp_time_t
Now() const override;
void
ExploreNetworkVia(const Key_t& peer) override;
private:
void
ScheduleCleanupTimer();
void
CleanupTX();
uint64_t ids;
Key_t ourKey;
};
Context::Context() : router(nullptr), allowTransit(false)
{
randombytes((byte_t *)&ids, sizeof(uint64_t));
randombytes((byte_t*)&ids, sizeof(uint64_t));
}
void
@ -43,7 +298,7 @@ namespace llarp
if(nodes->GetManyRandom(peers, N))
{
for(const auto &peer : peers)
for(const auto& peer : peers)
ExploreNetworkVia(peer);
}
else
@ -51,42 +306,42 @@ namespace llarp
}
void
Context::ExploreNetworkVia(const Key_t &askpeer)
Context::ExploreNetworkVia(const Key_t& askpeer)
{
uint64_t txid = ++ids;
TXOwner peer(askpeer, txid);
TXOwner whoasked(OurKey(), txid);
pendingExploreLookups.NewTX(
pendingExploreLookups().NewTX(
peer, whoasked, askpeer.as_array(),
new ExploreNetworkJob(askpeer.as_array(), this));
}
void
Context::handle_explore_timer(void *u, uint64_t orig, uint64_t left)
Context::handle_explore_timer(void* u, uint64_t orig, uint64_t left)
{
if(left)
return;
Context *ctx = static_cast< Context * >(u);
Context* ctx = static_cast< Context* >(u);
ctx->Explore(1);
ctx->router->logic()->call_later({orig, ctx, &handle_explore_timer});
}
void
Context::handle_cleaner_timer(void *u,
Context::handle_cleaner_timer(void* u,
__attribute__((unused)) uint64_t orig,
uint64_t left)
{
if(left)
return;
Context *ctx = static_cast< Context * >(u);
Context* ctx = static_cast< Context* >(u);
// clean up transactions
ctx->CleanupTX();
if(ctx->services)
if(ctx->_services)
{
// expire intro sets
auto now = ctx->Now();
auto &nodes = ctx->services->nodes;
auto& nodes = ctx->_services->nodes;
auto itr = nodes.begin();
while(itr != nodes.end())
{
@ -104,11 +359,11 @@ namespace llarp
std::set< service::IntroSet >
Context::FindRandomIntroSetsWithTagExcluding(
const service::Tag &tag, size_t max,
const std::set< service::IntroSet > &exclude)
const service::Tag& tag, size_t max,
const std::set< service::IntroSet >& exclude)
{
std::set< service::IntroSet > found;
auto &nodes = services->nodes;
auto& nodes = _services->nodes;
if(nodes.size() == 0)
{
return found;
@ -151,8 +406,8 @@ namespace llarp
void
Context::LookupRouterRelayed(
const Key_t &requester, uint64_t txid, const Key_t &target,
bool recursive, std::vector< std::unique_ptr< IMessage > > &replies)
const Key_t& requester, uint64_t txid, const Key_t& target,
bool recursive, std::vector< std::unique_ptr< IMessage > >& replies)
{
if(target == ourKey)
{
@ -201,13 +456,13 @@ namespace llarp
}
}
const llarp::service::IntroSet *
const llarp::service::IntroSet*
Context::GetIntroSetByServiceAddress(
const llarp::service::Address &addr) const
const llarp::service::Address& addr) const
{
auto key = addr.ToKey();
auto itr = services->nodes.find(key);
if(itr == services->nodes.end())
auto itr = _services->nodes.find(key);
if(itr == _services->nodes.end())
return nullptr;
return &itr->second.introset;
}
@ -218,34 +473,34 @@ namespace llarp
auto now = Now();
llarp::LogDebug("DHT tick");
pendingRouterLookups.Expire(now);
pendingIntrosetLookups.Expire(now);
pendingTagLookups.Expire(now);
pendingExploreLookups.Expire(now);
pendingRouterLookups().Expire(now);
_pendingIntrosetLookups.Expire(now);
pendingTagLookups().Expire(now);
pendingExploreLookups().Expire(now);
}
util::StatusObject
Context::ExtractStatus() const
{
util::StatusObject obj{
{"pendingRouterLookups", pendingRouterLookups.ExtractStatus()},
{"pendingIntrosetLookups", pendingIntrosetLookups.ExtractStatus()},
{"pendingTagLookups", pendingTagLookups.ExtractStatus()},
{"pendingExploreLookups", pendingExploreLookups.ExtractStatus()},
{"pendingRouterLookups", pendingRouterLookups().ExtractStatus()},
{"pendingIntrosetLookups", _pendingIntrosetLookups.ExtractStatus()},
{"pendingTagLookups", pendingTagLookups().ExtractStatus()},
{"pendingExploreLookups", pendingExploreLookups().ExtractStatus()},
{"nodes", nodes->ExtractStatus()},
{"services", services->ExtractStatus()},
{"services", _services->ExtractStatus()},
{"ourKey", ourKey.ToHex()}};
return obj;
}
void
Context::Init(const Key_t &us, AbstractRouter *r,
Context::Init(const Key_t& us, AbstractRouter* r,
llarp_time_t exploreInterval)
{
router = r;
ourKey = us;
nodes = std::make_unique< Bucket< RCNode > >(ourKey, llarp::randint);
services = std::make_unique< Bucket< ISNode > >(ourKey, llarp::randint);
router = r;
ourKey = us;
nodes = std::make_unique< Bucket< RCNode > >(ourKey, llarp::randint);
_services = std::make_unique< Bucket< ISNode > >(ourKey, llarp::randint);
llarp::LogDebug("initialize dht with key ", ourKey);
// start exploring
@ -262,7 +517,7 @@ namespace llarp
}
void
Context::DHTSendTo(const RouterID &peer, IMessage *msg, bool keepalive)
Context::DHTSendTo(const RouterID& peer, IMessage* msg, bool keepalive)
{
llarp::DHTImmediateMessage m;
m.msgs.emplace_back(msg);
@ -275,7 +530,7 @@ namespace llarp
}
bool
Context::RelayRequestForPath(const llarp::PathID_t &id, const IMessage *msg)
Context::RelayRequestForPath(const llarp::PathID_t& id, const IMessage* msg)
{
llarp::routing::DHTMessage reply;
if(!msg->HandleMessage(router->dht(), reply.M))
@ -289,84 +544,84 @@ namespace llarp
}
void
Context::LookupIntroSetForPath(const service::Address &addr, uint64_t txid,
const llarp::PathID_t &path,
const Key_t &askpeer)
Context::LookupIntroSetForPath(const service::Address& addr, uint64_t txid,
const llarp::PathID_t& path,
const Key_t& askpeer)
{
TXOwner asker(OurKey(), txid);
TXOwner peer(askpeer, ++ids);
pendingIntrosetLookups.NewTX(
_pendingIntrosetLookups.NewTX(
peer, asker, addr,
new LocalServiceAddressLookup(path, txid, addr, this, askpeer));
}
void
Context::PropagateIntroSetTo(const Key_t &from, uint64_t txid,
const service::IntroSet &introset,
const Key_t &tellpeer, uint64_t S,
const std::set< Key_t > &exclude)
Context::PropagateIntroSetTo(const Key_t& from, uint64_t txid,
const service::IntroSet& introset,
const Key_t& tellpeer, uint64_t S,
const std::set< Key_t >& exclude)
{
TXOwner asker(from, txid);
TXOwner peer(tellpeer, ++ids);
service::Address addr = introset.A.Addr();
pendingIntrosetLookups.NewTX(
_pendingIntrosetLookups.NewTX(
peer, asker, addr,
new PublishServiceJob(asker, introset, this, S, exclude));
}
void
Context::LookupIntroSetRecursive(const service::Address &addr,
const Key_t &whoasked, uint64_t txid,
const Key_t &askpeer, uint64_t R,
Context::LookupIntroSetRecursive(const service::Address& addr,
const Key_t& whoasked, uint64_t txid,
const Key_t& askpeer, uint64_t R,
service::IntroSetLookupHandler handler)
{
TXOwner asker(whoasked, txid);
TXOwner peer(askpeer, ++ids);
pendingIntrosetLookups.NewTX(
_pendingIntrosetLookups.NewTX(
peer, asker, addr,
new ServiceAddressLookup(asker, addr, this, R, handler));
}
void
Context::LookupIntroSetIterative(const service::Address &addr,
const Key_t &whoasked, uint64_t txid,
const Key_t &askpeer,
Context::LookupIntroSetIterative(const service::Address& addr,
const Key_t& whoasked, uint64_t txid,
const Key_t& askpeer,
service::IntroSetLookupHandler handler)
{
TXOwner asker(whoasked, txid);
TXOwner peer(askpeer, ++ids);
pendingIntrosetLookups.NewTX(
_pendingIntrosetLookups.NewTX(
peer, asker, addr,
new ServiceAddressLookup(asker, addr, this, 0, handler));
}
void
Context::LookupTagRecursive(const service::Tag &tag, const Key_t &whoasked,
uint64_t whoaskedTX, const Key_t &askpeer,
Context::LookupTagRecursive(const service::Tag& tag, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer,
uint64_t R)
{
TXOwner asker(whoasked, whoaskedTX);
TXOwner peer(askpeer, ++ids);
pendingTagLookups.NewTX(peer, asker, tag,
new TagLookup(asker, tag, this, R));
_pendingTagLookups.NewTX(peer, asker, tag,
new TagLookup(asker, tag, this, R));
llarp::LogInfo("ask ", askpeer, " for ", tag, " on behalf of ", whoasked,
" R=", R);
}
void
Context::LookupTagForPath(const service::Tag &tag, uint64_t txid,
const llarp::PathID_t &path, const Key_t &askpeer)
Context::LookupTagForPath(const service::Tag& tag, uint64_t txid,
const llarp::PathID_t& path, const Key_t& askpeer)
{
TXOwner peer(askpeer, ++ids);
TXOwner whoasked(OurKey(), txid);
pendingTagLookups.NewTX(peer, whoasked, tag,
new LocalTagLookup(path, txid, tag, this));
_pendingTagLookups.NewTX(peer, whoasked, tag,
new LocalTagLookup(path, txid, tag, this));
}
bool
Context::HandleExploritoryRouterLookup(
const Key_t &requester, uint64_t txid, const RouterID &target,
std::vector< std::unique_ptr< IMessage > > &reply)
const Key_t& requester, uint64_t txid, const RouterID& target,
std::vector< std::unique_ptr< IMessage > >& reply)
{
std::vector< RouterID > closer;
Key_t t(target.as_array());
@ -397,42 +652,42 @@ namespace llarp
want, " dht peers");
return false;
}
for(const auto &f : found)
for(const auto& f : found)
closer.emplace_back(f.as_array());
reply.emplace_back(new GotRouterMessage(txid, closer, false));
return true;
}
void
Context::LookupRouterForPath(const RouterID &target, uint64_t txid,
const llarp::PathID_t &path,
const Key_t &askpeer)
Context::LookupRouterForPath(const RouterID& target, uint64_t txid,
const llarp::PathID_t& path,
const Key_t& askpeer)
{
TXOwner peer(askpeer, ++ids);
TXOwner whoasked(OurKey(), txid);
pendingRouterLookups.NewTX(
_pendingRouterLookups.NewTX(
peer, whoasked, target,
new LocalRouterLookup(path, txid, target, this));
}
void
Context::LookupRouterRecursive(const RouterID &target,
const Key_t &whoasked, uint64_t txid,
const Key_t &askpeer,
Context::LookupRouterRecursive(const RouterID& target,
const Key_t& whoasked, uint64_t txid,
const Key_t& askpeer,
RouterLookupHandler handler)
{
TXOwner asker(whoasked, txid);
TXOwner peer(askpeer, ++ids);
if(target != askpeer)
{
pendingRouterLookups.NewTX(
_pendingRouterLookups.NewTX(
peer, asker, target,
new RecursiveRouterLookup(asker, target, this, handler));
}
}
llarp::Crypto *
llarp::Crypto*
Context::Crypto() const
{
return router->crypto();
@ -444,5 +699,11 @@ namespace llarp
return router->Now();
}
std::unique_ptr< AbstractContext >
makeContext()
{
return std::make_unique< Context >();
}
} // namespace dht
} // namespace llarp

@ -14,6 +14,7 @@
#include <util/time.hpp>
#include <util/status.hpp>
#include <memory>
#include <set>
namespace llarp
@ -22,8 +23,18 @@ namespace llarp
namespace dht
{
struct AbstractContext
struct AbstractContext : public util::IStateful
{
using PendingIntrosetLookups =
TXHolder< service::Address, service::IntroSet,
service::Address::Hash >;
using PendingTagLookups =
TXHolder< service::Tag, service::IntroSet, service::Tag::Hash >;
using PendingRouterLookups =
TXHolder< RouterID, RouterContact, RouterID::Hash >;
using PendingExploreLookups =
TXHolder< RouterID, RouterID, RouterID::Hash >;
virtual ~AbstractContext() = 0;
virtual bool
@ -50,218 +61,122 @@ namespace llarp
const service::Tag& tag, size_t max = 2,
const std::set< service::IntroSet >& excludes = {}) = 0;
virtual void
DHTSendTo(const RouterID& peer, IMessage* msg, bool keepalive = true) = 0;
virtual llarp_time_t
Now() const = 0;
virtual llarp::Crypto*
Crypto() const = 0;
virtual llarp::AbstractRouter*
GetRouter() const = 0;
virtual const Key_t&
OurKey() const = 0;
virtual Bucket< RCNode >*
Nodes() const = 0;
};
struct Context final : public AbstractContext, public util::IStateful
{
Context();
~Context()
{
}
util::StatusObject
ExtractStatus() const override;
llarp::Crypto*
Crypto() const override;
/// on behalf of whoasked request introset for target from dht router with
/// key askpeer
void
LookupIntroSetRecursive(
const service::Address& target, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer, uint64_t R,
service::IntroSetLookupHandler result = nullptr) override;
void
LookupIntroSetIterative(
const service::Address& target, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer,
service::IntroSetLookupHandler result = nullptr) override;
/// on behalf of whoasked request router with public key target from dht
/// router with key askpeer
void
LookupRouterRecursive(const RouterID& target, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer,
RouterLookupHandler result = nullptr);
bool
LookupRouter(const RouterID& target, RouterLookupHandler result) override
{
Key_t askpeer;
if(!nodes->FindClosest(Key_t(target), askpeer))
{
return false;
}
LookupRouterRecursive(target, OurKey(), 0, askpeer, result);
return true;
}
bool
HasRouterLookup(const RouterID& target) const
{
return pendingRouterLookups.HasLookupFor(target);
}
virtual bool
HasRouterLookup(const RouterID& target) const = 0;
/// on behalf of whoasked request introsets with tag from dht router with
/// key askpeer with Recursion depth R
void
virtual void
LookupTagRecursive(const service::Tag& tag, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer, uint64_t R);
uint64_t whoaskedTX, const Key_t& askpeer,
uint64_t R) = 0;
/// issue dht lookup for tag via askpeer and send reply to local path
void
virtual void
LookupTagForPath(const service::Tag& tag, uint64_t txid,
const llarp::PathID_t& path, const Key_t& askpeer);
const PathID_t& path, const Key_t& askpeer) = 0;
/// issue dht lookup for router via askpeer and send reply to local path
void
virtual void
LookupRouterForPath(const RouterID& target, uint64_t txid,
const llarp::PathID_t& path, const Key_t& askpeer);
const PathID_t& path, const Key_t& askpeer) = 0;
/// issue dht lookup for introset for addr via askpeer and send reply to
/// local path
void
virtual void
LookupIntroSetForPath(const service::Address& addr, uint64_t txid,
const llarp::PathID_t& path, const Key_t& askpeer);
const PathID_t& path, const Key_t& askpeer) = 0;
/// send a dht message to peer, if keepalive is true then keep the session
/// with that peer alive for 10 seconds
void
DHTSendTo(const RouterID& peer, IMessage* msg,
bool keepalive = true) override;
virtual void
DHTSendTo(const RouterID& peer, IMessage* msg, bool keepalive = true) = 0;
/// get routers closest to target excluding requester
bool
virtual bool
HandleExploritoryRouterLookup(
const Key_t& requester, uint64_t txid, const RouterID& target,
std::vector< std::unique_ptr< IMessage > >& reply);
std::set< service::IntroSet >
FindRandomIntroSetsWithTagExcluding(
const service::Tag& tag, size_t max = 2,
const std::set< service::IntroSet >& excludes = {}) override;
std::vector< std::unique_ptr< IMessage > >& reply) = 0;
/// handle rc lookup from requester for target
void
LookupRouterRelayed(const Key_t& requester, uint64_t txid,
const Key_t& target, bool recursive,
std::vector< std::unique_ptr< IMessage > >& replies);
virtual void
LookupRouterRelayed(
const Key_t& requester, uint64_t txid, const Key_t& target,
bool recursive,
std::vector< std::unique_ptr< IMessage > >& replies) = 0;
/// relay a dht message from a local path to the main network
bool
RelayRequestForPath(const llarp::PathID_t& localPath,
const IMessage* msg);
virtual bool
RelayRequestForPath(const PathID_t& localPath, const IMessage* msg) = 0;
/// send introset to peer from source with S counter and excluding peers
void
virtual void
PropagateIntroSetTo(const Key_t& source, uint64_t sourceTX,
const service::IntroSet& introset, const Key_t& peer,
uint64_t S, const std::set< Key_t >& exclude);
uint64_t S, const std::set< Key_t >& exclude) = 0;
/// initialize dht context and explore every exploreInterval milliseconds
void
virtual void
Init(const Key_t& us, AbstractRouter* router,
llarp_time_t exploreInterval);
llarp_time_t exploreInterval) = 0;
/// get localally stored introset by service address
const llarp::service::IntroSet*
GetIntroSetByServiceAddress(const llarp::service::Address& addr) const;
virtual const llarp::service::IntroSet*
GetIntroSetByServiceAddress(
const llarp::service::Address& addr) const = 0;
static void
handle_cleaner_timer(void* user, uint64_t orig, uint64_t left);
static void
handle_explore_timer(void* user, uint64_t orig, uint64_t left);
/// explore dht for new routers
void
Explore(size_t N = 3);
virtual llarp_time_t
Now() const = 0;
llarp::AbstractRouter* router;
// for router contacts
std::unique_ptr< Bucket< RCNode > > nodes;
virtual void
ExploreNetworkVia(const Key_t& peer) = 0;
// for introduction sets
std::unique_ptr< Bucket< ISNode > > services;
bool allowTransit;
virtual llarp::Crypto*
Crypto() const = 0;
Bucket< RCNode >*
Nodes() const override
{
return nodes.get();
}
virtual llarp::AbstractRouter*
GetRouter() const = 0;
const Key_t&
OurKey() const override
{
return ourKey;
}
virtual const Key_t&
OurKey() const = 0;
llarp::AbstractRouter*
GetRouter() const override
{
return router;
}
virtual PendingIntrosetLookups&
pendingIntrosetLookups() = 0;
TXHolder< service::Address, service::IntroSet, service::Address::Hash >
pendingIntrosetLookups;
virtual const PendingIntrosetLookups&
pendingIntrosetLookups() const = 0;
TXHolder< service::Tag, service::IntroSet, service::Tag::Hash >
pendingTagLookups;
virtual PendingTagLookups&
pendingTagLookups() = 0;
TXHolder< RouterID, RouterContact, RouterID::Hash > pendingRouterLookups;
virtual const PendingTagLookups&
pendingTagLookups() const = 0;
TXHolder< RouterID, RouterID, RouterID::Hash > pendingExploreLookups;
virtual PendingRouterLookups&
pendingRouterLookups() = 0;
uint64_t
NextID()
{
return ++ids;
}
virtual const PendingRouterLookups&
pendingRouterLookups() const = 0;
llarp_time_t
Now() const override;
virtual PendingExploreLookups&
pendingExploreLookups() = 0;
void
ExploreNetworkVia(const Key_t& peer);
virtual const PendingExploreLookups&
pendingExploreLookups() const = 0;
private:
void
ScheduleCleanupTimer();
virtual Bucket< ISNode >*
services() = 0;
void
CleanupTX();
virtual bool&
AllowTransit() = 0;
virtual const bool&
AllowTransit() const = 0;
uint64_t ids;
virtual Bucket< RCNode >*
Nodes() const = 0;
};
Key_t ourKey;
}; // namespace llarp
} // namespace dht
std::unique_ptr< AbstractContext >
makeContext();
} // namespace dht
} // namespace llarp
struct llarp_dht_context
{
llarp::dht::Context impl;
std::unique_ptr< llarp::dht::AbstractContext > impl;
llarp::AbstractRouter* parent;
llarp_dht_context(llarp::AbstractRouter* router);
};

@ -5,6 +5,7 @@
llarp_dht_context::llarp_dht_context(llarp::AbstractRouter *router)
{
parent = router;
impl = llarp::dht::makeContext();
}
struct llarp_dht_context *
@ -22,19 +23,19 @@ llarp_dht_context_free(struct llarp_dht_context *ctx)
void
__llarp_dht_remove_peer(struct llarp_dht_context *ctx, const byte_t *id)
{
ctx->impl.nodes->DelNode(llarp::dht::Key_t(id));
ctx->impl->Nodes()->DelNode(llarp::dht::Key_t(id));
}
void
llarp_dht_allow_transit(llarp_dht_context *ctx)
{
ctx->impl.allowTransit = true;
ctx->impl->AllowTransit() = true;
}
void
llarp_dht_context_start(struct llarp_dht_context *ctx, const byte_t *key)
{
ctx->impl.Init(llarp::dht::Key_t(key), ctx->parent, 20000);
ctx->impl->Init(llarp::dht::Key_t(key), ctx->parent, 20000);
}
void

@ -81,8 +81,8 @@ namespace llarp
llarp::LogError("R value too big, ", R, "> 5");
return false;
}
auto& dht = ctx->impl;
if(dht.pendingIntrosetLookups.HasPendingLookupFrom(TXOwner{From, T}))
auto& dht = *ctx->impl;
if(dht.pendingIntrosetLookups().HasPendingLookupFrom(TXOwner{From, T}))
{
llarp::LogWarn("duplicate FIM from ", From, " txid=", T);
return false;
@ -107,7 +107,7 @@ namespace llarp
Key_t target = S.ToKey();
Key_t closer;
// find closer peer
if(!dht.nodes->FindClosest(target, closer))
if(!dht.Nodes()->FindClosest(target, closer))
return false;
if(relayed)
dht.LookupIntroSetForPath(S, T, pathID, closer);
@ -120,7 +120,7 @@ namespace llarp
Key_t us = dht.OurKey();
Key_t target = S.ToKey();
// we are recursive
if(dht.nodes->FindCloseExcluding(target, peer, exclude))
if(dht.Nodes()->FindCloseExcluding(target, peer, exclude))
{
if(relayed)
dht.LookupIntroSetForPath(S, T, pathID, peer);
@ -154,7 +154,7 @@ namespace llarp
if(relayed)
{
// tag lookup
if(dht.nodes->GetRandomNodeExcluding(peer, exclude))
if(dht.Nodes()->GetRandomNodeExcluding(peer, exclude))
{
dht.LookupTagForPath(N, T, pathID, peer);
}
@ -182,7 +182,7 @@ namespace llarp
else if(R < 5)
{
// tag lookup
if(dht.nodes->GetRandomNodeExcluding(peer, exclude))
if(dht.Nodes()->GetRandomNodeExcluding(peer, exclude))
{
dht.LookupTagRecursive(N, From, T, peer, R - 1);
}

@ -16,17 +16,17 @@ namespace llarp
llarp_dht_context *ctx,
std::vector< std::unique_ptr< IMessage > > &replies) const
{
auto &dht = ctx->impl;
auto &dht = *ctx->impl;
/// lookup for us, send an immeidate reply
Key_t us = dht.OurKey();
Key_t k{K};
if(K == us)
{
auto path = dht.router->pathContext().GetByUpstream(K, pathID);
auto path = dht.GetRouter()->pathContext().GetByUpstream(K, pathID);
if(path)
{
replies.emplace_back(
new GotRouterMessage(k, txid, {dht.router->rc()}, false));
new GotRouterMessage(k, txid, {dht.GetRouter()->rc()}, false));
return true;
}
return false;
@ -35,13 +35,13 @@ namespace llarp
Key_t peer;
// check if we know this in our nodedb first
RouterContact found;
if(dht.router->nodedb()->Get(K, found))
if(dht.GetRouter()->nodedb()->Get(K, found))
{
replies.emplace_back(new GotRouterMessage(k, txid, {found}, false));
return true;
}
// lookup if we don't have it in our nodedb
if(dht.nodes->FindClosest(k, peer))
if(dht.Nodes()->FindClosest(k, peer))
dht.LookupRouterForPath(K, txid, pathID, peer);
return true;
}
@ -145,14 +145,14 @@ namespace llarp
llarp_dht_context *ctx,
std::vector< std::unique_ptr< IMessage > > &replies) const
{
auto &dht = ctx->impl;
if(!dht.allowTransit)
auto &dht = *ctx->impl;
if(!dht.AllowTransit())
{
llarp::LogWarn("Got DHT lookup from ", From,
" when we are not allowing dht transit");
return false;
}
if(dht.pendingRouterLookups.HasPendingLookupFrom({From, txid}))
if(dht.pendingRouterLookups().HasPendingLookupFrom({From, txid}))
{
llarp::LogWarn("Duplicate FRM from ", From, " txid=", txid);
return false;
@ -161,8 +161,9 @@ namespace llarp
Key_t k{K};
if(exploritory)
return dht.HandleExploritoryRouterLookup(From, txid, K, replies);
else if(dht.router->nodedb()->Get(K, found))
else if(dht.Nodes()->HasNode(k))
{
found = dht.Nodes()->nodes[k].rc;
replies.emplace_back(new GotRouterMessage(k, txid, {found}, false));
return true;
}

@ -25,8 +25,8 @@ namespace llarp
__attribute__((unused))
std::vector< std::unique_ptr< IMessage > > &replies) const
{
auto &dht = ctx->impl;
auto crypto = dht.router->crypto();
auto &dht = *ctx->impl;
auto crypto = dht.GetRouter()->crypto();
for(const auto &introset : I)
{
@ -40,23 +40,23 @@ namespace llarp
}
}
TXOwner owner(From, T);
auto tagLookup = dht.pendingTagLookups.GetPendingLookupFrom(owner);
auto tagLookup = dht.pendingTagLookups().GetPendingLookupFrom(owner);
if(tagLookup)
{
dht.pendingTagLookups.Found(owner, tagLookup->target, I);
dht.pendingTagLookups().Found(owner, tagLookup->target, I);
return true;
}
auto serviceLookup =
dht.pendingIntrosetLookups.GetPendingLookupFrom(owner);
dht.pendingIntrosetLookups().GetPendingLookupFrom(owner);
if(serviceLookup)
{
if(I.size())
{
dht.pendingIntrosetLookups.Found(owner, serviceLookup->target, I);
dht.pendingIntrosetLookups().Found(owner, serviceLookup->target, I);
}
else
{
dht.pendingIntrosetLookups.NotFound(owner, K);
dht.pendingIntrosetLookups().NotFound(owner, K);
}
return true;
}
@ -71,7 +71,8 @@ namespace llarp
std::vector< std::unique_ptr< IMessage > > &replies) const
{
// TODO: implement me better?
auto pathset = ctx->impl.router->pathContext().GetLocalPathSet(pathID);
auto pathset =
ctx->impl->GetRouter()->pathContext().GetLocalPathSet(pathID);
if(pathset)
{
return pathset->HandleGotIntroMessage(this);

@ -85,28 +85,29 @@ namespace llarp
__attribute__((unused))
std::vector< std::unique_ptr< IMessage > > &replies) const
{
auto &dht = ctx->impl;
auto &dht = *ctx->impl;
if(relayed)
{
auto pathset = ctx->impl.router->pathContext().GetLocalPathSet(pathID);
auto pathset =
ctx->impl->GetRouter()->pathContext().GetLocalPathSet(pathID);
return pathset && pathset->HandleGotRouterMessage(this);
}
// not relayed
TXOwner owner(From, txid);
if(dht.pendingExploreLookups.HasPendingLookupFrom(owner))
if(dht.pendingExploreLookups().HasPendingLookupFrom(owner))
{
if(N.size() == 0)
dht.pendingExploreLookups.NotFound(owner, K);
dht.pendingExploreLookups().NotFound(owner, K);
else
{
dht.pendingExploreLookups.Found(owner, From.as_array(), N);
dht.pendingExploreLookups().Found(owner, From.as_array(), N);
}
return true;
}
// not explore lookup
if(!dht.pendingRouterLookups.HasPendingLookupFrom(owner))
if(!dht.pendingRouterLookups().HasPendingLookupFrom(owner))
{
llarp::LogWarn("Unwarranted GRM from ", From, " txid=", txid);
return false;
@ -115,9 +116,9 @@ namespace llarp
llarp::LogInfo("DHT no pending lookup");
if(R.size() == 1)
dht.pendingRouterLookups.Found(owner, R[0].pubkey, {R[0]});
dht.pendingRouterLookups().Found(owner, R[0].pubkey, {R[0]});
else
dht.pendingRouterLookups.NotFound(owner, K);
dht.pendingRouterLookups().NotFound(owner, K);
return true;
}
} // namespace dht

@ -46,14 +46,14 @@ namespace llarp
llarp_dht_context *ctx,
std::vector< std::unique_ptr< IMessage > > &replies) const
{
auto now = ctx->impl.Now();
auto now = ctx->impl->Now();
if(S > 5)
{
llarp::LogWarn("invalid S value ", S, " > 5");
return false;
}
auto &dht = ctx->impl;
if(!I.Verify(dht.router->crypto(), now))
auto &dht = *ctx->impl;
if(!I.Verify(dht.Crypto(), now))
{
llarp::LogWarn("invalid introset: ", I);
// don't propogate or store
@ -63,7 +63,7 @@ namespace llarp
using namespace std::placeholders;
shorthash_func shorthash =
std::bind(&Crypto::shorthash, dht.router->crypto(), _1, _2);
std::bind(&Crypto::shorthash, dht.Crypto(), _1, _2);
if(I.W && !I.W->IsValid(shorthash, now))
{
llarp::LogWarn("proof of work not good enough for IntroSet");
@ -86,7 +86,7 @@ namespace llarp
replies.emplace_back(new GotIntroMessage({}, txID));
return true;
}
dht.services->PutNode(I);
dht.services()->PutNode(I);
replies.emplace_back(new GotIntroMessage({I}, txID));
Key_t peer;
std::set< Key_t > exclude;
@ -94,7 +94,7 @@ namespace llarp
exclude.insert(e);
exclude.insert(From);
exclude.insert(dht.OurKey());
if(S && dht.nodes->FindCloseExcluding(addr, peer, exclude))
if(S && dht.Nodes()->FindCloseExcluding(addr, peer, exclude))
{
dht.PropagateIntroSetTo(From, txID, I, peer, S - 1, exclude);
}

@ -55,12 +55,10 @@ namespace llarp
{
resultHandler(valuesFound);
}
else
{
if(whoasked.node != parent->OurKey())
parent->DHTSendTo(
whoasked.node.as_array(),
new GotRouterMessage({}, whoasked.txid, valuesFound, false));
}
new GotRouterMessage({}, whoasked.txid, valuesFound, false), false);
}
} // namespace dht
} // namespace llarp

@ -247,11 +247,10 @@ namespace llarp
{
if(questions.size())
{
hdr_fields |= flags_QR | flags_AA;
// don't allow recursion
// authorative response with recursion available
hdr_fields |= flags_QR | flags_AA | flags_RA;
// don't allow recursion on this request
hdr_fields &= ~flags_RD;
// don't advertise recurision
hdr_fields &= ~flags_RA;
const auto& question = questions[0];
if(question.qtype != qTypeAAAA)
{

@ -83,18 +83,21 @@ namespace llarp
if(expect)
{
ssize_t s = utp_writev(sock, vecs.data(), vecs.size());
if(s < 0)
return;
m_TXRate += s;
while(s > 0 && s >= static_cast< ssize_t >(vecq.front().iov_len))
size_t sz = s;
while(vecq.size() && sz >= vecq.front().iov_len)
{
s -= vecq.front().iov_len;
sz -= vecq.front().iov_len;
vecq.pop_front();
sendq.pop_front();
}
if(vecq.size())
{
auto& front = vecq.front();
front.iov_len -= s;
front.iov_base = ((byte_t*)front.iov_base) + s;
front.iov_len -= sz;
front.iov_base = ((byte_t*)front.iov_base) + sz;
}
}
}
@ -175,6 +178,7 @@ namespace llarp
PruneInboundMessages(now);
m_TXRate = 0;
m_RXRate = 0;
SendKeepAlive();
}
/// low level read
@ -1131,7 +1135,7 @@ namespace llarp
buf.underlying.cur = buf.underlying.base;
// process buffer
LogDebug("got message ", msgid, " from ", remoteAddr);
return parent->HandleMessage(this, buf.underlying);
parent->HandleMessage(this, buf.underlying);
}
return true;
}

@ -81,6 +81,6 @@ namespace llarp
result = router->SendToOrQueue(session->GetPubKey(), &reply);
}
}
return result;
return true;
}
} // namespace llarp

@ -203,10 +203,10 @@ namespace llarp
static_cast< LRCMFrameDecrypt* >(user));
// persist sessions to upstream and downstream routers until the commit
// ends
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
self->context->Router()->PersistSessionUntil(self->hop->info.upstream,
self->hop->ExpireTime());
self->context->Router()->PersistSessionUntil(
self->hop->info.downstream, self->hop->ExpireTime() + 10000);
self->context->Router()->PersistSessionUntil(
self->hop->info.upstream, self->hop->ExpireTime() + 10000);
// put hop
self->context->PutTransitHop(self->hop);
// forward to next hop
@ -221,8 +221,8 @@ namespace llarp
std::unique_ptr< LRCMFrameDecrypt > self(
static_cast< LRCMFrameDecrypt* >(user));
// persist session to downstream until path expiration
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
self->context->Router()->PersistSessionUntil(
self->hop->info.downstream, self->hop->ExpireTime() + 10000);
// put hop
self->context->PutTransitHop(self->hop);
// send path confirmation

@ -160,24 +160,26 @@ namespace llarp
IHopHandler*
PathContext::GetByUpstream(const RouterID& remote, const PathID_t& id)
{
auto own = MapGet(m_OurPaths, id,
[](__attribute__((unused)) const PathSet* s) -> bool {
// TODO: is this right?
return true;
},
[remote, id](PathSet* p) -> IHopHandler* {
return p->GetByUpstream(remote, id);
});
auto own = MapGet(
m_OurPaths, id,
[](__attribute__((unused)) const PathSet* s) -> bool {
// TODO: is this right?
return true;
},
[remote, id](PathSet* p) -> IHopHandler* {
return p->GetByUpstream(remote, id);
});
if(own)
return own;
return MapGet(m_TransitPaths, id,
[remote](const std::shared_ptr< TransitHop >& hop) -> bool {
return hop->info.upstream == remote;
},
[](const std::shared_ptr< TransitHop >& h) -> IHopHandler* {
return h.get();
});
return MapGet(
m_TransitPaths, id,
[remote](const std::shared_ptr< TransitHop >& hop) -> bool {
return hop->info.upstream == remote;
},
[](const std::shared_ptr< TransitHop >& h) -> IHopHandler* {
return h.get();
});
}
bool
@ -194,13 +196,14 @@ namespace llarp
IHopHandler*
PathContext::GetByDownstream(const RouterID& remote, const PathID_t& id)
{
return MapGet(m_TransitPaths, id,
[remote](const std::shared_ptr< TransitHop >& hop) -> bool {
return hop->info.downstream == remote;
},
[](const std::shared_ptr< TransitHop >& h) -> IHopHandler* {
return h.get();
});
return MapGet(
m_TransitPaths, id,
[remote](const std::shared_ptr< TransitHop >& hop) -> bool {
return hop->info.downstream == remote;
},
[](const std::shared_ptr< TransitHop >& h) -> IHopHandler* {
return h.get();
});
}
PathSet*

@ -129,7 +129,7 @@ namespace llarp
TransitHop::HandleDHTMessage(const llarp::dht::IMessage* msg,
AbstractRouter* r)
{
return r->dht()->impl.RelayRequestForPath(info.rxID, msg);
return r->dht()->impl->RelayRequestForPath(info.rxID, msg);
}
bool

@ -13,8 +13,9 @@ struct llarp_threadpool;
namespace llarp
{
struct Crypto;
class Logic;
struct Config;
struct Crypto;
struct RouterContact;
struct RouterID;
struct ILinkMessage;
@ -39,6 +40,11 @@ namespace llarp
struct IMessageHandler;
}
namespace service
{
struct Context;
}
struct AbstractRouter : public util::IStateful
{
virtual void
@ -90,9 +96,25 @@ namespace llarp
virtual llarp_threadpool *
diskworker() = 0;
virtual service::Context &
hiddenServiceContext() = 0;
virtual const service::Context &
hiddenServiceContext() const = 0;
virtual bool
Sign(Signature &sig, const llarp_buffer_t &buf) const = 0;
virtual bool
Configure(Config *conf) = 0;
virtual bool
Run(struct llarp_nodedb *nodedb) = 0;
/// stop running the router logic gracefully
virtual void
Stop() = 0;
virtual const byte_t *
pubkey() const = 0;
@ -102,6 +124,15 @@ namespace llarp
/// connect to N random routers
virtual void
ConnectToRandomRouters(int N) = 0;
/// inject configuration and reconfigure router
virtual bool
Reconfigure(Config *conf) = 0;
/// validate new configuration against old one
/// return true on 100% valid
/// return false if not 100% valid
virtual bool
ValidateConfig(Config *conf) const = 0;
/// called by link when a remote session has no more sessions open
virtual void

@ -196,7 +196,7 @@ namespace llarp
Router::OnSessionEstablished(RouterContact rc)
{
async_verify_RC(rc, nullptr);
LogInfo("session with ", rc.pubkey, " established");
LogInfo("session with ", RouterID(rc.pubkey), " established");
}
Router::Router(struct llarp_threadpool *_tp, struct llarp_ev_loop *__netloop,
@ -210,7 +210,7 @@ namespace llarp
, _exitContext(this)
, _dht(llarp_dht_context_new(this))
, inbound_link_msg_parser(this)
, hiddenServiceContext(this)
, _hiddenServiceContext(this)
{
// set rational defaults
this->ip4addr.sin_family = AF_INET;
@ -233,8 +233,8 @@ namespace llarp
util::StatusObject
Router::ExtractStatus() const
{
util::StatusObject obj{{"dht", _dht->impl.ExtractStatus()},
{"services", hiddenServiceContext.ExtractStatus()},
util::StatusObject obj{{"dht", _dht->impl->ExtractStatus()},
{"services", _hiddenServiceContext.ExtractStatus()},
{"exit", _exitContext.ExtractStatus()}};
std::vector< util::StatusObject > ob_links, ib_links;
std::transform(inboundLinks.begin(), inboundLinks.end(),
@ -345,9 +345,9 @@ namespace llarp
}
// we don't have the RC locally so do a dht lookup
_dht->impl.LookupRouter(remote,
std::bind(&Router::HandleDHTLookupForSendTo, this,
remote, std::placeholders::_1));
_dht->impl->LookupRouter(remote,
std::bind(&Router::HandleDHTLookupForSendTo, this,
remote, std::placeholders::_1));
return true;
}
@ -509,6 +509,7 @@ namespace llarp
static_cast< async_verify_context * >(job->user);
auto router = ctx->router;
PubKey pk(job->rc.pubkey);
router->m_Clients.insert(pk);
router->FlushOutboundFor(pk, router->GetLinkWithSessionByPubkey(pk));
delete ctx;
router->pendingVerifyRC.erase(pk);
@ -549,7 +550,7 @@ namespace llarp
router->validRouters.emplace(pk, rc);
// track valid router in dht
router->dht()->impl.nodes->PutNode(rc);
router->dht()->impl->Nodes()->PutNode(rc);
// mark success in profile
router->routerProfiling().MarkSuccess(pk);
@ -631,11 +632,11 @@ namespace llarp
}
else if(IsServiceNode() || !routerProfiling().IsBad(remote))
{
if(dht()->impl.HasRouterLookup(remote))
if(dht()->impl->HasRouterLookup(remote))
return;
LogInfo("looking up router ", remote);
// dht lookup as we don't know it
dht()->impl.LookupRouter(
dht()->impl->LookupRouter(
remote,
std::bind(&Router::HandleDHTLookupForTryEstablishTo, this, remote,
std::placeholders::_1));
@ -990,9 +991,9 @@ namespace llarp
// store it in nodedb async
async_verify_RC(newrc, nullptr);
// update dht if required
if(dht()->impl.nodes->HasNode(dht::Key_t{newrc.pubkey}))
if(dht()->impl->Nodes()->HasNode(dht::Key_t{newrc.pubkey}))
{
dht()->impl.nodes->PutNode(newrc);
dht()->impl->Nodes()->PutNode(newrc);
}
// update valid routers
{
@ -1009,9 +1010,9 @@ namespace llarp
void
Router::ServiceNodeLookupRouterWhenExpired(RouterID router)
{
dht()->impl.LookupRouter(router,
std::bind(&Router::HandleDHTLookupForExplore, this,
router, std::placeholders::_1));
dht()->impl->LookupRouter(router,
std::bind(&Router::HandleDHTLookupForExplore,
this, router, std::placeholders::_1));
}
void
@ -1039,6 +1040,7 @@ namespace llarp
}
paths.TickPaths(now);
paths.ExpirePaths(now);
{
auto itr = m_PersistingSessions.begin();
while(itr != m_PersistingSessions.end())
@ -1051,7 +1053,7 @@ namespace llarp
LogDebug("keepalive to ", itr->first);
link->KeepAliveSessionTo(itr->first);
}
else
else if(m_Clients.count(itr->first) == 0)
{
LogDebug("establish to ", itr->first);
TryEstablishTo(itr->first);
@ -1077,7 +1079,7 @@ namespace llarp
for(const auto &rc : bootstrapRCList)
{
TryConnectAsync(rc, 4);
dht()->impl.ExploreNetworkVia(dht::Key_t{rc.pubkey});
dht()->impl->ExploreNetworkVia(dht::Key_t{rc.pubkey});
}
}
else
@ -1094,7 +1096,7 @@ namespace llarp
ConnectToRandomRouters(dlt);
}
paths.BuildPaths(now);
hiddenServiceContext.Tick(now);
_hiddenServiceContext.Tick(now);
}
_exitContext.Tick(now);
if(rpcCaller)
@ -1149,9 +1151,11 @@ namespace llarp
void
Router::SessionClosed(RouterID remote)
{
__llarp_dht_remove_peer(dht(), remote.data());
dht::Key_t k(remote);
dht()->impl->Nodes()->DelNode(k);
// remove from valid routers if it's a valid router
validRouters.erase(remote);
m_Clients.erase(remote);
LogInfo("Session to ", remote, " fully closed");
}
@ -1436,7 +1440,7 @@ namespace llarp
}
LogInfo("starting hidden service context...");
if(!hiddenServiceContext.StartAll())
if(!hiddenServiceContext().StartAll())
{
LogError("Failed to start hidden service context");
return false;
@ -1506,7 +1510,7 @@ namespace llarp
{
// auto detect if we have any pre-defined endpoints
// no if we have a endpoints
if(hiddenServiceContext.hasEndpoints())
if(hiddenServiceContext().hasEndpoints())
{
LogInfo("Auto mode detected and we have endpoints");
netConfig.emplace("enabled", "false");
@ -1560,7 +1564,7 @@ namespace llarp
_stopping.store(true);
LogInfo("stopping router");
hiddenServiceContext.StopAll();
hiddenServiceContext().StopAll();
_exitContext.Stop();
if(rpcServer)
rpcServer->Stop();
@ -1730,7 +1734,7 @@ namespace llarp
++itr;
}
// add endpoint
return hiddenServiceContext.AddDefaultEndpoint(netConfig);
return hiddenServiceContext().AddDefaultEndpoint(netConfig);
}
bool
@ -1751,7 +1755,7 @@ namespace llarp
service::Config::section_t filteredConfig;
mergeHiddenServiceConfig(config.second, filteredConfig.second);
filteredConfig.first = config.first;
if(!hiddenServiceContext.AddEndpoint(filteredConfig))
if(!hiddenServiceContext().AddEndpoint(filteredConfig))
return false;
}
return true;

@ -225,7 +225,19 @@ namespace llarp
InboundMessageParser inbound_link_msg_parser;
routing::InboundMessageParser inbound_routing_msg_parser;
service::Context hiddenServiceContext;
service::Context _hiddenServiceContext;
service::Context &
hiddenServiceContext() override
{
return _hiddenServiceContext;
}
const service::Context &
hiddenServiceContext() const override
{
return _hiddenServiceContext;
}
using NetConfig_t = std::unordered_multimap< std::string, std::string >;
@ -297,6 +309,9 @@ namespace llarp
std::unordered_map< RouterID, llarp_time_t, RouterID::Hash >
m_PersistingSessions;
// RCs of connected clients
std::set< RouterID > m_Clients;
// lokinet routers from lokid, maps pubkey to when we think it will expire,
// set to max value right now
std::unordered_map< RouterID, llarp_time_t, PubKey::Hash > lokinetRouters;
@ -341,17 +356,17 @@ namespace llarp
AddHiddenService(const service::Config::section_t &config);
bool
Configure(Config *conf);
Configure(Config *conf) override;
bool
Ready();
bool
Run(struct llarp_nodedb *nodedb);
Run(struct llarp_nodedb *nodedb) override;
/// stop running the router logic gracefully
void
Stop();
Stop() override;
/// close all sessions and shutdown all links
void
@ -389,13 +404,13 @@ namespace llarp
/// inject configuration and reconfigure router
bool
Reconfigure(Config *conf);
Reconfigure(Config *conf) override;
/// validate new configuration against old one
/// return true on 100% valid
/// return false if not 100% valid
bool
ValidateConfig(Config *conf) const;
ValidateConfig(Config *conf) const override;
/// send to remote router or queue for sending
/// returns false on overflow

@ -82,6 +82,15 @@ namespace llarp
{
}
struct Hash
{
size_t
operator()(const RouterContact &r) const
{
return PubKey::Hash()(r.pubkey);
}
};
// advertised addresses
std::vector< AddressInfo > addrs;
// network identifier

@ -5,17 +5,13 @@
#include <router_id.hpp>
#include <exit/context.hpp>
#ifdef USE_ABYSS
#include <util/encode.hpp>
#include <libabyss.hpp>
#endif
namespace llarp
{
namespace rpc
{
#ifdef USE_ABYSS
struct CallerHandler : public ::abyss::http::IRPCClientHandler
{
CallerImpl* m_Parent;
@ -341,57 +337,6 @@ namespace llarp
(const sockaddr*)&saddr);
}
};
#else
struct ServerImpl
{
ServerImpl(__attribute__((unused)) AbstractRouter* r){};
bool
Start(__attribute__((unused)) const std::string& addr)
{
return true;
}
void
Stop()
{
}
};
struct CallerImpl
{
CallerImpl(__attribute__((unused)) AbstractRouter* r)
{
}
~CallerImpl()
{
}
bool
Start(const std::string&)
{
return true;
}
void
Stop()
{
}
void
Tick(llarp_time_t now)
{
(void)now;
}
void
SetBasicAuth(const std::string&, const std::string&)
{
}
};
#endif
Caller::Caller(AbstractRouter* r)
: m_Impl(std::make_unique< CallerImpl >(r))

@ -195,6 +195,12 @@ namespace llarp
{
RegenAndPublishIntroSet(now);
}
else if(NumInStatus(llarp::path::ePathEstablished) < 3)
{
if(m_IntroSet.HasExpiredIntros(now))
ManualRebuild(1);
}
// expire snode sessions
{
auto itr = m_SNodeSessions.begin();
@ -688,7 +694,16 @@ namespace llarp
void
Endpoint::IntroSetPublishFail()
{
// TODO: linear backoff
auto now = Now();
if(ShouldPublishDescriptors(now))
{
RegenAndPublishIntroSet(now);
}
else if(NumInStatus(llarp::path::ePathEstablished) < 3)
{
if(m_IntroSet.HasExpiredIntros(now))
ManualRebuild(1);
}
}
bool
@ -1144,29 +1159,7 @@ namespace llarp
Endpoint::OutboundContext::SwapIntros()
{
remoteIntro = m_NextIntro;
// prepare next intro
auto now = Now();
for(const auto& intro : currentIntroSet.I)
{
if(intro.ExpiresSoon(now))
continue;
if(m_BadIntros.find(intro) == m_BadIntros.end()
&& remoteIntro.router == intro.router)
{
m_NextIntro = intro;
return;
}
}
for(const auto& intro : currentIntroSet.I)
{
if(intro.ExpiresSoon(now))
continue;
if(m_BadIntros.find(intro) == m_BadIntros.end())
{
m_NextIntro = intro;
return;
}
}
m_DataHandler->PutIntroFor(currentConvoTag, remoteIntro);
}
bool
@ -1335,12 +1328,13 @@ namespace llarp
}
}
// no converstation
return EnsurePathToService(remote,
[](Address, OutboundContext* c) {
if(c)
c->UpdateIntroSet(true);
},
5000, false);
return EnsurePathToService(
remote,
[](Address, OutboundContext* c) {
if(c)
c->UpdateIntroSet(true);
},
5000, false);
}
bool
@ -1619,6 +1613,7 @@ namespace llarp
path = m_Endpoint->GetPathByRouter(remoteIntro.router);
if(path == nullptr)
{
BuildOneAlignedTo(remoteIntro.router);
llarp::LogWarn(Name(), " dropping intro frame, no path to ",
remoteIntro.router);
return;
@ -1648,13 +1643,13 @@ namespace llarp
path = m_Endpoint->GetPathByRouter(remoteIntro.router);
if(path)
{
++sequenceNo;
routing::PathTransferMessage transfer(msg, remoteIntro.pathID);
if(path->SendRoutingMessage(&transfer, m_Endpoint->Router()))
{
llarp::LogDebug("sent data to ", remoteIntro.pathID, " on ",
remoteIntro.router);
lastGoodSend = m_Endpoint->Now();
++sequenceNo;
return true;
}
else

@ -1,6 +1,8 @@
#include <util/bencode.h>
#include <util/logger.hpp>
#include <cstdlib>
#include <inttypes.h>
#include <stdio.h>
bool
bencode_read_integer(struct llarp_buffer_t* buffer, uint64_t* result)
@ -73,10 +75,22 @@ bencode_write_bytestring(llarp_buffer_t* buff, const void* data, size_t sz)
bool
bencode_write_uint64(llarp_buffer_t* buff, uint64_t i)
{
std::string str = "i";
str += std::to_string(i);
str += "e";
return buff->write(str.begin(), str.end());
#ifndef __LP64__
if(!buff->writef("i%llu", i))
#else
#if(__APPLE__ && __MACH__)
if(!buff->writef("i%llu", i))
#else
if(!buff->writef("i%lu", i))
#endif
#endif
{
return false;
}
static const char letter[1] = {'e'};
assert(std::distance(std::begin(letter), std::end(letter)) == 1);
return buff->write(std::begin(letter), std::end(letter));
}
bool

@ -80,9 +80,9 @@ namespace llarp
Base32Encode(const V& value, Stack& stack)
{
size_t ret = 0, pos = 1;
int bits = 8;
int bits = 8;
uint32_t tmp = value[0];
size_t len = value.size();
size_t len = value.size();
while(ret < sizeof(stack) && (bits > 0 || pos < len))
{
if(bits < 5)

@ -6,20 +6,14 @@ namespace llarp
{
StatusObject::StatusObject(const StatusObject& other)
{
#ifdef USE_ABYSS
Impl.SetObject();
auto& a = Impl.GetAllocator();
Impl.CopyFrom(other.Impl, a);
#else
(void)other;
#endif
}
StatusObject::~StatusObject()
{
#ifdef USE_ABYSS
Impl.RemoveAllMembers();
#endif
}
void
@ -48,39 +42,28 @@ namespace llarp
void
StatusObject::PutBool(String_t name, bool val)
{
#ifdef USE_ABYSS
auto& a = Impl.GetAllocator();
Value_t v;
v.SetBool(val);
auto s = llarp::string_view_string(name);
Value_t k(s.c_str(), a);
Impl.AddMember(k, v, a);
#else
(void)name;
(void)val;
#endif
}
void
StatusObject::PutInt(String_t name, uint64_t val)
{
#ifdef USE_ABYSS
auto& a = Impl.GetAllocator();
Value_t v;
v.SetUint64(val);
auto s = llarp::string_view_string(name);
Value_t k(s.c_str(), a);
Impl.AddMember(k, v, a);
#else
(void)name;
(void)val;
#endif
}
void
StatusObject::PutObject(String_t name, const StatusObject& val)
{
#ifdef USE_ABYSS
auto& a = Impl.GetAllocator();
Value_t v;
v.SetObject();
@ -88,17 +71,12 @@ namespace llarp
auto s = llarp::string_view_string(name);
Value_t k(s.c_str(), a);
Impl.AddMember(k, v, a);
#else
(void)name;
(void)val;
#endif
}
void
StatusObject::PutObjectArray(String_t name,
const std::vector< StatusObject >& arr)
{
#ifdef USE_ABYSS
auto& a = Impl.GetAllocator();
Value_t v;
v.SetArray();
@ -110,17 +88,12 @@ namespace llarp
auto s = llarp::string_view_string(name);
Value_t k(s.c_str(), a);
Impl.AddMember(k, v, a);
#else
(void)name;
(void)arr;
#endif
}
void
StatusObject::PutStringArray(String_t name,
const std::vector< std::string >& arr)
{
#ifdef USE_ABYSS
auto& a = Impl.GetAllocator();
Value_t v;
v.SetArray();
@ -132,26 +105,17 @@ namespace llarp
auto s = llarp::string_view_string(name);
Value_t k(s.c_str(), a);
Impl.AddMember(k, v, a);
#else
(void)name;
(void)arr;
#endif
}
void
StatusObject::PutString(String_t name, const std::string& val)
{
#ifdef USE_ABYSS
auto& a = Impl.GetAllocator();
Value_t v;
v.SetString(val.c_str(), a);
auto s = llarp::string_view_string(name);
Value_t k(s.c_str(), a);
Impl.AddMember(k, v, a);
#else
(void)name;
(void)val;
#endif
}
} // namespace util
} // namespace llarp

@ -1,9 +1,9 @@
#ifndef LLARP_UTIL_STATUS_HPP
#define LLARP_UTIL_STATUS_HPP
#ifdef USE_ABYSS
#include <util/json.hpp>
#endif
#include <util/string_view.hpp>
#include <vector>
#include <string>
#include <algorithm>
@ -13,17 +13,8 @@ namespace llarp
{
namespace util
{
#ifdef USE_ABYSS
using StatusObject_Impl = json::Document;
using Value_t = json::Value;
#else
struct StatusObject_Impl
{
};
struct Value_t
{
};
#endif
struct StatusObject
{
@ -38,9 +29,7 @@ namespace llarp
StatusObject(std::initializer_list< value_type > vals)
{
#ifdef USE_ABYSS
Impl.SetObject();
#endif
std::for_each(vals.begin(), vals.end(),
[&](const value_type& item) { Put(item); });
}

@ -16,8 +16,8 @@ struct llarp_threadpool
std::queue< std::function< void(void) > > jobs;
llarp_threadpool(int workers, const char *name)
: impl(std::make_unique< llarp::thread::ThreadPool >(workers,
workers * 128))
: impl(
std::make_unique< llarp::thread::ThreadPool >(workers, workers * 128))
{
(void)name;
}

@ -49,7 +49,7 @@ install (root):
build (where `$ARCH` is your platform - `i686` or `x86_64`):
$ pacman -Sy base-devel mingw-w64-$ARCH-toolchain git libtool autoconf mingw-w64-$ARCH-cmake
$ pacman -Sy base-devel mingw-w64-$ARCH-toolchain git libtool autoconf mingw-w64-$ARCH-cmake mingw-w64-$ARCH-rapidjson
$ git clone https://github.com/loki-project/loki-network.git
$ cd loki-network
$ mkdir -p build; cd build

@ -23,6 +23,7 @@ list(APPEND TEST_SRC
routing/test_llarp_routing_obtainexitmessage.cpp
service/test_llarp_service_address.cpp
service/test_llarp_service_identity.cpp
test_libabyss.cpp
test_llarp_dns.cpp
test_llarp_dnsd.cpp
test_llarp_encrypted_frame.cpp
@ -57,9 +58,3 @@ else()
target_sources(${TEST_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/win32/test.rc")
target_link_libraries(${TEST_EXE} PUBLIC ws2_32 iphlpapi)
endif(NOT WIN32)
if(USE_LIBABYSS)
target_sources(${TEST_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/test_libabyss.cpp")
target_link_libraries(${TEST_EXE} PUBLIC ${ABYSS_LIB})
endif()

@ -27,16 +27,87 @@ namespace llarp
std::set< service::IntroSet >(const service::Tag&, size_t,
const std::set< service::IntroSet >&));
MOCK_CONST_METHOD1(HasRouterLookup, bool(const RouterID& target));
MOCK_METHOD5(LookupTagRecursive,
void(const service::Tag&, const dht::Key_t&, uint64_t,
const dht::Key_t&, uint64_t));
MOCK_METHOD4(LookupTagForPath,
void(const service::Tag&, uint64_t, const PathID_t&,
const dht::Key_t&));
MOCK_METHOD4(LookupRouterForPath,
void(const RouterID& target, uint64_t txid,
const PathID_t& path, const dht::Key_t& askpeer));
MOCK_METHOD4(LookupIntroSetForPath,
void(const service::Address&, uint64_t, const PathID_t&,
const dht::Key_t&));
MOCK_METHOD3(DHTSendTo, void(const RouterID&, dht::IMessage*, bool));
MOCK_METHOD4(
HandleExploritoryRouterLookup,
bool(const dht::Key_t& requester, uint64_t txid,
const RouterID& target,
std::vector< std::unique_ptr< dht::IMessage > >& reply));
MOCK_METHOD5(
LookupRouterRelayed,
void(const dht::Key_t& requester, uint64_t txid,
const dht::Key_t& target, bool recursive,
std::vector< std::unique_ptr< dht::IMessage > >& replies));
MOCK_METHOD2(RelayRequestForPath,
bool(const PathID_t& localPath, const dht::IMessage* msg));
MOCK_METHOD6(PropagateIntroSetTo,
void(const dht::Key_t& source, uint64_t sourceTX,
const service::IntroSet& introset,
const dht::Key_t& peer, uint64_t S,
const std::set< dht::Key_t >& exclude));
MOCK_METHOD3(Init,
void(const dht::Key_t&, AbstractRouter*, llarp_time_t));
MOCK_CONST_METHOD1(
GetIntroSetByServiceAddress,
const llarp::service::IntroSet*(const llarp::service::Address&));
MOCK_CONST_METHOD0(ExtractStatus, util::StatusObject());
MOCK_CONST_METHOD0(Now, llarp_time_t());
MOCK_METHOD1(ExploreNetworkVia, void(const dht::Key_t& peer));
MOCK_CONST_METHOD0(Crypto, llarp::Crypto*());
MOCK_CONST_METHOD0(GetRouter, llarp::AbstractRouter*());
MOCK_CONST_METHOD0(OurKey, const dht::Key_t&());
MOCK_CONST_METHOD0(pendingIntrosetLookups,
const PendingIntrosetLookups&());
MOCK_METHOD0(pendingIntrosetLookups, PendingIntrosetLookups&());
MOCK_METHOD0(pendingTagLookups, PendingTagLookups&());
MOCK_CONST_METHOD0(pendingTagLookups, const PendingTagLookups&());
MOCK_METHOD0(pendingRouterLookups, PendingRouterLookups&());
MOCK_CONST_METHOD0(pendingRouterLookups, const PendingRouterLookups&());
MOCK_METHOD0(pendingExploreLookups, PendingExploreLookups&());
MOCK_CONST_METHOD0(pendingExploreLookups, const PendingExploreLookups&());
MOCK_METHOD0(services, dht::Bucket< dht::ISNode >*());
MOCK_CONST_METHOD0(AllowTransit, const bool&());
MOCK_METHOD0(AllowTransit, bool&());
MOCK_CONST_METHOD0(Nodes, dht::Bucket< dht::RCNode >*());
};

Loading…
Cancel
Save