aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Keane <rwkeane@google.com>2019-10-21 16:46:56 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-21 23:57:31 +0000
commitbd5d0f0af38846d90598d772e42073c4d16be313 (patch)
tree45e6f15e5d303f3562c216db003f558404737bfa
parent490c614a203664dc928a5de076dbdd0009e8b547 (diff)
downloadopenscreen-bd5d0f0af38846d90598d772e42073c4d16be313.tar.gz
DNS-SD: Class Skeletons
The class skeletons currently live in dnssd/public because they may be exposed for embedders to inject in their own implementation. These APIs may continue to evolve over time, but adding the public interfaces now will allow future CLs to go in parallel NOTES: - The factory methods for the public classes will come at a later point. - The dns_sd_temp.cc file is only here because ninja won't compile unreferenced header files. It will be removed in future. - Based on Max's suggestion, the public API may later change to expose a single class instead of querier + publisher. This can be addressed in future once the layout of each implementation is clearer. Change-Id: I81e521fbcb731943e39066ea69842564ae7a5699 Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/1860922 Commit-Queue: Ryan Keane <rwkeane@google.com> Reviewed-by: mark a. foltz <mfoltz@chromium.org> Reviewed-by: Max Yakimakha <yakimakha@chromium.org>
-rw-r--r--BUILD.gn2
-rw-r--r--discovery/BUILD.gn42
-rw-r--r--discovery/dnssd/dns_sd_temp.cc11
-rw-r--r--discovery/dnssd/public/instance_record.h66
-rw-r--r--discovery/dnssd/public/publisher.h33
-rw-r--r--discovery/dnssd/public/querier.h52
-rw-r--r--discovery/dnssd/public/txt_record.h37
7 files changed, 243 insertions, 0 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 4940cfc6..fa44dd81 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -12,6 +12,7 @@ group("gn_all") {
"cast/common:mdns",
"cast/common/certificate",
"cast/sender/channel",
+ "discovery:dnssd",
"osp",
"osp/msgs",
"platform",
@@ -52,6 +53,7 @@ executable("openscreen_unittests") {
"cast/common/certificate:unittests",
"cast/common/channel:unittests",
"cast/sender/channel:unittests",
+ "discovery:unittests",
"osp:unittests",
"osp/impl/discovery/mdns:unittests",
"osp/impl/testing:unittests",
diff --git a/discovery/BUILD.gn b/discovery/BUILD.gn
new file mode 100644
index 00000000..7499b500
--- /dev/null
+++ b/discovery/BUILD.gn
@@ -0,0 +1,42 @@
+# Copyright 2019 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build_overrides/build.gni")
+
+source_set("dnssd") {
+ defines = []
+
+ sources = [
+ "dnssd/dns_sd_temp.cc",
+ "dnssd/public/instance_record.h",
+ "dnssd/public/publisher.h",
+ "dnssd/public/querier.h",
+ "dnssd/public/txt_record.h",
+ ]
+
+ deps = [
+ "../cast/common:mdns",
+ "../platform",
+ "../third_party/abseil",
+ ]
+
+ configs += [ "../build:allow_build_from_embedder" ]
+}
+
+source_set("unittests") {
+ testonly = true
+
+ sources = []
+
+ deps = [
+ ":dnssd",
+ "../cast/common:mdns",
+ "../platform",
+ "../third_party/abseil",
+ "../third_party/googletest:gmock",
+ "../third_party/googletest:gtest",
+ ]
+
+ configs += [ "../../build:allow_build_from_embedder" ]
+}
diff --git a/discovery/dnssd/dns_sd_temp.cc b/discovery/dnssd/dns_sd_temp.cc
new file mode 100644
index 00000000..7762c575
--- /dev/null
+++ b/discovery/dnssd/dns_sd_temp.cc
@@ -0,0 +1,11 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// TODO(rwkeane): Remove this class when the below files are referenced
+// elsewhere.
+
+#include "discovery/dnssd/public/instance_record.h"
+#include "discovery/dnssd/public/publisher.h"
+#include "discovery/dnssd/public/querier.h"
+#include "discovery/dnssd/public/txt_record.h"
diff --git a/discovery/dnssd/public/instance_record.h b/discovery/dnssd/public/instance_record.h
new file mode 100644
index 00000000..8cefea8d
--- /dev/null
+++ b/discovery/dnssd/public/instance_record.h
@@ -0,0 +1,66 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DISCOVERY_DNSSD_PUBLIC_INSTANCE_RECORD_H_
+#define DISCOVERY_DNSSD_PUBLIC_INSTANCE_RECORD_H_
+
+#include "absl/strings/string_view.h"
+#include "absl/types/optional.h"
+#include "discovery/dnssd/public/txt_record.h"
+#include "platform/base/ip_address.h"
+
+namespace openscreen {
+namespace discovery {
+
+// Represents the data stored in DNS records of types SRV, TXT, A, and AAAA
+class DnsSdInstanceRecord {
+ public:
+ // These ctors expect valid input, and will cause a crash if they are not.
+ // TODO(rwkeane): Add validation methods for instance_id, service_id,
+ // domain_id.
+ DnsSdInstanceRecord(std::string instance_id,
+ std::string service_id,
+ std::string domain_id,
+ IPEndpoint endpoint,
+ DnsSdTxtRecord txt);
+
+ // NOTE: This constructor expects one endpoint to be an IPv4 address and the
+ // other to be an IPv6 address.
+ DnsSdInstanceRecord(std::string instance_id,
+ std::string service_id,
+ std::string domain_id,
+ IPEndpoint ipv4_endpoint,
+ IPEndpoint ipv6_endpoint,
+ DnsSdTxtRecord txt);
+
+ // Returns the instance name for this DNS-SD record.
+ const std::string& instance_id() const { return instance_id_; }
+
+ // Returns the service id for this DNS-SD record.
+ const std::string& service_id() const { return service_id_; }
+
+ // Returns the domain id for this DNS-SD record.
+ const std::string& domain_id() const { return domain_id_; }
+
+ // Returns the addess associated with this DNS-SD record. In any valid record,
+ // at least one will be set.
+ const absl::optional<IPEndpoint>& address_v4() const { return address_v4_; }
+ const absl::optional<IPEndpoint>& address_v6() const { return address_v6_; }
+
+ // Returns the TXT record associated with this DNS-SD record
+ const DnsSdTxtRecord& txt() const { return txt_; };
+
+ private:
+ std::string instance_id_;
+ std::string service_id_;
+ std::string domain_id_;
+ absl::optional<IPEndpoint> address_v4_;
+ absl::optional<IPEndpoint> address_v6_;
+ DnsSdTxtRecord txt_;
+};
+
+} // namespace discovery
+} // namespace openscreen
+
+#endif // DISCOVERY_DNSSD_PUBLIC_INSTANCE_RECORD_H_
diff --git a/discovery/dnssd/public/publisher.h b/discovery/dnssd/public/publisher.h
new file mode 100644
index 00000000..9d9be5c0
--- /dev/null
+++ b/discovery/dnssd/public/publisher.h
@@ -0,0 +1,33 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DISCOVERY_DNSSD_PUBLIC_PUBLISHER_H_
+#define DISCOVERY_DNSSD_PUBLIC_PUBLISHER_H_
+
+#include "absl/strings/string_view.h"
+#include "discovery/dnssd/public/instance_record.h"
+
+namespace openscreen {
+namespace discovery {
+
+class DnsSdPublisher {
+ public:
+ virtual ~DnsSdPublisher() = default;
+
+ // Publishes the PTR, SRV, TXT, A, and AAAA records provided in the
+ // DnsSdInstanceRecord.
+ // TODO(rwkeane): Document behavior if the record already exists.
+ virtual void Register(const DnsSdInstanceRecord& record) = 0;
+
+ // Unpublishes any PTR, SRV, TXT, A, and AAAA records associated with this
+ // (service, domain) pair. If no such records are published, this operation
+ // will be a no-op.
+ virtual void DeregisterAll(const absl::string_view& service,
+ const absl::string_view& domain) = 0;
+};
+
+} // namespace discovery
+} // namespace openscreen
+
+#endif // DISCOVERY_DNSSD_PUBLIC_PUBLISHER_H_
diff --git a/discovery/dnssd/public/querier.h b/discovery/dnssd/public/querier.h
new file mode 100644
index 00000000..e034891d
--- /dev/null
+++ b/discovery/dnssd/public/querier.h
@@ -0,0 +1,52 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DISCOVERY_DNSSD_PUBLIC_QUERIER_H_
+#define DISCOVERY_DNSSD_PUBLIC_QUERIER_H_
+
+#include "absl/strings/string_view.h"
+#include "discovery/dnssd/public/instance_record.h"
+
+namespace openscreen {
+namespace discovery {
+
+class DnsSdQuerier {
+ public:
+ // TODO(rwkeane): Add support for expiring records in addition to deleting
+ // them.
+ class Callback {
+ public:
+ virtual ~Callback() = default;
+
+ // Callback fired when a new InstanceRecord is created.
+ virtual void OnInstanceCreated(const DnsSdInstanceRecord& new_record) = 0;
+
+ // Callback fired when an existing InstanceRecord is updated.
+ virtual void OnInstanceUpdated(
+ const DnsSdInstanceRecord& modified_record) = 0;
+
+ // Callback fired when an existing InstanceRecord is deleted.
+ virtual void OnInstanceDeleted(const DnsSdInstanceRecord& old_record) = 0;
+ };
+
+ virtual ~DnsSdQuerier() = default;
+
+ // Begins a new query. The provided callback will be called whenever new
+ // information about the provided (service, domain) pair becomes available.
+ // The Callback provided is expected to persist until the StopQuery method is
+ // called or this instance is destroyed.
+ virtual void StartQuery(const absl::string_view& service,
+ const absl::string_view& domain,
+ Callback* cb) = 0;
+
+ // Stops an already running query.
+ virtual void StopQuery(const absl::string_view& service,
+ const absl::string_view& domain,
+ Callback* cb) = 0;
+};
+
+} // namespace discovery
+} // namespace openscreen
+
+#endif // DISCOVERY_DNSSD_PUBLIC_QUERIER_H_
diff --git a/discovery/dnssd/public/txt_record.h b/discovery/dnssd/public/txt_record.h
new file mode 100644
index 00000000..1505e902
--- /dev/null
+++ b/discovery/dnssd/public/txt_record.h
@@ -0,0 +1,37 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DISCOVERY_DNSSD_PUBLIC_TXT_RECORD_H_
+#define DISCOVERY_DNSSD_PUBLIC_TXT_RECORD_H_
+
+#include "absl/strings/string_view.h"
+#include "absl/types/span.h"
+#include "platform/base/error.h"
+
+namespace openscreen {
+namespace discovery {
+
+class DnsSdTxtRecord {
+ public:
+ // Sets the value currently stored in this DNS-SD TXT record. Returns error
+ // if the provided key is already set or if either the key or value is
+ // invalid, and Error::None() otherwise. Case of the key is ignored.
+ Error SetValue(const absl::string_view& key,
+ const absl::Span<uint8_t>& value);
+ Error SetFlag(const absl::string_view& key, bool value);
+
+ // Reads the value associated with the provided key, or an error if the key
+ // is invalid or not present. Case of the key is ignored.
+ ErrorOr<absl::Span<uint8_t>> GetValue(const absl::string_view& key) const;
+ ErrorOr<bool> GetFlag(const absl::string_view& key) const;
+
+ // Clears an existing TxtRecord value associated with the given key.
+ void ClearValue(const absl::string_view& key);
+ void ClearFlag(const absl::string_view& key);
+};
+
+} // namespace discovery
+} // namespace openscreen
+
+#endif // DISCOVERY_DNSSD_PUBLIC_TXT_RECORD_H_