Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Side by Side Diff: webrtc/p2p/client/basicportallocator.cc

Issue 1263603003: Remove PORTALLOCATOR_ENABLE_SHARED_SOCKET. Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/turnport_unittest.cc ('k') | webrtc/p2p/client/connectivitychecker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 sigslot::signal1<AllocationSequence*> SignalPortAllocationComplete; 114 sigslot::signal1<AllocationSequence*> SignalPortAllocationComplete;
115 115
116 private: 116 private:
117 typedef std::vector<ProtocolType> ProtocolList; 117 typedef std::vector<ProtocolType> ProtocolList;
118 118
119 bool IsFlagSet(uint32 flag) { 119 bool IsFlagSet(uint32 flag) {
120 return ((flags_ & flag) != 0); 120 return ((flags_ & flag) != 0);
121 } 121 }
122 void CreateUDPPorts(); 122 void CreateUDPPorts();
123 void CreateTCPPorts(); 123 void CreateTCPPorts();
124 void CreateStunPorts();
125 void CreateRelayPorts(); 124 void CreateRelayPorts();
126 void CreateGturnPort(const RelayServerConfig& config); 125 void CreateGturnPort(const RelayServerConfig& config);
127 void CreateTurnPort(const RelayServerConfig& config); 126 void CreateTurnPort(const RelayServerConfig& config);
128 127
129 void OnReadPacket(rtc::AsyncPacketSocket* socket, 128 void OnReadPacket(rtc::AsyncPacketSocket* socket,
130 const char* data, size_t size, 129 const char* data, size_t size,
131 const rtc::SocketAddress& remote_addr, 130 const rtc::SocketAddress& remote_addr,
132 const rtc::PacketTime& packet_time); 131 const rtc::PacketTime& packet_time);
133 132
134 void OnPortDestroyed(PortInterface* port); 133 void OnPortDestroyed(PortInterface* port);
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 ip_(network->GetBestIP()), 746 ip_(network->GetBestIP()),
748 config_(config), 747 config_(config),
749 state_(kInit), 748 state_(kInit),
750 flags_(flags), 749 flags_(flags),
751 udp_socket_(), 750 udp_socket_(),
752 udp_port_(NULL), 751 udp_port_(NULL),
753 phase_(0) { 752 phase_(0) {
754 } 753 }
755 754
756 bool AllocationSequence::Init() { 755 bool AllocationSequence::Init() {
757 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && 756 udp_socket_.reset(session_->socket_factory()->CreateUdpSocket(
758 !IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_UFRAG)) { 757 rtc::SocketAddress(ip_, 0), session_->allocator()->min_port(),
759 LOG(LS_ERROR) << "Shared socket option can't be set without " 758 session_->allocator()->max_port()));
760 << "shared ufrag."; 759 if (udp_socket_) {
761 ASSERT(false); 760 udp_socket_->SignalReadPacket.connect(
762 return false; 761 this, &AllocationSequence::OnReadPacket);
763 } 762 }
764 763 // Continuing if |udp_socket_| is NULL, as local TCP and RelayPort using TCP
765 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) { 764 // are next available options to setup a communication channel.
766 udp_socket_.reset(session_->socket_factory()->CreateUdpSocket(
767 rtc::SocketAddress(ip_, 0), session_->allocator()->min_port(),
768 session_->allocator()->max_port()));
769 if (udp_socket_) {
770 udp_socket_->SignalReadPacket.connect(
771 this, &AllocationSequence::OnReadPacket);
772 }
773 // Continuing if |udp_socket_| is NULL, as local TCP and RelayPort using TCP
774 // are next available options to setup a communication channel.
775 }
776 return true; 765 return true;
777 } 766 }
778 767
779 void AllocationSequence::Clear() { 768 void AllocationSequence::Clear() {
780 udp_port_ = NULL; 769 udp_port_ = NULL;
781 turn_ports_.clear(); 770 turn_ports_.clear();
782 } 771 }
783 772
784 AllocationSequence::~AllocationSequence() { 773 AllocationSequence::~AllocationSequence() {
785 session_->network_thread()->Clear(this); 774 session_->network_thread()->Clear(this);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 "Udp", "Relay", "Tcp", "SslTcp" 824 "Udp", "Relay", "Tcp", "SslTcp"
836 }; 825 };
837 826
838 // Perform all of the phases in the current step. 827 // Perform all of the phases in the current step.
839 LOG_J(LS_INFO, network_) << "Allocation Phase=" 828 LOG_J(LS_INFO, network_) << "Allocation Phase="
840 << PHASE_NAMES[phase_]; 829 << PHASE_NAMES[phase_];
841 830
842 switch (phase_) { 831 switch (phase_) {
843 case PHASE_UDP: 832 case PHASE_UDP:
844 CreateUDPPorts(); 833 CreateUDPPorts();
845 CreateStunPorts();
846 EnableProtocol(PROTO_UDP); 834 EnableProtocol(PROTO_UDP);
847 break; 835 break;
848 836
849 case PHASE_RELAY: 837 case PHASE_RELAY:
850 CreateRelayPorts(); 838 CreateRelayPorts();
851 break; 839 break;
852 840
853 case PHASE_TCP: 841 case PHASE_TCP:
854 CreateTCPPorts(); 842 CreateTCPPorts();
855 EnableProtocol(PROTO_TCP); 843 EnableProtocol(PROTO_TCP);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 883
896 void AllocationSequence::CreateUDPPorts() { 884 void AllocationSequence::CreateUDPPorts() {
897 if (IsFlagSet(PORTALLOCATOR_DISABLE_UDP)) { 885 if (IsFlagSet(PORTALLOCATOR_DISABLE_UDP)) {
898 LOG(LS_VERBOSE) << "AllocationSequence: UDP ports disabled, skipping."; 886 LOG(LS_VERBOSE) << "AllocationSequence: UDP ports disabled, skipping.";
899 return; 887 return;
900 } 888 }
901 889
902 // TODO(mallinath) - Remove UDPPort creating socket after shared socket 890 // TODO(mallinath) - Remove UDPPort creating socket after shared socket
903 // is enabled completely. 891 // is enabled completely.
904 UDPPort* port = NULL; 892 UDPPort* port = NULL;
905 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && udp_socket_) { 893 port = UDPPort::Create(session_->network_thread(),
906 port = UDPPort::Create(session_->network_thread(), 894 session_->socket_factory(), network_,
907 session_->socket_factory(), network_, 895 udp_socket_.get(),
908 udp_socket_.get(), 896 session_->username(), session_->password(),
909 session_->username(), session_->password(), 897 session_->allocator()->origin());
910 session_->allocator()->origin());
911 } else {
912 port = UDPPort::Create(session_->network_thread(),
913 session_->socket_factory(),
914 network_, ip_,
915 session_->allocator()->min_port(),
916 session_->allocator()->max_port(),
917 session_->username(), session_->password(),
918 session_->allocator()->origin());
919 }
920
921 if (port) { 898 if (port) {
922 // If shared socket is enabled, STUN candidate will be allocated by the 899 // If shared socket is enabled, STUN candidate will be allocated by the
923 // UDPPort. 900 // UDPPort.
924 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) { 901 udp_port_ = port;
925 udp_port_ = port; 902 port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed);
926 port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed);
927 903
928 // If STUN is not disabled, setting stun server address to port. 904 // If STUN is not disabled, setting stun server address to port.
929 if (!IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) { 905 if (!IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) {
930 if (config_ && !config_->StunServers().empty()) { 906 if (config_ && !config_->StunServers().empty()) {
931 LOG(LS_INFO) << "AllocationSequence: UDPPort will be handling the " 907 LOG(LS_INFO) << "AllocationSequence: UDPPort will be handling the "
932 << "STUN candidate generation."; 908 << "STUN candidate generation.";
933 port->set_server_addresses(config_->StunServers()); 909 port->set_server_addresses(config_->StunServers());
934 }
935 } 910 }
936 } 911 }
937 912
938 session_->AddAllocatedPort(port, this, true); 913 session_->AddAllocatedPort(port, this, true);
939 } 914 }
940 } 915 }
941 916
942 void AllocationSequence::CreateTCPPorts() { 917 void AllocationSequence::CreateTCPPorts() {
943 if (IsFlagSet(PORTALLOCATOR_DISABLE_TCP)) { 918 if (IsFlagSet(PORTALLOCATOR_DISABLE_TCP)) {
944 LOG(LS_VERBOSE) << "AllocationSequence: TCP ports disabled, skipping."; 919 LOG(LS_VERBOSE) << "AllocationSequence: TCP ports disabled, skipping.";
945 return; 920 return;
946 } 921 }
947 922
948 Port* port = TCPPort::Create(session_->network_thread(), 923 Port* port = TCPPort::Create(session_->network_thread(),
949 session_->socket_factory(), 924 session_->socket_factory(),
950 network_, ip_, 925 network_, ip_,
951 session_->allocator()->min_port(), 926 session_->allocator()->min_port(),
952 session_->allocator()->max_port(), 927 session_->allocator()->max_port(),
953 session_->username(), session_->password(), 928 session_->username(), session_->password(),
954 session_->allocator()->allow_tcp_listen()); 929 session_->allocator()->allow_tcp_listen());
955 if (port) { 930 if (port) {
956 session_->AddAllocatedPort(port, this, true); 931 session_->AddAllocatedPort(port, this, true);
957 // Since TCPPort is not created using shared socket, |port| will not be 932 // Since TCPPort is not created using shared socket, |port| will not be
958 // added to the dequeue. 933 // added to the dequeue.
959 } 934 }
960 } 935 }
961 936
962 void AllocationSequence::CreateStunPorts() {
963 if (IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) {
964 LOG(LS_VERBOSE) << "AllocationSequence: STUN ports disabled, skipping.";
965 return;
966 }
967
968 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) {
969 return;
970 }
971
972 if (!(config_ && !config_->StunServers().empty())) {
973 LOG(LS_WARNING)
974 << "AllocationSequence: No STUN server configured, skipping.";
975 return;
976 }
977
978 StunPort* port = StunPort::Create(session_->network_thread(),
979 session_->socket_factory(),
980 network_, ip_,
981 session_->allocator()->min_port(),
982 session_->allocator()->max_port(),
983 session_->username(), session_->password(),
984 config_->StunServers(),
985 session_->allocator()->origin());
986 if (port) {
987 session_->AddAllocatedPort(port, this, true);
988 // Since StunPort is not created using shared socket, |port| will not be
989 // added to the dequeue.
990 }
991 }
992
993 void AllocationSequence::CreateRelayPorts() { 937 void AllocationSequence::CreateRelayPorts() {
994 if (IsFlagSet(PORTALLOCATOR_DISABLE_RELAY)) { 938 if (IsFlagSet(PORTALLOCATOR_DISABLE_RELAY)) {
995 LOG(LS_VERBOSE) << "AllocationSequence: Relay ports disabled, skipping."; 939 LOG(LS_VERBOSE) << "AllocationSequence: Relay ports disabled, skipping.";
996 return; 940 return;
997 } 941 }
998 942
999 // If BasicPortAllocatorSession::OnAllocate left relay ports enabled then we 943 // If BasicPortAllocatorSession::OnAllocate left relay ports enabled then we
1000 // ought to have a relay list for them here. 944 // ought to have a relay list for them here.
1001 ASSERT(config_ && !config_->relays.empty()); 945 ASSERT(config_ && !config_->relays.empty());
1002 if (!(config_ && !config_->relays.empty())) { 946 if (!(config_ && !config_->relays.empty())) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 995
1052 void AllocationSequence::CreateTurnPort(const RelayServerConfig& config) { 996 void AllocationSequence::CreateTurnPort(const RelayServerConfig& config) {
1053 PortList::const_iterator relay_port; 997 PortList::const_iterator relay_port;
1054 for (relay_port = config.ports.begin(); 998 for (relay_port = config.ports.begin();
1055 relay_port != config.ports.end(); ++relay_port) { 999 relay_port != config.ports.end(); ++relay_port) {
1056 TurnPort* port = NULL; 1000 TurnPort* port = NULL;
1057 // Shared socket mode must be enabled only for UDP based ports. Hence 1001 // Shared socket mode must be enabled only for UDP based ports. Hence
1058 // don't pass shared socket for ports which will create TCP sockets. 1002 // don't pass shared socket for ports which will create TCP sockets.
1059 // TODO(mallinath) - Enable shared socket mode for TURN ports. Disabled 1003 // TODO(mallinath) - Enable shared socket mode for TURN ports. Disabled
1060 // due to webrtc bug https://code.google.com/p/webrtc/issues/detail?id=3537 1004 // due to webrtc bug https://code.google.com/p/webrtc/issues/detail?id=3537
1061 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && 1005 if (relay_port->proto == PROTO_UDP) {
1062 relay_port->proto == PROTO_UDP) {
1063 port = TurnPort::Create(session_->network_thread(), 1006 port = TurnPort::Create(session_->network_thread(),
1064 session_->socket_factory(), 1007 session_->socket_factory(),
1065 network_, udp_socket_.get(), 1008 network_, udp_socket_.get(),
1066 session_->username(), session_->password(), 1009 session_->username(), session_->password(),
1067 *relay_port, config.credentials, config.priority, 1010 *relay_port, config.credentials, config.priority,
1068 session_->allocator()->origin()); 1011 session_->allocator()->origin());
1069 turn_ports_.push_back(port); 1012 turn_ports_.push_back(port);
1070 // Listen to the port destroyed signal, to allow AllocationSequence to 1013 // Listen to the port destroyed signal, to allow AllocationSequence to
1071 // remove entrt from it's map. 1014 // remove entrt from it's map.
1072 port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed); 1015 port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 ServerAddresses servers; 1147 ServerAddresses servers;
1205 for (size_t i = 0; i < relays.size(); ++i) { 1148 for (size_t i = 0; i < relays.size(); ++i) {
1206 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1149 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1207 servers.insert(relays[i].ports.front().address); 1150 servers.insert(relays[i].ports.front().address);
1208 } 1151 }
1209 } 1152 }
1210 return servers; 1153 return servers;
1211 } 1154 }
1212 1155
1213 } // namespace cricket 1156 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/turnport_unittest.cc ('k') | webrtc/p2p/client/connectivitychecker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698