#include "talk/p2p/base/basicpacketsocketfactory.h"
-#include "talk/base/asyncudpsocket.h"
-#include "talk/base/asynctcpsocket.h"
-#include "talk/base/logging.h"
-#include "talk/base/nethelpers.h"
-#include "talk/base/physicalsocketserver.h"
-#include "talk/base/scoped_ptr.h"
-#include "talk/base/socketadapters.h"
-#include "talk/base/thread.h"
#include "talk/p2p/base/asyncstuntcpsocket.h"
#include "talk/p2p/base/stun.h"
-
-namespace talk_base {
+#include "webrtc/base/asynctcpsocket.h"
+#include "webrtc/base/asyncudpsocket.h"
+#include "webrtc/base/logging.h"
+#include "webrtc/base/nethelpers.h"
+#include "webrtc/base/physicalsocketserver.h"
+#include "webrtc/base/scoped_ptr.h"
+#include "webrtc/base/socketadapters.h"
+#include "webrtc/base/ssladapter.h"
+#include "webrtc/base/thread.h"
+
+namespace rtc {
BasicPacketSocketFactory::BasicPacketSocketFactory()
: thread_(Thread::Current()),
AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket(
const SocketAddress& address, int min_port, int max_port) {
// UDP sockets are simple.
- talk_base::AsyncSocket* socket =
+ rtc::AsyncSocket* socket =
socket_factory()->CreateAsyncSocket(
address.family(), SOCK_DGRAM);
if (!socket) {
delete socket;
return NULL;
}
- return new talk_base::AsyncUDPSocket(socket);
+ return new rtc::AsyncUDPSocket(socket);
}
AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket(
return NULL;
}
- talk_base::AsyncSocket* socket =
+ rtc::AsyncSocket* socket =
socket_factory()->CreateAsyncSocket(local_address.family(),
SOCK_STREAM);
if (!socket) {
// If using SSLTCP, wrap the TCP socket in a pseudo-SSL socket.
if (opts & PacketSocketFactory::OPT_SSLTCP) {
ASSERT(!(opts & PacketSocketFactory::OPT_TLS));
- socket = new talk_base::AsyncSSLSocket(socket);
+ socket = new rtc::AsyncSSLSocket(socket);
}
// Set TCP_NODELAY (via OPT_NODELAY) for improved performance.
// See http://go/gtalktcpnodelayexperiment
- socket->SetOption(talk_base::Socket::OPT_NODELAY, 1);
+ socket->SetOption(rtc::Socket::OPT_NODELAY, 1);
if (opts & PacketSocketFactory::OPT_STUN)
return new cricket::AsyncStunTCPSocket(socket, true);
- return new talk_base::AsyncTCPSocket(socket, true);
+ return new rtc::AsyncTCPSocket(socket, true);
}
AsyncPacketSocket* BasicPacketSocketFactory::CreateClientTcpSocket(
const SocketAddress& local_address, const SocketAddress& remote_address,
const ProxyInfo& proxy_info, const std::string& user_agent, int opts) {
- // Fail if TLS is required.
- if (opts & PacketSocketFactory::OPT_TLS) {
- LOG(LS_ERROR) << "TLS support currently is not available.";
- return NULL;
- }
-
- talk_base::AsyncSocket* socket =
+ rtc::AsyncSocket* socket =
socket_factory()->CreateAsyncSocket(local_address.family(), SOCK_STREAM);
if (!socket) {
return NULL;
}
// If using a proxy, wrap the socket in a proxy socket.
- if (proxy_info.type == talk_base::PROXY_SOCKS5) {
- socket = new talk_base::AsyncSocksProxySocket(
+ if (proxy_info.type == rtc::PROXY_SOCKS5) {
+ socket = new rtc::AsyncSocksProxySocket(
socket, proxy_info.address, proxy_info.username, proxy_info.password);
- } else if (proxy_info.type == talk_base::PROXY_HTTPS) {
- socket = new talk_base::AsyncHttpsProxySocket(
+ } else if (proxy_info.type == rtc::PROXY_HTTPS) {
+ socket = new rtc::AsyncHttpsProxySocket(
socket, user_agent, proxy_info.address,
proxy_info.username, proxy_info.password);
}
+ // If using TLS, wrap the socket in an SSL adapter.
+ if (opts & PacketSocketFactory::OPT_TLS) {
+ ASSERT(!(opts & PacketSocketFactory::OPT_SSLTCP));
+
+ rtc::SSLAdapter* ssl_adapter = rtc::SSLAdapter::Create(socket);
+ if (!ssl_adapter) {
+ return NULL;
+ }
+
+ socket = ssl_adapter;
+
+ if (ssl_adapter->StartSSL(remote_address.hostname().c_str(), false) != 0) {
+ delete ssl_adapter;
+ return NULL;
+ }
+
// If using SSLTCP, wrap the TCP socket in a pseudo-SSL socket.
- if (opts & PacketSocketFactory::OPT_SSLTCP) {
+ } else if (opts & PacketSocketFactory::OPT_SSLTCP) {
ASSERT(!(opts & PacketSocketFactory::OPT_TLS));
- socket = new talk_base::AsyncSSLSocket(socket);
+ socket = new rtc::AsyncSSLSocket(socket);
}
if (socket->Connect(remote_address) < 0) {
if (opts & PacketSocketFactory::OPT_STUN) {
tcp_socket = new cricket::AsyncStunTCPSocket(socket, false);
} else {
- tcp_socket = new talk_base::AsyncTCPSocket(socket, false);
+ tcp_socket = new rtc::AsyncTCPSocket(socket, false);
}
// Set TCP_NODELAY (via OPT_NODELAY) for improved performance.
// See http://go/gtalktcpnodelayexperiment
- tcp_socket->SetOption(talk_base::Socket::OPT_NODELAY, 1);
+ tcp_socket->SetOption(rtc::Socket::OPT_NODELAY, 1);
return tcp_socket;
}
AsyncResolverInterface* BasicPacketSocketFactory::CreateAsyncResolver() {
- return new talk_base::AsyncResolver();
+ return new rtc::AsyncResolver();
}
int BasicPacketSocketFactory::BindSocket(
} else {
// Otherwise, try to find a port in the provided range.
for (int port = min_port; ret < 0 && port <= max_port; ++port) {
- ret = socket->Bind(talk_base::SocketAddress(local_address.ipaddr(),
+ ret = socket->Bind(rtc::SocketAddress(local_address.ipaddr(),
port));
}
}
}
}
-} // namespace talk_base
+} // namespace rtc