Skip to content

Commit

Permalink
Imports corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
cengwins committed Jan 14, 2022
1 parent 4b930f8 commit 162e6c1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Consensus/testChandraConsensus.py
Original file line number Diff line number Diff line change
@@ -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()
34 changes: 34 additions & 0 deletions Consensus/testNakamotoConsesus.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ahc.Channels.Channels import FIFOBroadcastPerfectChannel
from ahc.EttusUsrp.UhdUtils import AhcUhdUtils


framers = FramerObjects()


Expand Down

0 comments on commit 162e6c1

Please sign in to comment.