Skip to content

Commit 1aea212

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 76bf379 commit 1aea212

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
@@ -157,6 +157,12 @@ class Node
157157
//! Get total bytes sent.
158158
virtual int64_t getTotalBytesSent() = 0;
159159

160+
//! Set total bytes recv
161+
virtual void setTotalBytesRecv(uint64_t bytes) = 0;
162+
163+
//! Set total bytes sent
164+
virtual void setTotalBytesSent(uint64_t bytes) = 0;
165+
160166
//! Get mempool size.
161167
virtual size_t getMempoolSize() = 0;
162168

src/net.cpp

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

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

src/net.h

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

12621262
uint64_t GetTotalBytesRecv() const;
12631263
uint64_t GetTotalBytesSent() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1264+
void SetTotalBytesRecv(uint64_t bytes);
1265+
void SetTotalBytesSent(uint64_t bytes);
12641266

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

src/node/interfaces.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ class NodeImpl : public Node
285285
}
286286
int64_t getTotalBytesRecv() override { return m_context->connman ? m_context->connman->GetTotalBytesRecv() : 0; }
287287
int64_t getTotalBytesSent() override { return m_context->connman ? m_context->connman->GetTotalBytesSent() : 0; }
288+
void setTotalBytesRecv(uint64_t bytes) override { if (m_context->connman) m_context->connman->SetTotalBytesRecv(bytes); }
289+
void setTotalBytesSent(uint64_t bytes) override { if (m_context->connman) m_context->connman->SetTotalBytesSent(bytes); }
288290
size_t getMempoolSize() override { return m_context->mempool ? m_context->mempool->size() : 0; }
289291
size_t getMempoolDynamicUsage() override { return m_context->mempool ? m_context->mempool->DynamicMemoryUsage() : 0; }
290292
size_t getMempoolMaxUsage() override { return m_context->mempool ? m_context->mempool->m_opts.max_size_bytes : 0; }

0 commit comments

Comments
 (0)