Skip to content

Commit

Permalink
Merge pull request #6421 from drew2a/refactoring/merge_libtorrent
Browse files Browse the repository at this point in the history
Merge libtorrent module and component
  • Loading branch information
drew2a authored Oct 6, 2021
2 parents 39f9841 + dc78d49 commit 37484c5
Show file tree
Hide file tree
Showing 69 changed files with 176 additions and 181 deletions.
2 changes: 1 addition & 1 deletion experiment/popularity_community/initial_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ipv8.peerdiscovery.discovery import RandomWalk
from ipv8_service import IPv8
from tribler_core.components.ipv8.ipv8_component import Ipv8Component
from tribler_core.components.libtorrent import LibtorrentComponent
from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent
from tribler_core.components.masterkey.masterkey_component import MasterKeyComponent
from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent
from tribler_core.components.popularity import PopularityComponent
Expand Down
4 changes: 2 additions & 2 deletions src/seedbox/disseminator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
from tribler_core.components.gigachannel.gigachannel_component import GigaChannelComponent
from tribler_core.components.gigachannel_manager.gigachannel_manager_component import GigachannelManagerComponent
from tribler_core.components.ipv8.ipv8_component import Ipv8Component
from tribler_core.components.libtorrent import LibtorrentComponent
from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent
from tribler_core.components.masterkey.masterkey_component import MasterKeyComponent
from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW
from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent
from tribler_core.components.restapi import RESTComponent
from tribler_core.components.socks_configurator import SocksServersComponent
from tribler_core.config.tribler_config import TriblerConfig
from tribler_core.modules.libtorrent.torrentdef import TorrentDef
from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.utilities.tiny_tribler_service import TinyTriblerService

# fmt: off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

from tribler_common.simpledefs import DLSTATUS_SEEDING, NTFY

from tribler_core.modules.libtorrent.download_config import DownloadConfig
from tribler_core.modules.libtorrent.download_manager import DownloadManager
from tribler_core.modules.libtorrent.torrentdef import TorrentDef
from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig
from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager
from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.components.metadata_store.db.orm_bindings.channel_node import COMMITTED
from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT
from tribler_core.components.metadata_store.db.store import MetadataStore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tribler_core.components.gigachannel_manager.gigachannel_manager import GigaChannelManager
from tribler_core.components.libtorrent import LibtorrentComponent
from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent
from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent
from tribler_core.components.restapi import RestfulComponent

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

from tribler_common.simpledefs import DLSTATUS_SEEDING

from tribler_core.modules.libtorrent.torrentdef import TorrentDef
from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.components.gigachannel_manager.gigachannel_manager import GigaChannelManager
from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW
from tribler_core.tests.tools.base_test import MockObject
Expand Down Expand Up @@ -104,7 +104,7 @@ async def mock_remove_download(download_obj, **_):
# Test regenerating a non-empty channel
gigachannel_manager.updated_my_channel = Mock()
metadata_store.ChannelMetadata.consolidate_channel_torrent = lambda *_: Mock()
with patch("tribler_core.modules.libtorrent.torrentdef.TorrentDef.load_from_dict"):
with patch("tribler_core.components.libtorrent.torrentdef.TorrentDef.load_from_dict"):
await gigachannel_manager.regenerate_channel_torrent(chan_pk, chan_id)
gigachannel_manager.updated_my_channel.assert_called_once()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from unittest.mock import patch

import pytest

from tribler_core.components.base import Session
from tribler_core.components.gigachannel_manager.gigachannel_manager_component import GigachannelManagerComponent
from tribler_core.components.libtorrent import LibtorrentComponent
from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent
from tribler_core.components.masterkey.masterkey_component import MasterKeyComponent
from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent
from tribler_core.components.restapi import RESTComponent
from tribler_core.components.socks_configurator import SocksServersComponent
from tribler_core.restapi.rest_manager import RESTManager


# pylint: disable=protected-access
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
from tribler_common.simpledefs import DLSTATUS_SEEDING, DLSTATUS_STOPPED, DOWNLOAD, NTFY

from tribler_core.exceptions import SaveResumeDataError
from tribler_core.modules.libtorrent import check_handle, require_handle
from tribler_core.modules.libtorrent.download_config import DownloadConfig
from tribler_core.modules.libtorrent.download_state import DownloadState
from tribler_core.modules.libtorrent.settings import DownloadDefaultsSettings
from tribler_core.modules.libtorrent.stream import Stream
from tribler_core.modules.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo
from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig
from tribler_core.components.libtorrent.download_manager.download_state import DownloadState
from tribler_core.components.libtorrent.settings import DownloadDefaultsSettings
from tribler_core.components.libtorrent.download_manager.stream import Stream
from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo
from tribler_core.notifier import Notifier
from tribler_core.utilities.libtorrent_helper import libtorrent as lt
from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt
from tribler_core.utilities.path_util import Path
from tribler_core.utilities.torrent_utils import get_info_from_handle
from tribler_core.components.libtorrent.utils.torrent_utils import check_handle, get_info_from_handle, require_handle
from tribler_core.utilities.unicode import ensure_unicode, hexlify
from tribler_core.utilities.utilities import bdecode_compat

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

from tribler_core.exceptions import InvalidConfigException
from tribler_core.utilities.install_dir import get_lib_path
from tribler_core.utilities.libtorrent_helper import libtorrent as lt
from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt
from tribler_core.utilities.path_util import Path
from tribler_core.utilities.utilities import bdecode_compat

SPEC_FILENAME = 'download_config.spec'
CONFIG_SPEC_PATH = get_lib_path() / 'modules' / 'libtorrent' / SPEC_FILENAME
CONFIG_SPEC_PATH = get_lib_path() / 'components/libtorrent/download_manager' / SPEC_FILENAME
NONPERSISTENT_DEFAULTS = {}


class DownloadConfig:
def __init__(self, config=None, state_dir=None):
self.config = config or ConfigObj(configspec=str(CONFIG_SPEC_PATH), default_encoding='utf8')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
from tribler_common.utilities import uri_to_path

from tribler_core.modules.dht_health_manager import DHTHealthManager
from tribler_core.modules.libtorrent.download import Download
from tribler_core.modules.libtorrent.download_config import DownloadConfig
from tribler_core.modules.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings
from tribler_core.modules.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo
from tribler_core.components.libtorrent.download_manager.download import Download
from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig
from tribler_core.components.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings
from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo
from tribler_core.notifier import Notifier
from tribler_core.utilities import path_util, torrent_utils
from tribler_core.utilities.libtorrent_helper import libtorrent as lt
from tribler_core.utilities import path_util
from tribler_core.components.libtorrent.utils import torrent_utils
from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt
from tribler_core.utilities.path_util import Path
from tribler_core.utilities.unicode import hexlify
from tribler_core.utilities.utilities import bdecode_compat, has_bep33_support, parse_magnetlink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

from tribler_common.simpledefs import DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING

from tribler_core.modules.libtorrent import check_vod
from tribler_core.utilities.torrent_utils import get_info_from_handle
from tribler_core.components.libtorrent.utils.torrent_utils import check_vod, get_info_from_handle

# Header and footer sizes are necessary for video client to detect file codecs and muxer metadata.
# Without below pieces are ready, streamer should not start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tribler_core.components.restapi import RestfulComponent
from tribler_core.components.socks_configurator import SocksServersComponent
from tribler_core.components.upgrade import UpgradeComponent
from tribler_core.modules.libtorrent.download_manager import DownloadManager
from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager


class LibtorrentComponent(RestfulComponent):
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from marshmallow.fields import String

from tribler_core.exceptions import DuplicateDownloadException
from tribler_core.modules.libtorrent.download_config import DownloadConfig
from tribler_core.modules.libtorrent.torrentdef import TorrentDef
from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig
from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.restapi.rest_endpoint import HTTP_BAD_REQUEST, RESTEndpoint, RESTResponse
from tribler_core.restapi.schema import HandledErrorSchema
from tribler_core.restapi.util import return_handled_exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
dlstatus_strings,
)

from tribler_core.modules.libtorrent.download_config import DownloadConfig
from tribler_core.modules.libtorrent.download_manager import DownloadManager
from tribler_core.modules.libtorrent.stream import STREAM_PAUSE_TIME, StreamChunk
from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig
from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager
from tribler_core.components.libtorrent.download_manager.stream import STREAM_PAUSE_TIME, StreamChunk
from tribler_core.restapi.rest_endpoint import (
HTTP_BAD_REQUEST,
HTTP_INTERNAL_SERVER_ERROR,
Expand All @@ -32,7 +32,7 @@
RESTStreamResponse,
)
from tribler_core.restapi.util import return_handled_exception
from tribler_core.utilities.libtorrent_helper import libtorrent as lt
from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt
from tribler_core.utilities.path_util import Path
from tribler_core.utilities.unicode import ensure_unicode, hexlify
from tribler_core.utilities.utilities import froze_it
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

from tribler_common.simpledefs import DLSTATUS_CIRCUITS, DLSTATUS_DOWNLOADING, DLSTATUS_EXIT_NODES, DLSTATUS_STOPPED

from tribler_core.modules.libtorrent.download_state import DownloadState
from tribler_core.modules.libtorrent.restapi.downloads_endpoint import DownloadsEndpoint, get_extended_status
from tribler_core.components.libtorrent.download_manager.download_state import DownloadState
from tribler_core.components.libtorrent.restapi.downloads_endpoint import DownloadsEndpoint, get_extended_status
from tribler_core.restapi.base_api_test import do_request
from tribler_core.restapi.rest_manager import error_middleware
from tribler_core.tests.tools.common import TESTS_DATA_DIR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from tribler_core.modules.libtorrent.restapi.libtorrent_endpoint import LibTorrentEndpoint
from tribler_core.components.libtorrent.restapi.libtorrent_endpoint import LibTorrentEndpoint
from tribler_core.restapi.base_api_test import do_request
from tribler_core.restapi.rest_manager import error_middleware
from tribler_core.utilities.unicode import hexlify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

from tribler_common.simpledefs import NTFY

from tribler_core.modules.libtorrent.restapi.torrentinfo_endpoint import TorrentInfoEndpoint
from tribler_core.modules.libtorrent.torrentdef import TorrentDef
from tribler_core.components.libtorrent.restapi.torrentinfo_endpoint import TorrentInfoEndpoint
from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.components.metadata_store.db.orm_bindings.torrent_metadata import tdef_to_metadata_dict
from tribler_core.restapi.base_api_test import do_request
from tribler_core.restapi.rest_manager import error_middleware
Expand Down Expand Up @@ -79,7 +79,7 @@ async def mock_http_query(*_):
with open(tmp_path / "ubuntu.torrent", 'rb') as f:
return f.read()

with patch("tribler_core.modules.libtorrent.restapi.torrentinfo_endpoint.query_http_uri", new=mock_http_query):
with patch("tribler_core.components.libtorrent.restapi.torrentinfo_endpoint.query_http_uri", new=mock_http_query):
verify_valid_dict(await do_request(rest_api, f'torrentinfo?uri={quote_plus(path)}', expected_code=200))

path = quote_plus(f'magnet:?xt=urn:btih:{hexlify(UBUNTU_1504_INFOHASH)}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from tribler_common.simpledefs import NTFY
from tribler_common.utilities import uri_to_path

from tribler_core.modules.libtorrent.torrentdef import TorrentDef
from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.components.metadata_store.db.orm_bindings.torrent_metadata import tdef_to_metadata_dict
from tribler_core.restapi.rest_endpoint import HTTP_BAD_REQUEST, HTTP_INTERNAL_SERVER_ERROR, RESTEndpoint, RESTResponse
from tribler_core.utilities.libtorrent_helper import libtorrent as lt
from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt
from tribler_core.utilities.unicode import hexlify, recursive_unicode
from tribler_core.utilities.utilities import bdecode_compat, froze_it, parse_magnetlink

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

# pylint: disable=no-self-argument
from tribler_core.config.tribler_config_section import TriblerConfigSection
from tribler_core.modules.libtorrent.download_config import get_default_dest_dir
from tribler_core.components.libtorrent.download_manager.download_config import get_default_dest_dir


@validator('port', 'anon_listen_port')
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from tribler_core.modules.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo
from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import pytest

from tribler_core.exceptions import SaveResumeDataError
from tribler_core.modules.libtorrent.download_config import DownloadConfig
from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig
from tribler_core.tests.tools.base_test import MockObject
from tribler_core.tests.tools.common import TESTS_DATA_DIR
from tribler_core.utilities.torrent_utils import get_info_from_handle
from tribler_core.components.libtorrent.utils.torrent_utils import get_info_from_handle
from tribler_core.utilities.unicode import hexlify
from tribler_core.utilities.utilities import bdecode_compat

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

import pytest

from tribler_core.modules.libtorrent.download_config import DownloadConfig, get_default_dest_dir
from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig, get_default_dest_dir
from tribler_core.tests.tools.common import TESTS_DATA_DIR


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

from tribler_common.simpledefs import DLSTATUS_SEEDING

from tribler_core.modules.libtorrent.download_manager import DownloadManager
from tribler_core.modules.libtorrent.settings import LibtorrentSettings
from tribler_core.modules.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo
from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager
from tribler_core.components.libtorrent.settings import LibtorrentSettings
from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo
from tribler_core.tests.tools.common import TESTS_DATA_DIR, TORRENT_UBUNTU_FILE
from tribler_core.utilities.path_util import Path
from tribler_core.utilities.unicode import hexlify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from tribler_common.simpledefs import DLSTATUS_DOWNLOADING, DOWNLOAD, UPLOAD

from tribler_core.modules.libtorrent.download_state import DownloadState
from tribler_core.components.libtorrent.download_manager.download_state import DownloadState


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest

from tribler_core.components.base import Session
from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent
from tribler_core.components.masterkey.masterkey_component import MasterKeyComponent
from tribler_core.components.restapi import RESTComponent
from tribler_core.components.socks_configurator import SocksServersComponent

pytestmark = pytest.mark.asyncio


# pylint: disable=protected-access

async def test_libtorrent_component(tribler_config):
components = [RESTComponent(), MasterKeyComponent(), SocksServersComponent(), LibtorrentComponent()]
session = Session(tribler_config, components)
with session:
await session.start()

comp = LibtorrentComponent.instance()
assert comp.started_event.is_set() and not comp.failed
assert comp.download_manager

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

from tribler_common.network_utils import NetworkUtils

from tribler_core.modules.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings, SeedingMode
from tribler_core.components.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings, SeedingMode


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from tribler_common.simpledefs import DLSTATUS_SEEDING

from tribler_core.modules.libtorrent.download_config import DownloadConfig
from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig
from tribler_core.tests.tools.common import TESTS_DATA_DIR


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

import pytest

from tribler_core.modules.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo
from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo
from tribler_core.tests.tools.common import TESTS_DATA_DIR, TORRENT_UBUNTU_FILE
from tribler_core.utilities.path_util import Path
from tribler_core.utilities.utilities import bdecode_compat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from tribler_common.simpledefs import INFOHASH_LENGTH

from tribler_core.utilities import maketorrent, path_util
from tribler_core.utilities.libtorrent_helper import libtorrent as lt
from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt
from tribler_core.utilities.path_util import Path
from tribler_core.utilities.torrent_utils import create_torrent_file
from tribler_core.components.libtorrent.utils.torrent_utils import create_torrent_file
from tribler_core.utilities.unicode import ensure_unicode
from tribler_core.utilities.utilities import bdecode_compat, is_valid_url, parse_magnetlink

Expand Down
Empty file.
Loading

0 comments on commit 37484c5

Please sign in to comment.