diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/consensus/Makefile.am | 18 | ||||
-rw-r--r-- | src/consensus/consensus-simulation.py.in (renamed from src/consensus/consensus-simulation.py) | 18 |
2 files changed, 25 insertions, 11 deletions
diff --git a/src/consensus/Makefile.am b/src/consensus/Makefile.am index c0205ee5d..c673e0407 100644 --- a/src/consensus/Makefile.am +++ b/src/consensus/Makefile.am | |||
@@ -27,6 +27,15 @@ libexec_PROGRAMS += \ | |||
27 | gnunet-service-evil-consensus | 27 | gnunet-service-evil-consensus |
28 | endif | 28 | endif |
29 | 29 | ||
30 | do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' | ||
31 | |||
32 | SUFFIXES = .py.in .py | ||
33 | |||
34 | .py.in.py: | ||
35 | $(do_subst) < $< > $@ | ||
36 | chmod +x $@ | ||
37 | |||
38 | |||
30 | lib_LTLIBRARIES = \ | 39 | lib_LTLIBRARIES = \ |
31 | libgnunetconsensus.la | 40 | libgnunetconsensus.la |
32 | 41 | ||
@@ -103,5 +112,12 @@ test_consensus_api_LDADD = \ | |||
103 | $(top_builddir)/src/testing/libgnunettesting.la \ | 112 | $(top_builddir)/src/testing/libgnunettesting.la \ |
104 | libgnunetconsensus.la | 113 | libgnunetconsensus.la |
105 | 114 | ||
115 | noinst_SCRIPTS = \ | ||
116 | consensus-simulation.py | ||
117 | |||
118 | CLEANFILES = \ | ||
119 | $(noinst_SCRIPTS) | ||
120 | |||
106 | EXTRA_DIST = \ | 121 | EXTRA_DIST = \ |
107 | test_consensus.conf | 122 | test_consensus.conf \ |
123 | consensus-simulation.py.in | ||
diff --git a/src/consensus/consensus-simulation.py b/src/consensus/consensus-simulation.py.in index 542fe0dac..71a91302e 100644 --- a/src/consensus/consensus-simulation.py +++ b/src/consensus/consensus-simulation.py.in | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/python | 1 | #!@PYTHON@ |
2 | # This file is part of GNUnet | 2 | # This file is part of GNUnet |
3 | # (C) 2013 Christian Grothoff (and other contributing authors) | 3 | # (C) 2013, 2018 Christian Grothoff (and other contributing authors) |
4 | # | 4 | # |
5 | # GNUnet is free software; you can redistribute it and/or modify | 5 | # GNUnet is free software; you can redistribute it and/or modify |
6 | # it under the terms of the GNU General Public License as published | 6 | # it under the terms of the GNU General Public License as published |
@@ -41,7 +41,7 @@ def simulate(k, n, verbose): | |||
41 | largest_arc = int(2**ceil(log(n, 2))) / 2 | 41 | largest_arc = int(2**ceil(log(n, 2))) / 2 |
42 | num_ghosts = (2 * largest_arc) - n | 42 | num_ghosts = (2 * largest_arc) - n |
43 | if verbose: | 43 | if verbose: |
44 | print "we have", num_ghosts, "ghost peers" | 44 | print("we have", num_ghosts, "ghost peers") |
45 | # n.b. all peers with idx<k are evil | 45 | # n.b. all peers with idx<k are evil |
46 | peers = range(n) | 46 | peers = range(n) |
47 | info = [1 << x for x in xrange(n)] | 47 | info = [1 << x for x in xrange(n)] |
@@ -53,11 +53,11 @@ def simulate(k, n, verbose): | |||
53 | rounds = 0 | 53 | rounds = 0 |
54 | while not done_p(): | 54 | while not done_p(): |
55 | if verbose: | 55 | if verbose: |
56 | print "-- round --" | 56 | print("-- round --") |
57 | arc = 1 | 57 | arc = 1 |
58 | while arc <= largest_arc: | 58 | while arc <= largest_arc: |
59 | if verbose: | 59 | if verbose: |
60 | print "-- subround --" | 60 | prin( "-- subround --") |
61 | new_info = [x for x in info] | 61 | new_info = [x for x in info] |
62 | for peer_physical in xrange(n): | 62 | for peer_physical in xrange(n): |
63 | peer_logical = peers[peer_physical] | 63 | peer_logical = peers[peer_physical] |
@@ -66,7 +66,7 @@ def simulate(k, n, verbose): | |||
66 | partner_physical = peers.index(partner_logical) | 66 | partner_physical = peers.index(partner_logical) |
67 | if peer_physical < k or partner_physical < k: | 67 | if peer_physical < k or partner_physical < k: |
68 | if verbose: | 68 | if verbose: |
69 | print "bad peer in connection", peer_physical, "--", partner_physical | 69 | print("bad peer in connection", peer_physical, "--", partner_physical) |
70 | continue | 70 | continue |
71 | if peer_logical & arc == 0: | 71 | if peer_logical & arc == 0: |
72 | # we are outgoing | 72 | # we are outgoing |
@@ -84,7 +84,7 @@ def simulate(k, n, verbose): | |||
84 | else: | 84 | else: |
85 | peer_type = "incoming" | 85 | peer_type = "incoming" |
86 | if verbose > 1: | 86 | if verbose > 1: |
87 | print "type of", str(peer_physical) + ":", peer_type | 87 | print("type of", str(peer_physical) + ":", peer_type) |
88 | info = new_info | 88 | info = new_info |
89 | arc = arc << 1; | 89 | arc = arc << 1; |
90 | rounds = rounds + 1 | 90 | rounds = rounds + 1 |
@@ -103,6 +103,4 @@ if __name__ == "__main__": | |||
103 | sum = 0.0; | 103 | sum = 0.0; |
104 | for n in xrange (0, args.r): | 104 | for n in xrange (0, args.r): |
105 | sum += simulate(args.k, args.n, args.verbose) | 105 | sum += simulate(args.k, args.n, args.verbose) |
106 | printsum / args.r; | 106 | print(sum / args.r) |
107 | |||
108 | |||