Struct librice::stun::attribute::ErrorCodeBuilder
source · pub struct ErrorCodeBuilder<'reason> { /* private fields */ }
Implementations§
source§impl<'reason> ErrorCodeBuilder<'reason>
impl<'reason> ErrorCodeBuilder<'reason>
sourcepub fn build(self) -> Result<ErrorCode, StunParseError>
pub fn build(self) -> Result<ErrorCode, StunParseError>
Create the ErrorCode
with the configured paramaters
Errors
- When the code value is out of range [300, 699]
Examples found in repository?
src/conncheck.rs (line 888)
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
async fn handle_binding_request(
weak_inner: Weak<Mutex<ConnCheckListInner>>,
component_id: usize,
local: &Candidate,
agent: StunAgent,
msg: &Message,
from: SocketAddr,
) -> Result<Option<Message>, AgentError> {
trace!("have request {}", msg);
let local_credentials = agent
.local_credentials()
.ok_or(AgentError::ResourceNotFound)?;
if let Some(error_msg) = Message::check_attribute_types(
msg,
&[
USERNAME,
FINGERPRINT,
MESSAGE_INTEGRITY,
ICE_CONTROLLED,
ICE_CONTROLLING,
PRIORITY,
USE_CANDIDATE,
],
&[USERNAME, FINGERPRINT, MESSAGE_INTEGRITY, PRIORITY],
) {
// failure -> send error response
return Ok(Some(error_msg));
}
let peer_nominating =
if let Some(use_candidate_raw) = msg.attribute::<RawAttribute>(USE_CANDIDATE) {
if UseCandidate::from_raw(&use_candidate_raw).is_ok() {
true
} else {
return Ok(Some(Message::bad_request(msg)?));
}
} else {
false
};
let priority = match msg.attribute::<Priority>(PRIORITY) {
Some(p) => p.priority(),
None => {
return Ok(Some(Message::bad_request(msg)?));
}
};
let ice_controlling = msg.attribute::<IceControlling>(ICE_CONTROLLING);
let ice_controlled = msg.attribute::<IceControlled>(ICE_CONTROLLED);
let response = {
let checklist = weak_inner.upgrade().ok_or(AgentError::ConnectionClosed)?;
let mut checklist = checklist.lock().unwrap();
if checklist.state == CheckListState::Completed && !peer_nominating {
// ignore binding requests if we are completed
trace!("ignoring binding request as we have completed");
return Ok(None);
}
// validate username
if let Some(username) = msg.attribute::<Username>(USERNAME) {
if !validate_username(username, &checklist.local_credentials) {
warn!("binding request failed username validation -> UNAUTHORIZED");
let mut response = Message::new_error(msg);
response.add_attribute(ErrorCode::builder(ErrorCode::UNAUTHORIZED).build()?)?;
return Ok(Some(response));
}
} else {
// existence is checked above so can only fail when the username is invalid
return Ok(Some(Message::bad_request(msg)?));
}
{
// Deal with role conflicts
// RFC 8445 7.3.1.1. Detecting and Repairing Role Conflicts
let set = checklist
.set_inner
.upgrade()
.ok_or(AgentError::ConnectionClosed)?;
let mut set = set.lock().unwrap();
if let Some(ice_controlling) = ice_controlling {
// o If the agent is in the controlling role, and the ICE-CONTROLLING
// attribute is present in the request:
if set.controlling {
if set.tie_breaker >= ice_controlling.tie_breaker() {
// * If the agent's tiebreaker value is larger than or equal to the
// contents of the ICE-CONTROLLING attribute, the agent generates
// a Binding error response and includes an ERROR-CODE attribute
// with a value of 487 (Role Conflict) but retains its role.
let mut response = Message::new_error(msg);
response.add_attribute(
ErrorCode::builder(ErrorCode::ROLE_CONFLICT).build()?,
)?;
return Ok(Some(response));
} else {
// * If the agent's tiebreaker value is less than the contents of
// the ICE-CONTROLLING attribute, the agent switches to the
// controlled role.
set.controlling = false;
checklist.controlling = false;
// TODO: update priorities and other things
}
}
}
if let Some(ice_controlled) = ice_controlled {
// o If the agent is in the controlled role, and the ICE-CONTROLLED
// attribute is present in the request:
if !set.controlling {
if set.tie_breaker >= ice_controlled.tie_breaker() {
// * If the agent's tiebreaker value is larger than or equal to the
// contents of the ICE-CONTROLLED attribute, the agent switches to
// the controlling role.
set.controlling = true;
checklist.set_controlling(false);
for l in set.checklists.iter() {
if l.checklist_id == checklist.checklist_id {
continue;
}
let mut l = l.inner.lock().unwrap();
l.set_controlling(false);
}
} else {
// * If the agent's tiebreaker value is less than the contents of
// the ICE-CONTROLLED attribute, the agent generates a Binding
// error response and includes an ERROR-CODE attribute with a
// value of 487 (Role Conflict) but retains its role.
let mut response = Message::new_error(msg);
response.add_attribute(
ErrorCode::builder(ErrorCode::ROLE_CONFLICT).build()?,
)?;
return Ok(Some(response));
}
}
}
}
checklist.handle_binding_request(
peer_nominating,
component_id,
local,
agent,
from,
priority,
)?
};
if let Some(component) = response {
component.set_state(ComponentState::Connected).await;
}
Ok(Some(binding_success_response(
msg,
from,
local_credentials,
)?))
}