|
@@ -3,6 +3,7 @@
|
|
|
import random # For simulation, not cryptography!
|
|
|
import math
|
|
|
import sys
|
|
|
+import os
|
|
|
import logging
|
|
|
import resource
|
|
|
|
|
@@ -52,9 +53,18 @@ class Simulator:
|
|
|
# we treat them as "new") over several days in late Dec 2019,
|
|
|
# newmean is about 16% of all clients, and newstddev is about 4%
|
|
|
# of all clients.
|
|
|
- self.client_newmean = 0.16 * self.clienttarget
|
|
|
- self.client_newstddev = 0.04 * self.clienttarget
|
|
|
- self.client_oldprob = 0.16
|
|
|
+
|
|
|
+ # if the environment variable WOSIM_CLIENT_CHURN is set to 0,
|
|
|
+ # don't churn clients at all. This allows us to see the effect
|
|
|
+ # of client churn on relay bandwidth.
|
|
|
+ if os.getenv('WOSIM_CLIENT_CHURN', '1') == '0':
|
|
|
+ self.client_newmean = 0
|
|
|
+ self.client_newstddev = 0
|
|
|
+ self.client_oldprob = 0
|
|
|
+ else:
|
|
|
+ self.client_newmean = 0.16 * self.clienttarget
|
|
|
+ self.client_newstddev = 0.04 * self.clienttarget
|
|
|
+ self.client_oldprob = 0.16
|
|
|
|
|
|
# Start some dirauths
|
|
|
self.dirauthaddrs = []
|
|
@@ -246,35 +256,36 @@ class Simulator:
|
|
|
bw = int(200000-(200000-25000)/3*math.log10(x))
|
|
|
self.relays.append(relay.Relay(self.dirauthaddrs, bw, 0))
|
|
|
|
|
|
- # TODO: churn clients
|
|
|
-
|
|
|
- # Stop some of the clients
|
|
|
- clients_remaining = []
|
|
|
- numclients = len(self.clients)
|
|
|
- numclientsterminated = 0
|
|
|
- lastpercent = 0
|
|
|
- logging.info("Terminating some clients")
|
|
|
- for i, c in enumerate(self.clients):
|
|
|
- percent = int(100*(i+1)/numclients)
|
|
|
- if random.random() < self.client_oldprob:
|
|
|
- c.terminate()
|
|
|
- numclientsterminated += 1
|
|
|
- else:
|
|
|
- # Keep this client
|
|
|
- clients_remaining.append(c)
|
|
|
- if percent != lastpercent:
|
|
|
- lastpercent = percent
|
|
|
- logging.info("%d%% clients considered, %d terminated",
|
|
|
- percent, numclientsterminated)
|
|
|
- self.clients = clients_remaining
|
|
|
-
|
|
|
- # Start some new clients
|
|
|
- clients_new = int(random.normalvariate(self.client_newmean,
|
|
|
- self.client_newstddev))
|
|
|
- logging.info("Starting %d new clients", clients_new)
|
|
|
- if clients_new > 0:
|
|
|
- for i in range(clients_new):
|
|
|
- self.clients.append(client.Client(self.dirauthaddrs))
|
|
|
+ # churn clients
|
|
|
+
|
|
|
+ if self.client_oldprob > 0:
|
|
|
+ # Stop some of the clients
|
|
|
+ clients_remaining = []
|
|
|
+ numclients = len(self.clients)
|
|
|
+ numclientsterminated = 0
|
|
|
+ lastpercent = 0
|
|
|
+ logging.info("Terminating some clients")
|
|
|
+ for i, c in enumerate(self.clients):
|
|
|
+ percent = int(100*(i+1)/numclients)
|
|
|
+ if random.random() < self.client_oldprob:
|
|
|
+ c.terminate()
|
|
|
+ numclientsterminated += 1
|
|
|
+ else:
|
|
|
+ # Keep this client
|
|
|
+ clients_remaining.append(c)
|
|
|
+ if percent != lastpercent:
|
|
|
+ lastpercent = percent
|
|
|
+ logging.info("%d%% clients considered, %d terminated",
|
|
|
+ percent, numclientsterminated)
|
|
|
+ self.clients = clients_remaining
|
|
|
+
|
|
|
+ # Start some new clients
|
|
|
+ clients_new = int(random.normalvariate(self.client_newmean,
|
|
|
+ self.client_newstddev))
|
|
|
+ logging.info("Starting %d new clients", clients_new)
|
|
|
+ if clients_new > 0:
|
|
|
+ for i in range(clients_new):
|
|
|
+ self.clients.append(client.Client(self.dirauthaddrs))
|
|
|
|
|
|
# Tick the epoch
|
|
|
network.thenetwork.nextepoch()
|