openthread-br
0.3.0-72c0388
|
#include <src/mdns/mdns.hpp>
Classes | |
struct | DiscoveredHostInfo |
struct | DiscoveredInstanceInfo |
class | HostRegistration |
class | Registration |
class | ServiceRegistration |
struct | TxtEntry |
Public Types | |
enum | State { State::kIdle, State::kReady } |
typedef std::vector< TxtEntry > | TxtList |
typedef std::vector< std::string > | SubTypeList |
typedef std::vector< Ip6Address > | AddressList |
using | DiscoveredServiceInstanceCallback = std::function< void(const std::string &aType, const DiscoveredInstanceInfo &aInstanceInfo)> |
using | DiscoveredHostCallback = std::function< void(const std::string &aHostName, const DiscoveredHostInfo &aHostInfo)> |
using | StateCallback = std::function< void(State aNewState)> |
using | ResultCallback = OnceCallback< void(otbrError aError)> |
Public Member Functions | |
virtual otbrError | Start (void)=0 |
virtual void | Stop (void)=0 |
virtual bool | IsStarted (void) const =0 |
void | PublishService (const std::string &aHostName, const std::string &aName, const std::string &aType, const SubTypeList &aSubTypeList, uint16_t aPort, const TxtList &aTxtList, ResultCallback &&aCallback) |
virtual void | UnpublishService (const std::string &aName, const std::string &aType, ResultCallback &&aCallback)=0 |
void | PublishHost (const std::string &aName, const std::vector< Ip6Address > &aAddresses, ResultCallback &&aCallback) |
virtual void | UnpublishHost (const std::string &aName, ResultCallback &&aCallback)=0 |
virtual void | SubscribeService (const std::string &aType, const std::string &aInstanceName)=0 |
virtual void | UnsubscribeService (const std::string &aType, const std::string &aInstanceName)=0 |
virtual void | SubscribeHost (const std::string &aHostName)=0 |
virtual void | UnsubscribeHost (const std::string &aHostName)=0 |
uint64_t | AddSubscriptionCallbacks (DiscoveredServiceInstanceCallback aInstanceCallback, DiscoveredHostCallback aHostCallback) |
void | RemoveSubscriptionCallbacks (uint64_t aSubscriberId) |
const MdnsTelemetryInfo & | GetMdnsTelemetryInfo () const |
Static Public Member Functions | |
static Publisher * | Create (StateCallback aCallback) |
static void | Destroy (Publisher *aPublisher) |
static otbrError | EncodeTxtData (const TxtList &aTxtList, std::vector< uint8_t > &aTxtData) |
static otbrError | DecodeTxtData (TxtList &aTxtList, const uint8_t *aTxtData, uint16_t aTxtLength) |
Protected Types | |
using | ServiceRegistrationPtr = std::unique_ptr< ServiceRegistration > |
using | ServiceRegistrationMap = std::map< std::string, ServiceRegistrationPtr > |
using | HostRegistrationPtr = std::unique_ptr< HostRegistration > |
using | HostRegistrationMap = std::map< std::string, HostRegistrationPtr > |
Protected Member Functions | |
virtual otbrError | PublishServiceImpl (const std::string &aHostName, const std::string &aName, const std::string &aType, const SubTypeList &aSubTypeList, uint16_t aPort, const TxtList &aTxtList, ResultCallback &&aCallback)=0 |
virtual otbrError | PublishHostImpl (const std::string &aName, const std::vector< Ip6Address > &aAddresses, ResultCallback &&aCallback)=0 |
virtual void | OnServiceResolveFailedImpl (const std::string &aType, const std::string &aInstanceName, int32_t aErrorCode)=0 |
virtual void | OnHostResolveFailedImpl (const std::string &aHostName, int32_t aErrorCode)=0 |
virtual otbrError | DnsErrorToOtbrError (int32_t aError)=0 |
void | AddServiceRegistration (ServiceRegistrationPtr &&aServiceReg) |
void | RemoveServiceRegistration (const std::string &aName, const std::string &aType, otbrError aError) |
ServiceRegistration * | FindServiceRegistration (const std::string &aName, const std::string &aType) |
void | OnServiceResolved (const std::string &aType, const DiscoveredInstanceInfo &aInstanceInfo) |
void | OnServiceResolveFailed (const std::string &aType, const std::string &aInstanceName, int32_t aErrorCode) |
void | OnServiceRemoved (uint32_t aNetifIndex, const std::string &aType, const std::string &aInstanceName) |
void | OnHostResolved (const std::string &aHostName, const DiscoveredHostInfo &aHostInfo) |
void | OnHostResolveFailed (const std::string &aHostName, int32_t aErrorCode) |
ResultCallback | HandleDuplicateServiceRegistration (const std::string &aHostName, const std::string &aName, const std::string &aType, const SubTypeList &aSubTypeList, uint16_t aPort, const TxtList &aTxtList, ResultCallback &&aCallback) |
ResultCallback | HandleDuplicateHostRegistration (const std::string &aName, const std::vector< Ip6Address > &aAddresses, ResultCallback &&aCallback) |
void | AddHostRegistration (HostRegistrationPtr &&aHostReg) |
void | RemoveHostRegistration (const std::string &aName, otbrError aError) |
HostRegistration * | FindHostRegistration (const std::string &aName) |
void | UpdateServiceRegistrationEmaLatency (const std::string &aInstanceName, const std::string &aType, otbrError aError) |
void | UpdateHostRegistrationEmaLatency (const std::string &aHostName, otbrError aError) |
void | UpdateServiceInstanceResolutionEmaLatency (const std::string &aInstanceName, const std::string &aType, otbrError aError) |
void | UpdateHostResolutionEmaLatency (const std::string &aHostName, otbrError aError) |
Static Protected Member Functions | |
static SubTypeList | SortSubTypeList (SubTypeList aSubTypeList) |
static TxtList | SortTxtList (TxtList aTxtList) |
static AddressList | SortAddressList (AddressList aAddressList) |
static std::string | MakeFullServiceName (const std::string &aName, const std::string &aType) |
static std::string | MakeFullHostName (const std::string &aName) |
static void | UpdateMdnsResponseCounters (otbr::MdnsResponseCounters &aCounters, otbrError aError) |
static void | UpdateEmaLatency (uint32_t &aEmaLatency, uint32_t aLatency, otbrError aError) |
Protected Attributes | |
ServiceRegistrationMap | mServiceRegistrations |
HostRegistrationMap | mHostRegistrations |
uint64_t | mNextSubscriberId = 1 |
std::map< uint64_t, std::pair< DiscoveredServiceInstanceCallback, DiscoveredHostCallback > > | mDiscoveredCallbacks |
std::map< std::pair< std::string, std::string >, Timepoint > | mServiceRegistrationBeginTime |
std::map< std::string, Timepoint > | mHostRegistrationBeginTime |
std::map< std::pair< std::string, std::string >, Timepoint > | mServiceInstanceResolutionBeginTime |
std::map< std::string, Timepoint > | mHostResolutionBeginTime |
otbr::MdnsTelemetryInfo | mTelemetryInfo {} |
Static Protected Attributes | |
static constexpr uint8_t | kMaxTextEntrySize = 255 |
This interface defines the functionality of mDNS publisher.
using otbr::Mdns::Publisher::DiscoveredHostCallback = std::function<void(const std::string &aHostName, const DiscoveredHostInfo &aHostInfo)> |
This function is called to notify a discovered host.
using otbr::Mdns::Publisher::DiscoveredServiceInstanceCallback = std::function<void(const std::string &aType, const DiscoveredInstanceInfo &aInstanceInfo)> |
This function is called to notify a discovered service instance.
using otbr::Mdns::Publisher::ResultCallback = OnceCallback<void(otbrError aError)> |
The callback for receiving the result of a operation.
using otbr::Mdns::Publisher::StateCallback = std::function<void(State aNewState)> |
The callback for receiving mDNS publisher state changes.
|
strong |
uint64_t otbr::Mdns::Publisher::AddSubscriptionCallbacks | ( | Publisher::DiscoveredServiceInstanceCallback | aInstanceCallback, |
Publisher::DiscoveredHostCallback | aHostCallback | ||
) |
This method sets the callbacks for subscriptions.
[in] | aInstanceCallback | The callback function to receive discovered service instances. |
[in] | aHostCallback | The callback function to receive discovered hosts. |
|
static |
This function creates a mDNS publisher.
[in] | aCallback | The callback for receiving mDNS publisher state changes. |
|
static |
This function decodes a TXT entry list from a TXT data buffer.
The input data should be in standard DNS-SD TXT data format. See RFC 6763 for details: https://tools.ietf.org/html/rfc6763#section-6.
[out] | aTxtList | A TXT entry list. |
[in] | aTxtData | A pointer to TXT data. |
[in] | aTxtLength | The TXT data length. |
OTBR_ERROR_NONE | Successfully decoded the TXT data. |
OTBR_ERROR_INVALID_ARGS | The aTxtdata has invalid TXT format. |
|
static |
This function destroys the mDNS publisher.
[in] | aPublisher | A pointer to the publisher. |
|
static |
This function writes the TXT entry list to a TXT data buffer. The TXT entries will be sorted by their keys.
The output data is in standard DNS-SD TXT data format. See RFC 6763 for details: https://tools.ietf.org/html/rfc6763#section-6.
[in] | aTxtList | A TXT entry list. |
[out] | aTxtData | A TXT data buffer. |
OTBR_ERROR_NONE | Successfully write the TXT entry list. |
OTBR_ERROR_INVALID_ARGS | The aTxtList includes invalid TXT entry. |
|
inline |
This method returns the mDNS statistics information of the publisher.
|
pure virtual |
This method checks if publisher has been started.
true | Already started. |
false | Not started. |
Implemented in otbr::Mdns::PublisherAvahi, and otbr::Mdns::PublisherMDnsSd.
void otbr::Mdns::Publisher::PublishHost | ( | const std::string & | aName, |
const std::vector< Ip6Address > & | aAddresses, | ||
ResultCallback && | aCallback | ||
) |
This method publishes or updates a host.
Publishing a host is advertising an AAAA RR for the host name. This method should be called before a service with non-empty host name is published.
[in] | aName | The name of the host. |
[in] | aAddresses | The addresses of the host. |
[in] | aCallback | The callback for receiving the publishing result.OTBR_ERROR_NONE will be returned if the operation is successful and all other values indicate a failure. Specifically, OTBR_ERROR_DUPLICATED indicates that the name has already been published and the caller can re-publish with a new name if an alternative name is available/acceptable. |
void otbr::Mdns::Publisher::PublishService | ( | const std::string & | aHostName, |
const std::string & | aName, | ||
const std::string & | aType, | ||
const SubTypeList & | aSubTypeList, | ||
uint16_t | aPort, | ||
const TxtList & | aTxtList, | ||
ResultCallback && | aCallback | ||
) |
This method publishes or updates a service.
[in] | aHostName | The name of the host which this service resides on. If an empty string is provided, this service resides on local host and it is the implementation to provide specific host name. Otherwise, the caller MUST publish the host with method PublishHost. |
[in] | aName | The name of this service. |
[in] | aType | The type of this service. |
[in] | aSubTypeList | A list of service subtypes. |
[in] | aPort | The port number of this service. |
[in] | aTxtList | A list of TXT name/value pairs. |
[in] | aCallback | The callback for receiving the publishing result. OTBR_ERROR_NONE will be returned if the operation is successful and all other values indicate a failure. Specifically, OTBR_ERROR_DUPLICATED indicates that the name has already been published and the caller can re-publish with a new name if an alternative name is available/acceptable. |
void otbr::Mdns::Publisher::RemoveSubscriptionCallbacks | ( | uint64_t | aSubscriberId | ) |
This method cancels callbacks for subscriptions.
[in] | aSubscriberId | The Subscriber ID previously returned by AddSubscriptionCallbacks . |
|
pure virtual |
This method starts the mDNS publisher.
OTBR_ERROR_NONE | Successfully started mDNS publisher; |
OTBR_ERROR_MDNS | Failed to start mDNS publisher. |
Implemented in otbr::Mdns::PublisherAvahi, and otbr::Mdns::PublisherMDnsSd.
|
pure virtual |
This method stops the mDNS publisher.
Implemented in otbr::Mdns::PublisherAvahi, and otbr::Mdns::PublisherMDnsSd.
|
pure virtual |
This method subscribes a given host.
mDNS implementations should use the DiscoveredHostCallback
function to notify discovered hosts.
[in] | aHostName | The host name (without domain). |
Implemented in otbr::Mdns::PublisherAvahi, and otbr::Mdns::PublisherMDnsSd.
|
pure virtual |
This method subscribes a given service or service instance.
If aInstanceName
is not empty, this method subscribes the service instance. Otherwise, this method subscribes the service. mDNS implementations should use the DiscoveredServiceInstanceCallback
function to notify discovered service instances.
[in] | aType | The service type. |
[in] | aInstanceName | The service instance to subscribe, or empty to subscribe the service. |
Implemented in otbr::Mdns::PublisherAvahi, and otbr::Mdns::PublisherMDnsSd.
|
pure virtual |
This method un-publishes a host.
[in] | aName | A host name. |
[in] | aCallback | The callback for receiving the publishing result. |
Implemented in otbr::Mdns::PublisherAvahi, and otbr::Mdns::PublisherMDnsSd.
|
pure virtual |
This method un-publishes a service.
[in] | aName | The name of this service. |
[in] | aType | The type of this service. |
[in] | aCallback | The callback for receiving the publishing result. |
Implemented in otbr::Mdns::PublisherAvahi, and otbr::Mdns::PublisherMDnsSd.
|
pure virtual |
This method unsubscribes a given host.
[in] | aHostName | The host name (without domain). |
Implemented in otbr::Mdns::PublisherAvahi, and otbr::Mdns::PublisherMDnsSd.
|
pure virtual |
This method unsubscribes a given service or service instance.
If aInstanceName
is not empty, this method unsubscribes the service instance. Otherwise, this method unsubscribes the service.
[in] | aType | The service type. |
[in] | aInstanceName | The service instance to unsubscribe, or empty to unsubscribe the service. |
Implemented in otbr::Mdns::PublisherAvahi, and otbr::Mdns::PublisherMDnsSd.