-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f85203
commit 0906e7c
Showing
8 changed files
with
94 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/lonelypss/ws/handlers/open/processors/process_confirm_receive.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import time | ||
from typing import TYPE_CHECKING | ||
|
||
from lonelypsp.auth.config import AuthResult | ||
from lonelypsp.stateful.messages.confirm_receive import S2B_ConfirmReceive | ||
|
||
from lonelypss.ws.handlers.open.processors.protocol import S2B_MessageProcessor | ||
from lonelypss.ws.handlers.open.websocket_url import ( | ||
make_for_receive_websocket_url_and_change_counter, | ||
) | ||
from lonelypss.ws.state import StateOpen | ||
|
||
|
||
async def process_confirm_receive( | ||
state: StateOpen, message: S2B_ConfirmReceive | ||
) -> None: | ||
expected_ack = state.expecting_acks.get_nowait() | ||
if expected_ack.type != message.type: | ||
raise Exception(f"unexpected confirm receive (expecting a {expected_ack.type})") | ||
if expected_ack.identifier != message.identifier: | ||
raise Exception( | ||
f"unexpected confirm receive (expecting identifier {expected_ack.identifier!r}, got {message.identifier!r})" | ||
) | ||
|
||
receive_url = make_for_receive_websocket_url_and_change_counter(state) | ||
auth_result = await state.broadcaster_config.is_confirm_receive_allowed( | ||
tracing=message.tracing, | ||
identifier=message.identifier, | ||
num_subscribers=message.num_subscribers, | ||
url=receive_url, | ||
now=time.time(), | ||
authorization=message.authorization, | ||
) | ||
if auth_result != AuthResult.OK: | ||
raise Exception(f"confirm receive auth: {auth_result}") | ||
|
||
|
||
if TYPE_CHECKING: | ||
_: S2B_MessageProcessor[S2B_ConfirmReceive] = process_confirm_receive |
42 changes: 42 additions & 0 deletions
42
src/lonelypss/ws/handlers/open/processors/process_continue_receive.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import time | ||
from typing import TYPE_CHECKING | ||
|
||
from lonelypsp.auth.config import AuthResult | ||
from lonelypsp.stateful.messages.continue_receive import S2B_ContinueReceive | ||
|
||
from lonelypss.ws.handlers.open.processors.protocol import S2B_MessageProcessor | ||
from lonelypss.ws.handlers.open.websocket_url import ( | ||
make_for_receive_websocket_url_and_change_counter, | ||
) | ||
from lonelypss.ws.state import StateOpen | ||
|
||
|
||
async def process_continue_receive( | ||
state: StateOpen, message: S2B_ContinueReceive | ||
) -> None: | ||
expected_ack = state.expecting_acks.get_nowait() | ||
if expected_ack.type != message.type: | ||
raise Exception( | ||
f"unexpected continue receive (expecting a {expected_ack.type})" | ||
) | ||
if expected_ack.identifier != message.identifier: | ||
raise Exception( | ||
f"unexpected continue receive (expecting identifier {expected_ack.identifier!r}, got {message.identifier!r})" | ||
) | ||
if expected_ack.part_id != message.part_id: | ||
raise Exception( | ||
f"unexpected continue receive (expecting part_id {expected_ack.part_id}, got {message.part_id})" | ||
) | ||
|
||
receive_url = make_for_receive_websocket_url_and_change_counter(state) | ||
auth_result = await state.broadcaster_config.is_stateful_continue_receive_allowed( | ||
url=receive_url, | ||
message=message, | ||
now=time.time(), | ||
) | ||
if auth_result != AuthResult.OK: | ||
raise Exception(f"continue receive auth: {auth_result}") | ||
|
||
|
||
if TYPE_CHECKING: | ||
_: S2B_MessageProcessor[S2B_ContinueReceive] = process_continue_receive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters