Skip to content
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

Default to use an IPV4 address #25668

Merged
merged 2 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/tv-casting-app/tv-casting-common/include/CastingServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,19 @@ class CastingServer
static void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
void ReadServerClusters(chip::EndpointId endpointId);

/**
* @brief Retrieve the IP Address to use for the UDC request.
* This function will look for an IPv4 address in the list of IPAddresses passed in if available and return
cliffamzn marked this conversation as resolved.
Show resolved Hide resolved
* that address if found. If there are no available IPv4 addresses, it will default to the first available address.
* This logic is similar to the one used by the UDC server that prefers IPv4 addresses.
*
* @param ipAddresses - The list of ip addresses available to use
* @param numIPs - The number of ip addresses available in the array
*
* @returns The IPv4 address in the array if available, otherwise will return the first address in the list.
*/
static chip::Inet::IPAddress * getIpAddressForUDCRequest(chip::Inet::IPAddress ipAddresses[], const size_t numIPs);

PersistenceManager mPersistenceManager;
bool mInited = false;
bool mUdcInProgress = false;
Expand Down
26 changes: 24 additions & 2 deletions examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,35 @@ CHIP_ERROR CastingServer::SendUserDirectedCommissioningRequest(chip::Transport::
return Server::GetInstance().SendUserDirectedCommissioningRequest(commissioner);
}

chip::Inet::IPAddress * CastingServer::getIpAddressForUDCRequest(chip::Inet::IPAddress ipAddresses[], const size_t numIPs)
{
size_t ipIndexToUse = 0;
for (size_t i = 0; i < numIPs; i++)
{
if (ipAddresses[i].IsIPv4())
{
ipIndexToUse = i;
ChipLogProgress(AppServer, "Found IPv4 address at index: %lu - prioritizing use of IPv4", ipIndexToUse);
break;
}

if (i == (numIPs - 1))
{
ChipLogProgress(AppServer, "Could not find an IPv4 address, defaulting to the first address in IP list");
}
}

return &ipAddresses[ipIndexToUse];
}

CHIP_ERROR CastingServer::SendUserDirectedCommissioningRequest(Dnssd::DiscoveredNodeData * selectedCommissioner)
{
mUdcInProgress = true;
// Send User Directed commissioning request
chip::Inet::IPAddress * ipAddressToUse =
getIpAddressForUDCRequest(selectedCommissioner->resolutionData.ipAddress, selectedCommissioner->resolutionData.numIPs);
ReturnErrorOnFailure(SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP(
selectedCommissioner->resolutionData.ipAddress[0], selectedCommissioner->resolutionData.port,
selectedCommissioner->resolutionData.interfaceId)));
*ipAddressToUse, selectedCommissioner->resolutionData.port, selectedCommissioner->resolutionData.interfaceId)));
mTargetVideoPlayerVendorId = selectedCommissioner->commissionData.vendorId;
mTargetVideoPlayerProductId = selectedCommissioner->commissionData.productId;
mTargetVideoPlayerDeviceType = selectedCommissioner->commissionData.deviceType;
Expand Down