diff --git a/Consensus/testChandraConsensus.py b/Consensus/testChandraConsensus.py new file mode 100644 index 0000000..4ed60af --- /dev/null +++ b/Consensus/testChandraConsensus.py @@ -0,0 +1,27 @@ +from enum import Enum +from threading import Timer +from ahc.Ahc import Topology, ComponentModel, ConnectorTypes, ComponentRegistry +from ahc.Consensus.ChandraConsensus import ChandraChannel, ChandraComponents +registry = ComponentRegistry() + +class ChandraConsensusNode(ComponentModel): + + def __init__(self, componentname, componentid, numberofNodes=10): + self.channel = ChandraChannel("ChandraChannel", 0) + for n in range(0, numberofNodes): + tComp = ChandraComponents("ChandraNode", n, numberofNodes) + tComp.connect_me_to_channel(ConnectorTypes.DOWN, self.channel) + registry.add_component(tComp) + + registry.get_component_by_key("ChandraNode", 0).set_as_coordinator() + super().__init__(componentname, componentid) + +def main(): + topo = Topology() + topo.construct_single_node(ChandraConsensusNode, 0) + topo.start() + while True: pass + + +if __name__ == '__main__': + main() diff --git a/Consensus/testNakamotoConsesus.py b/Consensus/testNakamotoConsesus.py new file mode 100644 index 0000000..5b392a6 --- /dev/null +++ b/Consensus/testNakamotoConsesus.py @@ -0,0 +1,34 @@ + +import sys +from copy import deepcopy +from enum import Enum + +import networkx as nx +from random import choice + +import matplotlib.pyplot as plt + +from ahc.Channels.Channels import Channel +from ahc.Ahc import ComponentRegistry, Topology +from ahc.Consensus.NakamotoConsensus import transaction_generator + +# TODO: Check if this is a valid implementation +PATH_OF_DATA = "data" +sys.setrecursionlimit(1500) + +def main(): + number_of_nodes = 5 + number_of_txn = 50 + G = nx.erdos_renyi_graph(number_of_nodes, 0.4) + transaction_generator(number_of_nodes,number_of_txn) + topo = Topology() + topo.construct_from_graph(G, NkComponent, Channel) + + ComponentRegistry().print_components() + topo.start() + nx.draw(G, with_labels=True, font_weight='bold') + plt.show() + +if __name__ == '__main__': + main() + while True: pass \ No newline at end of file diff --git a/main.py b/main.py index f3c26a2..56da63d 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,7 @@ from ahc.Channels.Channels import FIFOBroadcastPerfectChannel from ahc.EttusUsrp.UhdUtils import AhcUhdUtils + framers = FramerObjects()