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.
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "librats",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "Node.js bindings for librats - A high-performance peer-to-peer networking library",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",