Skip to content

Commit

Permalink
Merge pull request #6371 from drew2a/feature/merge_bandwidth_accounting
Browse files Browse the repository at this point in the history
Merge bandwidth_accounting module and component
  • Loading branch information
drew2a authored Sep 27, 2021
2 parents 953fb5a + f5b59e0 commit cb8e5ef
Show file tree
Hide file tree
Showing 35 changed files with 68 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/tribler-core/run_bandwidth_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

from tribler_common.simpledefs import STATEDIR_DB_DIR
from tribler_core.config.tribler_config import TriblerConfig
from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase
from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase
from tribler_core.modules.bandwidth_accounting.launcher import BandwidthCommunityLauncher
from tribler_core.modules.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.components.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.start_core import Session


Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from tribler_core.components.reporter import ReporterComponent
from tribler_core.components.restapi import RESTComponent
from tribler_core.components.upgrade import UpgradeComponent
from tribler_core.modules.bandwidth_accounting.community import (
from tribler_core.components.bandwidth_accounting.community.community import (
BandwidthAccountingCommunity,
BandwidthAccountingTestnetCommunity,
)
from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase
from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase
from tribler_core.restapi.rest_manager import RESTManager


Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ipv8.requestcache import RandomNumberCache

from tribler_core.modules.bandwidth_accounting.transaction import BandwidthTransactionData
from tribler_core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData


class BandwidthTransactionSignCache(RandomNumberCache):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
from ipv8.peer import Peer
from ipv8.requestcache import RequestCache
from ipv8.types import Address

from tribler_core.modules.bandwidth_accounting import EMPTY_SIGNATURE
from tribler_core.modules.bandwidth_accounting.cache import BandwidthTransactionSignCache
from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase
from tribler_core.modules.bandwidth_accounting.payload import (
from tribler_core.components.bandwidth_accounting.community.cache import BandwidthTransactionSignCache
from tribler_core.components.bandwidth_accounting.community.payload import (
BandwidthTransactionPayload,
BandwidthTransactionQueryPayload,
)
from tribler_core.modules.bandwidth_accounting.transaction import BandwidthTransactionData
from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase
from tribler_core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData, EMPTY_SIGNATURE
from tribler_core.modules.tribler_community import TriblerCommunity
from tribler_core.utilities.unicode import hexlify

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from pony.orm import Database, count, db_session, select, sum

from tribler_core.modules.bandwidth_accounting import history, misc, transaction as db_transaction
from tribler_core.modules.bandwidth_accounting.transaction import BandwidthTransactionData
from tribler_core.components.bandwidth_accounting.db import history, misc, transaction as db_transaction
from tribler_core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData
from tribler_core.utilities.utilities import MEMORY_DB


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

from pony.orm import PrimaryKey, Required, db_session

from tribler_core.modules.bandwidth_accounting import EMPTY_SIGNATURE
from tribler_core.modules.bandwidth_accounting.payload import BandwidthTransactionPayload
from tribler_core.components.bandwidth_accounting.community.payload import BandwidthTransactionPayload

EMPTY_SIGNATURE = b'0' * 64

@dataclass
class BandwidthTransactionData:
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from unittest.mock import patch

from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent
from tribler_core.components.base import Session
from tribler_core.components.ipv8 import Ipv8Component
from tribler_core.components.masterkey import MasterKeyComponent
from tribler_core.components.restapi import RESTComponent
from tribler_core.restapi.rest_manager import RESTManager


# pylint: disable=protected-access


async def test_bandwidth_accounting_component(tribler_config):
components = [RESTComponent(), MasterKeyComponent(), Ipv8Component(), BandwidthAccountingComponent()]
session = Session(tribler_config, components)
with session:
comp = BandwidthAccountingComponent.instance()
with patch.object(RESTManager, 'get_endpoint'):
await session.start()

assert comp.community
assert comp._rest_manager
assert comp._ipv8

await session.shutdown()
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import pytest

from tribler_core.modules.bandwidth_accounting import EMPTY_SIGNATURE
from tribler_core.modules.bandwidth_accounting.bandwidth_endpoint import BandwidthEndpoint
from tribler_core.modules.bandwidth_accounting.community import BandwidthAccountingCommunity
from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase
from tribler_core.modules.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.modules.bandwidth_accounting.transaction import BandwidthTransactionData
from tribler_core.components.bandwidth_accounting.restapi.bandwidth_endpoint import BandwidthEndpoint
from tribler_core.components.bandwidth_accounting.community.community import BandwidthAccountingCommunity
from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase
from tribler_core.components.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData, EMPTY_SIGNATURE
from tribler_core.restapi.base_api_test import do_request
from tribler_core.utilities.unicode import hexlify

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
from ipv8.test.base import TestBase
from ipv8.test.mocking.ipv8 import MockIPv8

from tribler_core.modules.bandwidth_accounting import EMPTY_SIGNATURE
from tribler_core.modules.bandwidth_accounting.cache import BandwidthTransactionSignCache
from tribler_core.modules.bandwidth_accounting.community import BandwidthAccountingCommunity
from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase
from tribler_core.modules.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.modules.bandwidth_accounting.transaction import BandwidthTransactionData
from tribler_core.components.bandwidth_accounting.community.cache import BandwidthTransactionSignCache
from tribler_core.components.bandwidth_accounting.community.community import BandwidthAccountingCommunity
from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase
from tribler_core.components.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData, EMPTY_SIGNATURE
from tribler_core.utilities.utilities import MEMORY_DB


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

import pytest

from tribler_core.modules.bandwidth_accounting import EMPTY_SIGNATURE
from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase
from tribler_core.modules.bandwidth_accounting.transaction import BandwidthTransactionData
from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase
from tribler_core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData, EMPTY_SIGNATURE
from tribler_core.utilities.utilities import MEMORY_DB


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from ipv8.keyvault.crypto import default_eccrypto

from tribler_core.modules.bandwidth_accounting import EMPTY_SIGNATURE
from tribler_core.modules.bandwidth_accounting.transaction import BandwidthTransactionData
from tribler_core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData, EMPTY_SIGNATURE


def test_sign_transaction():
Expand Down
2 changes: 1 addition & 1 deletion src/tribler-core/tribler_core/components/payout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tribler_common.simpledefs import NTFY
from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent
from tribler_core.components.base import Component
from tribler_core.components.bandwidth_accounting import BandwidthAccountingComponent
from tribler_core.components.ipv8 import Ipv8Component
from tribler_core.components.reporter import ReporterComponent
from tribler_core.modules.payout.payout_manager import PayoutManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest

from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent
from tribler_core.components.base import Session, SessionError
from tribler_core.components.bandwidth_accounting import BandwidthAccountingComponent
from tribler_core.components.gigachannel import GigaChannelComponent
from tribler_core.components.gigachannel_manager import GigachannelManagerComponent
from tribler_core.components.ipv8 import Ipv8Component
Expand Down Expand Up @@ -62,19 +62,6 @@ async def test_masterkey_component(tribler_config):
await session.shutdown()


async def test_bandwidth_accounting_component(tribler_config):
components = [RESTComponent(), MasterKeyComponent(), Ipv8Component(), BandwidthAccountingComponent()]
session = Session(tribler_config, components)
with session:
comp = BandwidthAccountingComponent.instance()
with patch.object(RESTManager, 'get_endpoint'):
await session.start()

assert comp.community
assert comp._rest_manager
assert comp._ipv8

await session.shutdown()


async def test_giga_channel_component(tribler_config):
Expand Down
2 changes: 1 addition & 1 deletion src/tribler-core/tribler_core/components/tunnels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from ipv8.messaging.anonymization.community import TunnelSettings
from ipv8.peerdiscovery.discovery import RandomWalk
from ipv8_service import IPv8
from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent
from tribler_core.components.base import Component
from tribler_core.components.bandwidth_accounting import BandwidthAccountingComponent
from tribler_core.components.ipv8 import Ipv8Component
from tribler_core.components.libtorrent import LibtorrentComponent
from tribler_core.components.reporter import ReporterComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import BaseSettings, Extra

from tribler_core.modules.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.components.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.modules.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings
from tribler_core.modules.metadata_store.settings import ChantSettings
from tribler_core.modules.popularity.settings import PopularityCommunitySettings
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from tribler_common.simpledefs import DLSTATUS_DOWNLOADING, DLSTATUS_METADATA, DLSTATUS_SEEDING, DLSTATUS_STOPPED, NTFY

from tribler_core.modules.bandwidth_accounting.transaction import BandwidthTransactionData
from tribler_core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData
from tribler_core.modules.tunnel.community.caches import BalanceRequestCache, HTTPRequestCache
from tribler_core.modules.tunnel.community.discovery import GoldenRatioStrategy
from tribler_core.modules.tunnel.community.dispatcher import TunnelDispatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

from tribler_common.network_utils import NetworkUtils

from tribler_core.modules.bandwidth_accounting.community import BandwidthAccountingCommunity
from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase
from tribler_core.modules.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.components.bandwidth_accounting.community.community import BandwidthAccountingCommunity
from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase
from tribler_core.components.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.modules.tunnel.community.community import PEER_FLAG_EXIT_HTTP, TriblerTunnelCommunity
from tribler_core.modules.tunnel.community.payload import BandwidthTransactionPayload
from tribler_core.modules.tunnel.community.settings import TunnelCommunitySettings
Expand Down
2 changes: 1 addition & 1 deletion src/tribler-core/tribler_core/restapi/root_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ipv8.REST.root_endpoint import RootEndpoint as IPV8RootEndpoint

from tribler_core.config.tribler_config import TriblerConfig
from tribler_core.modules.bandwidth_accounting.bandwidth_endpoint import BandwidthEndpoint
from tribler_core.components.bandwidth_accounting.restapi.bandwidth_endpoint import BandwidthEndpoint
from tribler_core.modules.libtorrent.restapi.create_torrent_endpoint import CreateTorrentEndpoint
from tribler_core.modules.libtorrent.restapi.downloads_endpoint import DownloadsEndpoint
from tribler_core.modules.libtorrent.restapi.libtorrent_endpoint import LibTorrentEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import pytest

from tribler_core.modules.bandwidth_accounting.community import BandwidthAccountingCommunity
from tribler_core.modules.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.components.bandwidth_accounting.community.community import BandwidthAccountingCommunity
from tribler_core.components.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler_core.restapi.base_api_test import do_request
from tribler_core.restapi.rest_manager import error_middleware
from tribler_core.restapi.statistics_endpoint import StatisticsEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import pytest

from tribler_core.exceptions import TrustGraphException
from tribler_core.modules.bandwidth_accounting import EMPTY_SIGNATURE
from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase
from tribler_core.modules.bandwidth_accounting.transaction import BandwidthTransactionData
from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase
from tribler_core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData, EMPTY_SIGNATURE
from tribler_core.modules.trust_calculation.trust_graph import TrustGraph
from tribler_core.restapi.base_api_test import do_request
from tribler_core.restapi.rest_manager import error_middleware
Expand Down
2 changes: 1 addition & 1 deletion src/tribler-core/tribler_core/start_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import tribler_core
from tribler_core.check_os import check_and_enable_code_tracing, set_process_priority
from tribler_core.components.bandwidth_accounting import BandwidthAccountingComponent
from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent
from tribler_core.components.base import Component, Session
from tribler_core.components.gigachannel import GigaChannelComponent
from tribler_core.components.gigachannel_manager import GigachannelManagerComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from tribler_common.simpledefs import NTFY

import tribler_core.utilities.permid as permid_module
from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase
from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase
from tribler_core.modules.metadata_store.orm_bindings.channel_metadata import CHANNEL_DIR_NAME_LENGTH
from tribler_core.modules.metadata_store.store import CURRENT_DB_VERSION, MetadataStore
from tribler_core.notifier import Notifier
Expand Down
2 changes: 1 addition & 1 deletion src/tribler-core/tribler_core/upgrade/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from tribler_common.simpledefs import NTFY, STATEDIR_DB_DIR, STATEDIR_CHANNELS_DIR

from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase
from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase
from tribler_core.modules.category_filter.l2_filter import is_forbidden
from tribler_core.modules.metadata_store.orm_bindings.channel_metadata import CHANNEL_DIR_NAME_LENGTH
from tribler_core.modules.metadata_store.serialization import CHANNEL_TORRENT
Expand Down

0 comments on commit cb8e5ef

Please sign in to comment.