Exemple #1
0
    def create_node(self):
        config = TunnelCommunitySettings()
        mock_ipv8 = MockIPv8("curve25519",
                             TriblerTunnelCommunity,
                             settings={'remove_tunnel_delay': 0},
                             config=config,
                             exitnode_cache=Path(self.temporary_directory()) /
                             "exitnode_cache.dat")
        mock_ipv8.overlay.settings.max_circuits = 1

        db = BandwidthDatabase(
            db_path=MEMORY_DB,
            my_pub_key=mock_ipv8.my_peer.public_key.key_to_bin())

        # Load the bandwidth accounting community
        mock_ipv8.overlay.bandwidth_community = BandwidthAccountingCommunity(
            mock_ipv8.my_peer,
            mock_ipv8.endpoint,
            mock_ipv8.network,
            settings=BandwidthAccountingSettings(),
            database=db)
        mock_ipv8.overlay.dht_provider = MockDHTProvider(
            Peer(mock_ipv8.overlay.my_peer.key,
                 mock_ipv8.overlay.my_estimated_wan))

        return mock_ipv8
Exemple #2
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}

        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
Exemple #3
0
async def mock_ipv8(session):
    db_path = session.config.get_state_dir() / "bandwidth.db"
    mock_ipv8 = MockIPv8("low",
                         BandwidthAccountingCommunity,
                         database_path=db_path)
    session.bandwidth_community = mock_ipv8.overlay
    yield mock_ipv8
    await mock_ipv8.stop()
    async def setUp(self):
        await super(TestTrustchainStatsEndpoint, self).setUp()

        self.mock_ipv8 = MockIPv8(u"low",
                                  TrustChainCommunity,
                                  working_directory=self.session.config.get_state_dir())
        self.session.trustchain_community = self.mock_ipv8.overlay
        self.session.wallets['MB'] = TrustchainWallet(self.session.trustchain_community)
async def create_tunnel_community(temp_path_factory,
                                  comm_config: TunnelCommunitySettings = None,
                                  exitnode=False,
                                  start_lt=False) -> TriblerTunnelCommunity:
    """
    Load the tunnel community in a given session. We are using our own tunnel community here instead of the one
    used in Tribler.
    """
    socks_servers = []
    socks_ports = []
    # Start the SOCKS5 servers
    if start_lt:
        for _ in range(NUM_SOCKS_PROXIES):
            socks_server = Socks5Server()
            socks_servers.append(socks_server)
            await socks_server.start()
            socks_ports.append(socks_server.port)

    dlmgr = None
    if start_lt:
        # If libtorrent tries to connect to the socks5 servers before they are loaded,
        # it will never recover (on Mac/Linux with Libtorrent >=1.2.0). Therefore, we start
        # libtorrent afterwards.
        dlmgr_settings = LibtorrentSettings()
        dlmgr_settings.dht = False

        dlmgr = DownloadManager(
            state_dir=temp_path_factory.mktemp('state_dir'),
            config=dlmgr_settings,
            peer_mid=MagicMock(),
            socks_listen_ports=socks_ports,
            notifier=MagicMock())
        dlmgr.metadata_tmpdir = temp_path_factory.mktemp('metadata_tmpdir')

    comm_config = comm_config or TunnelCommunitySettings()
    comm_config.exitnode_enabled = exitnode
    mock_ipv8 = MockIPv8("curve25519",
                         TriblerTunnelCommunity,
                         settings={"max_circuits": 1},
                         config=comm_config,
                         socks_servers=socks_servers,
                         dlmgr=dlmgr)
    if start_lt:
        dlmgr.peer_mid = mock_ipv8.my_peer.mid
        dlmgr.initialize()
        dlmgr.is_shutdown_ready = lambda: True
    tunnel_community = mock_ipv8.overlay

    if exitnode:
        mock_ipv8.overlay.settings.peer_flags.add(PEER_FLAG_EXIT_BT)
    mock_ipv8.overlay.dht_provider = MockDHTProvider(
        Peer(mock_ipv8.overlay.my_peer.key,
             mock_ipv8.overlay.my_estimated_wan))
    mock_ipv8.overlay.settings.remove_tunnel_delay = 0

    return tunnel_community
Exemple #6
0
async def mock_ipv8():
    ipv8 = MockIPv8("low",
                    BandwidthAccountingCommunity,
                    database=Mock(),
                    settings=BandwidthAccountingSettings())
    ipv8.overlays = [ipv8.overlay]
    ipv8.endpoint.bytes_up = 100
    ipv8.endpoint.bytes_down = 20
    yield ipv8
    await ipv8.stop()
async def mock_ipv8(session):
    db_path = Path(":memory:")
    mock_ipv8 = MockIPv8("low", BandwidthAccountingCommunity, database_path=db_path)
    mock_ipv8.overlays = [mock_ipv8.overlay]
    mock_ipv8.endpoint.bytes_up = 100
    mock_ipv8.endpoint.bytes_down = 20
    session.ipv8 = mock_ipv8
    session.config.set_ipv8_enabled(True)
    yield mock_ipv8
    session.ipv8 = None
    await mock_ipv8.stop()
Exemple #8
0
    def create_node(self, *args, **kwargs):
        mds = MetadataStore(
            Path(self.temporary_directory()) / ("%d.db" % self.count),
            Path(self.temporary_directory()),
            default_eccrypto.generate_key("curve25519"))

        torrent_checker = MockObject()
        torrent_checker.torrents_checked = set()

        return MockIPv8("curve25519",
                        PopularityCommunity,
                        metadata_store=mds,
                        torrent_checker=torrent_checker)
Exemple #9
0
 def test_one_sub(self, monkeypatch):
     monkeypatch.setattr(MockSubCommunityRoutines, "my_subcoms", [])
     monkeypatch.setattr(MockSubCommunityRoutines,
                         "discovered_peers_by_subcom", lambda _, __: [])
     key = default_eccrypto.generate_key(u"medium").pub().key_to_bin()
     monkeypatch.setattr(
         FakeRoutines,
         "ipv8",
         MockIPv8(u"curve25519", IPv8SubCommunity, subcom_id=key),
     )
     f = FakeSubCommunity()
     f.discovery_strategy = MockSubCommunityDiscoveryStrategy(None)
     f.subscribe_to_subcom(b"test1")
    async def setUp(self):
        await super(TestStatisticsEndpoint, self).setUp()

        self.mock_ipv8 = MockIPv8(
            u"low",
            TrustChainCommunity,
            working_directory=self.session.config.get_state_dir())
        self.mock_ipv8.overlays = [self.mock_ipv8.overlay]
        self.mock_ipv8.endpoint.bytes_up = 100
        self.mock_ipv8.endpoint.bytes_down = 20
        self.session.ipv8 = self.mock_ipv8
        self.session.config.set_ipv8_enabled(True)
        my_key = default_eccrypto.generate_key(u"curve25519")
        self.session.mds = MetadataStore(self.session_base_dir / 'test.db',
                                         self.session_base_dir, my_key)
Exemple #11
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}

        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):
        mock_ipv8 = MockIPv8(
            "curve25519",
            TriblerTunnelCommunity,
            socks_listen_ports=[],
            settings={'remove_tunnel_delay': 0},
            exitnode_cache=mkdtemp(suffix="_tribler_test_cache") / 'cache.dat')
        mock_ipv8.overlay.settings.max_circuits = 1

        # Load the bandwidth accounting community
        mock_ipv8.overlay.bandwidth_community = BandwidthAccountingCommunity(
            mock_ipv8.my_peer,
            mock_ipv8.endpoint,
            mock_ipv8.network,
            database_path=":memory:")
        mock_ipv8.overlay.dht_provider = MockDHTProvider(
            Peer(mock_ipv8.overlay.my_peer.key,
                 mock_ipv8.overlay.my_estimated_wan))

        return mock_ipv8
    async def setUp(self):
        await super(TestTrustViewEndpoint, self).setUp()

        self.mock_ipv8 = MockIPv8(
            u"low",
            TrustChainCommunity,
            working_directory=self.session.config.get_state_dir())
        self.session.trustchain_community = self.mock_ipv8.overlay

        self.session.bootstrap = Mock()
        self.session.bootstrap.shutdown = lambda: succeed(None)

        bootstrap_download_state = MockObject()
        bootstrap_download_state.get_total_transferred = lambda _: random.randint(
            0, 10000)
        bootstrap_download_state.get_progress = lambda: random.randint(10, 100)

        self.session.bootstrap.download.get_state = lambda: bootstrap_download_state

        self.endpoint = self.session.api_manager.root_endpoint.endpoints[
            '/trustview']
Exemple #14
0
    def create_node(self):
        mock_ipv8 = MockIPv8(
            u"curve25519",
            TriblerTunnelCommunity,
            socks_listen_ports=[],
            exitnode_cache=mkdtemp(suffix="_tribler_test_cache") / 'cache.dat')
        mock_ipv8.overlay.settings.max_circuits = 1

        # Load the TrustChain community
        mock_ipv8.trustchain = TrustChainCommunity(
            mock_ipv8.my_peer,
            mock_ipv8.endpoint,
            mock_ipv8.network,
            working_directory=u":memory:")
        mock_ipv8.overlay.bandwidth_wallet = TrustchainWallet(
            mock_ipv8.trustchain)
        mock_ipv8.overlay.dht_provider = MockDHTProvider(
            Peer(mock_ipv8.overlay.my_peer.key,
                 mock_ipv8.overlay.my_estimated_wan))

        return mock_ipv8
Exemple #15
0
async def load_tunnel_community_in_session(session,
                                           exitnode=False,
                                           start_lt=False):
    """
    Load the tunnel community in a given session. We are using our own tunnel community here instead of the one
    used in Tribler.
    """
    session.config.set_tunnel_community_exitnode_enabled(exitnode)

    mock_ipv8 = MockIPv8("curve25519",
                         TriblerTunnelCommunity,
                         settings={"max_circuits": 1},
                         tribler_session=session)
    session.ipv8 = mock_ipv8

    if exitnode:
        mock_ipv8.overlay.settings.peer_flags.add(PEER_FLAG_EXIT_BT)
    mock_ipv8.overlay.dht_provider = MockDHTProvider(
        Peer(mock_ipv8.overlay.my_peer.key,
             mock_ipv8.overlay.my_estimated_wan))
    mock_ipv8.overlay.settings.remove_tunnel_delay = 0

    await mock_ipv8.overlay.wait_for_socks_servers()

    if start_lt:
        # If libtorrent tries to connect to the socks5 servers before they are loaded,
        # it will never recover (on Mac/Linux with Libtorrent >=1.2.0). Therefore, we start
        # libtorrent afterwards.
        tunnel_community_ports = session.config.get_tunnel_community_socks5_listen_ports(
        )
        session.config.set_anon_proxy_settings(
            2, ("127.0.0.1", tunnel_community_ports))
        session.dlmgr = DownloadManager(session)
        session.dlmgr.initialize()
        session.dlmgr.is_shutdown_ready = lambda: True

    session.tunnel_community = mock_ipv8.overlay

    return mock_ipv8.overlay
    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
Exemple #17
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}

        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
Exemple #18
0
 def create_node(self):
     return MockIPv8(u"curve25519", TrustChainCommunity, working_directory=u":memory:")
Exemple #19
0
 def create_node(self):
     peer = Peer(default_eccrypto.generate_key("curve25519"), address=("1.2.3.4", 5))
     db = BandwidthDatabase(db_path=MEMORY_DB, my_pub_key=peer.public_key.key_to_bin())
     ipv8 = MockIPv8(peer, BandwidthAccountingCommunity, database=db,
                     settings=BandwidthAccountingSettings())
     return ipv8
 def create_node(self, *args, **kwargs):
     return MockIPv8("curve25519", VersionCommunity)
Exemple #21
0
 def create_node(self):
     return MockIPv8("curve25519",
                     BandwidthAccountingCommunity,
                     database_path=":memory:")
Exemple #22
0
def create_node(overlay_class, work_dir=".", **kwargs):
    ipv8 = MockIPv8("curve25519", overlay_class, work_dir=work_dir, **kwargs)
    ipv8.overlay.ipv8 = ipv8
    return ipv8
Exemple #23
0
 def create_node(self, *args, **kwargs):
     return MockIPv8("curve25519",
                     TagCommunity,
                     db=TagDatabase(),
                     tags_key=LibNaCLSK(),
                     request_interval=REQUEST_INTERVAL_FOR_RANDOM_TAGS)