pull/440/head
Jeff Becker 5 years ago
parent 0fa8325e4e
commit d4cb6808ec
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -185,9 +185,9 @@ namespace abyss
&& m_Request["params"].is_object())
{
nlohmann::json response;
response["jsonrpc"] = "2.0";
response["id"] = m_Request["id"];
auto value = handler->HandleJSONRPC(
response["jsonrpc"] = "2.0";
response["id"] = m_Request["id"];
auto value = handler->HandleJSONRPC(
m_Request["method"].get< std::string >(),
m_Request["params"]);
if(value)

@ -365,6 +365,7 @@ namespace llarp
{
if(tcp.closed)
tcp.closed(&tcp);
::shutdown(fd, SHUT_RDWR);
return false;
}
else if(tcp.tick)

@ -88,10 +88,11 @@ namespace llarp
llarp::LogWarn("no udp set");
return;
}
const llarp::Addr srcaddr(*from);
// maybe check from too?
// no it's never null
static_cast< ILinkLayer* >(udp->user)->RecvFrom(
*from, buf.underlying.base, buf.underlying.sz);
srcaddr, buf.underlying.base, buf.underlying.sz);
}
void

@ -521,9 +521,6 @@ llarp_nodedb::select_random_hop_excluding(
const size_t sz = entries.size();
if(sz < 3)
{
llarp::LogWarn(
"we don't have enough entries in nodedb to select hop, have ", sz,
" need ", 3);
return false;
}
llarp_time_t now = llarp::time_now_ms();

@ -562,6 +562,7 @@ namespace llarp
m_LastLatencyTestID = latency.T;
m_LastLatencyTestTime = now;
SendRoutingMessage(&latency, r);
return;
}
if(SupportsAnyRoles(ePathRoleExit | ePathRoleSVC))
{
@ -591,7 +592,7 @@ namespace llarp
EnterState(ePathTimeout, now);
}
}
else if(dlt >= 10000 && m_LastRecvMessage == 0)
else if(dlt >= PATH_ALIVE_TIMEOUT && m_LastRecvMessage == 0)
{
r->routerProfiling().MarkPathFail(this);
EnterState(ePathTimeout, now);
@ -650,7 +651,10 @@ namespace llarp
n ^= hop.nonceXOR;
r->crypto()->xchacha20(buf, hop.shared, n);
}
return HandleRoutingMessage(buf, r);
if(!HandleRoutingMessage(buf, r))
return false;
m_LastRecvMessage = r->Now();
return true;
}
bool
@ -661,7 +665,6 @@ namespace llarp
LogWarn("Failed to parse inbound routing message");
return false;
}
m_LastRecvMessage = r->Now();
return true;
}
@ -795,10 +798,10 @@ namespace llarp
bool
Path::HandleDHTMessage(const dht::IMessage* msg, AbstractRouter* r)
{
MarkActive(r->Now());
routing::DHTMessage reply;
if(!msg->HandleMessage(r->dht(), reply.M))
return false;
MarkActive(r->Now());
if(reply.M.size())
return SendRoutingMessage(&reply, r);
return true;

@ -28,7 +28,7 @@
#define DEFAULT_PATH_LIFETIME (10 * 60 * 1000)
#define PATH_BUILD_TIMEOUT (15 * 1000)
#define MESSAGE_PAD_SIZE (128)
#define PATH_ALIVE_TIMEOUT (30 * 1000)
#define PATH_ALIVE_TIMEOUT (60 * 1000)
namespace llarp
{

@ -127,9 +127,10 @@ namespace llarp
Profiling::MarkPathSuccess(path::Path* p)
{
lock_t lock(&m_ProfilesMutex);
const auto sz = p->hops.size();
for(const auto& hop : p->hops)
{
m_Profiles[hop.rc.pubkey].pathSuccessCount += 1;
m_Profiles[hop.rc.pubkey].pathSuccessCount += sz;
m_Profiles[hop.rc.pubkey].lastUpdated = llarp::time_now_ms();
}
}
@ -151,6 +152,7 @@ namespace llarp
if(f.is_open())
{
f.write((char*)buf.base, buf.sz);
m_LastSave = llarp::time_now_ms();
}
}
return res;
@ -206,4 +208,10 @@ namespace llarp
return true;
}
bool
Profiling::ShouldSave(llarp_time_t now) const
{
auto dlt = now - m_LastSave;
return dlt > 60000;
}
} // namespace llarp

@ -84,6 +84,9 @@ namespace llarp
bool
Save(const char* fname) LOCKS_EXCLUDED(m_ProfilesMutex);
bool
ShouldSave(llarp_time_t now) const;
private:
bool
BEncodeNoLock(llarp_buffer_t* buf) const
@ -91,6 +94,7 @@ namespace llarp
using lock_t = util::Lock;
mutable util::Mutex m_ProfilesMutex; // protects m_Profiles
std::map< RouterID, RouterProfile > m_Profiles GUARDED_BY(m_ProfilesMutex);
llarp_time_t m_LastSave = 0;
};
} // namespace llarp

@ -471,6 +471,15 @@ namespace llarp
return outboundLinks.size() > 0;
}
/// called in disk worker thread
static void
HandleSaveRC(void *u)
{
Router *self = static_cast< Router * >(u);
std::string fname = self->our_rc_file.string();
self->_rc.Write(fname.c_str());
}
bool
Router::SaveRC()
{
@ -481,8 +490,8 @@ namespace llarp
LogError("RC is invalid, not saving");
return false;
}
std::string fname = our_rc_file.string();
return _rc.Write(fname.c_str());
llarp_threadpool_queue_job(diskworker(), {this, &HandleSaveRC});
return true;
}
bool
@ -692,6 +701,7 @@ namespace llarp
{
crypto()->encryption_keygen(nextOnionKey);
std::string f = encryption_keyfile.string();
// TODO: use disk worker
if(nextOnionKey.SaveToFile(f.c_str()))
{
nextRC.enckey = seckey_topublic(nextOnionKey);
@ -710,9 +720,8 @@ namespace llarp
LogWarn("failed to renegotiate session");
});
// TODO: do this async
return SaveRC();
} // namespace llarp
}
void
Router::router_iter_config(const char *section, const char *key,
@ -1112,6 +1121,16 @@ namespace llarp
_exitContext.Tick(now);
if(rpcCaller)
rpcCaller->Tick(now);
// save profiles async
if(routerProfiling().ShouldSave(now))
{
llarp_threadpool_queue_job(
diskworker(),
{this, [](void *u) {
Router *self = static_cast< Router * >(u);
self->routerProfiling().Save(self->routerProfilesFile.c_str());
}});
}
}
bool

Loading…
Cancel
Save