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

Make minmdns use a distinct policy for endpoint and IP choices #22168

Merged
merged 16 commits into from
Aug 29, 2022
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
122 changes: 0 additions & 122 deletions examples/minimal-mdns/AllInterfaceListener.h

This file was deleted.

2 changes: 1 addition & 1 deletion examples/minimal-mdns/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import("${chip_root}/build/chip/tools.gni")

static_library("minimal-mdns-example-common") {
sources = [
"AllInterfaceListener.h",
"PacketReporter.cpp",
"PacketReporter.h",
]
Expand Down Expand Up @@ -53,6 +52,7 @@ executable("minimal-mdns-server") {
":minimal-mdns-example-common",
"${chip_root}/src/lib",
"${chip_root}/src/lib/dnssd/minimal_mdns",
"${chip_root}/src/lib/dnssd/minimal_mdns:default_policy",
"${chip_root}/src/lib/dnssd/minimal_mdns/responders",
]

Expand Down
23 changes: 7 additions & 16 deletions examples/minimal-mdns/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <inet/InetInterface.h>
#include <inet/UDPEndPoint.h>
#include <lib/dnssd/minimal_mdns/AddressPolicy.h>
#include <lib/dnssd/minimal_mdns/AddressPolicy_DefaultImpl.h>
#include <lib/dnssd/minimal_mdns/QueryBuilder.h>
#include <lib/dnssd/minimal_mdns/Server.h>
#include <lib/dnssd/minimal_mdns/core/QName.h>
Expand All @@ -30,7 +32,6 @@
#include <platform/CHIPDeviceLayer.h>
#include <system/SystemPacketBuffer.h>

#include "AllInterfaceListener.h"
#include "PacketReporter.h"

using namespace chip;
Expand All @@ -39,7 +40,6 @@ namespace {

struct Options
{
bool enableIpV4 = false;
bool unicastAnswers = true;
uint32_t runtimeMs = 500;
uint16_t querySendPort = 5353;
Expand All @@ -53,9 +53,8 @@ constexpr size_t kMdnsMaxPacketSize = 1'024;

using namespace chip::ArgParser;

constexpr uint16_t kOptionEnableIpV4 = '4';
constexpr uint16_t kOptionQuery = 'q';
constexpr uint16_t kOptionType = 't';
constexpr uint16_t kOptionQuery = 'q';
constexpr uint16_t kOptionType = 't';

// non-ascii options have no short option version
constexpr uint16_t kOptionListenPort = 0x100;
Expand All @@ -67,10 +66,6 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
{
switch (aIdentifier)
{
case kOptionEnableIpV4:
gOptions.enableIpV4 = true;
return true;

case kOptionListenPort:
if (!ParseInt(aValue, gOptions.listenPort))
{
Expand Down Expand Up @@ -145,7 +140,6 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,

OptionDef cmdLineOptionsDef[] = {
{ "listen-port", kArgumentRequired, kOptionListenPort },
{ "enable-ip-v4", kNoArgument, kOptionEnableIpV4 },
{ "query", kArgumentRequired, kOptionQuery },
{ "type", kArgumentRequired, kOptionType },
{ "query-port", kArgumentRequired, kOptionQueryPort },
Expand All @@ -157,9 +151,6 @@ OptionDef cmdLineOptionsDef[] = {
OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS",
" --listen-port <number>\n"
" The port number to listen on\n"
" -4\n"
" --enable-ip-v4\n"
" enable listening on IPv4\n"
" -q\n"
" --query\n"
" The query to send\n"
Expand Down Expand Up @@ -324,13 +315,13 @@ int main(int argc, char ** args)
ReportDelegate reporter;
CHIP_ERROR err;

mdns::Minimal::SetDefaultAddressPolicy();
gMdnsServer.SetDelegate(&reporter);

{
auto endpoints = mdns::Minimal::GetAddressPolicy()->GetListenEndpoints();

MdnsExample::AllInterfaces allInterfaces(gOptions.enableIpV4);

err = gMdnsServer.Listen(chip::DeviceLayer::UDPEndPointManager(), &allInterfaces, gOptions.listenPort);
err = gMdnsServer.Listen(chip::DeviceLayer::UDPEndPointManager(), endpoints.get(), gOptions.listenPort);
if (err != CHIP_NO_ERROR)
{
printf("Server failed to listen on all interfaces: %s\n", chip::ErrorStr(err));
Expand Down
9 changes: 6 additions & 3 deletions examples/minimal-mdns/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <inet/InetInterface.h>
#include <inet/UDPEndPoint.h>
#include <lib/dnssd/ServiceNaming.h>
#include <lib/dnssd/minimal_mdns/AddressPolicy.h>
#include <lib/dnssd/minimal_mdns/AddressPolicy_DefaultImpl.h>
#include <lib/dnssd/minimal_mdns/QueryBuilder.h>
#include <lib/dnssd/minimal_mdns/ResponseSender.h>
#include <lib/dnssd/minimal_mdns/Server.h>
Expand All @@ -36,7 +38,6 @@
#include <platform/CHIPDeviceLayer.h>
#include <system/SystemPacketBuffer.h>

#include "AllInterfaceListener.h"
#include "PacketReporter.h"

using namespace chip;
Expand Down Expand Up @@ -198,6 +199,8 @@ int main(int argc, char ** args)
return 1;
}

mdns::Minimal::SetDefaultAddressPolicy();

printf("Running on port %d using %s...\n", gOptions.listenPort, gOptions.enableIpV4 ? "IPv4 AND IPv6" : "IPv6 ONLY");

mdns::Minimal::QueryResponder<16 /* maxRecords */> queryResponder;
Expand Down Expand Up @@ -265,9 +268,9 @@ int main(int argc, char ** args)
gMdnsServer.SetDelegate(&delegate);

{
MdnsExample::AllInterfaces allInterfaces(gOptions.enableIpV4);
auto endpoints = mdns::Minimal::GetAddressPolicy()->GetListenEndpoints();

if (gMdnsServer.Listen(DeviceLayer::UDPEndPointManager(), &allInterfaces, gOptions.listenPort) != CHIP_NO_ERROR)
if (gMdnsServer.Listen(DeviceLayer::UDPEndPointManager(), endpoints.get(), gOptions.listenPort) != CHIP_NO_ERROR)
{
printf("Server failed to listen on all interfaces\n");
return 1;
Expand Down
Loading