Skip to content

Commit

Permalink
Merge pull request #193 from ivmarkov/replace-mdns
Browse files Browse the repository at this point in the history
Option to replace initial mDNS and DevAtt post-construction
  • Loading branch information
kedars authored Jun 23, 2024
2 parents 2076dc6 + 2121d82 commit eb7c152
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions rs-matter/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,31 @@ impl<'a> Matter<'a> {
self.port
}

/// A utility method to replace the initial mDNS implementation with another one.
///
/// Useful in particular with `MdnsService::Provided`, where the user would still like
/// to create the `Matter` instance in a const-context, as in e.g.:
/// `const MATTER: Matter<'static> = Matter::new(...);`
///
/// The above const-creation is incompatible with `MdnsService::Provided` which carries a
/// `&dyn Mdns` pointer, which cannot be initialized from within a const context with anything
/// else than a `const`. (At least not yet - there is an unstable nightly Rust feature for that).
///
/// The solution is to const-construct the `Matter` object with `MdnsService::Disabled`, and
/// after that - while/if we still have exclusive, mutable access to the `Matter` object -
/// replace the `MdnsService::Disabled` initial impl with another, like `MdnsService::Provided`.
pub fn replace_mdns(&mut self, mdns: MdnsService<'a>) {
self.transport_mgr
.replace_mdns(mdns.new_impl(self.dev_det, self.port));
}

/// A utility method to replace the initial Device Attestation Data Fetcher with another one.
///
/// Reasoning and use-cases explained in the documentation of `replace_mdns`.
pub fn replace_dev_att(&mut self, dev_att: &'a dyn DevAttDataFetcher) {
self.dev_att = dev_att;
}

pub fn load_fabrics(&self, data: &[u8]) -> Result<(), Error> {
self.fabric_mgr
.borrow_mut()
Expand Down
4 changes: 4 additions & 0 deletions rs-matter/src/transport/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ impl<'m> TransportMgr<'m> {
}
}

pub(crate) fn replace_mdns(&mut self, mdns: MdnsImpl<'m>) {
self.mdns = mdns;
}

#[cfg(all(feature = "large-buffers", feature = "alloc"))]
pub fn initialize_buffers(&self) -> Result<(), Error> {
let mut rx = self.rx.try_lock().map_err(|_| ErrorCode::InvalidState)?;
Expand Down

0 comments on commit eb7c152

Please sign in to comment.