Exemplo n.º 1
0
    def setUp(self):
        yield BaseTestMarketCommunity.setUp(self)

        self.node_a, self.node_b, self.node_c = yield self.create_nodes(3)
        self.node_a.community.is_matchmaker = False
        self.node_b.community.is_matchmaker = False

        dummy1_a = DummyWallet1()
        dummy1_b = DummyWallet1()
        dummy1_c = DummyWallet1()
        dummy2_a = DummyWallet2()
        dummy2_b = DummyWallet2()
        dummy2_c = DummyWallet2()

        self.node_a.community.wallets = {
            dummy1_a.get_identifier(): dummy1_a,
            dummy2_a.get_identifier(): dummy2_a
        }
        self.node_b.community.wallets = {
            dummy1_b.get_identifier(): dummy1_b,
            dummy2_b.get_identifier(): dummy2_b
        }
        self.node_c.community.wallets = {
            dummy1_c.get_identifier(): dummy1_c,
            dummy2_c.get_identifier(): dummy2_c
        }
Exemplo n.º 2
0
 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')
Exemplo n.º 3
0
 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')
Exemplo n.º 4
0
    def setUp(self, autoload_discovery=True):
        yield super(TestMarketEndpoint, self).setUp(autoload_discovery=autoload_discovery)
        dummy1_wallet = DummyWallet1()
        dummy2_wallet = DummyWallet2()

        self.session.lm.market_community.wallets = {dummy1_wallet.get_identifier(): dummy1_wallet,
                                                    dummy2_wallet.get_identifier(): dummy2_wallet}
    def load_market_community_in_session(self, session, market_member,
                                         mc_community):
        """
        Load the market community and tradechain community in a given session.
        """
        wallets = {
            'BTC':
            BitcoinWallet(
                os.path.join(session.config.get_state_dir(), 'wallet')),
            'MC':
            TrustchainWallet(mc_community),
            'DUM1':
            DummyWallet1(),
            'DUM2':
            DummyWallet2()
        }
        wallets['MC'].check_negative_balance = False

        dispersy = session.get_dispersy_instance()

        # Load MarketCommunity
        market_kargs = {'tribler_session': session, 'wallets': wallets}
        self.market_communities[session] = dispersy.define_auto_load(
            MarketCommunityTests, market_member, kargs=market_kargs,
            load=True)[0]
        return self.market_communities[session]
Exemplo n.º 6
0
    def setUp(self):
        yield BaseTestMarketCommunity.setUp(self)

        self.node_a, self.node_b = yield self.create_nodes(2)

        dummy1_a = DummyWallet1()
        dummy1_b = DummyWallet1()
        dummy2_a = DummyWallet2()
        dummy2_b = DummyWallet2()

        self.node_a.community.wallets = {
            dummy1_a.get_identifier(): dummy1_a,
            dummy2_a.get_identifier(): dummy2_a
        }
        self.node_b.community.wallets = {
            dummy1_b.get_identifier(): dummy1_b,
            dummy2_b.get_identifier(): dummy2_b
        }
Exemplo n.º 7
0
    def setUp(self):
        yield DispersyTestFunc.setUp(self)

        self.temp_dir = mkdtemp(suffix="_iom_tests")

        self.node_a, self.node_b = yield self.create_nodes(2)

        dummy1_a = DummyWallet1()
        dummy1_b = DummyWallet1()
        dummy2_a = DummyWallet2()
        dummy2_b = DummyWallet2()

        self.node_a.community.wallets = {
            dummy1_a.get_identifier(): dummy1_a,
            dummy2_a.get_identifier(): dummy2_a
        }
        self.node_b.community.wallets = {
            dummy1_b.get_identifier(): dummy1_b,
            dummy2_b.get_identifier(): dummy2_b
        }
Exemplo n.º 8
0
    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}

        return MockIPv8(u"curve25519",
                        MarketCommunity,
                        is_matchmaker=True,
                        wallets=wallets,
                        use_database=False,
                        working_directory=u":memory:")
Exemplo n.º 9
0
    def setUp(self, annotate=True):
        yield super(CommunityTestSuite, self).setUp(annotate=annotate)

        dummy1_wallet = DummyWallet1()
        dummy2_wallet = DummyWallet2()

        self.market_community = MarketCommunity(self.dispersy,
                                                self.master_member,
                                                self.member)
        self.market_community.initialize(wallets={
            dummy1_wallet.get_identifier():
            dummy1_wallet,
            dummy2_wallet.get_identifier():
            dummy2_wallet
        },
                                         use_database=False)
        self.market_community.use_local_address = True
        self.dispersy._lan_address = ("127.0.0.1", 1234)
        self.dispersy._endpoint.open(self.dispersy)

        self.dispersy.attach_community(self.market_community)

        eccrypto = ECCrypto()
        ec = eccrypto.generate_key(u"curve25519")
        member = Member(self.dispersy, ec, 1)

        trader_id = hashlib.sha1(member.public_key).digest().encode('hex')
        self.ask = Ask(
            MessageId(TraderId('0'), MessageNumber('message_number')),
            OrderId(TraderId(trader_id), OrderNumber(1234)),
            Price(63400, 'DUM1'), Quantity(30, 'DUM2'), Timeout(3600),
            Timestamp.now())
        self.ask.sign(member)

        self.bid = Bid(
            MessageId(TraderId('1'), MessageNumber('message_number')),
            OrderId(TraderId(trader_id), OrderNumber(1235)),
            Price(343, 'DUM1'), Quantity(22, 'DUM2'), Timeout(3600),
            Timestamp.now())
        self.bid.sign(member)
        self.order = Order(
            OrderId(TraderId(self.market_community.mid), OrderNumber(24)),
            Price(20, 'DUM1'), Quantity(30, 'DUM2'), Timeout(3600.0),
            Timestamp.now(), False)
        self.proposed_trade = Trade.propose(
            MessageId(TraderId('0'), MessageNumber('message_number')),
            OrderId(TraderId('0'), OrderNumber(23)),
            OrderId(TraderId(self.market_community.mid), OrderNumber(24)),
            Price(20, 'DUM1'), Quantity(30, 'DUM2'), Timestamp.now())
Exemplo n.º 10
0
    def setUp(self, autoload_discovery=True):
        yield super(TestMarketEndpoint,
                    self).setUp(autoload_discovery=autoload_discovery)

        dummy1_wallet = DummyWallet1()
        dummy2_wallet = DummyWallet2()
        wallets_dict = {
            dummy1_wallet.get_identifier(): dummy1_wallet,
            dummy2_wallet.get_identifier(): dummy2_wallet
        }
        self.mock_ipv8 = MockIPv8(
            u"low",
            MarketCommunity,
            wallets=wallets_dict,
            working_directory=self.session.config.get_state_dir())
        self.session.lm.market_community = self.mock_ipv8.overlay
Exemplo n.º 11
0
    def load_ipv8_overlays(self):
        # Discovery Community
        with open(self.session.config.get_permid_keypair_filename(),
                  'r') as key_file:
            content = key_file.read()
        content = content[31:-30].replace('\n', '').decode("BASE64")
        peer = Peer(M2CryptoSK(keystring=content))
        discovery_community = DiscoveryCommunity(peer, self.ipv8.endpoint,
                                                 self.ipv8.network)
        discovery_community.resolve_dns_bootstrap_addresses()
        self.ipv8.overlays.append(discovery_community)
        self.ipv8.strategies.append((RandomChurn(discovery_community), -1))

        if not self.session.config.get_dispersy_enabled():
            self.ipv8.strategies.append((RandomWalk(discovery_community), 20))

        # TriblerChain Community
        if self.session.config.get_trustchain_enabled():
            triblerchain_peer = Peer(self.session.trustchain_keypair)

            from Tribler.community.triblerchain.community import TriblerChainCommunity
            self.triblerchain_community = TriblerChainCommunity(
                triblerchain_peer,
                self.ipv8.endpoint,
                self.ipv8.network,
                tribler_session=self.session,
                working_directory=self.session.config.get_state_dir())
            self.ipv8.overlays.append(self.triblerchain_community)
            self.ipv8.strategies.append(
                (EdgeWalk(self.triblerchain_community), 20))

        # Tunnel Community
        if self.session.config.get_tunnel_community_enabled():
            tunnel_peer = Peer(self.session.trustchain_keypair)

            from Tribler.community.triblertunnel.community import TriblerTunnelCommunity
            self.tunnel_community = TriblerTunnelCommunity(
                tunnel_peer,
                self.ipv8.endpoint,
                self.ipv8.network,
                tribler_session=self.session,
                dht_provider=MainlineDHTProvider(
                    self.mainline_dht,
                    self.session.config.get_dispersy_port()),
                triblerchain_community=self.triblerchain_community)
            self.ipv8.overlays.append(self.tunnel_community)
            self.ipv8.strategies.append(
                (RandomWalk(self.tunnel_community), 20))

        # Market Community
        if self.session.config.get_market_community_enabled():
            wallets = {}

            try:
                from Tribler.community.market.wallet.btc_wallet import BitcoinWallet, BitcoinTestnetWallet
                wallet_type = BitcoinTestnetWallet if self.session.config.get_btc_testnet(
                ) else BitcoinWallet
                btc_wallet = wallet_type(
                    os.path.join(self.session.config.get_state_dir(),
                                 'wallet'))
                wallets[btc_wallet.get_identifier()] = btc_wallet
            except ImportError:
                self._logger.error(
                    "Electrum wallet cannot be found, Bitcoin trading not available!"
                )

            mc_wallet = TrustchainWallet(self.triblerchain_community)
            wallets[mc_wallet.get_identifier()] = mc_wallet

            if self.session.config.get_dummy_wallets_enabled():
                # For debugging purposes, we create dummy wallets
                dummy_wallet1 = DummyWallet1()
                wallets[dummy_wallet1.get_identifier()] = dummy_wallet1

                dummy_wallet2 = DummyWallet2()
                wallets[dummy_wallet2.get_identifier()] = dummy_wallet2

            from Tribler.community.market.community import MarketCommunity
            market_peer = Peer(self.session.tradechain_keypair)

            self.market_community = MarketCommunity(
                market_peer,
                self.ipv8.endpoint,
                self.ipv8.network,
                tribler_session=self.session,
                wallets=wallets,
                working_directory=self.session.config.get_state_dir())

            self.ipv8.overlays.append(self.market_community)

            self.ipv8.strategies.append(
                (RandomWalk(self.market_community), 20))
Exemplo n.º 12
0
    def load_communities(self):
        self._logger.info("tribler: Preparing communities...")
        now_time = timemod.time()
        default_kwargs = {'tribler_session': self.session}

        # Search Community
        if self.session.config.get_torrent_search_enabled():
            from Tribler.community.search.community import SearchCommunity
            self.dispersy.define_auto_load(SearchCommunity,
                                           self.session.dispersy_member,
                                           load=True,
                                           kargs=default_kwargs)

        # AllChannel Community
        if self.session.config.get_channel_search_enabled():
            from Tribler.community.allchannel.community import AllChannelCommunity
            self.dispersy.define_auto_load(AllChannelCommunity,
                                           self.session.dispersy_member,
                                           load=True,
                                           kargs=default_kwargs)

        # Channel Community
        if self.session.config.get_channel_community_enabled():
            from Tribler.community.channel.community import ChannelCommunity
            self.dispersy.define_auto_load(ChannelCommunity,
                                           self.session.dispersy_member,
                                           load=True,
                                           kargs=default_kwargs)

        # PreviewChannel Community
        if self.session.config.get_preview_channel_community_enabled():
            from Tribler.community.channel.preview import PreviewChannelCommunity
            self.dispersy.define_auto_load(PreviewChannelCommunity,
                                           self.session.dispersy_member,
                                           kargs=default_kwargs)

        # Tunnel Community
        mc_community = None
        if self.session.config.get_tunnel_community_enabled():
            tunnel_settings = TunnelSettings(tribler_session=self.session)
            tunnel_kwargs = {
                'tribler_session': self.session,
                'settings': tunnel_settings
            }

            if self.session.config.get_trustchain_enabled():
                trustchain_kwargs = {'tribler_session': self.session}

                # If the trustchain is enabled, we use the permanent trustchain keypair
                # for both the trustchain and the tunnel community
                keypair = self.session.trustchain_keypair
                dispersy_member = self.dispersy.get_member(
                    private_key=keypair.key_to_bin())

                from Tribler.community.triblerchain.community import TriblerChainCommunity
                mc_community = self.dispersy.define_auto_load(
                    TriblerChainCommunity,
                    dispersy_member,
                    load=True,
                    kargs=trustchain_kwargs)[0]

            else:
                keypair = self.dispersy.crypto.generate_key(u"curve25519")
                dispersy_member = self.dispersy.get_member(
                    private_key=self.dispersy.crypto.key_to_bin(keypair))

            from Tribler.community.tunnel.hidden_community import HiddenTunnelCommunity
            self.tunnel_community = self.dispersy.define_auto_load(
                HiddenTunnelCommunity,
                dispersy_member,
                load=True,
                kargs=tunnel_kwargs)[0]

            # We don't want to automatically load other instances of this community with other master members.
            self.dispersy.undefine_auto_load(HiddenTunnelCommunity)

        # Use the permanent TrustChain ID for Market community/TradeChain if it's available
        if self.session.config.get_market_community_enabled():
            wallets = {}
            btc_wallet = BitcoinWallet(
                os.path.join(self.session.config.get_state_dir(), 'wallet'),
                testnet=self.session.config.get_btc_testnet())
            wallets[btc_wallet.get_identifier()] = btc_wallet

            mc_wallet = TrustchainWallet(mc_community)
            wallets[mc_wallet.get_identifier()] = mc_wallet

            if self.session.config.get_dummy_wallets_enabled():
                # For debugging purposes, we create dummy wallets
                dummy_wallet1 = DummyWallet1()
                wallets[dummy_wallet1.get_identifier()] = dummy_wallet1

                dummy_wallet2 = DummyWallet2()
                wallets[dummy_wallet2.get_identifier()] = dummy_wallet2

            from Tribler.community.market.community import MarketCommunity
            keypair = self.session.tradechain_keypair
            dispersy_member = self.dispersy.get_member(
                private_key=keypair.key_to_bin())

            market_kwargs = {
                'tribler_session': self.session,
                'wallets': wallets
            }
            self.market_community = self.dispersy.define_auto_load(
                MarketCommunity,
                dispersy_member,
                load=True,
                kargs=market_kwargs)[0]

        self.session.config.set_anon_proxy_settings(
            2,
            ("127.0.0.1",
             self.session.config.get_tunnel_community_socks5_listen_ports()))

        self._logger.info("tribler: communities are ready in %.2f seconds",
                          timemod.time() - now_time)