Merge pull request #1865 from majestrate/proto-fix-2022-03-06

fix wire protocol race condition
This commit is contained in:
majestrate 2022-03-07 15:55:43 -05:00 committed by GitHub
commit 27d883157d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View File

@ -174,7 +174,10 @@ namespace llarp
if (m_State == State::Ready)
m_Parent->UnmapAddr(m_RemoteAddr);
m_State = State::Closed;
if (m_SentClosed.test_and_set())
return;
EncryptAndSend(std::move(close_msg));
LogInfo(m_Parent->PrintableName(), " closing connection to ", m_RemoteAddr);
}
@ -338,7 +341,7 @@ namespace llarp
bool
Session::TimedOut(llarp_time_t now) const
{
if (m_State == State::Ready || m_State == State::LinkIntro)
if (m_State == State::Ready)
{
return now > m_LastRX
&& now - m_LastRX

View File

@ -203,6 +203,7 @@ namespace llarp
std::atomic_flag m_PlaintextEmpty;
llarp::thread::Queue<CryptoQueue_t> m_PlaintextRecv;
std::atomic_flag m_SentClosed;
void
EncryptWorker(CryptoQueue_t msgs);

View File

@ -443,6 +443,8 @@ namespace llarp
LogError("RC is invalid, not saving");
return false;
}
if (m_isServiceNode)
_nodedb->Put(_rc);
QueueDiskIO([&]() { HandleSaveRC(); });
return true;
}