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

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

Issue 1241943002: Fix an NPE. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Updated the comments. Created 5 years, 5 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/client/basicportallocator.h ('k') | webrtc/p2p/client/portallocator_unittest.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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 const int SHAKE_MAX_DELAY = 90 * 1000; // 90 seconds 51 const int SHAKE_MAX_DELAY = 90 * 1000; // 90 seconds
52 52
53 int ShakeDelay() { 53 int ShakeDelay() {
54 int range = SHAKE_MAX_DELAY - SHAKE_MIN_DELAY + 1; 54 int range = SHAKE_MAX_DELAY - SHAKE_MIN_DELAY + 1;
55 return SHAKE_MIN_DELAY + CreateRandomId() % range; 55 return SHAKE_MIN_DELAY + CreateRandomId() % range;
56 } 56 }
57 57
58 } // namespace 58 } // namespace
59 59
60 namespace cricket { 60 namespace cricket {
61
62 const uint32 DISABLE_ALL_PHASES = 61 const uint32 DISABLE_ALL_PHASES =
63 PORTALLOCATOR_DISABLE_UDP 62 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_TCP |
64 | PORTALLOCATOR_DISABLE_TCP 63 PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY;
65 | PORTALLOCATOR_DISABLE_STUN
66 | PORTALLOCATOR_DISABLE_RELAY;
67
68 // Performs the allocation of ports, in a sequenced (timed) manner, for a given
69 // network and IP address.
70 class AllocationSequence : public rtc::MessageHandler,
71 public sigslot::has_slots<> {
72 public:
73 enum State {
74 kInit, // Initial state.
75 kRunning, // Started allocating ports.
76 kStopped, // Stopped from running.
77 kCompleted, // All ports are allocated.
78
79 // kInit --> kRunning --> {kCompleted|kStopped}
80 };
81
82 AllocationSequence(BasicPortAllocatorSession* session,
83 rtc::Network* network,
84 PortConfiguration* config,
85 uint32 flags);
86 ~AllocationSequence();
87 bool Init();
88 void Clear();
89
90 State state() const { return state_; }
91
92 // Disables the phases for a new sequence that this one already covers for an
93 // equivalent network setup.
94 void DisableEquivalentPhases(rtc::Network* network,
95 PortConfiguration* config, uint32* flags);
96
97 // Starts and stops the sequence. When started, it will continue allocating
98 // new ports on its own timed schedule.
99 void Start();
100 void Stop();
101
102 // MessageHandler
103 void OnMessage(rtc::Message* msg);
104
105 void EnableProtocol(ProtocolType proto);
106 bool ProtocolEnabled(ProtocolType proto) const;
107
108 // Signal from AllocationSequence, when it's done with allocating ports.
109 // This signal is useful, when port allocation fails which doesn't result
110 // in any candidates. Using this signal BasicPortAllocatorSession can send
111 // its candidate discovery conclusion signal. Without this signal,
112 // BasicPortAllocatorSession doesn't have any event to trigger signal. This
113 // can also be achieved by starting timer in BPAS.
114 sigslot::signal1<AllocationSequence*> SignalPortAllocationComplete;
115
116 private:
117 typedef std::vector<ProtocolType> ProtocolList;
118
119 bool IsFlagSet(uint32 flag) {
120 return ((flags_ & flag) != 0);
121 }
122 void CreateUDPPorts();
123 void CreateTCPPorts();
124 void CreateStunPorts();
125 void CreateRelayPorts();
126 void CreateGturnPort(const RelayServerConfig& config);
127 void CreateTurnPort(const RelayServerConfig& config);
128
129 void OnReadPacket(rtc::AsyncPacketSocket* socket,
130 const char* data, size_t size,
131 const rtc::SocketAddress& remote_addr,
132 const rtc::PacketTime& packet_time);
133
134 void OnPortDestroyed(PortInterface* port);
135
136 BasicPortAllocatorSession* session_;
137 rtc::Network* network_;
138 rtc::IPAddress ip_;
139 PortConfiguration* config_;
140 State state_;
141 uint32 flags_;
142 ProtocolList protocols_;
143 rtc::scoped_ptr<rtc::AsyncPacketSocket> udp_socket_;
144 // There will be only one udp port per AllocationSequence.
145 UDPPort* udp_port_;
146 std::vector<TurnPort*> turn_ports_;
147 int phase_;
148 };
149 64
150 // BasicPortAllocator 65 // BasicPortAllocator
151 BasicPortAllocator::BasicPortAllocator( 66 BasicPortAllocator::BasicPortAllocator(
152 rtc::NetworkManager* network_manager, 67 rtc::NetworkManager* network_manager,
153 rtc::PacketSocketFactory* socket_factory) 68 rtc::PacketSocketFactory* socket_factory)
154 : network_manager_(network_manager), 69 : network_manager_(network_manager),
155 socket_factory_(socket_factory), 70 socket_factory_(socket_factory),
156 stun_servers_() { 71 stun_servers_() {
157 ASSERT(socket_factory_ != NULL); 72 ASSERT(socket_factory_ != NULL);
158 Construct(); 73 Construct();
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 void AllocationSequence::CreateTurnPort(const RelayServerConfig& config) { 975 void AllocationSequence::CreateTurnPort(const RelayServerConfig& config) {
1061 PortList::const_iterator relay_port; 976 PortList::const_iterator relay_port;
1062 for (relay_port = config.ports.begin(); 977 for (relay_port = config.ports.begin();
1063 relay_port != config.ports.end(); ++relay_port) { 978 relay_port != config.ports.end(); ++relay_port) {
1064 TurnPort* port = NULL; 979 TurnPort* port = NULL;
1065 // Shared socket mode must be enabled only for UDP based ports. Hence 980 // Shared socket mode must be enabled only for UDP based ports. Hence
1066 // don't pass shared socket for ports which will create TCP sockets. 981 // don't pass shared socket for ports which will create TCP sockets.
1067 // TODO(mallinath) - Enable shared socket mode for TURN ports. Disabled 982 // TODO(mallinath) - Enable shared socket mode for TURN ports. Disabled
1068 // due to webrtc bug https://code.google.com/p/webrtc/issues/detail?id=3537 983 // due to webrtc bug https://code.google.com/p/webrtc/issues/detail?id=3537
1069 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && 984 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) &&
1070 relay_port->proto == PROTO_UDP) { 985 relay_port->proto == PROTO_UDP && udp_socket_) {
1071 port = TurnPort::Create(session_->network_thread(), 986 port = TurnPort::Create(session_->network_thread(),
1072 session_->socket_factory(), 987 session_->socket_factory(),
1073 network_, udp_socket_.get(), 988 network_, udp_socket_.get(),
1074 session_->username(), session_->password(), 989 session_->username(), session_->password(),
1075 *relay_port, config.credentials, config.priority, 990 *relay_port, config.credentials, config.priority,
1076 session_->allocator()->origin()); 991 session_->allocator()->origin());
1077 turn_ports_.push_back(port); 992 turn_ports_.push_back(port);
1078 // Listen to the port destroyed signal, to allow AllocationSequence to 993 // Listen to the port destroyed signal, to allow AllocationSequence to
1079 // remove entrt from it's map. 994 // remove entrt from it's map.
1080 port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed); 995 port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 ServerAddresses servers; 1120 ServerAddresses servers;
1206 for (size_t i = 0; i < relays.size(); ++i) { 1121 for (size_t i = 0; i < relays.size(); ++i) {
1207 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1122 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1208 servers.insert(relays[i].ports.front().address); 1123 servers.insert(relays[i].ports.front().address);
1209 } 1124 }
1210 } 1125 }
1211 return servers; 1126 return servers;
1212 } 1127 }
1213 1128
1214 } // namespace cricket 1129 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/client/basicportallocator.h ('k') | webrtc/p2p/client/portallocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698