Skip to content

Commit a288917

Browse files
authored
Merge pull request #1 from dr7ana/liblokinet-cherrypick
Merging cherry-picks back to testnet branch: - oxen-io#2164 - oxen-io#2134
2 parents 74e0fc2 + aea631b commit a288917

File tree

7 files changed

+37
-13
lines changed

7 files changed

+37
-13
lines changed

llarp/iwp/session.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ namespace llarp
144144
void
145145
Session::EncryptAndSend(ILinkSession::Packet_t data)
146146
{
147+
if (m_State == State::Closed)
148+
return;
147149
m_EncryptNext.emplace_back(std::move(data));
148150
TriggerPump();
149151
if (!IsEstablished())
@@ -179,12 +181,9 @@ namespace llarp
179181
return;
180182
auto close_msg = CreatePacket(Command::eCLOS, 0, 16, 16);
181183
m_Parent->UnmapAddr(m_RemoteAddr);
182-
m_State = State::Closed;
183-
if (m_SentClosed.test_and_set())
184-
return;
185184
EncryptAndSend(std::move(close_msg));
186-
187185
LogInfo(m_Parent->PrintableName(), " closing connection to ", m_RemoteAddr);
186+
m_State = State::Closed;
188187
}
189188

190189
bool
@@ -355,7 +354,7 @@ namespace llarp
355354
bool
356355
Session::TimedOut(llarp_time_t now) const
357356
{
358-
if (m_State == State::Ready)
357+
if (m_State == State::Ready || m_State == State::LinkIntro)
359358
{
360359
return now > m_LastRX
361360
&& now - m_LastRX

llarp/iwp/session.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ namespace llarp
206206

207207
std::atomic_flag m_PlaintextEmpty;
208208
llarp::thread::Queue<CryptoQueue_t> m_PlaintextRecv;
209-
std::atomic_flag m_SentClosed;
210209

211210
void
212211
EncryptWorker(CryptoQueue_t msgs);

llarp/lokinet_shared.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,7 @@ extern "C"
715715
return;
716716
}
717717

718-
auto on_open = [ctx, localAddr, remote, open_cb](
719-
bool success, void* user_data) {
718+
auto on_open = [ctx, localAddr, remote, open_cb](bool success, void* user_data) {
720719
llarp::log::info(
721720
logcat,
722721
"Quic tunnel {}<->{}.",

llarp/quic/endpoint.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,13 @@ namespace llarp::quic
298298
ngtcp2_pkt_info pi;
299299

300300
auto written = ngtcp2_conn_write_connection_close(
301-
conn, &conn.path.path, &pi, u8data(conn.conn_buffer), conn.conn_buffer.size(), &err, get_timestamp());
301+
conn,
302+
&conn.path.path,
303+
&pi,
304+
u8data(conn.conn_buffer),
305+
conn.conn_buffer.size(),
306+
&err,
307+
get_timestamp());
302308
if (written <= 0)
303309
{
304310
log::warning(

llarp/quic/tunnel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ namespace llarp::quic
135135
log::info(logcat, "EOF on connection to {}:{}", c.peer().ip, c.peer().port);
136136
if (auto stream = c.data<Stream>())
137137
{
138-
stream->set_eof(); // CloseEvent will send graceful shutdown to other end
138+
stream->set_eof(); // CloseEvent will send graceful shutdown to other end
139139
}
140140
c.close();
141141
});

llarp/router/router.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,23 @@ namespace llarp
7272
_lastTick = llarp::time_now_ms();
7373
m_NextExploreAt = Clock_t::now();
7474
m_Pump = _loop->make_waker([this]() { PumpLL(); });
75+
m_Work = _loop->make_waker([this]() { submit_work(); });
7576
}
7677

7778
Router::~Router()
7879
{
7980
llarp_dht_context_free(_dht);
8081
}
8182

83+
void
84+
Router::submit_work()
85+
{
86+
m_lmq->job([work = std::move(m_WorkJobs)]() {
87+
for (const auto& job : work)
88+
job();
89+
});
90+
}
91+
8292
void
8393
Router::PumpLL()
8494
{
@@ -482,8 +492,8 @@ namespace llarp
482492
LogError("RC is invalid, not saving");
483493
return false;
484494
}
485-
if (m_isServiceNode)
486-
_nodedb->Put(_rc);
495+
if (IsServiceNode())
496+
_nodedb->Put(rc());
487497
QueueDiskIO([&]() { HandleSaveRC(); });
488498
return true;
489499
}
@@ -1631,7 +1641,10 @@ namespace llarp
16311641
void
16321642
Router::QueueWork(std::function<void(void)> func)
16331643
{
1634-
m_lmq->job(std::move(func));
1644+
_loop->call([this, func = std::move(func)]() mutable {
1645+
m_WorkJobs.push_back(std::move(func));
1646+
m_Work->Trigger();
1647+
});
16351648
}
16361649

16371650
void

llarp/router/router.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ namespace llarp
7878
path::BuildLimiter m_PathBuildLimiter;
7979

8080
std::shared_ptr<EventLoopWakeup> m_Pump;
81+
std::shared_ptr<EventLoopWakeup> m_Work;
82+
std::vector<std::function<void()>> m_WorkJobs;
83+
84+
/// submits cpu heavy work from last event loop tick cycle to worker threads.
85+
void
86+
submit_work();
8187

8288
path::BuildLimiter&
8389
pathBuildLimiter() override
@@ -196,9 +202,11 @@ namespace llarp
196202
return _vpnPlatform.get();
197203
}
198204

205+
/// queue functionally pure cpu heavy work to be done in another thread.
199206
void
200207
QueueWork(std::function<void(void)> func) override;
201208

209+
/// queue disk io bound work to be done in the disk io thread.
202210
void
203211
QueueDiskIO(std::function<void(void)> func) override;
204212

0 commit comments

Comments
 (0)