Skip to content

Commit b4719e7

Browse files
authored
Added recommender component (#8197)
2 parents 8d63b8e + b4170a3 commit b4719e7

17 files changed

+1051
-2
lines changed

src/run_unit_tests.py

+11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
windows_missing_libsodium,
2121
)
2222

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

2435
def task_tribler_test(*test_names: str) -> tuple[bool, int, float, list[tuple[str, str, str]], str]:
2536
"""

src/tribler/core/components.py

+40
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,46 @@ def finalize(self, ipv8: IPv8, session: Session, community: Community) -> None:
282282
session.rest_manager.get_endpoint("/api/ipv8").endpoints["/dht"].dht = community
283283

284284

285+
@precondition('session.config.get("recommender/enabled")')
286+
@overlay("tribler.core.recommender.community", "RecommenderCommunity")
287+
class RecommenderComponent(CommunityLauncherWEndpoints):
288+
"""
289+
Launch instructions for the user recommender community.
290+
"""
291+
292+
def get_kwargs(self, session: Session) -> dict:
293+
"""
294+
Create and forward the rendezvous database for the Community.
295+
"""
296+
from tribler.core.recommender.manager import Manager
297+
298+
db_path = str(Path(session.config.get_version_state_dir()) / "sqlite" / "recommender.db")
299+
if session.config.get("memory_db"):
300+
db_path = ":memory:"
301+
302+
out = super().get_kwargs(session)
303+
out["manager"] = Manager(db_path)
304+
305+
return out
306+
307+
def finalize(self, ipv8: IPv8, session: Session, community: Community) -> None:
308+
"""
309+
When we are done launching, register our REST API.
310+
"""
311+
from tribler.core.recommender.community import RecommenderCommunity
312+
313+
endpoint = session.rest_manager.get_endpoint("/api/recommender")
314+
endpoint.manager = cast(RecommenderCommunity, community).manager
315+
316+
def get_endpoints(self) -> list[RESTEndpoint]:
317+
"""
318+
Add the knowledge endpoint.
319+
"""
320+
from tribler.core.recommender.restapi.endpoint import RecommenderEndpoint
321+
322+
return [*super().get_endpoints(), RecommenderEndpoint()]
323+
324+
285325
@set_in_session("tunnel_community")
286326
@precondition('session.config.get("tunnel_community/enabled")')
287327
@after("DHTDiscoveryComponent")

src/tribler/core/recommender/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)