1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

more agressive network exploration

add install target for makefile
This commit is contained in:
Jeff Becker 2018-09-15 07:37:46 -04:00
parent dd6a8360ba
commit 7027ba2cf1
No known key found for this signature in database
GPG key ID: F357B3B42F6F9B05
4 changed files with 42 additions and 11 deletions

View file

@ -5,6 +5,8 @@ SIGN = gpg --sign --detach
REPO := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PREFIX ?= /usr/local
CC ?= cc
CXX ?= c++
@ -105,3 +107,9 @@ test: debug
format:
clang-format -i $$(find daemon llarp include | grep -E '\.[h,c](pp)?$$')
install:
rm -f $(PREFIX)/bin/lokinet
cp $(EXE) $(PREFIX)/bin/lokinet
chmod 755 $(PREFIX)/bin/lokinet
setcap cap_net_admin=+eip $(PREFIX)/bin/lokinet

View file

@ -150,7 +150,12 @@ namespace llarp
{
lock_t lock(m_ProfilesMutex);
m_Profiles.clear();
return BDecodeReadFile(fname, *this);
if(!BDecodeReadFile(fname, *this))
{
llarp::LogWarn("failed to load router profiles from ", fname);
return false;
}
return true;
}
} // namespace llarp

View file

@ -52,12 +52,22 @@ struct TryConnectJob
void
AttemptTimedout()
{
router->routerProfiling.MarkTimeout(rc.pubkey);
if(ShouldRetry())
{
Attempt();
return;
}
if(router->routerProfiling.IsBad(rc.pubkey))
llarp_nodedb_del_rc(router->nodedb, rc.pubkey);
// delete this
router->pendingEstablishJobs.erase(rc.pubkey);
}
void
Attempt()
{
--triesLeft;
link->TryEstablishTo(rc);
}
@ -383,9 +393,11 @@ llarp_router::TryEstablishTo(const llarp::RouterID &remote)
void
llarp_router::OnConnectTimeout(const llarp::RouterID &remote)
{
routerProfiling.MarkTimeout(remote);
if(routerProfiling.IsBad(remote))
llarp_nodedb_del_rc(nodedb, remote);
auto itr = pendingEstablishJobs.find(remote);
if(itr != pendingEstablishJobs.end())
{
itr->second->AttemptTimedout();
}
}
void
@ -394,7 +406,7 @@ llarp_router::HandleDHTLookupForTryEstablishTo(
{
if(results.size() == 0)
{
OnConnectTimeout(remote);
routerProfiling.MarkTimeout(remote);
}
for(const auto &result : results)
{
@ -448,17 +460,17 @@ llarp_router::Tick()
if(inboundLinks.size() == 0)
{
auto N = llarp_nodedb_num_loaded(nodedb);
if(N < 4)
if(N < minRequiredRouters)
{
llarp::LogInfo(
"We need at least 4 service nodes to build paths but we have ", N);
llarp::LogInfo("We need at least ", minRequiredRouters,
" service nodes to build paths but we have ", N);
auto explore = std::max(NumberOfConnectedRouters(), 1UL);
dht->impl.Explore(explore);
}
paths.BuildPaths();
hiddenServiceContext.Tick();
}
else if(NumberOfConnectedRouters() < minConnectedRouters)
if(NumberOfConnectedRouters() < minConnectedRouters)
{
ConnectToRandomRouters(minConnectedRouters);
}
@ -762,8 +774,9 @@ llarp_router::HasSessionTo(const llarp::RouterID &remote) const
}
void
llarp_router::ConnectToRandomRouters(size_t want)
llarp_router::ConnectToRandomRouters(int want)
{
int wanted = want;
llarp_router *self = this;
llarp_nodedb_visit_loaded(
self->nodedb, [self, &want](const llarp::RouterContact &other) -> bool {
@ -776,6 +789,9 @@ llarp_router::ConnectToRandomRouters(size_t want)
}
return want > 0;
});
llarp::LogInfo("connecting to ", abs(want - wanted), " out of ", wanted,
" random routers");
}
bool

View file

@ -81,6 +81,8 @@ struct llarp_router
/// hard upperbound limit on the number of router to router connections
size_t maxConnectedRouters = 2000;
int minRequiredRouters = 4;
// should we be sending padded messages every interval?
bool sendPadding = false;
@ -226,7 +228,7 @@ struct llarp_router
GetLinkWithSessionByPubkey(const llarp::RouterID &remote);
void
ConnectToRandomRouters(size_t N);
ConnectToRandomRouters(int N);
size_t
NumberOfConnectedRouters() const;