def test_wallet_name(self): """ Test the name of a dummy wallet """ self.assertEqual(self.dummy_wallet.get_name(), 'Dummy') self.assertEqual(DummyWallet1().get_name(), 'Dummy 1') self.assertEqual(DummyWallet2().get_name(), 'Dummy 2')
def create_node(self): dum1_wallet = DummyWallet1() dum2_wallet = DummyWallet2() dum1_wallet.MONITOR_DELAY = 0 dum2_wallet.MONITOR_DELAY = 0 wallets = {'DUM1': dum1_wallet, 'DUM2': dum2_wallet} mock_ipv8 = MockIPv8(u"curve25519", MarketCommunity, create_trustchain=True, create_dht=True, is_matchmaker=True, wallets=wallets, use_database=False, working_directory=u":memory:") mock_ipv8.overlay.settings.single_trade = False mock_ipv8.overlay.clearing_policies = [] mock_ipv8.overlays = [mock_ipv8.overlay] # Start REST API self.restapi = RESTManager(mock_ipv8) random_port = get_random_port() self.restapi.start(random_port) return mock_ipv8
def test_wallet_id(self): """ Test the identifier of a dummy wallet """ self.assertEqual(self.dummy_wallet.get_identifier(), 'DUM') self.assertEqual(DummyWallet1().get_identifier(), 'DUM1') self.assertEqual(DummyWallet2().get_identifier(), 'DUM2')
def test_wallet_name(dummy_wallet): """ Test the name of a dummy wallet """ assert dummy_wallet.get_name() == 'Dummy' assert DummyWallet1().get_name() == 'Dummy 1' assert DummyWallet2().get_name() == 'Dummy 2'
def test_wallet_id(dummy_wallet): """ Test the identifier of a dummy wallet """ assert dummy_wallet.get_identifier() == 'DUM' assert DummyWallet1().get_identifier() == 'DUM1' assert DummyWallet2().get_identifier() == 'DUM2'
def create_node(self): dum1_wallet = DummyWallet1() dum2_wallet = DummyWallet2() dum1_wallet.MONITOR_DELAY = 0 dum2_wallet.MONITOR_DELAY = 0 wallets = {'DUM1': dum1_wallet, 'DUM2': dum2_wallet} mock_ipv8 = MockIPv8(u"curve25519", MarketCommunity, create_trustchain=True, create_dht=True, is_matchmaker=True, wallets=wallets, use_database=False, working_directory=u":memory:") tc_wallet = TrustchainWallet(mock_ipv8.trustchain) mock_ipv8.overlay.wallets['MB'] = tc_wallet return mock_ipv8
def create_node(self): dum1_wallet = DummyWallet1() dum2_wallet = DummyWallet2() dum1_wallet.MONITOR_DELAY = 0 dum2_wallet.MONITOR_DELAY = 0 wallets = {'DUM1': dum1_wallet, 'DUM2': dum2_wallet} mock_ipv8 = MockIPv8("curve25519", MarketCommunity, create_dht=True, is_matchmaker=True, wallets=wallets, use_database=self.use_database(), working_directory=self.get_db_location()) trustchain = TrustChainCommunity(mock_ipv8.my_peer, mock_ipv8.endpoint, mock_ipv8.network, working_directory=":memory:") mock_ipv8.overlay.trustchain = trustchain mock_ipv8.overlay.initialize_trustchain() tc_wallet = TrustchainWallet(mock_ipv8.overlay.trustchain) mock_ipv8.overlay.wallets['MB'] = tc_wallet mock_ipv8.overlay.settings.max_concurrent_trades = 0 mock_ipv8.overlay.clearing_policies = [] return mock_ipv8
def create_node(self): dum1_wallet = DummyWallet1() dum2_wallet = DummyWallet2() dum1_wallet.MONITOR_DELAY = 0 dum2_wallet.MONITOR_DELAY = 0 wallets = {'DUM1': dum1_wallet, 'DUM2': dum2_wallet} mock_ipv8 = MockIPv8(u"curve25519", MarketCommunity, create_trustchain=True, create_dht=True, is_matchmaker=True, wallets=wallets, use_database=self.use_database(), working_directory=self.get_db_location()) tc_wallet = TrustchainWallet(mock_ipv8.trustchain) mock_ipv8.overlay.wallets['MB'] = tc_wallet mock_ipv8.overlay.settings.single_trade = False mock_ipv8.overlay.clearing_policies = [] return mock_ipv8
async def create_node(self, *args, **kwargs): ipv8 = MockRestIPv8(u"curve25519", overlay_classes=self.overlay_classes, *args, **kwargs) self.rest_manager = RESTManager(ipv8, root_endpoint_class=RootEndpoint) ipv8.rest_manager = self.rest_manager await self.rest_manager.start(0) ipv8.rest_port = self.rest_manager.site._server.sockets[0].getsockname( )[1] dum1_wallet = DummyWallet1() dum2_wallet = DummyWallet2() dum1_wallet.MONITOR_DELAY = 0 dum2_wallet.MONITOR_DELAY = 0 wallets = {'DUM1': dum1_wallet, 'DUM2': dum2_wallet} market_community = ipv8.get_overlay(MarketCommunity) market_community.wallets = wallets market_community.settings.single_trade = False market_community.clearing_policies = [] return ipv8
async def start(self): """ Start a Tribler session by initializing the LaunchManyCore class, opening the database and running the upgrader. Returns a deferred that fires when the Tribler session is ready for use. :param config: a TriblerConfig object """ self._logger.info("Session is using state directory: %s", self.config.get_state_dir()) self.get_ports_in_config() self.create_state_directory_structure() self.init_keypair() # Start the REST API before the upgrader since we want to send interesting upgrader events over the socket if self.config.get_http_api_enabled(): self.api_manager = RESTManager(self) self.readable_status = STATE_START_API await self.api_manager.start() if self.upgrader_enabled: self.upgrader = TriblerUpgrader(self) self.readable_status = STATE_UPGRADING_READABLE try: await self.upgrader.run() except Exception as e: self._logger.error("Error in Upgrader callback chain: %s", e) self.tracker_manager = TrackerManager(self) # On Mac, we bundle the root certificate for the SSL validation since Twisted is not using the root # certificates provided by the system trust store. if sys.platform == 'darwin': os.environ['SSL_CERT_FILE'] = str( (get_lib_path() / 'root_certs_mac.pem')) if self.config.get_chant_enabled(): channels_dir = self.config.get_chant_channels_dir() metadata_db_name = 'metadata.db' if not self.config.get_testnet( ) else 'metadata_testnet.db' database_path = self.config.get_state_dir( ) / 'sqlite' / metadata_db_name self.mds = MetadataStore(database_path, channels_dir, self.trustchain_keypair) # IPv8 if self.config.get_ipv8_enabled(): from ipv8.configuration import get_default_configuration ipv8_config = get_default_configuration() ipv8_config['port'] = self.config.get_ipv8_port() ipv8_config['address'] = self.config.get_ipv8_address() ipv8_config['overlays'] = [] ipv8_config['keys'] = [] # We load the keys ourselves ipv8_config['working_directory'] = str(self.config.get_state_dir()) if self.config.get_ipv8_bootstrap_override(): import ipv8.community as community_file community_file._DEFAULT_ADDRESSES = [ self.config.get_ipv8_bootstrap_override() ] community_file._DNS_ADDRESSES = [] self.ipv8 = IPv8( ipv8_config, enable_statistics=self.config.get_ipv8_statistics()) await self.ipv8.start() self.config.set_anon_proxy_settings( 2, ("127.0.0.1", self.config.get_tunnel_community_socks5_listen_ports())) self.ipv8_start_time = timemod.time() self.load_ipv8_overlays() self.enable_ipv8_statistics() if self.api_manager: self.api_manager.set_ipv8_session(self.ipv8) if self.config.get_tunnel_community_enabled(): await self.tunnel_community.wait_for_socks_servers() # Note that currently we should only start libtorrent after the SOCKS5 servers have been started if self.config.get_libtorrent_enabled(): self.readable_status = STATE_START_LIBTORRENT from tribler_core.modules.libtorrent.download_manager import DownloadManager self.dlmgr = DownloadManager(self) self.dlmgr.initialize() self.readable_status = STATE_LOAD_CHECKPOINTS await self.dlmgr.load_checkpoints() self.readable_status = STATE_READABLE_STARTED if self.config.get_torrent_checking_enabled(): self.readable_status = STATE_START_TORRENT_CHECKER self.torrent_checker = TorrentChecker(self) await self.torrent_checker.initialize() if self.config.get_dummy_wallets_enabled(): # For debugging purposes, we create dummy wallets dummy_wallet1 = DummyWallet1() self.wallets[dummy_wallet1.get_identifier()] = dummy_wallet1 dummy_wallet2 = DummyWallet2() self.wallets[dummy_wallet2.get_identifier()] = dummy_wallet2 if self.config.get_watch_folder_enabled(): self.readable_status = STATE_START_WATCH_FOLDER self.watch_folder = WatchFolder(self) self.watch_folder.start() if self.config.get_resource_monitor_enabled(): self.resource_monitor = ResourceMonitor(self) self.resource_monitor.start() if self.config.get_version_checker_enabled(): self.version_check_manager = VersionCheckManager(self) self.version_check_manager.start() if self.config.get_ipv8_enabled( ) and self.config.get_trustchain_enabled(): self.payout_manager = PayoutManager(self.trustchain_community, self.dht_community) # GigaChannel Manager should be started *after* resuming the downloads, # because it depends on the states of torrent downloads if self.config.get_chant_enabled() and self.config.get_chant_manager_enabled()\ and self.config.get_libtorrent_enabled: self.gigachannel_manager = GigaChannelManager(self) self.gigachannel_manager.start() if self.config.get_bootstrap_enabled(): self.register_task('bootstrap_download', self.start_bootstrap_download) self.notifier.notify(NTFY.TRIBLER_STARTED)
def start_anydex(self, options): """ Main method to startup AnyDex. """ config = get_anydex_configuration() if options["statedir"]: # If we use a custom state directory, update various variables for key in config["keys"]: key["file"] = os.path.join(options["statedir"], key["file"]) for community in config["overlays"]: if community["class"] == "TrustChainCommunity": community["initialize"]["working_directory"] = options["statedir"] if 'testnet' in options and options['testnet']: for community in config["overlays"]: if community["class"] == "TrustChainCommunity": community["class"] = "TrustChainTestnetCommunity" self.ipv8 = IPv8(config, enable_statistics=options['statistics']) def signal_handler(sig, _): msg("Received shut down signal %s" % sig) if not self._stopping: self._stopping = True if self.restapi: self.restapi.stop() self.ipv8.stop() signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) msg("Starting AnyDex") if not options['no-rest-api']: self.restapi = RESTManager(self.ipv8) reactor.callLater(0.0, self.restapi.start) factory = WebSocketServerFactory(u"ws://127.0.0.1:9000") factory.protocol = AnyDexWebsocketProtocol reactor.listenTCP(9000, factory) # Get Trustchain + DHT overlays for overlay in self.ipv8.overlays: if isinstance(overlay, TrustChainTestnetCommunity): self.trustchain = overlay elif isinstance(overlay, DHTDiscoveryCommunity): self.dht = overlay # Initialize wallets dummy_wallet1 = DummyWallet1() self.wallets[dummy_wallet1.get_identifier()] = dummy_wallet1 dummy_wallet2 = DummyWallet2() self.wallets[dummy_wallet2.get_identifier()] = dummy_wallet2 # Load market community self.market = MarketTestnetCommunity(self.trustchain.my_peer, self.ipv8.endpoint, self.ipv8.network, trustchain=self.trustchain, dht=self.dht, wallets=self.wallets, working_directory=options["statedir"], record_transactions=False) self.ipv8.overlays.append(self.market) self.ipv8.strategies.append((RandomWalk(self.market), 20))
async def start_anydex(self, options): """ Main method to startup AnyDex. """ config = get_anydex_configuration() if options.statedir: # If we use a custom state directory, update various variables for key in config["keys"]: key["file"] = os.path.join(options.statedir, key["file"]) for community in config["overlays"]: if community["class"] == "TrustChainCommunity": community["initialize"][ "working_directory"] = options.statedir if options.testnet: for community in config["overlays"]: if community["class"] == "TrustChainCommunity": community["class"] = "TrustChainTestnetCommunity" self.ipv8 = IPv8(config, enable_statistics=options.statistics) await self.ipv8.start() print("Starting AnyDex") if not options.no_rest_api: self.restapi = RESTManager(self.ipv8) await self.restapi.start(options.apiport) async def signal_handler(sig): print("Received shut down signal %s" % sig) if not self._stopping: self._stopping = True if self.restapi: await self.restapi.stop() self.restapi = None await self.ipv8.stop() get_event_loop().stop() signal.signal(signal.SIGINT, lambda sig, _: ensure_future(signal_handler(sig))) signal.signal(signal.SIGTERM, lambda sig, _: ensure_future(signal_handler(sig))) # Get Trustchain + DHT overlays for overlay in self.ipv8.overlays: if isinstance(overlay, (TrustChainCommunity, TrustChainTestnetCommunity)): self.trustchain = overlay elif isinstance(overlay, DHTDiscoveryCommunity): self.dht = overlay # Initialize wallets dummy_wallet1 = DummyWallet1() self.wallets[dummy_wallet1.get_identifier()] = dummy_wallet1 dummy_wallet2 = DummyWallet2() self.wallets[dummy_wallet2.get_identifier()] = dummy_wallet2 # Load market community self.market = MarketTestnetCommunity( self.trustchain.my_peer, self.ipv8.endpoint, self.ipv8.network, trustchain=self.trustchain, dht=self.dht, wallets=self.wallets, working_directory=options.statedir, record_transactions=False, is_matchmaker=not options.no_matchmaker) self.ipv8.overlays.append(self.market) self.ipv8.strategies.append((RandomWalk(self.market), 20))