-
Notifications
You must be signed in to change notification settings - Fork 1
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
Support ANNOUNCE_OK and ANNOUNCE_ERROR handler #116
Merged
tetter27
merged 5 commits into
impl/subscribe_namespace_handler
from
impl/announce_responce_handler
Oct 29, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2433892
feat: handle announce responce
tetter27 638605c
Merge branch 'impl/subscribe_namespace_handler' into impl/announce_re…
tetter27 2b94194
Propagate announce if the namespace was subscribed by subscribers (#117)
tetter27 23e6de4
refactor: import grouping
tetter27 f9937b3
Merge branch 'impl/announce_responce_handler' of https://github.com/n…
tetter27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use anyhow::Result; | ||
use moqt_core::pubsub_relation_manager_repository::PubSubRelationManagerRepository; | ||
use moqt_core::{messages::control_messages::announce_ok::AnnounceOk, MOQTClient}; | ||
|
||
pub(crate) async fn announce_ok_handler( | ||
announce_ok_message: AnnounceOk, | ||
client: &mut MOQTClient, | ||
pubsub_relation_manager_repository: &mut dyn PubSubRelationManagerRepository, | ||
) -> Result<()> { | ||
tracing::trace!("announce_ok_handler start."); | ||
tracing::debug!("announce_ok_message: {:#?}", announce_ok_message); | ||
|
||
// Record the announced Track Namespace | ||
pubsub_relation_manager_repository | ||
.set_downstream_announced_namespace( | ||
announce_ok_message.track_namespace().clone(), | ||
client.id, | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod success { | ||
use crate::modules::handlers::announce_ok_handler::announce_ok_handler; | ||
use crate::modules::pubsub_relation_manager::{ | ||
commands::PubSubRelationCommand, manager::pubsub_relation_manager, | ||
wrapper::PubSubRelationManagerWrapper, | ||
}; | ||
use moqt_core::messages::moqt_payload::MOQTPayload; | ||
use moqt_core::pubsub_relation_manager_repository::PubSubRelationManagerRepository; | ||
use moqt_core::{messages::control_messages::announce_ok::AnnounceOk, moqt_client::MOQTClient}; | ||
use tokio::sync::mpsc; | ||
|
||
#[tokio::test] | ||
async fn normal_case() { | ||
// Generate ANNOUNCE message | ||
let track_namespace = Vec::from(["test".to_string(), "test".to_string()]); | ||
let announce_ok_message = AnnounceOk::new(track_namespace.clone()); | ||
let mut buf = bytes::BytesMut::new(); | ||
announce_ok_message.packetize(&mut buf); | ||
|
||
// Generate client | ||
let downstream_session_id = 0; | ||
let mut client = MOQTClient::new(downstream_session_id); | ||
|
||
// Generate PubSubRelationManagerWrapper | ||
let (track_namespace_tx, mut track_namespace_rx) = | ||
mpsc::channel::<PubSubRelationCommand>(1024); | ||
tokio::spawn(async move { pubsub_relation_manager(&mut track_namespace_rx).await }); | ||
let mut pubsub_relation_manager: PubSubRelationManagerWrapper = | ||
PubSubRelationManagerWrapper::new(track_namespace_tx); | ||
|
||
let max_subscribe_id = 10; | ||
|
||
let _ = pubsub_relation_manager | ||
.setup_subscriber(max_subscribe_id, downstream_session_id) | ||
.await; | ||
|
||
// Execute announce_ok_handler and get result | ||
let result = announce_ok_handler( | ||
announce_ok_message, | ||
&mut client, | ||
&mut pubsub_relation_manager, | ||
) | ||
.await; | ||
|
||
assert!(result.is_ok()); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
moqt-server/src/modules/server_processes/announce_error_message.rs
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,19 @@ | ||
use anyhow::{bail, Result}; | ||
use bytes::BytesMut; | ||
use moqt_core::messages::{ | ||
control_messages::announce_error::AnnounceError, moqt_payload::MOQTPayload, | ||
}; | ||
|
||
pub(crate) async fn process_announce_error_message(payload_buf: &mut BytesMut) -> Result<()> { | ||
let announce_error_message = match AnnounceError::depacketize(payload_buf) { | ||
Ok(announce_error_message) => announce_error_message, | ||
Err(err) => { | ||
tracing::error!("{:#?}", err); | ||
bail!(err.to_string()); | ||
} | ||
}; | ||
|
||
tracing::warn!("announce_error_message: {:#?}", announce_error_message); | ||
|
||
Ok(()) | ||
} |
29 changes: 29 additions & 0 deletions
29
moqt-server/src/modules/server_processes/announce_ok_message.rs
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,29 @@ | ||
use crate::modules::handlers::announce_ok_handler::announce_ok_handler; | ||
use anyhow::{bail, Result}; | ||
use bytes::BytesMut; | ||
use moqt_core::pubsub_relation_manager_repository::PubSubRelationManagerRepository; | ||
use moqt_core::{ | ||
messages::{control_messages::announce_ok::AnnounceOk, moqt_payload::MOQTPayload}, | ||
MOQTClient, | ||
}; | ||
|
||
pub(crate) async fn process_announce_ok_message( | ||
payload_buf: &mut BytesMut, | ||
client: &mut MOQTClient, | ||
pubsub_relation_manager_repository: &mut dyn PubSubRelationManagerRepository, | ||
) -> Result<()> { | ||
let announce_ok_message = match AnnounceOk::depacketize(payload_buf) { | ||
Ok(announce_ok_message) => announce_ok_message, | ||
Err(err) => { | ||
tracing::error!("{:#?}", err); | ||
bail!(err.to_string()); | ||
} | ||
}; | ||
|
||
announce_ok_handler( | ||
announce_ok_message, | ||
client, | ||
pubsub_relation_manager_repository, | ||
) | ||
.await | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use grouping