Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: split peer module #70

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: remove unused dependencies, add event for received searches
  • Loading branch information
JurgenR committed Oct 5, 2023
commit 6dab4823b3885e5e0b786c46ae26a6627a3e07ae
8 changes: 8 additions & 0 deletions src/aioslsk/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ class SearchResultEvent(Event):
result: SearchResult


@dataclass(frozen=True)
class SearchRequestReceivedEvent(Event):
"""Emitted when a search request by another user has been received"""
username: str
query: str
result_count: int


@dataclass(frozen=True)
class SimilarUsersEvent(Event):
users: List[User]
Expand Down
20 changes: 10 additions & 10 deletions src/aioslsk/search/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,16 @@
InternalEventBus,
ConnectionStateChangedEvent,
MessageReceivedEvent,
UserDirectoryEvent,
UserInfoEvent,
UserSharesReplyEvent,
SearchRequestReceivedEvent,
SearchResultEvent,
)
from ..protocol.messages import (
ChatRoomSearch,
DistributedSearchRequest,
DistributedServerSearchRequest,
FileSearch,
MessageDataclass,
PeerDirectoryContentsRequest,
PeerDirectoryContentsReply,
PeerSearchReply,
PeerSharesRequest,
PeerSharesReply,
PeerUserInfoReply,
PeerUserInfoRequest,
ServerSearchRequest,
UserSearch,
WishlistInterval,
Expand Down Expand Up @@ -145,11 +137,19 @@ async def _query_shares_and_reply(self, ticket: int, username: str, query: str):
"""
visible, locked = self._shares_manager.query(query, username=username)

result_count = len(visible) + len(locked)
self.received_searches.append(
ReceivedSearch(
username=username,
query=query,
matched_files=len(visible) + len(locked)
result_count=result_count
)
)
await self._event_bus.emit(
SearchRequestReceivedEvent(
username=username,
query=query,
result_count=result_count
)
)

Expand Down
6 changes: 4 additions & 2 deletions src/aioslsk/search/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class SearchType(Enum):

@dataclass
class ReceivedSearch:
"""Used for keeping track of searches received from the distributed parent"""
"""Used for keeping track of searches received from the distributed parent
or server
"""
username: str
query: str
matched_files: int
result_count: int


@dataclass
Expand Down