|
@@ -4,6 +4,14 @@ import random
|
|
|
import pickle
|
|
|
from enum import Enum
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+symbolic_byte_counters = False
|
|
|
+
|
|
|
+if symbolic_byte_counters:
|
|
|
+ import sympy
|
|
|
+
|
|
|
class WOMode(Enum):
|
|
|
"""The different Walking Onion modes"""
|
|
|
VANILLA = 0
|
|
@@ -37,6 +45,17 @@ class PerfStats:
|
|
|
self.ent_type = ent_type
|
|
|
|
|
|
self.name = None
|
|
|
+ self.reset()
|
|
|
+
|
|
|
+ def __str__(self):
|
|
|
+ return "%s: type=%s boot=%s sent=%s recv=%s keygen=%d sig=%d verif=%d dh=%d" % \
|
|
|
+ (self.name, self.ent_type.name, self.is_bootstrapping, \
|
|
|
+ self.bytes_sent, self.bytes_received, self.keygens, \
|
|
|
+ self.sigs, self.verifs, self.dhs)
|
|
|
+
|
|
|
+ def reset(self):
|
|
|
+ """Reset the counters, typically at the beginning of each
|
|
|
+ epoch."""
|
|
|
|
|
|
self.is_bootstrapping = False
|
|
|
|
|
@@ -49,12 +68,6 @@ class PerfStats:
|
|
|
self.verifs = 0
|
|
|
self.dhs = 0
|
|
|
|
|
|
- def __str__(self):
|
|
|
- return "%s: type=%s boot=%s sent=%d recv=%d keygen=%d sig=%d verif=%d dh=%d" % \
|
|
|
- (self.name, self.ent_type.name, self.is_bootstrapping, \
|
|
|
- self.bytes_sent, self.bytes_received, self.keygens, \
|
|
|
- self.sigs, self.verifs, self.dhs)
|
|
|
-
|
|
|
|
|
|
class NetAddr:
|
|
|
"""A class representing a network address"""
|
|
@@ -203,8 +216,15 @@ class NetMsg:
|
|
|
pickle it and return the length of that. There's some
|
|
|
unnecessary overhead in this method; if you want specific
|
|
|
messages to have more accurate sizes, override this method in
|
|
|
- the subclass."""
|
|
|
- sz = len(pickle.dumps(self))
|
|
|
+ the subclass. Alternately, if symbolic_byte_counters is set,
|
|
|
+ return a symbolic representation of the message size instead, so
|
|
|
+ that the total byte counts will clearly show how many of each
|
|
|
+ message type were sent and received."""
|
|
|
+ if symbolic_byte_counters:
|
|
|
+ sz = sympy.symbols(type(self).__name__)
|
|
|
+ else:
|
|
|
+ sz = len(pickle.dumps(self))
|
|
|
+
|
|
|
return sz
|
|
|
|
|
|
|