From 6825cc0eec05a888baec1842a087acbb4123a449 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 27 Dec 2018 14:10:38 -0500 Subject: [PATCH] fix crashes --- llarp/link/server.cpp | 7 ++++--- llarp/link/utp.cpp | 21 ++++++++++----------- llarp/threadpool.cpp | 3 ++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/llarp/link/server.cpp b/llarp/link/server.cpp index 612f9c648..b9e85af29 100644 --- a/llarp/link/server.cpp +++ b/llarp/link/server.cpp @@ -93,7 +93,7 @@ namespace llarp auto itr = m_AuthedLinks.begin(); while(itr != m_AuthedLinks.end()) { - if(!itr->second->TimedOut(_now)) + if(itr->second.get() && !itr->second->TimedOut(_now)) { itr->second->Pump(); ++itr; @@ -112,7 +112,7 @@ namespace llarp auto itr = m_Pending.begin(); while(itr != m_Pending.end()) { - if(!(*itr)->TimedOut(_now)) + if(itr->get() && !(*itr)->TimedOut(_now)) { (*itr)->Pump(); ++itr; @@ -324,7 +324,8 @@ namespace llarp void ILinkLayer::OnTick(uint64_t interval) { - Tick(Now()); + auto now = Now(); + Tick(now); ScheduleTick(interval); } diff --git a/llarp/link/utp.cpp b/llarp/link/utp.cpp index e9be9f047..363fb0a18 100644 --- a/llarp/link/utp.cpp +++ b/llarp/link/utp.cpp @@ -706,6 +706,9 @@ namespace llarp llarp::LogDebug("Sent reply LIM"); gotLIM = true; EnterState(eSessionReady); + /// future LIM are used for session renegotiation + GotLIM = std::bind(&Session::GotSessionRenegotiate, this, + std::placeholders::_1); } return true; } @@ -749,6 +752,8 @@ namespace llarp return false; } EnterState(eSessionReady); + /// future LIM are used for session renegotiation + GotLIM = std::bind(&Session::GotSessionRenegotiate, this,std::placeholders::_1); return true; } @@ -944,9 +949,6 @@ namespace llarp { parent->MapAddr(remoteRC.pubkey.data(), this); parent->SessionEstablished(remoteRC); - /// future LIM are used for session renegotiation - GotLIM = std::bind(&Session::GotSessionRenegotiate, this, - std::placeholders::_1); } } @@ -1066,17 +1068,17 @@ namespace llarp llarp::LogError("inbound buffer is full"); return false; // not enough room } - // determine if this message is done - bool result = true; // mutate key if(!MutateKey(rxKey, A)) { llarp::LogError("failed to mutate rx key"); return false; } - + if(remaining == 0) { + // we done with this guy, prune next tick + itr->second.lastActive = 0; llarp_buffer_t buf = itr->second.buffer; // resize buf.sz = buf.cur - buf.base; @@ -1084,12 +1086,9 @@ namespace llarp buf.cur = buf.base; // process buffer llarp::LogDebug("got message ", msgid, " from ", remoteAddr); - result = parent->HandleMessage(this, buf); - // get rid of message buffer - if(result) - m_RecvMsgs.erase(itr->first); + return parent->HandleMessage(this, buf); } - return result; + return true; } void diff --git a/llarp/threadpool.cpp b/llarp/threadpool.cpp index bf7cd2722..ae9dfa026 100644 --- a/llarp/threadpool.cpp +++ b/llarp/threadpool.cpp @@ -97,7 +97,8 @@ llarp_threadpool_tick(struct llarp_threadpool *pool) job = std::move(pool->jobs.front()); pool->jobs.pop(); } - job(); + if(job) + job(); } }