librats 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/native-src/CMakeLists.txt +10 -2
- package/native-src/src/bt_network.cpp +296 -183
- package/native-src/src/bt_network.h +25 -5
- package/native-src/src/io_poller.cpp +910 -0
- package/native-src/src/io_poller.h +138 -0
- package/native-src/src/librats.cpp +809 -1236
- package/native-src/src/librats.h +146 -54
- package/native-src/src/librats_bittorrent.cpp +1 -5
- package/native-src/src/librats_c.cpp +1 -1
- package/native-src/src/librats_discovery.cpp +309 -0
- package/native-src/src/librats_encryption.cpp +130 -283
- package/native-src/src/librats_file_transfer.cpp +2 -6
- package/native-src/src/librats_gossipsub.cpp +1 -5
- package/native-src/src/librats_ice.cpp +1 -1
- package/native-src/src/librats_log_macros.h +36 -0
- package/native-src/src/librats_logging.cpp +1 -7
- package/native-src/src/librats_mdns.cpp +1 -11
- package/native-src/src/librats_persistence.cpp +1 -11
- package/native-src/src/librats_reconnection.cpp +2 -13
- package/native-src/src/librats_statistic.cpp +97 -0
- package/package.json +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#include "librats.h"
|
|
2
|
+
#include "librats_log_macros.h"
|
|
3
|
+
#include "os.h"
|
|
4
|
+
|
|
5
|
+
namespace librats {
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// =========================================================================
|
|
9
|
+
// Statistics and Information
|
|
10
|
+
// =========================================================================
|
|
11
|
+
|
|
12
|
+
nlohmann::json RatsClient::get_connection_statistics() const {
|
|
13
|
+
nlohmann::json stats;
|
|
14
|
+
|
|
15
|
+
{
|
|
16
|
+
std::lock_guard<std::mutex> lock(peers_mutex_);
|
|
17
|
+
stats["total_peers"] = peers_.size();
|
|
18
|
+
stats["validated_peers"] = get_peer_count_unlocked();
|
|
19
|
+
stats["max_peers"] = max_peers_;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
stats["running"] = is_running();
|
|
23
|
+
stats["listen_port"] = listen_port_;
|
|
24
|
+
stats["our_peer_id"] = get_our_peer_id();
|
|
25
|
+
stats["encryption_enabled"] = is_encryption_enabled();
|
|
26
|
+
|
|
27
|
+
// DHT statistics
|
|
28
|
+
if (dht_client_ && dht_client_->is_running()) {
|
|
29
|
+
stats["dht_running"] = true;
|
|
30
|
+
stats["dht_routing_table_size"] = get_dht_routing_table_size();
|
|
31
|
+
} else {
|
|
32
|
+
stats["dht_running"] = false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// mDNS statistics
|
|
36
|
+
stats["mdns_running"] = is_mdns_running();
|
|
37
|
+
|
|
38
|
+
// Reconnection statistics
|
|
39
|
+
{
|
|
40
|
+
std::lock_guard<std::mutex> lock(reconnect_mutex_);
|
|
41
|
+
stats["reconnect_enabled"] = reconnect_config_.enabled;
|
|
42
|
+
stats["reconnect_queue_size"] = reconnect_queue_.size();
|
|
43
|
+
stats["reconnect_max_attempts"] = reconnect_config_.max_attempts;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return stats;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Cached formatting helpers - computed once on first use
|
|
50
|
+
static const std::string& get_box_separator() {
|
|
51
|
+
static const std::string separator = supports_unicode() ?
|
|
52
|
+
"════════════════════════════════════════════════════════════════════" :
|
|
53
|
+
"=====================================================================";
|
|
54
|
+
return separator;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static const std::string& get_box_vertical() {
|
|
58
|
+
static const std::string vertical = supports_unicode() ? "│" : "|";
|
|
59
|
+
return vertical;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static const std::string& get_checkmark() {
|
|
63
|
+
static const std::string checkmark = supports_unicode() ? "✓" : "[*]";
|
|
64
|
+
return checkmark;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
void RatsClient::log_handshake_completion_unlocked(const RatsPeer& peer) {
|
|
68
|
+
// Calculate connection duration
|
|
69
|
+
auto now = std::chrono::steady_clock::now();
|
|
70
|
+
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now - peer.connected_at);
|
|
71
|
+
|
|
72
|
+
// Get current peer count (assumes peers_mutex_ is already locked)
|
|
73
|
+
int current_peer_count = get_peer_count_unlocked();
|
|
74
|
+
|
|
75
|
+
// Create visually appealing log output
|
|
76
|
+
std::string connection_type = peer.is_outgoing ? "OUTGOING" : "INCOMING";
|
|
77
|
+
const std::string& separator = get_box_separator();
|
|
78
|
+
const std::string& vertical = get_box_vertical();
|
|
79
|
+
const std::string& checkmark = get_checkmark();
|
|
80
|
+
|
|
81
|
+
LOG_CLIENT_INFO("");
|
|
82
|
+
LOG_CLIENT_INFO(separator);
|
|
83
|
+
LOG_CLIENT_INFO(checkmark << " HANDSHAKE COMPLETED - NEW PEER CONNECTED");
|
|
84
|
+
LOG_CLIENT_INFO(separator);
|
|
85
|
+
LOG_CLIENT_INFO(vertical << " Peer ID : " << peer.peer_id);
|
|
86
|
+
LOG_CLIENT_INFO(vertical << " Address : " << peer.ip << ":" << peer.port);
|
|
87
|
+
LOG_CLIENT_INFO(vertical << " Connection : " << connection_type);
|
|
88
|
+
LOG_CLIENT_INFO(vertical << " Protocol Ver. : " << peer.version);
|
|
89
|
+
LOG_CLIENT_INFO(vertical << " Socket : " << peer.socket);
|
|
90
|
+
LOG_CLIENT_INFO(vertical << " Duration : " << duration.count() << "ms");
|
|
91
|
+
LOG_CLIENT_INFO(vertical << " Network Peers : " << current_peer_count << "/" << max_peers_);
|
|
92
|
+
|
|
93
|
+
LOG_CLIENT_INFO(separator);
|
|
94
|
+
LOG_CLIENT_INFO("");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|