-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[python/mdns] Add "resolve" command for operational discovery #5025
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2569a43
[mdns] Add Resolver interface
Damian-Nordic 1506913
[mdns] Fix build with chip_mdns_advertiser="platform"
Damian-Nordic e27935a
[mdns/python] Add command to resolve address of a CHIP device
Damian-Nordic 0b9c043
[mdns] Fix improper global object initialization order.
Damian-Nordic a716dce
[mdns] Apply code review comments
Damian-Nordic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,14 +119,14 @@ class DLL_EXPORT Device | |
app::CommandSender * GetCommandSender() { return mCommandSender; } | ||
|
||
/** | ||
* @brief | ||
* Get the IP address assigned to the device. | ||
* @brief Get the IP address and port assigned to the device. | ||
* | ||
* @param[out] addr The reference to the IP address. | ||
* @param[out] addr IP address of the device. | ||
* @param[out] port Port number of the device. | ||
* | ||
* @return true, if the IP address was filled in the out parameter, false otherwise | ||
* @return true, if the IP address and port were filled in the out parameters, false otherwise | ||
*/ | ||
bool GetIpAddress(Inet::IPAddress & addr) const; | ||
bool GetAddress(Inet::IPAddress & addr, uint16_t & port) const; | ||
|
||
/** | ||
* @brief | ||
8000
|
@@ -261,6 +261,19 @@ class DLL_EXPORT Device | |
*/ | ||
CHIP_ERROR OpenPairingWindow(uint32_t timeout, PairingWindowOption option, SetupPayload & setupPayload); | ||
|
||
/** | ||
* @brief | ||
* Update address of the device. | ||
* | ||
* This function will set new IP address and port of the device. Since the device settings might | ||
* have been moved from RAM to the persistent storage, the function will load the device settings | ||
* first, before making the changes. | ||
* | ||
* @param[in] addr Address of the device to be set. | ||
* | ||
* @return CHIP_NO_ERROR if the address has been updated, an error code otherwise. | ||
*/ | ||
CHIP_ERROR UpdateAddress(const Transport::PeerAddress & addr); | ||
/** | ||
* @brief | ||
* Return whether the current device object is actively associated with a paired CHIP | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "DeviceAddressUpdater.h" | ||
|
||
#include <controller/CHIPDeviceController.h> | ||
#include <support/ReturnMacros.h> | ||
|
||
namespace chip { | ||
namespace Controller { | ||
|
||
CHIP_ERROR DeviceAddressUpdater::Init(DeviceController * controller, DeviceAddressUpdateDelegate * delegate) | ||
{ | ||
VerifyOrReturnError(mController == nullptr, CHIP_ERROR_INCORRECT_STATE); | ||
VerifyOrReturnError(mDelegate == nullptr, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
mController = controller; | ||
mDelegate = delegate; | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void DeviceAddressUpdater::OnNodeIdResolved(NodeId nodeId, const Mdns::ResolvedNodeData & nodeData) | ||
{ | ||
CHIP_ERROR error = CHIP_NO_ERROR; | ||
Device * device = nullptr; | ||
|
||
VerifyOrExit(nodeData.mAddress.Type() != Inet::kIPAddressType_Any, error = CHIP_ERROR_INVALID_ADDRESS); | ||
VerifyOrExit(mController != nullptr, error = CHIP_ERROR_INCORRECT_STATE); | ||
SuccessOrExit(error = mController->GetDevice(nodeId, &device)); | ||
|
||
device->UpdateAddress(Transport::PeerAddress::UDP(nodeData.mAddress, nodeData.mPort, nodeData.mInterfaceId)); | ||
|
||
exit: | ||
if (mDelegate != nullptr) | ||
{ | ||
mDelegate->OnAddressUpdateComplete(nodeId, error); | ||
} | ||
} | ||
|
||
void DeviceAddressUpdater::OnNodeIdResolutionFailed(NodeId nodeId, CHIP_ERROR error) | ||
{ | ||
if (mDelegate != nullptr) | ||
{ | ||
mDelegate->OnAddressUpdateComplete(nodeId, error); | ||
} | ||
} | ||
|
||
} // namespace Controller | ||
} // namespace chip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <mdns/Resolver.h> | ||
#include <support/DLLUtil.h> | ||
#include <transport/raw/MessageHeader.h> | ||
|
||
namespace chip { | ||
namespace Controller { | ||
|
||
class DeviceController; | ||
|
||
/// Callbacks for CHIP device address resolution | ||
class DLL_EXPORT DeviceAddressUpdateDelegate | ||
{ | ||
public: | ||
virtual ~DeviceAddressUpdateDelegate() {} | ||
virtual void OnAddressUpdateComplete(NodeId nodeId, CHIP_ERROR error) = 0; | ||
}; | ||
|
||
/// Class for updating CHIP devices' addresses based on responses from mDNS Resolver | ||
class DLL_EXPORT DeviceAddressUpdater : public Mdns::ResolverDelegate | ||
{ | ||
public: | ||
CHIP_ERROR Init(DeviceController * controller, DeviceAddressUpdateDelegate * delegate = nullptr); | ||
|
||
private: | ||
// Mdns::ResolverDelegate Implementation | ||
void OnNodeIdResolved(NodeId nodeId, const Mdns::ResolvedNodeData & nodeData) override; | ||
void OnNodeIdResolutionFailed(NodeId nodeId, CHIP_ERROR error) override; | ||
|
||
DeviceController * mController = nullptr; | ||
DeviceAddressUpdateDelegate * mDelegate = nullptr; | ||
}; | ||
|
||
} // namespace Controller | ||
} // namespace chip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.