示例#1
0
 def process(self, packet, link, time):
     if (packet.type == 'HELLO'):
         self.neighbours[link] = (time, packet.source, link.cost)
     elif (packet.type == 'ADVERT'):
         self.process_advertisement(packet, link, time)
     else:
         NODE.process(self, packet, link, time)
示例#2
0
 def __init__(self, location, address=None):
     NODE.__init__(self, location, address = address)
     self.neighbours = {}
     self.routes = {}
     self.spcost = {}
     self.routes[self.address] = 'self'
     self.spcost[self.address] = 0
示例#3
0
 def test_dont_lose_nodes(self):
     n1 = Node(1)
     n2 = Node(2)
     n1.add_arc(Arc(n2))
     nw = Network([n1])
     self.assertEqual(nw.find_node(2), n2)
     n3 = Node(3)
     n2.add_arc(Arc(n3))
     self.assertEqual(nw.find_node(3), n3)
示例#4
0
文件: vbmap.py 项目: sh4rkfin/misc
 def create_non_zero_flow_network(self, color):
     if not self.is_colored_vbmap_problem():
         raise ValueError("VbMapProblem instance is not a colored map problem")
     network = Network()
     za = self.get_active_vbucket_moves()[color]
     for i, a in enumerate(self.prev_avb()[color]):
         if a > 0:
             node = Node(("prev_avb", i), a)
             network.add_node(node)
             for j, x in enumerate(za[i]):
                 if x > 0:
                     to_node = network.find_or_create_node(('avb', j))
                     node.add_arc(Arc(to_node, x))
     avb = self.get_colored_avb()[color]
     # print "avb: ", avb
     x = self.get_colored_replication_map()[color]
     # for i in range(len(x)):
     #     print "x[{0}]: ".format(i), x[i]
     for i, a in enumerate(avb):
         if a > 0:
             node = network.find_or_create_node(("avb", i))
             for j, y in enumerate(x[i]):
                 if y > 0:
                     to_node = network.find_or_create_node(('rvb', j))
                     node.add_arc(Arc(to_node, y))
     zr = self.get_replica_vbucket_moves()[color]
     for i, a in enumerate(self.prev_rvb()[color]):
         if a > 0:
             node = network.find_or_create_node(("prev_rvb", i))
             node.set_source(-a)
             for j in range(len(zr)):
                 y = zr[j][i]
                 if y > 0:
                     from_node = network.find_node(('rvb', j))
                     from_node.add_arc(Arc(node, y))
     return network
示例#5
0
 def __init__(self):
     Node.__init__(self)
示例#6
0
                logger.info("Header #{} collated by {}: {}".format(
                    number, collator, header))

    # plot_shard(smc_handler.shards[0])


collator_pool = ['collator_{}'.format(i) for i in range(5)]
proposer_pool = ['proposer_{}'.format(i) for i in range(10)]

main_chain = MainChain()
smc_handler = SMCHandler(main_chain, 2, 5, collator_pool)

network = Network()

# Set the p2p connections between proposers
nodes = [Node(network, address) for address in proposer_pool]
network.nodes = nodes
network.generate_peers()

general_coros = [
    main_chain.run(),
    smc_handler.run(),
    stop(),
]

collator_coros = [
    collator(network, address, smc_handler) for address in collator_pool
]

proposer_coros = [
    proposer(network, 0, address, smc_handler)
示例#7
0
 def __init__(self, execute_fn):
     Node.__init__(self)
     self.execute_fn = execute_fn
示例#8
0
 def test_has_arc(self):
     n1 = Node(1)
     n2 = Node(2)
     a = Arc(n2)
     n1.add_arc(a)
     self.assertTrue(n1.has_arc(a))
示例#9
0
 def __init__(self):
     Node.__init__(self)
示例#10
0
import numpy as np
'''
This file still works, but not kept up-to-date with `newton_raphson.py`
'''

# TODO : DELETE START
from examples_example_input import parameter_set2
nodes, lines, transformers = parameter_set2
from network import Node, Line, Transformer, Network
from network_utils import check_network, form_inductance_array, print_inductance_array

nodes = [Node.from_str(node.strip()) for node in nodes.strip().split("\n")]
transformers = [
    Transformer.from_str(transformer.strip())
    for transformer in transformers.strip().split("\n")
]
transformers = [
    transformer for transformer in transformers if transformer is not None
]
lines = [Line.from_str(line.strip()) for line in lines.strip().split("\n")]
branches = transformers + lines

node_num = check_network(branches, nodes)
Y = form_inductance_array(branches)
# print_inductance_array(Y)
network = Network(nodes, Y)

eps = 1e-5
max_num_iter = 15
# TODO : DELETE END
示例#11
0
 def __init__(self, execute_fn):
     Node.__init__(self)
     self.execute_fn = execute_fn
示例#12
0
                    help='threshold; 0 < trs <= 100')

if __name__ == '__main__':
    log_level = logging.DEBUG
    if '-s' in sys.argv[1:]:
        log_level = logging.INFO

    log.set_level(log_level)

    options = parser.parse_args()
    log.main.debug('options: %s', options)

    client0_config = NodeConfig('client', None, None, None)
    client0_node = Node(
        client0_config.name,
        client0_config.endpoint,
        None,
        client0_config.port,
    )
    log.main.debug('client node created: %s', client0_node)

    nodes_config = dict()
    for i in range(options.nodes):
        name = 'n%d' % i
        endpoint = 'sock://memory:%d' % i
        port = 3000 + i
        nodes_config[name] = NodeConfig(name, endpoint, port, options.trs)

    log.main.debug('node configs created: %s', nodes_config)

    quorums = dict()
    for name, config in nodes_config.items():
示例#13
0
 def node_mutation(self):
     con = self.network.connections[math.floor(
         len(self.network.connections) * random())]
     self.network.insert_node(Node(self.neat.node_counter), con)
示例#14
0
from network import Node, Network


def simulate_transactions(node1, node2, num=3):
    """ simulating nodes using the tokens """
    print('simulating {} transactions'.format(num))
    return [
        node1.make_transaction(node2, float(np.random.randint(10)))
        for _ in range(num)
    ]


if __name__ == '__main__':
    OVERDRAFT_LIMIT = -10

    net = Network([Node('node'), Node('other')],
                  overdraft_limit=OVERDRAFT_LIMIT)

    balances = defaultdict(int)
    for _ in range(3):
        #  simulate a few transactions between nodes
        new_transactions = simulate_transactions(net[0], net[1])

        #  check the transactions are valid
        balances, transactions = net.validate_transactions(
            balances, new_transactions)

        new_proof = net.proof_of_work()
        #  randomly select a miner
        miner = net[np.random.randint(len(net))]
示例#15
0
 def reset(self):
     NODE.reset(self)
     self.spcost[self.address] = 0
示例#16
0
    for account in accounts:
        node_id = 0
        for server in servers:
            if str(account) == str(server.node.pub_key.to_string()):
                node_id = server.node.node_id
        print("Node {} has a balance of {} Coins".format(
            node_id, accounts[account]))
    print("=====================================================")


if __name__ == '__main__':
    listOfConfigs = ['node1.txt', 'node2.txt', 'node3.txt', 'node4.txt', \
  'node5.txt', 'node6.txt', 'node7.txt', 'node8.txt', 'node9.txt', 'node10.txt']
    servers = []
    for conf in listOfConfigs:
        node = Node(conf)
        server = Server(node)
        servers.append(server)
        server.start()

    for i in range(2):
        time.sleep(5)
        randomIndex = random.randint(0, len(servers) - 1)
        createRewardTransaction(servers[randomIndex].node)
        randomIndex = random.randint(0, len(servers) - 1)
        servers[randomIndex].node.sendBlock()
        time.sleep(12)
        print(
            "Blockchain Summaries\n====================================================="
        )
        for server in servers:
示例#17
0
文件: vbmap.py 项目: sh4rkfin/misc
    def add_to_network(self, color, network):
        prev_avb = self.prev_avb()[color]
        for i, a in enumerate(prev_avb):
            if a > 0:
                n1 = network.find_or_create_node(('prev_avb', i, color))
                n1.set_source(a, color)
                for j in range(self.node_count):
                    n2 = network.find_or_create_node(('avb', j))
                    a = Arc(n2)
                    n1.add_arc(a)
                    a.set_cost(1 if i != j else 0)
        avbs = network.find_nodes_satisfying(lambda x: x.key()[0] == 'avb')
        for n1 in avbs:
            key = ('avbp', n1.key()[1])
            n2 = network.find_node(key)
            if n2 is None:
                n2 = Node(key)
                network.add_node(n2)
                arc = Arc(n2)
                arc.set_capacity(math.floor(1024.0 / len(avbs)))
                arc.set_cost(-100000)
                n1.add_arc(arc)
                n1.add_arc(Arc(n2))

        replica_network = self._replica_networks[0]
        for i, connections in enumerate(replica_network):
            for j, connection in enumerate(connections):
                if connection != 0:
                    n1 = network.find_or_create_node(('avbp', i))
                    n2 = network.find_or_create_node(('rvbp', j))
                    a = n1.get_arc(n2)
                    if not a:
                        a = Arc(n2)
                        n1.add_arc(a)
                        capacity = math.ceil(1024.0 / (self.node_count * self.slave_factor))
                        print "cap: ", capacity
                        a.set_capacity(capacity)

        rvbps = network.find_nodes_satisfying(lambda x: x.key()[0] == 'rvbp')
        for n1 in rvbps:
            key = ('rvb', n1.key()[1])
            n2 = network.find_node(key)
            if n2 is None:
                n2 = Node(key)
                network.add_node(n2)
                arc = Arc(n2)
                arc.set_capacity(math.floor(1024.0 / len(avbs)))
                arc.set_cost(-100000)
                n1.add_arc(arc)
                n1.add_arc(Arc(n2))

        prev_rvb = self.prev_rvb()[color]
        for i, r in enumerate(prev_rvb):
            if r > 0:
                n1 = network.find_or_create_node(('prev_rvb', i, color))
                for j in range(self.node_count):
                    n2 = network.find_or_create_node(('rvb', j))
                    a = Arc(n1)
                    n2.add_arc(a)
                    a.set_cost(1 if i != j else 0)
                    n1.set_source(-r, color)