Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/p2p/port_allocator.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "content/renderer/p2p/host_address_request.h" | |
| 9 #include "jingle/glue/utils.cc" | |
| 10 #include "net/base/ip_endpoint.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 P2PPortAllocator::P2PPortAllocator( | |
| 15 P2PSocketDispatcher* socket_dispatcher, | |
| 16 talk_base::NetworkManager* network_manager, | |
| 17 talk_base::PacketSocketFactory* socket_factory, | |
| 18 const webkit_glue::P2PTransport::Config& config) | |
| 19 : cricket::BasicPortAllocator(network_manager, socket_factory), | |
| 20 socket_dispatcher_(socket_dispatcher), | |
| 21 config_(config) { | |
| 22 } | |
| 23 | |
| 24 P2PPortAllocator::~P2PPortAllocator() { | |
| 25 } | |
| 26 | |
| 27 cricket::PortAllocatorSession* P2PPortAllocator::CreateSession( | |
| 28 const std::string& name, | |
| 29 const std::string& session_type) { | |
| 30 return new P2PPortAllocatorSession(this, name, session_type); | |
| 31 } | |
| 32 | |
| 33 P2PPortAllocatorSession::P2PPortAllocatorSession( | |
| 34 P2PPortAllocator* allocator, | |
| 35 const std::string& name, | |
| 36 const std::string& session_type) | |
| 37 : cricket::BasicPortAllocatorSession(allocator, name, session_type), | |
| 38 allocator_(allocator), | |
| 39 stun_server_port_(0) { | |
| 40 } | |
| 41 | |
| 42 P2PPortAllocatorSession::~P2PPortAllocatorSession() { | |
| 43 if (stun_address_request_) | |
| 44 stun_address_request_->Cancel(); | |
| 45 } | |
| 46 | |
| 47 void P2PPortAllocatorSession::GetPortConfigurations() { | |
| 48 // Add empty configuration synchronously, so local connection can be | |
| 49 // started immediately. | |
|
Wez
2011/08/29 18:01:57
nit: Missing "an" and "a".
Sergey Ulanov
2011/08/29 22:13:39
Done.
| |
| 50 ConfigReady(new cricket::PortConfiguration( | |
| 51 talk_base::SocketAddress(), "", "", "")); | |
| 52 | |
| 53 ResolveStunAddress(); | |
| 54 | |
| 55 // TODO(sergeyu): Implement relay server support. | |
|
Wez
2011/08/29 18:01:57
Do you have a bug created to track that?
Sergey Ulanov
2011/08/29 22:13:39
No, but I have a CL :)
There is crbug.com/41776 al
| |
| 56 } | |
| 57 | |
| 58 void P2PPortAllocatorSession::ResolveStunAddress() { | |
| 59 if (allocator_->config_.stun_server.empty()) | |
| 60 return; | |
| 61 | |
| 62 std::string hostname; | |
| 63 if (!net::ParseHostAndPort(allocator_->config_.stun_server, | |
| 64 &hostname, &stun_server_port_)) { | |
| 65 LOG(ERROR) << "Invalid stun server address: " | |
| 66 << allocator_->config_.stun_server; | |
|
Wez
2011/08/29 18:01:57
Shouldn't this expose an error to the caller, rath
Sergey Ulanov
2011/08/29 22:13:39
Yes, It should. I moved this to ppb_transport_impl
| |
| 67 return; | |
| 68 } | |
| 69 | |
| 70 DCHECK(!stun_address_request_); | |
| 71 stun_address_request_ = | |
| 72 new P2PHostAddressRequest(allocator_->socket_dispatcher_); | |
|
Wez
2011/08/29 18:01:57
Could this request class have a more descriptive n
Sergey Ulanov
2011/08/29 22:13:39
Added TODO for this in host_address_request.h.
| |
| 73 stun_address_request_->Request(hostname, base::Bind( | |
| 74 &P2PPortAllocatorSession::OnStunAddress, | |
| 75 base::Unretained(this))); | |
| 76 } | |
| 77 | |
| 78 void P2PPortAllocatorSession::OnStunAddress( | |
|
Wez
2011/08/29 18:01:57
nit: OnStunAddress->OnStunHostAddress.
Sergey Ulanov
2011/08/29 22:13:39
Renamed it to OnStunServerAddress
| |
| 79 const net::IPAddressNumber& address) { | |
| 80 talk_base::SocketAddress socket_address; | |
| 81 if (!jingle_glue::IPEndPointToSocketAddress( | |
| 82 net::IPEndPoint(address, stun_server_port_), &socket_address)) { | |
|
Wez
2011/08/29 18:01:57
nit: I'd wrap &socket_address, too, for readabilit
Wez
2011/08/29 18:01:57
Initially I thought this strange - it seemed to be
Sergey Ulanov
2011/08/29 22:13:39
Done.
| |
| 83 return; | |
| 84 } | |
| 85 | |
| 86 ConfigReady(new cricket::PortConfiguration(socket_address, "", "", "")); | |
| 87 } | |
| 88 | |
| 89 } // namespace content | |
| OLD | NEW |