Skip to content

Commit

Permalink
Added recommender component (#8197)
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink authored Oct 8, 2024
2 parents 8d63b8e + b4170a3 commit b4719e7
Show file tree
Hide file tree
Showing 17 changed files with 1,051 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/run_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
windows_missing_libsodium,
)

if platform.system() == "Darwin":
"""
The unit tests on Mac lock up on multiprocess getaddrinfo calls. We establish the lan addresses once here before
spawning any children.
File "/Users/runner/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/socket.py", line 966, in getaddrinfo
| for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
"""
from ipv8.messaging.interfaces.lan_addresses.interfaces import get_lan_addresses
get_lan_addresses()


def task_tribler_test(*test_names: str) -> tuple[bool, int, float, list[tuple[str, str, str]], str]:
"""
Expand Down
40 changes: 40 additions & 0 deletions src/tribler/core/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,46 @@ def finalize(self, ipv8: IPv8, session: Session, community: Community) -> None:
session.rest_manager.get_endpoint("/api/ipv8").endpoints["/dht"].dht = community


@precondition('session.config.get("recommender/enabled")')
@overlay("tribler.core.recommender.community", "RecommenderCommunity")
class RecommenderComponent(CommunityLauncherWEndpoints):
"""
Launch instructions for the user recommender community.
"""

def get_kwargs(self, session: Session) -> dict:
"""
Create and forward the rendezvous database for the Community.
"""
from tribler.core.recommender.manager import Manager

db_path = str(Path(session.config.get_version_state_dir()) / "sqlite" / "recommender.db")
if session.config.get("memory_db"):
db_path = ":memory:"

out = super().get_kwargs(session)
out["manager"] = Manager(db_path)

return out

def finalize(self, ipv8: IPv8, session: Session, community: Community) -> None:
"""
When we are done launching, register our REST API.
"""
from tribler.core.recommender.community import RecommenderCommunity

endpoint = session.rest_manager.get_endpoint("/api/recommender")
endpoint.manager = cast(RecommenderCommunity, community).manager

def get_endpoints(self) -> list[RESTEndpoint]:
"""
Add the knowledge endpoint.
"""
from tribler.core.recommender.restapi.endpoint import RecommenderEndpoint

return [*super().get_endpoints(), RecommenderEndpoint()]


@set_in_session("tunnel_community")
@precondition('session.config.get("tunnel_community/enabled")')
@after("DHTDiscoveryComponent")
Expand Down
Empty file.
Loading

0 comments on commit b4719e7

Please sign in to comment.