Ejemplo n.º 1
0
def main(argv):
	#load configuration
	try:
		configuration_file = open('config.json','r')
		CONFIG = json.loads(configuration_file.read())
		check_configuration(CONFIG)
		configuration_file.close()
		print 'Configuration loaded.'
	except IOError:
		print 'missing configuration file'
		sys.exit(2)
	except ValueError:
		print 'configuration file is corrupt'
		sys.exit(2)

	print Globals.RESOURCES_RESOURCE_CODE

	#Load database
	print '\nLoading Database'
	DATABASE = Database(CONFIG)

	#Load encryption key
	print '\nLoading encryption key'
	CRYPTO = Crypto(CONFIG, DATABASE)

	#Create network manager
	print '\nCreating network manager'
	NETWORK_MANAGER = NetworkManager(CONFIG, DATABASE, CRYPTO)

	#Create server
	print '\nCreating server'
	SERVER = Server(CONFIG, CRYPTO)

	#Create block manager
	print '\nCreating block manager'
	BLOCK_MANAGER = BlockManager(CONFIG, DATABASE, CRYPTO, NETWORK_MANAGER, SERVER)
	SERVER.set_blocks_manager(BLOCK_MANAGER)

	#Connect to nodes
	print '\nConnecting to network'
	NETWORK_MANAGER.connect_to_all(BLOCK_MANAGER)

	print '\nStartup complete, waiting for synchronization'

	while True:
		try:
			cmd = raw_input()
			if cmd in ['shutdown', 'SHUTDOWN', '^C', '^Z', 'exit', 'EXIT', 'close', 'CLOSE']:
				break
		except KeyboardInterrupt:
			break

	print 'Shutdown signal received, stopping everything'
	SERVER.shutdown()
	NETWORK_MANAGER.shutdown()
	print 'All was correctly stopped, exiting'
	sys.exit(0)
Ejemplo n.º 2
0
def main(argv):

	#Load configuration
	print '\nLoading Configuration'
	CONFIG = load_configuration()

	#Load database
	print '\nLoading Database'
	DATABASE = Database(CONFIG)

	#Load encryption key
	print '\nLoading encryption key'
	CRYPTO = Crypto(CONFIG, DATABASE)

	#Create network manager
	print '\nCreating network manager'
	NETWORK_MANAGER = NetworkManager(CONFIG, DATABASE, CRYPTO)

	#Create server
	print '\nCreating server'
	SERVER = Server(CONFIG, CRYPTO)

	#Create block manager
	print '\nCreating block manager'
	BLOCK_MANAGER = BlockManager(CONFIG, DATABASE, CRYPTO, NETWORK_MANAGER, SERVER)
	SERVER.set_blocks_manager(BLOCK_MANAGER)

	#Connect to nodes
	print '\nConnecting to network'
	NETWORK_MANAGER.connect_to_all(BLOCK_MANAGER)

	print '\nStartup complete, waiting for synchronization'

	while True:
		try:
			time.sleep(1)
			os.system('clear')
			print 'Ready for Interruption'
			cmd = raw_input()
			if cmd in ['shutdown', 'SHUTDOWN', '^C', '^Z', 'exit', 'EXIT', 'close', 'CLOSE']:
				break
		except KeyboardInterrupt:
			break

	print 'Shutdown signal received, stopping everything'
	SERVER.shutdown()
	NETWORK_MANAGER.shutdown()
	print 'All was correctly stopped, exiting'
	sys.exit(0)