forked from cengwins/ahc_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cengwins
committed
Jan 14, 2022
1 parent
4b930f8
commit 162e6c1
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters