-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[python/mdns] Add "resolve" command for operational discovery #5025
Conversation
IgnoreUnusedVariable(nodeData); | ||
} | ||
|
||
CHIP_ERROR DeviceController::DiscoverDevice(uint64_t fabricId, NodeId nodeId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am concerned that we make the device controller do too much - this couples the device controller with global state regarding resolution.
How about having discovery be independent of the controller?
For the long term, I imagine we want to cache these resolutions so that we do not require to rediscover nodes on every operation. For that purpose, a separate object whose purpose is to do cached discovery seems desirable. I would also make it easier to follow the 'only one delegate' support in the Resolver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wasn't sure what would be the final usage of this method and where to put it. According to the spec we should perform the discovery when the address is unknown or a message dispatch failed (I guess that will be possible to verify once CRMP is used), so I'm not sure if the global cache will be necessary. I put the method here as I believed the controller will know the fabric ID and the method will be needed after commissioning, but I can move it somewhere else. Do you think some singleton class like chip::Controller::DiscoveryManager
would be a better place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I perfer to have a simple ResolveNode
and leave the caching mechanism to the implementation. Avahi and mDNSResponder are shipped with caching and TTL managmement. Another cache in CHIP will be hard on these platforms since they do not expose the TTL to us. On minimal mDNS we may maintain our own cache.
The api we expose to other modules can be a simple ResolveNodeId
but I'd also like it to be a separate class other than the DeviceController
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I perfer to have a simple
ResolveNode
and leave the caching mechanism to the implementation. Avahi and mDNSResponder are shipped with caching and TTL managmement. Another cache in CHIP will be hard on these platforms since they do not expose the TTL to us. On minimal mDNS we may maintain our own cache.
I have to agree. Building caching into the CHIP stack seems like it pulls way more into the sdk than we need to. If we have an mDNS resolver that doesn't cache, it seems like effort would be better expended to fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a separate DeviceAddressUpdater
, but it can't be completely independent from the controller since it must update addresses in device objects owned by the controller. However, it should be a bit more separated now.
cc03577
to
5262630
Compare
Clean Mdns initialization orderconnectedhomeip/src/lib/mdns/Discovery_ImplPlatform.cpp Lines 352 to 361 in 5262630
This comment was generated by todo based on a
|
4ebe5a5
to
099be4e
Compare
if len(args) == 2: | ||
err = self.devCtrl.ResolveNode(int(args[0]), int(args[1])) | ||
if err == 0: | ||
address = self.devCtrl.GetAddressAndPort(int(args[1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the resolution synchronous? I don't find it easy to follow the entire path, however it seems that at least avahi is asyn: you ask for a resolve and will later get a callback of 'node id resolved'.
What guarantees that GetAddressAndPort here is available as soon as ResolveNode completes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResolveNode
like other long-running commands spawn the asynchronous node id resolution using CallAsync
function which basically waits until a completion event is signaled. So the underlying work is done asynchronously and only ResolveNode
waits till it completes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving since my comments are nitpicks.
Please address them before merging.
Expose the mDNS resolver functionality implemented for Avahi/Linux using a new Resolver interface.
Add DeviceAddressUpdater class which updates device addresses in the device controller based on responses from mDNS resolver. A result of an update/resolution request can be passed to an optional DeviceAddressUpdateDelegate. Add "resolve <fabricid> <nodeid>" command to the Python CHIP controller. Usage: 1. Build CHIP with chip_mdns_advertiser="platform" argument. 2. Start Python CHIP controller. 3. Pair a CHIP device using "connect -ble" command. 4. Resolve the node ID using "resolve <fabricid> <nodeid>". Note that Thread devices currently don't support the DNS-SD service registration, but one can still test the new command by registering the necessary services manually, e.g. avahi-publish-address test-host.local. fd11:22::1 & avahi-publish-publish-service -H test-host.local \ <fabricid-hex>-<nodeid-hex> _chip._tcp 11097
On Linux, DiscoveryImplPlatform constructor refers to MdnsAvahi global object which may not yet be initialized. Some refactoring in the code is required to come up with a better solution, but for now make sure that DiscoveryImplPlatform is not initialized prior to MdnsAvahi.
Also, fix updating the device address in the device controller as previously the connection state wasn't updated.
099be4e
to
a716dce
Compare
Size increase report for "gn_qpg6100-example-build" from c85120e
Full report output
|
Size increase report for "nrfconnect-example-build" from c85120e
Full report output
|
Problem
DiscoveryImplPlatform
class contains code for DNS-SD discovery (currently, only Linux provides a backend based on Avahi), but no common interface for the functionality exists.Summary of Changes
DeviceAddressUpdater
class which updates device addresses in the device controller based on responses from mDNS resolver. A result of an update/resolution request can be passed to an optionalDeviceAddressUpdateDelegate
, too.discover <fabricid> <nodeid>
command to the Python controller.DiscoveryImplPlatform
constructor refers toMdnsAvahi
global object which may not yet be initialized. Some refactoring in the code is required to come up with a better solution, but for now make sure thatDiscoveryImplPlatform
is not initialized prior toMdnsAvahi
.Usage:
chip_mdns_advertiser="platform"
argument.connect -ble ...
command.discover <fabricid> <nodeid>
.Note that Thread devices currently don't support the DNS-SD service registration, but one can still test the new command by registering a service manually, e.g. given that the default node ID 12344321 is used run the following commands to register the corresponding service:
After that,
resolve 123 12344321
should returnfd11:22::1:12345
.