Skip to content

Commit

Permalink
Try to pair over all discovered ips instead of only the first one tha…
Browse files Browse the repository at this point in the history
…t has been discovered (#22789)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jun 5, 2023
1 parent 69d335e commit 13682a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions scripts/tools/check_includes_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@
# Uses platform-define to switch between list and array
'src/lib/dnssd/minimal_mdns/ResponseSender.h': {'list'},

# Not really for embedded consumers; uses std::queue to keep track
# Not really for embedded consumers; uses std::deque to keep track
# of a list of discovered things.
'src/controller/SetUpCodePairer.h': {'queue'},
'src/controller/SetUpCodePairer.h': {'deque'},

'src/controller/ExamplePersistentStorage.cpp': {'fstream'}
}
17 changes: 11 additions & 6 deletions src/controller/SetUpCodePairer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ bool SetUpCodePairer::ConnectToDiscoveredDevice()
// connection attempt fails and calls right back into us to try the next
// thing.
SetUpCodePairerParameters params(mDiscoveredParameters.front());
mDiscoveredParameters.pop();
mDiscoveredParameters.pop_front();

params.SetSetupPINCode(mSetUpPINCode);

Expand Down Expand Up @@ -272,7 +272,7 @@ void SetUpCodePairer::OnDiscoveredDeviceOverBle(BLE_CONNECTION_OBJECT connObj)

mWaitingForDiscovery[kBLETransport] = false;

mDiscoveredParameters.emplace(connObj);
mDiscoveredParameters.emplace_front(connObj);
ConnectToDiscoveredDevice();
}

Expand Down Expand Up @@ -341,7 +341,12 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::Discover

ChipLogProgress(Controller, "Discovered device to be commissioned over DNS-SD");

mDiscoveredParameters.emplace(nodeData.resolutionData);
auto & resolutionData = nodeData.resolutionData;
for (size_t i = 0; i < resolutionData.numIPs; i++)
{
mDiscoveredParameters.emplace_back(nodeData.resolutionData, i);
}

ConnectToDiscoveredDevice();
}

Expand Down Expand Up @@ -394,7 +399,7 @@ void SetUpCodePairer::ResetDiscoveryState()

while (!mDiscoveredParameters.empty())
{
mDiscoveredParameters.pop();
mDiscoveredParameters.pop_front();
}

mCurrentPASEParameters.ClearValue();
Expand Down Expand Up @@ -542,12 +547,12 @@ void SetUpCodePairer::OnDeviceDiscoveredTimeoutCallback(System::Layer * layer, v
}
}

SetUpCodePairerParameters::SetUpCodePairerParameters(const Dnssd::CommonResolutionData & data)
SetUpCodePairerParameters::SetUpCodePairerParameters(const Dnssd::CommonResolutionData & data, size_t index)
{
mInterfaceId = data.interfaceId;
Platform::CopyString(mHostName, data.hostName);

auto & ip = data.ipAddress[0];
auto & ip = data.ipAddress[index];
SetPeerAddress(Transport::PeerAddress::UDP(ip, data.port, ip.IsIPv6LinkLocal() ? data.interfaceId : Inet::InterfaceId::Null()));

if (data.mrpRetryIntervalIdle.HasValue())
Expand Down
8 changes: 4 additions & 4 deletions src/controller/SetUpCodePairer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#include <controller/DeviceDiscoveryDelegate.h>

#include <queue>
#include <deque>

namespace chip {
namespace Controller {
Expand All @@ -51,7 +51,7 @@ class DeviceCommissioner;
class SetUpCodePairerParameters : public RendezvousParameters
{
public:
SetUpCodePairerParameters(const Dnssd::CommonResolutionData & data);
SetUpCodePairerParameters(const Dnssd::CommonResolutionData & data, size_t index);
#if CONFIG_NETWORK_LAYER_BLE
SetUpCodePairerParameters(BLE_CONNECTION_OBJECT connObj);
#endif // CONFIG_NETWORK_LAYER_BLE
Expand Down Expand Up @@ -188,10 +188,10 @@ class DLL_EXPORT SetUpCodePairer : public DevicePairingDelegate
// process happening via the relevant transport.
bool mWaitingForDiscovery[kTransportTypeCount] = { false };

// Queue of things we have discovered but not tried connecting to yet. The
// Double ended-queue of things we have discovered but not tried connecting to yet. The
// general discovery/pairing process will terminate once this queue is empty
// and all the booleans in mWaitingForDiscovery are false.
std::queue<SetUpCodePairerParameters> mDiscoveredParameters;
std::deque<SetUpCodePairerParameters> mDiscoveredParameters;

// Current thing we are trying to connect to over UDP. If a PASE connection fails with
// a CHIP_ERROR_TIMEOUT, the discovered parameters will be used to ask the
Expand Down

0 comments on commit 13682a7

Please sign in to comment.