Chromium Code Reviews| 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..0396a5ef5af5468ddf0ddd93b33b16522c023367 100644 |
| --- a/cloud_print/gcp20/prototype/dns_sd_server.h |
| +++ b/cloud_print/gcp20/prototype/dns_sd_server.h |
| @@ -2,27 +2,69 @@ |
| // 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 |true| if packet is not empty. |
| + virtual int HaveAnswers() const = 0; |
| + |
| + // Methods for checking accordance |qname| to different types of queries. |
| + virtual bool IsSamePtr(const std::string& qname) = 0; |
|
gene
2013/06/15 02:13:23
can IsSameXXX() functions modify members or they s
maksymb
2013/06/18 01:14:48
Deleted functions at all.
|
| + virtual bool IsSameSrv(const std::string& qname) = 0; |
| + virtual bool IsSameA(const std::string& qname) = 0; |
| + virtual bool IsSameTxt(const std::string& qname) = 0; |
| + |
| + // Methods for appending different types of responses to packet. |
| + virtual void AppendPtr(uint32 ttl) = 0; |
|
gene
2013/06/15 02:13:23
Where do you get metadata (for example service nam
maksymb
2013/06/18 01:14:48
Now it is in parameters.
|
| + virtual void AppendSrv(uint32 ttl) = 0; |
| + virtual void AppendA(uint32 ttl) = 0; |
| + virtual void AppendTxt(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. |
|
gene
2013/06/15 02:13:23
"Constructs not started server." -> "Constructor d
maksymb
2013/06/18 01:14:48
Done.
|
| 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, |
|
gene
2013/06/15 02:13:23
Usually factory is a singleton type of object. Unl
maksymb
2013/06/18 01:14:48
Deleted.
|
| + uint32 full_ttl) WARN_UNUSED_RESULT; |
| // Sends announcement if server works. |
| void Update(); |
| @@ -30,9 +72,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 +79,28 @@ class DnsSdServer { |
| // Binds a socket to multicast address. Returns |true| on success. |
| bool CreateSocket(); |
| + // Processes DNS message. |
| + void ProcessMessage(int len, net::IOBufferWithSize* buf); |
| + |
| + // 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; |
|
gene
2013/06/15 02:13:23
I am confused what is parser doing in the CreateRe
maksymb
2013/06/18 01:14:48
Method was deleted.
|
| + |
| + // 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 +111,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_ |