Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions libcoap/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ pub enum MulticastGroupJoinError {
Unknown,
}

#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
pub enum MulticastHopLimitError {
/// Unknown error inside of libcoap
#[error("CoAP multicast hop limit error: unable to set hop limit for multicast")]
Unknown,
}

#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
pub enum EndpointCreationError {
/// Unknown error inside of libcoap
Expand Down
19 changes: 16 additions & 3 deletions libcoap/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use std::{
};

use libcoap_sys::{
coap_context_t, coap_fixed_point_t, coap_mid_t, coap_new_message_id, coap_pdu_get_token, coap_pdu_t,
coap_response_t, coap_response_t_COAP_RESPONSE_FAIL, coap_response_t_COAP_RESPONSE_OK, coap_send,
coap_context_t, coap_fixed_point_t, coap_mcast_set_hops, coap_mid_t, coap_new_message_id, coap_pdu_get_token,
coap_pdu_t, coap_response_t, coap_response_t_COAP_RESPONSE_FAIL, coap_response_t_COAP_RESPONSE_OK, coap_send,
coap_session_get_ack_random_factor, coap_session_get_ack_timeout, coap_session_get_addr_local,
coap_session_get_addr_remote, coap_session_get_ifindex, coap_session_get_max_retransmit, coap_session_get_proto,
coap_session_get_state, coap_session_get_type, coap_session_init_token, coap_session_max_pdu_size,
Expand All @@ -38,7 +38,7 @@ use libcoap_sys::{coap_session_get_psk_hint, coap_session_get_psk_identity, coap
use self::sealed::{CoapSessionCommonInternal, CoapSessionInnerProvider};
pub use self::{client::CoapClientSession, server::CoapServerSession};
use crate::{
error::{MessageConversionError, SessionGetAppDataError},
error::{MessageConversionError, MulticastHopLimitError, SessionGetAppDataError},
message::{request::CoapRequest, response::CoapResponse, CoapMessage, CoapMessageCommon},
protocol::CoapToken,
types::{CoapAddress, CoapMessageId, CoapProtocol, IfIndex, MaxRetransmit},
Expand Down Expand Up @@ -296,6 +296,19 @@ pub trait CoapSessionCommon<'a>: CoapSessionCommonInternal<'a> {
unsafe { coap_session_set_mtu(self.inner_mut().raw_session, mtu) }
}

/// Sets maximum number of hops for multicast request
fn set_mcast_hops_limit(&self, hops: usize) -> Result<(), MulticastHopLimitError> {
// In some cases the default hoplimit of 1 is not enough to reach the destination. Choose limit accordingly
// SAFETY: Provided session pointer being valid is an invariant of CoapSessionInner
unsafe {
let ret = coap_mcast_set_hops(self.inner_mut().raw_session, hops);
if ret == 0 {
return Err(MulticastHopLimitError::Unknown);
}
};
Ok(())
}

/// Returns the next message ID that should be used for this session.
fn next_message_id(&self) -> CoapMessageId {
// SAFETY: Provided session pointer being valid is an invariant of CoapSessionInner
Expand Down