GNUnet 0.21.0
consensus-simulation Namespace Reference

Functions

def bsc (n)
 
def simulate (k, n, verbose)
 

Variables

 parser = argparse.ArgumentParser()
 
 metavar
 
 type
 
 int
 
 help
 
 action
 
 args = parser.parse_args()
 
float sum = 0.0
 

Function Documentation

◆ bsc()

def consensus-simulation.bsc (   n)
 count the bits set in n

Definition at line 25 of file consensus-simulation.py.

25def bsc(n):
26 """ count the bits set in n"""
27 l = n.bit_length()
28 c = 0
29 x = 1
30 for _ in range(0, l):
31 if n & x:
32 c = c + 1
33 x = x << 1
34 return c
35
36

Referenced by simulate().

Here is the caller graph for this function:

◆ simulate()

def consensus-simulation.simulate (   k,
  n,
  verbose 
)

Definition at line 37 of file consensus-simulation.py.

37def simulate(k, n, verbose):
38 assert k < n
39 largest_arc = int(2**ceil(log(n, 2))) // 2
40 num_ghosts = (2 * largest_arc) - n
41 if verbose:
42 print("we have", num_ghosts, "ghost peers")
43 # n.b. all peers with idx<k are evil
44 peers = list(range(n))
45 info = [1 << x for x in range(n)]
46
47 def done_p():
48 for x in range(k, n):
49 if bsc(info[x]) < n - k:
50 return False
51 return True
52
53 rounds = 0
54 while not done_p():
55 if verbose:
56 print("-- round --")
57 arc = 1
58 while arc <= largest_arc:
59 if verbose:
60 print("-- subround --")
61 new_info = [x for x in info]
62 for peer_physical in range(n):
63 peer_logical = peers[peer_physical]
64 peer_type = None
65 partner_logical = (peer_logical + arc) % n
66 partner_physical = peers.index(partner_logical)
67 if peer_physical < k or partner_physical < k:
68 if verbose:
69 print(
70 "bad peer in connection", peer_physical, "--",
71 partner_physical
72 )
73 continue
74 if peer_logical & arc == 0:
75 # we are outgoing
76 if verbose:
77 print(peer_physical, "connects to", partner_physical)
78 peer_type = "outgoing"
79 if peer_logical < num_ghosts:
80 # we have a ghost, check if the peer who connects
81 # to our ghost is actually outgoing
82 ghost_partner_logical = (peer_logical - arc) % n
83 if ghost_partner_logical & arc == 0:
84 peer_type = peer_type + ", ghost incoming"
85 new_info[peer_physical] = new_info[peer_physical] | info[
86 peer_physical] | info[partner_physical]
87 new_info[partner_physical
88 ] = new_info[partner_physical] | info[
89 peer_physical] | info[partner_physical]
90 else:
91 peer_type = "incoming"
92 if verbose > 1:
93 print("type of", str(peer_physical) + ":", peer_type)
94 info = new_info
95 arc = arc << 1
96 rounds = rounds + 1
97 random.shuffle(peers)
98 return rounds
99
100
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:69
def simulate(k, n, verbose)

References bsc(), int, and list.

Here is the call graph for this function:

Variable Documentation

◆ parser

consensus-simulation.parser = argparse.ArgumentParser()

Definition at line 102 of file consensus-simulation.py.

Referenced by GNUNET_JSON_parse().

◆ metavar

consensus-simulation.metavar

Definition at line 103 of file consensus-simulation.py.

◆ type

consensus-simulation.type

Definition at line 103 of file consensus-simulation.py.

◆ int

◆ help

consensus-simulation.help

Definition at line 103 of file consensus-simulation.py.

◆ action

◆ args

◆ sum