[tor-commits] [pluggable-transports/snowflake-webext] 15/15: feat: add logging of connection stats

gitolite role git at cupani.torproject.org
Wed Nov 9 14:41:04 UTC 2022


This is an automated email from the git hooks/post-receive script.

cohosh pushed a commit to branch main
in repository pluggable-transports/snowflake-webext.

commit ce185410d3e79163a8b1f028278b8af1328312cf
Author: WofWca <wofwca at protonmail.com>
AuthorDate: Mon Nov 7 20:48:01 2022 +0400

    feat: add logging of connection stats
---
 proxypair.js | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/proxypair.js b/proxypair.js
index ecbaf88..f3df964 100644
--- a/proxypair.js
+++ b/proxypair.js
@@ -1,4 +1,4 @@
-/* global snowflake, log, dbg, Util, Parse, WS */
+/* global snowflake, log, dbg, debug, Util, Parse, WS */
 
 /**
 Represents a single:
@@ -235,6 +235,32 @@ class ProxyPair {
 
   /** Close both WebRTC and websocket. */
   close() {
+    if (debug) {
+      this.pc.getStats().then(report => {
+        let transportStats;
+        for (const stat of report.values()) {
+          // Also consider 'data-channel'.
+          if (stat.type === 'transport') {
+            transportStats = stat;
+            break;
+          }
+        }
+        if (!transportStats) {
+          return;
+        }
+        function bytesToMBytesStr(numBytes) {
+          return (numBytes / 1024 / 1024).toFixed(3);
+        }
+        log(
+          `Connection closed. Traffic (up|down):`
+          + ` ${bytesToMBytesStr(transportStats.bytesReceived)} MB|`
+          + `${bytesToMBytesStr(transportStats.bytesSent)} MB`
+          + `, packets: ${transportStats.packetsReceived}|`
+          + `${transportStats.packetsSent}`
+        );
+      });
+    }
+
     clearTimeout(this.connectToRelayTimeoutId);
     clearTimeout(this.messageTimer);
     clearTimeout(this.answerTimeoutId);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tor-commits mailing list