Browse Source

Sample relay bandwidths from a distribution similar to that of the live Tor network in Dec 2019

Ian Goldberg 4 years ago
parent
commit
2166f9a647
2 changed files with 15 additions and 1 deletions
  1. 5 0
      network.py
  2. 10 1
      relay.py

+ 5 - 0
network.py

@@ -1,5 +1,7 @@
 #!/usr/bin/env python3
 
+import random
+
 class NetAddr:
     """A class representing a network address"""
     nextaddr = 1
@@ -97,6 +99,9 @@ class Network:
 # The singleton instance of Network
 thenetwork = Network()
 
+# Initialize the (non-cryptographic) random seed
+random.seed(1)
+
 class NetMsg:
     """The parent class of network messages.  Subclass this class to
     implement specific kinds of network messages."""

+ 10 - 1
relay.py

@@ -1,5 +1,8 @@
 #!/usr/bin/env python3
 
+import random # For simulation, not cryptography!
+import math
+
 import nacl.utils
 import nacl.signing
 import nacl.public
@@ -66,7 +69,13 @@ if __name__ == '__main__':
     # Start some relays
     numrelays = 10
     for i in range(numrelays):
-        Relay(dirauthaddrs, 500, 0)
+        # Relay bandwidths (at least the ones fast enough to get used)
+        # in the live Tor network (as of Dec 2019) are well approximated
+        # by (200000-(200000-25000)/3*log10(x)) where x is a
+        # uniform integer in [1,2500]
+        x = random.randint(1,2500)
+        bw = int(200000-(200000-25000)/3*math.log10(x))
+        Relay(dirauthaddrs, bw, 0)
 
     # Tick the epoch
     network.thenetwork.nextepoch()