def setup(config={}): """Setup a node.""" config = Config(config=config) start_logger() loop = asyncio.get_event_loop() orchestrator = Orchestrator(config) coro = loop.create_server(lambda: ServerProtocol(orchestrator), *config.client_address) server = loop.run_until_complete(coro) logger.info('Serving Client on %s', config.client_address) return server
def _generate_configs(self, numIds, keys, clientKey): """ keys are the node private keys """ storage_dir = "%s/persistStorage" % os.path.abspath( os.path.dirname(__file__)) # keys = [RSA.generate(2048) for i in range(numIds)] clusterAddresses = [("127.0.0.1", 9110 + i) for i in range(numIds)] # [(ip_addr, port)] clusterMap = { k: keys[i].publickey() for i, k in enumerate(clusterAddresses) } #[(ip_addr, port) -> public key] self.configs = [ Config(storage_dir, clusterMap, i, keys[i], clusterAddresses[i], clientKey, True) for i in range(numIds) ]
def setup(config={}): """Setup a node.""" config = Config(config=config) start_logger() loop = asyncio.get_event_loop() orchestrator = Orchestrator() coro = loop.create_datagram_endpoint(lambda: PeerProtocol(orchestrator), local_addr=config.address) transport, _ = loop.run_until_complete(coro) orchestrator.peer_transport = transport coro = loop.create_server(lambda: ClientProtocol(orchestrator), *config.address) server = loop.run_until_complete(coro) logger.info('Serving on %s', config.address) return server
def run(): """Start a node. e.g python3 main.py /Users/saachi/Desktop/cs244b/zatt/zatt_cluster/config.json 1 --debug True """ parser = argparse.ArgumentParser(description='Start node for Raft BFT') parser.add_argument('configFile', type=str, help='the configuration file') parser.add_argument('id', type=int, help='the node id to be started') parser.add_argument('--debug',type=bool, default=False, help="print debugger log") args = parser.parse_args() config = Config.CreateConfig(args.configFile, args.id, args.debug) server = setup(config) loop = asyncio.get_event_loop() try: loop.run_forever() except KeyboardInterrupt: pass # # Close the server server.close() loop.run_until_complete(server.wait_closed()) loop.close()
def createClientDict(addr, port, config): config = Config.CreateConfig(config, -1, False) return DistributedDict(addr, port, config.cluster, config.private_key)
self.assertEqual(d['adams'], 'the hitchhiker guide') del d['adams'] self.pool.start(0) self.pool.stop(1) d['foo'] = 'bar' self.assertEqual(d['adams'], None) self.assertEqual(d['foo'], 'bar') self.pool.start(1) self.pool.stop(2) d['bar'] = 'foo' del d['foo'] self.assertEqual(d['adams'], None) self.assertEqual(d['foo'], None) self.assertEqual(d['bar'], 'foo') del d['bar'] self.pool.start(2) self.pool.stop(0) d['1'] = '0' self.assertEqual(d['adams'], None) self.assertEqual(d['foo'], None) self.assertEqual(d['bar'], None) self.assertEqual(d['1'], '0') self.pool.start(0) del d if __name__ == '__main__': config = Config(config={}) start_logger() unittest.main(verbosity=2)