Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: cloud_print/gcp20/prototype/dns_sd_server.h

Issue 16975004: Finished DNS-SD server. Finished Privet-specified DNS-SD server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Lint errors. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cloud_print/gcp20/prototype/dns_sd_server.h
diff --git a/cloud_print/gcp20/prototype/dns_sd_server.h b/cloud_print/gcp20/prototype/dns_sd_server.h
index 9c8ed96b7d33d62790d7797dc061f5b963911f2f..314054cabd3eb0e4a31271262e24d535e5ad888f 100644
--- a/cloud_print/gcp20/prototype/dns_sd_server.h
+++ b/cloud_print/gcp20/prototype/dns_sd_server.h
@@ -2,27 +2,72 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef GCP20_PROTOTYPE_DNS_SD_H_
-#define GCP20_PROTOTYPE_DNS_SD_H_
+#ifndef CLOUD_PRINT_GCP20_PROTOTYPE_DNS_SD_SERVER_H_
+#define CLOUD_PRINT_GCP20_PROTOTYPE_DNS_SD_SERVER_H_
+#include <string>
#include <vector>
+#include "cloud_print/gcp20/prototype/dns_packet_parser.h"
#include "net/dns/dns_protocol.h"
#include "net/udp/udp_socket.h"
+// Interface for building service-specified responses.
+class DnsResponseBuilderInterface {
+ public:
+ // Destroys builder.
+ virtual ~DnsResponseBuilderInterface() {}
+
+ // Returns length of packet.
+ virtual int size() const = 0;
+
+ // Returns |true| if packet is not empty.
+ virtual int HaveAnswers() const = 0;
+
+ // Methods for checking accordance |qname| to different types of queries.
+ virtual bool CheckPtr(const std::string& qname) = 0;
+ virtual bool CheckSrv(const std::string& qname) = 0;
+ virtual bool CheckA(const std::string& qname) = 0;
+ virtual bool CheckTxt(const std::string& qname) = 0;
+
+ // Methods for appending different types of responses to packet.
+ virtual void AppendPtr(const uint32 ttl) = 0;
+ virtual void AppendSrv(const uint32 ttl) = 0;
+ virtual void AppendA(const uint32 ttl) = 0;
+ virtual void AppendTxt(const uint32 ttl) = 0;
+
+ // Serializes packet to byte sequence.
+ virtual scoped_refptr<net::IOBufferWithSize> Build() const = 0;
+
+ // Builds DNS packet for announcement with certain TTL.
+ virtual scoped_refptr<net::IOBufferWithSize>
+ BuildAnnouncement(uint32 ttl) = 0;
+};
+
+// Factory for builders.
+class DnsResponseBuilderFactoryInterface {
+ public:
+ virtual ~DnsResponseBuilderFactoryInterface() {}
+
+ // Creates new builder.
+ virtual DnsResponseBuilderInterface* Create(uint16 id) = 0;
+};
+
// Class for sending multicast announcements, receiving queries and answering on
// them. Client should call |ProccessMessages| periodically to make server work.
+// TODO(maksymb): Implement probing.
class DnsSdServer {
public:
- // Constructs unstarted server.
+ // Constructs not started server.
DnsSdServer();
// Stops server.
- ~DnsSdServer();
+ virtual ~DnsSdServer();
// Starts the server. Returns |true| if server works. Also sends
// announcement.
- bool Start();
+ bool Start(DnsResponseBuilderFactoryInterface* response_builder_factory,
+ const uint32 full_ttl) WARN_UNUSED_RESULT;
Vitaly Buka (NO REVIEWS) 2013/06/14 19:27:07 no need const here
maksymb 2013/06/14 22:17:14 Done.
// Sends announcement if server works.
void Update();
@@ -30,9 +75,6 @@ class DnsSdServer {
// Stops server with announcement.
void Shutdown();
- // Process pending queries for the server.
- void ProcessMessages();
-
// Returns |true| if server works.
bool is_online() { return is_online_; }
@@ -40,11 +82,29 @@ class DnsSdServer {
// Binds a socket to multicast address. Returns |true| on success.
bool CreateSocket();
+ // Processes DNS message.
+ void ProcessMessage(
+ int len, const scoped_refptr<net::IOBufferWithSize>& buf);
Vitaly Buka (NO REVIEWS) 2013/06/14 19:27:07 const scoped_refptr<net::IOBufferWithSize>& buf ->
maksymb 2013/06/14 22:17:14 Done.
+
+ // Template method for parsing packet. Returns NULL if there is no answer for
+ // these packet.
+ scoped_refptr<net::IOBufferWithSize> CreateResponsePacket(
+ const net::dns_protocol::Header& header,
+ DnsPacketParser* parser) const;
+
+ // CompletionCallback for receiving data from DNS.
+ void DoLoop(int rv);
+
+ // Function to start listening to socket (delegate to DoLoop function).
+ void OnDatagramReceived();
+
// Sends announcement.
void SendAnnouncement(uint32 ttl);
- // Returns |true| if server received some questions.
- bool CheckPendingQueries();
+ scoped_refptr<net::IOBufferWithSize> BuildAnnouncement(uint32 ttl) const;
+
+ // Work with incoming message and call |CheckPendingQueries| again.
+ void OnReceiveMessage(int val);
// Stores |true| if server was started.
bool is_online_;
@@ -55,8 +115,23 @@ class DnsSdServer {
// Stores multicast address end point.
net::IPEndPoint multicast_address_;
+ // Stores time until last announcement is live.
+ base::Time time_until_live_;
+
+ // Service-specified response builder factory.
+ DnsResponseBuilderFactoryInterface* response_builder_factory_;
+
+ // Stores the buffer for receiving messages.
+ scoped_refptr<net::IOBufferWithSize> recv_buf_;
+
+ // Stores address from where last message was sent.
+ net::IPEndPoint recv_address_;
+
+ // TTL for announcements
+ uint32 full_ttl_;
+
DISALLOW_COPY_AND_ASSIGN(DnsSdServer);
};
-#endif // GCP20_PROTOTYPE_DNS_SD_H_
+#endif // CLOUD_PRINT_GCP20_PROTOTYPE_DNS_SD_SERVER_H_

Powered by Google App Engine
This is Rietveld 408576698