Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/dns/mdns_client_impl.h" | 5 #include "net/dns/mdns_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/time/default_clock.h" | 10 #include "base/time/default_clock.h" |
|
davidben
2014/09/17 13:32:00
Nit: This should
#include "base/time/time.h"
sin
| |
| 11 #include "net/base/dns_util.h" | 11 #include "net/base/dns_util.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/net_log.h" | 13 #include "net/base/net_log.h" |
| 14 #include "net/base/rand_callback.h" | 14 #include "net/base/rand_callback.h" |
| 15 #include "net/dns/dns_protocol.h" | 15 #include "net/dns/dns_protocol.h" |
| 16 #include "net/dns/record_rdata.h" | 16 #include "net/dns/record_rdata.h" |
| 17 #include "net/udp/datagram_socket.h" | 17 #include "net/udp/datagram_socket.h" |
| 18 | 18 |
| 19 // TODO(gene): Remove this temporary method of disabling NSEC support once it | 19 // TODO(gene): Remove this temporary method of disabling NSEC support once it |
| 20 // becomes clear whether this feature should be | 20 // becomes clear whether this feature should be |
| 21 // supported. http://crbug.com/255232 | 21 // supported. http://crbug.com/255232 |
| 22 #define ENABLE_NSEC | 22 #define ENABLE_NSEC |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const unsigned MDnsTransactionTimeoutSeconds = 3; | 28 const unsigned MDnsTransactionTimeoutSeconds = 3; |
| 29 // The fractions of the record's original TTL after which an active listener | 29 // The fractions of the record's original TTL after which an active listener |
| 30 // (one that had |SetActiveRefresh(true)| called) will send a query to refresh | 30 // (one that had |SetActiveRefresh(true)| called) will send a query to refresh |
| 31 // its cache. This happens both at 85% of the original TTL and again at 95% of | 31 // its cache. This happens both at 85% of the original TTL and again at 95% of |
| 32 // the original TTL. | 32 // the original TTL. |
| 33 const double kListenerRefreshRatio1 = 0.85; | 33 const double kListenerRefreshRatio1 = 0.85; |
| 34 const double kListenerRefreshRatio2 = 0.95; | 34 const double kListenerRefreshRatio2 = 0.95; |
| 35 const unsigned kMillisecondsPerSecond = 1000; | |
| 36 | |
|
davidben
2014/09/17 13:32:00
Really nitpicky nit: I would leave the blank line
| |
| 37 } // namespace | 35 } // namespace |
| 38 | 36 |
| 39 void MDnsSocketFactoryImpl::CreateSockets( | 37 void MDnsSocketFactoryImpl::CreateSockets( |
| 40 ScopedVector<DatagramServerSocket>* sockets) { | 38 ScopedVector<DatagramServerSocket>* sockets) { |
| 41 InterfaceIndexFamilyList interfaces(GetMDnsInterfacesToBind()); | 39 InterfaceIndexFamilyList interfaces(GetMDnsInterfacesToBind()); |
| 42 for (size_t i = 0; i < interfaces.size(); ++i) { | 40 for (size_t i = 0; i < interfaces.size(); ++i) { |
| 43 DCHECK(interfaces[i].second == net::ADDRESS_FAMILY_IPV4 || | 41 DCHECK(interfaces[i].second == net::ADDRESS_FAMILY_IPV4 || |
| 44 interfaces[i].second == net::ADDRESS_FAMILY_IPV6); | 42 interfaces[i].second == net::ADDRESS_FAMILY_IPV6); |
| 45 scoped_ptr<DatagramServerSocket> socket( | 43 scoped_ptr<DatagramServerSocket> socket( |
| 46 CreateAndBindMDnsSocket(interfaces[i].second, interfaces[i].first)); | 44 CreateAndBindMDnsSocket(interfaces[i].second, interfaces[i].first)); |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 return; | 529 return; |
| 532 } | 530 } |
| 533 | 531 |
| 534 next_refresh_.Reset(base::Bind(&MDnsListenerImpl::DoRefresh, | 532 next_refresh_.Reset(base::Bind(&MDnsListenerImpl::DoRefresh, |
| 535 AsWeakPtr())); | 533 AsWeakPtr())); |
| 536 | 534 |
| 537 // Schedule refreshes at both 85% and 95% of the original TTL. These will both | 535 // Schedule refreshes at both 85% and 95% of the original TTL. These will both |
| 538 // be canceled and rescheduled if the record's TTL is updated due to a | 536 // be canceled and rescheduled if the record's TTL is updated due to a |
| 539 // response being received. | 537 // response being received. |
| 540 base::Time next_refresh1 = last_update_ + base::TimeDelta::FromMilliseconds( | 538 base::Time next_refresh1 = last_update_ + base::TimeDelta::FromMilliseconds( |
| 541 static_cast<int>(kMillisecondsPerSecond * | 539 static_cast<int>(base::Time::kMillisecondsPerSecond * |
| 542 kListenerRefreshRatio1 * ttl_)); | 540 kListenerRefreshRatio1 * ttl_)); |
| 543 | 541 |
| 544 base::Time next_refresh2 = last_update_ + base::TimeDelta::FromMilliseconds( | 542 base::Time next_refresh2 = last_update_ + base::TimeDelta::FromMilliseconds( |
| 545 static_cast<int>(kMillisecondsPerSecond * | 543 static_cast<int>(base::Time::kMillisecondsPerSecond * |
| 546 kListenerRefreshRatio2 * ttl_)); | 544 kListenerRefreshRatio2 * ttl_)); |
| 547 | 545 |
| 548 base::MessageLoop::current()->PostDelayedTask( | 546 base::MessageLoop::current()->PostDelayedTask( |
| 549 FROM_HERE, | 547 FROM_HERE, |
| 550 next_refresh_.callback(), | 548 next_refresh_.callback(), |
| 551 next_refresh1 - base::Time::Now()); | 549 next_refresh1 - base::Time::Now()); |
| 552 | 550 |
| 553 base::MessageLoop::current()->PostDelayedTask( | 551 base::MessageLoop::current()->PostDelayedTask( |
| 554 FROM_HERE, | 552 FROM_HERE, |
| 555 next_refresh_.callback(), | 553 next_refresh_.callback(), |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 701 | 699 |
| 702 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) { | 700 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) { |
| 703 TriggerCallback(RESULT_NSEC, NULL); | 701 TriggerCallback(RESULT_NSEC, NULL); |
| 704 } | 702 } |
| 705 | 703 |
| 706 void MDnsTransactionImpl::OnCachePurged() { | 704 void MDnsTransactionImpl::OnCachePurged() { |
| 707 // TODO(noamsml): Cache purge situations not yet implemented | 705 // TODO(noamsml): Cache purge situations not yet implemented |
| 708 } | 706 } |
| 709 | 707 |
| 710 } // namespace net | 708 } // namespace net |
| OLD | NEW |