Skip to content

Commit 12509d0

Browse files
committed
net: Add setTotalBytes functionality for traffic data persistence
Add functions to set total bytes sent/received counts to enable restoring traffic statistics between application sessions. This allows for continuous traffic monitoring even after application restarts, improving the usefulness of the traffic graph widget.
1 parent 5f82566 commit 12509d0

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/interfaces/node.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ class Node
160160

161161
virtual CTxMemPool& mempool() = 0;
162162

163+
//! Set total bytes recv
164+
virtual void setTotalBytesRecv(uint64_t bytes) = 0;
165+
166+
//! Set total bytes sent
167+
virtual void setTotalBytesSent(uint64_t bytes) = 0;
168+
163169
//! Get mempool size.
164170
virtual size_t getMempoolSize() = 0;
165171

src/net.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3778,6 +3778,14 @@ uint64_t CConnman::GetTotalBytesSent() const
37783778
return nTotalBytesSent;
37793779
}
37803780

3781+
void CConnman::SetTotalBytesRecv(uint64_t bytes) { nTotalBytesRecv.store(bytes); }
3782+
3783+
void CConnman::SetTotalBytesSent(uint64_t bytes) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
3784+
{
3785+
WAIT_LOCK(m_total_bytes_sent_mutex, lock);
3786+
nTotalBytesSent = bytes;
3787+
}
3788+
37813789
ServiceFlags CConnman::GetLocalServices() const
37823790
{
37833791
return nLocalServices;

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,8 @@ class CConnman
12761276

12771277
uint64_t GetTotalBytesRecv() const;
12781278
uint64_t GetTotalBytesSent() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1279+
void SetTotalBytesRecv(uint64_t bytes);
1280+
void SetTotalBytesSent(uint64_t bytes);
12791281

12801282
/** Get a unique deterministic randomizer. */
12811283
CSipHasher GetDeterministicRandomizer(uint64_t id) const;

src/node/interfaces.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ class NodeImpl : public Node
276276
}
277277
int64_t getTotalBytesRecv() override { return m_context->connman ? m_context->connman->GetTotalBytesRecv() : 0; }
278278
int64_t getTotalBytesSent() override { return m_context->connman ? m_context->connman->GetTotalBytesSent() : 0; }
279+
void setTotalBytesRecv(uint64_t bytes) override { if (m_context->connman) m_context->connman->SetTotalBytesRecv(bytes); }
280+
void setTotalBytesSent(uint64_t bytes) override { if (m_context->connman) m_context->connman->SetTotalBytesSent(bytes); }
279281
size_t getMempoolSize() override { return m_context->mempool ? m_context->mempool->size() : 0; }
280282
size_t getMempoolDynamicUsage() override { return m_context->mempool ? m_context->mempool->DynamicMemoryUsage() : 0; }
281283
size_t getMempoolMaxUsage() override { return m_context->mempool ? m_context->mempool->m_opts.max_size_bytes : 0; }

0 commit comments

Comments
 (0)