From 6a0970caf19cdeca2878eb2cb09c8bacc508ffcf Mon Sep 17 00:00:00 2001 From: Marcos B <15697303+gmarcosb@users.noreply.github.com> Date: Mon, 18 Oct 2021 15:18:15 -0600 Subject: [PATCH 1/7] Output information about what's being broadcast --- src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp b/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp index 1db519e033b397..98c31940584859 100644 --- a/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp +++ b/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp @@ -56,6 +56,7 @@ QueryResponderSettings QueryResponderBase::AddResponder(RecordResponder * respon { return QueryResponderSettings(); } + ChipLogDetail(Discovery, "Responding with %s", responder->GetQName()); for (size_t i = 0; i < mResponderInfoSize; i++) { From b8180e53b209c81dfb77bf7d99385a5871c89c2d Mon Sep 17 00:00:00 2001 From: gmarcosb <15697303+gmarcosb@users.noreply.github.com> Date: Thu, 16 Jun 2022 11:39:39 -0600 Subject: [PATCH 2/7] Expose/promote QNameString in Logging to allow other logging locations to get a formatted FullQName --- build_overrides/pigweed_environment.gni | 21 ++--- src/lib/dnssd/minimal_mdns/Logging.cpp | 80 ++++++++----------- src/lib/dnssd/minimal_mdns/Logging.h | 18 +++++ .../responders/QueryResponder.cpp | 3 +- 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/build_overrides/pigweed_environment.gni b/build_overrides/pigweed_environment.gni index 16ace4c8ae862a..8ec6ff090c740f 100644 --- a/build_overrides/pigweed_environment.gni +++ b/build_overrides/pigweed_environment.gni @@ -1,13 +1,8 @@ -# Copyright (c) 2022 Project CHIP Authors -# -# 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. +# This file is automatically generated by Pigweed's environment setup. Do not +# edit it manually or check it in. +declare_args() { + dir_cipd_arm = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/cipd/packages/arm" + dir_cipd_pigweed = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/cipd/packages/pigweed" + dir_cipd_python = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/cipd/packages/python" + dir_virtual_env = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/pigweed-venv" +} diff --git a/src/lib/dnssd/minimal_mdns/Logging.cpp b/src/lib/dnssd/minimal_mdns/Logging.cpp index 355086c5b4b7a0..3a87f4f65e6166 100644 --- a/src/lib/dnssd/minimal_mdns/Logging.cpp +++ b/src/lib/dnssd/minimal_mdns/Logging.cpp @@ -15,13 +15,45 @@ * limitations under the License. */ #include -#include #include namespace mdns { namespace Minimal { namespace Logging { +QNameString::QNameString(const mdns::Minimal::FullQName & name) +{ + for (unsigned i = 0; i < name.nameCount; i++) + { + if (i != 0) + { + mBuffer.Add("."); + } + mBuffer.Add(name.names[i]); + } +} + +QNameString::QNameString(mdns::Minimal::SerializedQNameIterator name) +{ + bool first = true; + while (name.Next()) + { + if (first) + { + first = false; + } + else + { + mBuffer.Add("."); + } + mBuffer.Add(name.Value()); + } + if (!name.IsValid()) + { + mBuffer.Add("(!INVALID!)"); + } +} + namespace { #if CHIP_PROGRESS_LOGGING @@ -53,52 +85,6 @@ const char * QueryTypeToString(mdns::Minimal::QType type) } #endif // CHIP_PROGRESS_LOGGING - -class QNameString -{ -public: - QNameString(const mdns::Minimal::FullQName & name) - { - for (unsigned i = 0; i < name.nameCount; i++) - { - if (i != 0) - { - mBuffer.Add("."); - } - mBuffer.Add(name.names[i]); - } - } - - QNameString(mdns::Minimal::SerializedQNameIterator name) - { - bool first = true; - while (name.Next()) - { - if (first) - { - first = false; - } - else - { - mBuffer.Add("."); - } - mBuffer.Add(name.Value()); - } - if (!name.IsValid()) - { - mBuffer.Add("(!INVALID!)"); - } - } - - const char * c_str() const { return mBuffer.c_str(); } - - bool Fit() const { return mBuffer.Fit(); } - -private: - static constexpr size_t kMaxQNameLength = 128; - chip::StringBuilder mBuffer; -}; - } // namespace void LogSendingQuery(const mdns::Minimal::Query & query) diff --git a/src/lib/dnssd/minimal_mdns/Logging.h b/src/lib/dnssd/minimal_mdns/Logging.h index de00df4e2a7dca..235d0714fd1256 100644 --- a/src/lib/dnssd/minimal_mdns/Logging.h +++ b/src/lib/dnssd/minimal_mdns/Logging.h @@ -20,6 +20,7 @@ #include #include #include +#include namespace mdns { namespace Minimal { @@ -28,6 +29,23 @@ namespace Minimal { /// MinMdns. namespace Logging { +// Allows for a FullQName to be represented as a user-readable logging string +class QNameString +{ +public: + QNameString(const mdns::Minimal::FullQName & name); + + QNameString(mdns::Minimal::SerializedQNameIterator name); + + inline const char * c_str() const { return mBuffer.c_str(); } + + inline bool Fit() const { return mBuffer.Fit(); } + +private: + static constexpr size_t kMaxQNameLength = 128; + chip::StringBuilder mBuffer; +}; + #if CHIP_MINMDNS_HIGH_VERBOSITY void LogSendingQuery(const mdns::Minimal::Query & query); diff --git a/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp b/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp index aa5e29c8ddeace..20beb48b49805d 100644 --- a/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp +++ b/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp @@ -18,6 +18,7 @@ #include "QueryResponder.h" #include +#include #include @@ -56,7 +57,7 @@ QueryResponderSettings QueryResponderBase::AddResponder(RecordResponder * respon { return QueryResponderSettings(); } - ChipLogDetail(Discovery, "Responding with %s", responder->GetQName()); + ChipLogDetail(Discovery, "Responding with %s", Logging::QNameString(responder->GetQName()).c_str()); for (size_t i = 0; i < mResponderInfoSize; i++) { From df6a721aee4339007d3a4a54c1895682d05c8571 Mon Sep 17 00:00:00 2001 From: gmarcosb <15697303+gmarcosb@users.noreply.github.com> Date: Thu, 16 Jun 2022 11:52:22 -0600 Subject: [PATCH 3/7] Revert inadvertent build_overrides/pigweed_environment.gni This partially reverts commit 15639cf3c5ef3c21480e68b11bdbcd39012a7a11. # Conflicts: # build_overrides/pigweed_environment.gni --- build_overrides/pigweed_environment.gni | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/build_overrides/pigweed_environment.gni b/build_overrides/pigweed_environment.gni index 8ec6ff090c740f..16ace4c8ae862a 100644 --- a/build_overrides/pigweed_environment.gni +++ b/build_overrides/pigweed_environment.gni @@ -1,8 +1,13 @@ -# This file is automatically generated by Pigweed's environment setup. Do not -# edit it manually or check it in. -declare_args() { - dir_cipd_arm = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/cipd/packages/arm" - dir_cipd_pigweed = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/cipd/packages/pigweed" - dir_cipd_python = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/cipd/packages/python" - dir_virtual_env = "/usr/local/google/home/mboyington/IdeaProjects/connectedhomeip/.environment/pigweed-venv" -} +# Copyright (c) 2022 Project CHIP Authors +# +# 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. From c98a86ec18bc7ef0849df0da641471af3e10181d Mon Sep 17 00:00:00 2001 From: gmarcosb <15697303+gmarcosb@users.noreply.github.com> Date: Thu, 23 Jun 2022 12:50:35 -0600 Subject: [PATCH 4/7] Update BUILD.gn deps for QNameString & move it to its own file to avoid circular deps in /responders --- src/lib/dnssd/minimal_mdns/Logging.cpp | 34 +---------- src/lib/dnssd/minimal_mdns/Logging.h | 17 ------ src/lib/dnssd/minimal_mdns/core/BUILD.gn | 2 + .../dnssd/minimal_mdns/core/QNameString.cpp | 56 +++++++++++++++++++ src/lib/dnssd/minimal_mdns/core/QNameString.h | 43 ++++++++++++++ .../responders/QueryResponder.cpp | 4 +- 6 files changed, 104 insertions(+), 52 deletions(-) create mode 100644 src/lib/dnssd/minimal_mdns/core/QNameString.cpp create mode 100644 src/lib/dnssd/minimal_mdns/core/QNameString.h diff --git a/src/lib/dnssd/minimal_mdns/Logging.cpp b/src/lib/dnssd/minimal_mdns/Logging.cpp index 3a87f4f65e6166..544fa2587f0232 100644 --- a/src/lib/dnssd/minimal_mdns/Logging.cpp +++ b/src/lib/dnssd/minimal_mdns/Logging.cpp @@ -15,45 +15,13 @@ * limitations under the License. */ #include +#include #include namespace mdns { namespace Minimal { namespace Logging { -QNameString::QNameString(const mdns::Minimal::FullQName & name) -{ - for (unsigned i = 0; i < name.nameCount; i++) - { - if (i != 0) - { - mBuffer.Add("."); - } - mBuffer.Add(name.names[i]); - } -} - -QNameString::QNameString(mdns::Minimal::SerializedQNameIterator name) -{ - bool first = true; - while (name.Next()) - { - if (first) - { - first = false; - } - else - { - mBuffer.Add("."); - } - mBuffer.Add(name.Value()); - } - if (!name.IsValid()) - { - mBuffer.Add("(!INVALID!)"); - } -} - namespace { #if CHIP_PROGRESS_LOGGING diff --git a/src/lib/dnssd/minimal_mdns/Logging.h b/src/lib/dnssd/minimal_mdns/Logging.h index 235d0714fd1256..3ba44a11ffecf9 100644 --- a/src/lib/dnssd/minimal_mdns/Logging.h +++ b/src/lib/dnssd/minimal_mdns/Logging.h @@ -29,23 +29,6 @@ namespace Minimal { /// MinMdns. namespace Logging { -// Allows for a FullQName to be represented as a user-readable logging string -class QNameString -{ -public: - QNameString(const mdns::Minimal::FullQName & name); - - QNameString(mdns::Minimal::SerializedQNameIterator name); - - inline const char * c_str() const { return mBuffer.c_str(); } - - inline bool Fit() const { return mBuffer.Fit(); } - -private: - static constexpr size_t kMaxQNameLength = 128; - chip::StringBuilder mBuffer; -}; - #if CHIP_MINMDNS_HIGH_VERBOSITY void LogSendingQuery(const mdns::Minimal::Query & query); diff --git a/src/lib/dnssd/minimal_mdns/core/BUILD.gn b/src/lib/dnssd/minimal_mdns/core/BUILD.gn index 0fc83eaddfdd15..c0be6ef0680f9d 100644 --- a/src/lib/dnssd/minimal_mdns/core/BUILD.gn +++ b/src/lib/dnssd/minimal_mdns/core/BUILD.gn @@ -21,6 +21,8 @@ static_library("core") { "DnsHeader.h", "QName.cpp", "QName.h", + "QNameString.cpp", + "QNameString.h", "RecordWriter.cpp", "RecordWriter.h", ] diff --git a/src/lib/dnssd/minimal_mdns/core/QNameString.cpp b/src/lib/dnssd/minimal_mdns/core/QNameString.cpp new file mode 100644 index 00000000000000..417451ebcbbde9 --- /dev/null +++ b/src/lib/dnssd/minimal_mdns/core/QNameString.cpp @@ -0,0 +1,56 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * 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 + +namespace mdns { +namespace Minimal { + +QNameString::QNameString(const mdns::Minimal::FullQName & name) +{ + for (unsigned i = 0; i < name.nameCount; i++) + { + if (i != 0) + { + mBuffer.Add("."); + } + mBuffer.Add(name.names[i]); + } +} + +QNameString::QNameString(mdns::Minimal::SerializedQNameIterator name) +{ + bool first = true; + while (name.Next()) + { + if (first) + { + first = false; + } + else + { + mBuffer.Add("."); + } + mBuffer.Add(name.Value()); + } + if (!name.IsValid()) + { + mBuffer.Add("(!INVALID!)"); + } +} + +} // namespace Minimal +} // namespace mdns \ No newline at end of file diff --git a/src/lib/dnssd/minimal_mdns/core/QNameString.h b/src/lib/dnssd/minimal_mdns/core/QNameString.h new file mode 100644 index 00000000000000..797308840e7f01 --- /dev/null +++ b/src/lib/dnssd/minimal_mdns/core/QNameString.h @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * 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 +#include + +namespace mdns { +namespace Minimal { + +// Allows for a FullQName to be represented as a user-readable logging string +class QNameString +{ +public: + QNameString(const mdns::Minimal::FullQName & name); + + QNameString(mdns::Minimal::SerializedQNameIterator name); + + inline const char * c_str() const { return mBuffer.c_str(); } + + inline bool Fit() const { return mBuffer.Fit(); } + +private: + static constexpr size_t kMaxQNameLength = 128; + chip::StringBuilder mBuffer; +}; + +} // namespace Minimal +} // namespace mdns \ No newline at end of file diff --git a/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp b/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp index 20beb48b49805d..538685a48c0c62 100644 --- a/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp +++ b/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp @@ -18,7 +18,7 @@ #include "QueryResponder.h" #include -#include +#include #include @@ -57,7 +57,7 @@ QueryResponderSettings QueryResponderBase::AddResponder(RecordResponder * respon { return QueryResponderSettings(); } - ChipLogDetail(Discovery, "Responding with %s", Logging::QNameString(responder->GetQName()).c_str()); + ChipLogDetail(Discovery, "Responding with %s", QNameString(responder->GetQName()).c_str()); for (size_t i = 0; i < mResponderInfoSize; i++) { From c35c534c6ace570ea5b9ee08a2b4e493c717b250 Mon Sep 17 00:00:00 2001 From: gmarcosb <15697303+gmarcosb@users.noreply.github.com> Date: Thu, 23 Jun 2022 12:53:58 -0600 Subject: [PATCH 5/7] Remove unnecessary StringBuilder addition as QNameString is now in its own file --- src/lib/dnssd/minimal_mdns/Logging.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/dnssd/minimal_mdns/Logging.h b/src/lib/dnssd/minimal_mdns/Logging.h index 3ba44a11ffecf9..de00df4e2a7dca 100644 --- a/src/lib/dnssd/minimal_mdns/Logging.h +++ b/src/lib/dnssd/minimal_mdns/Logging.h @@ -20,7 +20,6 @@ #include #include #include -#include namespace mdns { namespace Minimal { From 4f38a1deda516ff6a2465c37d2c52d675f03f4e9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 23 Jun 2022 18:54:15 +0000 Subject: [PATCH 6/7] Restyled by whitespace --- src/lib/dnssd/minimal_mdns/core/QNameString.cpp | 2 +- src/lib/dnssd/minimal_mdns/core/QNameString.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/dnssd/minimal_mdns/core/QNameString.cpp b/src/lib/dnssd/minimal_mdns/core/QNameString.cpp index 417451ebcbbde9..c299520b75b547 100644 --- a/src/lib/dnssd/minimal_mdns/core/QNameString.cpp +++ b/src/lib/dnssd/minimal_mdns/core/QNameString.cpp @@ -53,4 +53,4 @@ QNameString::QNameString(mdns::Minimal::SerializedQNameIterator name) } } // namespace Minimal -} // namespace mdns \ No newline at end of file +} // namespace mdns diff --git a/src/lib/dnssd/minimal_mdns/core/QNameString.h b/src/lib/dnssd/minimal_mdns/core/QNameString.h index 797308840e7f01..fcbd8ffbfe81ae 100644 --- a/src/lib/dnssd/minimal_mdns/core/QNameString.h +++ b/src/lib/dnssd/minimal_mdns/core/QNameString.h @@ -40,4 +40,4 @@ class QNameString }; } // namespace Minimal -} // namespace mdns \ No newline at end of file +} // namespace mdns From 72c159737620e289f0894fe7eff3d70730d137a2 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 23 Jun 2022 18:54:17 +0000 Subject: [PATCH 7/7] Restyled by clang-format --- src/lib/dnssd/minimal_mdns/core/QNameString.h | 2 +- src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/dnssd/minimal_mdns/core/QNameString.h b/src/lib/dnssd/minimal_mdns/core/QNameString.h index fcbd8ffbfe81ae..6a548e8b474394 100644 --- a/src/lib/dnssd/minimal_mdns/core/QNameString.h +++ b/src/lib/dnssd/minimal_mdns/core/QNameString.h @@ -16,8 +16,8 @@ */ #pragma once -#include #include +#include namespace mdns { namespace Minimal { diff --git a/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp b/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp index 6d5dfca34d9272..47731c7a42ddfd 100644 --- a/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp +++ b/src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp @@ -17,8 +17,8 @@ #include "QueryResponder.h" -#include #include +#include #include