Struct CoapContext

Source
pub struct CoapContext<'a> { /* private fields */ }
Expand description

A CoAP Context — container for general state and configuration information relating to CoAP

The equivalent to the [coap_context_t] type in libcoap.

Implementations§

Source§

impl<'a> CoapContext<'a>

Source

pub fn new() -> Result<CoapContext<'a>, ContextConfigurationError>

Creates a new context.

§Errors

Returns an error if the underlying libcoap library was unable to create a new context (probably an allocation error?).

Source

pub fn set_psk_context( &mut self, psk_context: ServerPskContext<'a>, ) -> Result<(), ContextConfigurationError>

Sets the server-side cryptography information provider.

§Errors

Returns ContextConfigurationError::Unknown if the call to the underlying libcoap library function fails and ContextConfigurationError::CryptoContextAlreadySet if the PSK context has already been set previously.

Source

pub fn set_pki_rpk_context( &mut self, pki_context: impl Into<ServerPkiRpkCryptoContext<'a>>, ) -> Result<(), ContextConfigurationError>

Sets the server-side cryptography information provider.

§Errors

Returns ContextConfigurationError::Unknown if the call to the underlying libcoap library function fails and ContextConfigurationError::CryptoContextAlreadySet if the PSK context has already been set previously.

Source

pub fn set_pki_root_ca_paths( &mut self, ca_file: Option<impl AsRef<Path>>, ca_dir: Option<impl AsRef<Path>>, ) -> Result<(), ContextConfigurationError>

Convenience wrapper around set_pki_root_cas that can be provided with any type that implements AsRef<Path>.

ca_file should be the full path of a PEM-encoded file containing all root CAs to be used or None, ca_dir should be a directory path containing PEM-encoded CA certificates to be used or None.

As not all implementations of [OsString] (which is the basis of Path) provide conversions to non-zero byte sequences, this function is only available on Unix. On other operating systems, perform manual conversion of paths into CString and call set_pki_root_cas directly instead.

See the Rust standard library documentation on FFI conversions and the OsString type for more information.

§Errors

Will return ContextConfigurationError::Unknown if the call to the underlying libcoap function fails (indicating an error in either libcoap or the underlying TLS library).

Source

pub fn set_pki_root_cas( &mut self, ca_file: Option<CString>, ca_dir: Option<CString>, ) -> Result<(), ContextConfigurationError>

Sets the path to a CA certificate file and/or a directory of CA certificate files that should be used as this context’s default root CA information.

ca_file should be the full path of a PEM-encoded file containing all root CAs to be used or None, ca_dir should be a directory path containing PEM-encoded CA certificates to be used or None.

§Errors

Will return ContextConfigurationError::Unknown if the call to the underlying libcoap function fails (indicating an error in either libcoap or the underlying TLS library).

Source§

impl CoapContext<'_>

Source

pub fn shutdown( self, exit_wait_timeout: Option<Duration>, ) -> Result<(), IoProcessError>

Performs a controlled shutdown of the CoAP context.

This will perform all still outstanding IO operations until [coap_can_exit()] confirms that the context has no more outstanding IO and can be dropped without interrupting sessions.

Source

pub fn add_endpoint_udp( &mut self, addr: SocketAddr, ) -> Result<(), EndpointCreationError>

Creates a new UDP endpoint that is bound to the given address.

Source

pub fn add_endpoint_tcp( &mut self, addr: SocketAddr, ) -> Result<(), EndpointCreationError>

Creates a new TCP endpoint that is bound to the given address.

Source

pub fn add_endpoint_dtls( &mut self, addr: SocketAddr, ) -> Result<(), EndpointCreationError>

Creates a new DTLS endpoint that is bound to the given address.

Note that in order to actually connect to DTLS clients, you need to set a crypto provider using CoapContext::set_psk_context and/or CoapContext::set_pki_rpk_context.

Source

pub fn add_resource<D: Any + ?Sized + Debug>(&mut self, res: CoapResource<D>)

Adds the given resource to the resource pool of this context.

Source

pub fn do_io( &mut self, timeout: Option<Duration>, ) -> Result<Duration, IoProcessError>

Performs currently outstanding IO operations, waiting for a maximum duration of timeout.

This is the function where most of the IO operations made using this library are actually executed. It is recommended to call this function in a loop for as long as the CoAP context is used.

Source

pub fn session_timeout(&self) -> Duration

Return the duration that idle server-side sessions are kept alive if they are not referenced or used anywhere else.

Source

pub fn set_session_timeout(&self, timeout: Duration)

Set the duration that idle server-side sessions are kept alive if they are not referenced or used anywhere else.

§Panics

Panics if the provided duration is too large to be provided to libcoap (larger than a [libc::c_uint]).

Source

pub fn max_handshake_sessions(&self) -> c_uint

Returns the maximum number of server-side sessions that can concurrently be in a handshake state.

If this number is exceeded, no new handshakes will be accepted.

Source

pub fn set_max_handshake_sessions(&self, max_handshake_sessions: c_uint)

Sets the maximum number of server-side sessions that can concurrently be in a handshake state.

If this number is exceeded, no new handshakes will be accepted.

Source

pub fn max_idle_sessions(&self) -> c_uint

Returns the maximum number of idle server-side sessions for this context.

If this number is exceeded, the oldest unreferenced session will be freed.

Source

pub fn set_max_idle_sessions(&self, max_idle_sessions: c_uint)

Sets the maximum number of idle server-side sessions for this context.

If this number is exceeded, the oldest unreferenced session will be freed.

Source

pub fn csm_max_message_size(&self) -> u32

Returns the maximum size for Capabilities and Settings Messages

CSMs are used in CoAP over TCP as specified in RFC 8323, Section 5.3.

Source

pub fn set_csm_max_message_size(&self, csm_max_message_size: u32)

Sets the maximum size for Capabilities and Settings Messages

CSMs are used in CoAP over TCP as specified in RFC 8323, Section 5.3.

Source

pub fn csm_timeout(&self) -> Duration

Returns the timeout for Capabilities and Settings Messages

CSMs are used in CoAP over TCP as specified in RFC 8323, Section 5.3.

Source

pub fn set_csm_timeout(&self, csm_timeout: Duration)

Sets the timeout for Capabilities and Settings Messages

CSMs are used in CoAP over TCP as specified in RFC 8323, Section 5.3.

§Panics

Panics if the provided timeout is too large for libcoap (> u32::MAX).

Source

pub fn set_keepalive(&self, timeout: Option<Duration>)

Sets the number of seconds to wait before sending a CoAP keepalive message for idle sessions.

If the provided value is None, CoAP-level keepalive messages will be disabled.

§Panics

Panics if the provided duration is too large to be provided to libcoap (larger than a [libc::c_uint]).

Trait Implementations§

Source§

impl<'a> Debug for CoapContext<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CoapContext<'a>

§

impl<'a> !RefUnwindSafe for CoapContext<'a>

§

impl<'a> !Send for CoapContext<'a>

§

impl<'a> !Sync for CoapContext<'a>

§

impl<'a> Unpin for CoapContext<'a>

§

impl<'a> !UnwindSafe for CoapContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T