[Pkg-privacy-commits] [obfsproxy] 79/353: Add unique IP counter to the heartbeat.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:42 UTC 2015


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

infinity0 pushed a commit to branch master
in repository obfsproxy.

commit 3b2ca51f9f96f0f235a4a879356a57e7bdcb204a
Author: George Kadianakis <desnacked at riseup.net>
Date:   Fri Nov 2 01:23:40 2012 +0200

    Add unique IP counter to the heartbeat.
---
 obfsproxy/common/heartbeat.py | 30 +++++++++++++++++++++---------
 obfsproxy/network/network.py  |  2 +-
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/obfsproxy/common/heartbeat.py b/obfsproxy/common/heartbeat.py
index 3cb036d..bc36729 100644
--- a/obfsproxy/common/heartbeat.py
+++ b/obfsproxy/common/heartbeat.py
@@ -1,6 +1,7 @@
 """heartbeat code"""
 
 import datetime
+import socket # for socket.inet_aton()
 
 import obfsproxy.common.log as log
 
@@ -11,27 +12,36 @@ class Heartbeat(object):
     It keeps stats on a number of things that the obfsproxy operator
     might be interested in, and every now and then it reports them in
     the logs.
+
+    'unique_ips': A Python set that contains unique IPs (in integer
+    form) that have connected to obfsproxy.
     """
 
     def __init__(self):
-        self.n_unique_ips = 0
         self.n_connections = 0
         self.started = datetime.datetime.now()
         self.last_reset = self.started
+        self.unique_ips = set()
 
-    def register_ip(self, ip): # XXX NOP
-        pass
-
-    def register_connection(self):
+    def register_connection(self, ip_str):
         """Register a new connection."""
-
         self.n_connections += 1
+        self._register_ip(ip_str)
+
+    def _register_ip(self, ip_str):
+        """
+        See if 'ip_str' has connected to obfsproxy before. If not, add
+        it to the list of unique IPs.
+        """
+        ip = socket.inet_aton(ip_str)
+        if ip not in self.unique_ips:
+            self.unique_ips.add(ip)
 
     def reset_stats(self):
         """Reset stats."""
 
         self.n_connections = 0
-        self.n_unique_ips = 0
+        self.unique_ips = set()
         self.last_reset = datetime.datetime.now()
 
     def say_uptime(self):
@@ -53,8 +63,10 @@ class Heartbeat(object):
         now = datetime.datetime.now()
         reset_delta = now - self.last_reset
 
-        log.info("Heartbeat: During the last %d hour(s) we saw %d connection(s)." % \
-                     (reset_delta.seconds//3600 + reset_delta.days*24, self.n_connections))
+        log.info("Heartbeat: During the last %d hour(s) we saw %d connection(s)" \
+                 " from %d unique address(es)." % \
+                     (reset_delta.seconds//3600 + reset_delta.days*24, self.n_connections,
+                      len(self.unique_ips)))
 
         # Reset stats every 24 hours.
         if (reset_delta.days > 0):
diff --git a/obfsproxy/network/network.py b/obfsproxy/network/network.py
index 581bba8..4d21e32 100644
--- a/obfsproxy/network/network.py
+++ b/obfsproxy/network/network.py
@@ -217,7 +217,7 @@ class StaticDestinationProtocol(Protocol):
                       "Setting it as downstream on our circuit." % self.name)
 
             # Gather some statistics for our heartbeat.
-            heartbeat.heartbeat.register_connection()
+            heartbeat.heartbeat.register_connection(self.peer_addr.host)
 
             self.circuit.setDownstreamConnection(self)
         elif self.mode == 'server':

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfsproxy.git



More information about the Pkg-privacy-commits mailing list