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

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: Fixel little mistake in GetLocalIp. 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..f7a2c1a6e6f4d90afd4a51380f8eed56e79ecc26 100644
--- a/cloud_print/gcp20/prototype/dns_sd_server.h
+++ b/cloud_print/gcp20/prototype/dns_sd_server.h
@@ -2,27 +2,33 @@
// 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 "cloud_print/gcp20/prototype/dns_response_builder.h"
+#include "cloud_print/gcp20/prototype/service_parameters.h"
#include "net/dns/dns_protocol.h"
#include "net/udp/udp_socket.h"
Vitaly Buka (NO REVIEWS) 2013/06/21 01:03:39 put forward declaration of net::UDPSocket here and
maksymb 2013/06/21 03:22:48 Done.
// Class for sending multicast announcements, receiving queries and answering on
-// them. Client should call |ProccessMessages| periodically to make server work.
+// them.
+// TODO(maksymb): Implement probing.
class DnsSdServer {
public:
- // Constructs unstarted server.
+ // Constructor does not start server.
DnsSdServer();
- // Stops server.
+ // Stops the server and destroys the object.
~DnsSdServer();
// Starts the server. Returns |true| if server works. Also sends
// announcement.
- bool Start();
+ bool Start(const ServiceParameters& serv_params, uint32 full_ttl,
+ const std::vector<std::string>& metadata) WARN_UNUSED_RESULT;
// Sends announcement if server works.
void Update();
@@ -30,24 +36,35 @@ 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_; }
+ bool IsOnline() { return socket_.get() != NULL; }
Vitaly Buka (NO REVIEWS) 2013/06/21 01:03:39 return socket_;
maksymb 2013/06/21 03:22:48 Done.
+
+ // Updates data for TXT respond.
+ void UpdateMetadata(const std::vector<std::string>& metadata);
private:
// Binds a socket to multicast address. Returns |true| on success.
bool CreateSocket();
+ // Processes single query.
+ void ProccessQuery(uint32 current_ttl, const DnsQueryRecord& query,
+ DnsResponseBuilder* builder) const;
+
+ // Processes DNS message.
+ void ProcessMessage(int len, net::IOBufferWithSize* buf);
+
+ // 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();
-
- // Stores |true| if server was started.
- bool is_online_;
+ // Calculates and returns current TTL (with accordance to last send
+ // announcement time.
+ uint32 GetCurrentTLL() const;
// Stores socket to multicast address.
scoped_ptr<net::UDPSocket> socket_;
@@ -55,8 +72,26 @@ class DnsSdServer {
// Stores multicast address end point.
net::IPEndPoint multicast_address_;
+ // Stores time until last announcement is live.
+ base::Time time_until_live_;
+
+ // Stores service parameters (like service-name and service-type etc.)
+ ServiceParameters serv_params_;
+
+ // Stores the buffer for receiving messages.
+ scoped_refptr<net::IOBufferWithSize> recv_buf_;
+
+ // Stores address from where last message was sent.
+ net::IPEndPoint recv_address_;
+
+ // Stores information for TXT respond.
+ std::vector<std::string> metadata_;
+
+ // 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