Chromium Code Reviews| Index: content/renderer/p2p/port_allocator.cc |
| diff --git a/content/renderer/p2p/port_allocator.cc b/content/renderer/p2p/port_allocator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6286302472d16edaafb17a48b17a351e82c1a4cc |
| --- /dev/null |
| +++ b/content/renderer/p2p/port_allocator.cc |
| @@ -0,0 +1,89 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/p2p/port_allocator.h" |
| + |
| +#include "base/bind.h" |
| +#include "content/renderer/p2p/host_address_request.h" |
| +#include "jingle/glue/utils.cc" |
| +#include "net/base/ip_endpoint.h" |
| + |
| +namespace content { |
| + |
| +P2PPortAllocator::P2PPortAllocator( |
| + P2PSocketDispatcher* socket_dispatcher, |
| + talk_base::NetworkManager* network_manager, |
| + talk_base::PacketSocketFactory* socket_factory, |
| + const webkit_glue::P2PTransport::Config& config) |
| + : cricket::BasicPortAllocator(network_manager, socket_factory), |
| + socket_dispatcher_(socket_dispatcher), |
| + config_(config) { |
| +} |
| + |
| +P2PPortAllocator::~P2PPortAllocator() { |
| +} |
| + |
| +cricket::PortAllocatorSession* P2PPortAllocator::CreateSession( |
| + const std::string& name, |
| + const std::string& session_type) { |
| + return new P2PPortAllocatorSession(this, name, session_type); |
| +} |
| + |
| +P2PPortAllocatorSession::P2PPortAllocatorSession( |
| + P2PPortAllocator* allocator, |
| + const std::string& name, |
| + const std::string& session_type) |
| + : cricket::BasicPortAllocatorSession(allocator, name, session_type), |
| + allocator_(allocator), |
| + stun_server_port_(0) { |
| +} |
| + |
| +P2PPortAllocatorSession::~P2PPortAllocatorSession() { |
| + if (stun_address_request_) |
| + stun_address_request_->Cancel(); |
| +} |
| + |
| +void P2PPortAllocatorSession::GetPortConfigurations() { |
| + // Add empty configuration synchronously, so local connection can be |
| + // started immediately. |
|
Wez
2011/08/29 18:01:57
nit: Missing "an" and "a".
Sergey Ulanov
2011/08/29 22:13:39
Done.
|
| + ConfigReady(new cricket::PortConfiguration( |
| + talk_base::SocketAddress(), "", "", "")); |
| + |
| + ResolveStunAddress(); |
| + |
| + // 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
|
| +} |
| + |
| +void P2PPortAllocatorSession::ResolveStunAddress() { |
| + if (allocator_->config_.stun_server.empty()) |
| + return; |
| + |
| + std::string hostname; |
| + if (!net::ParseHostAndPort(allocator_->config_.stun_server, |
| + &hostname, &stun_server_port_)) { |
| + LOG(ERROR) << "Invalid stun server address: " |
| + << 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
|
| + return; |
| + } |
| + |
| + DCHECK(!stun_address_request_); |
| + stun_address_request_ = |
| + 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.
|
| + stun_address_request_->Request(hostname, base::Bind( |
| + &P2PPortAllocatorSession::OnStunAddress, |
| + base::Unretained(this))); |
| +} |
| + |
| +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
|
| + const net::IPAddressNumber& address) { |
| + talk_base::SocketAddress socket_address; |
| + if (!jingle_glue::IPEndPointToSocketAddress( |
| + 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.
|
| + return; |
| + } |
| + |
| + ConfigReady(new cricket::PortConfiguration(socket_address, "", "", "")); |
| +} |
| + |
| +} // namespace content |