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

Side by Side Diff: webrtc/p2p/base/testturnserver.h

Issue 2141863003: Adding an end-to-end connection time test. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Merge with master. Created 4 years, 3 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/base/fakenetwork.h ('k') | no next file » | 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 2012 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2012 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const std::vector<rtc::SocketAddress>& alternate_server_addresses_; 45 const std::vector<rtc::SocketAddress>& alternate_server_addresses_;
46 std::vector<rtc::SocketAddress>::const_iterator iter_; 46 std::vector<rtc::SocketAddress>::const_iterator iter_;
47 }; 47 };
48 48
49 class TestTurnServer : public TurnAuthInterface { 49 class TestTurnServer : public TurnAuthInterface {
50 public: 50 public:
51 TestTurnServer(rtc::Thread* thread, 51 TestTurnServer(rtc::Thread* thread,
52 const rtc::SocketAddress& int_addr, 52 const rtc::SocketAddress& int_addr,
53 const rtc::SocketAddress& udp_ext_addr, 53 const rtc::SocketAddress& udp_ext_addr,
54 ProtocolType int_protocol = PROTO_UDP) 54 ProtocolType int_protocol = PROTO_UDP)
55 : server_(thread) { 55 : server_(thread), thread_(thread) {
56 AddInternalSocket(int_addr, int_protocol); 56 AddInternalSocket(int_addr, int_protocol);
57 server_.SetExternalSocketFactory(new rtc::BasicPacketSocketFactory(), 57 server_.SetExternalSocketFactory(new rtc::BasicPacketSocketFactory(thread),
58 udp_ext_addr); 58 udp_ext_addr);
59 server_.set_realm(kTestRealm); 59 server_.set_realm(kTestRealm);
60 server_.set_software(kTestSoftware); 60 server_.set_software(kTestSoftware);
61 server_.set_auth_hook(this); 61 server_.set_auth_hook(this);
62 } 62 }
63 63
64 void set_enable_otu_nonce(bool enable) { 64 void set_enable_otu_nonce(bool enable) {
65 server_.set_enable_otu_nonce(enable); 65 server_.set_enable_otu_nonce(enable);
66 } 66 }
67 67
68 TurnServer* server() { return &server_; } 68 TurnServer* server() { return &server_; }
69 69
70 void set_redirect_hook(TurnRedirectInterface* redirect_hook) { 70 void set_redirect_hook(TurnRedirectInterface* redirect_hook) {
71 server_.set_redirect_hook(redirect_hook); 71 server_.set_redirect_hook(redirect_hook);
72 } 72 }
73 73
74 void set_enable_permission_checks(bool enable) { 74 void set_enable_permission_checks(bool enable) {
75 server_.set_enable_permission_checks(enable); 75 server_.set_enable_permission_checks(enable);
76 } 76 }
77 77
78 void AddInternalSocket(const rtc::SocketAddress& int_addr, 78 void AddInternalSocket(const rtc::SocketAddress& int_addr,
79 ProtocolType proto) { 79 ProtocolType proto) {
80 rtc::Thread* thread = rtc::Thread::Current();
81 if (proto == cricket::PROTO_UDP) { 80 if (proto == cricket::PROTO_UDP) {
82 server_.AddInternalSocket(rtc::AsyncUDPSocket::Create( 81 server_.AddInternalSocket(
83 thread->socketserver(), int_addr), proto); 82 rtc::AsyncUDPSocket::Create(thread_->socketserver(), int_addr),
83 proto);
84 } else if (proto == cricket::PROTO_TCP) { 84 } else if (proto == cricket::PROTO_TCP) {
85 // For TCP we need to create a server socket which can listen for incoming 85 // For TCP we need to create a server socket which can listen for incoming
86 // new connections. 86 // new connections.
87 rtc::AsyncSocket* socket = 87 rtc::AsyncSocket* socket =
88 thread->socketserver()->CreateAsyncSocket(SOCK_STREAM); 88 thread_->socketserver()->CreateAsyncSocket(SOCK_STREAM);
89 socket->Bind(int_addr); 89 socket->Bind(int_addr);
90 socket->Listen(5); 90 socket->Listen(5);
91 server_.AddInternalServerSocket(socket, proto); 91 server_.AddInternalServerSocket(socket, proto);
92 } 92 }
93 } 93 }
94 94
95 // Finds the first allocation in the server allocation map with a source 95 // Finds the first allocation in the server allocation map with a source
96 // ip and port matching the socket address provided. 96 // ip and port matching the socket address provided.
97 TurnServerAllocation* FindAllocation(const rtc::SocketAddress& src) { 97 TurnServerAllocation* FindAllocation(const rtc::SocketAddress& src) {
98 const TurnServer::AllocationMap& map = server_.allocations(); 98 const TurnServer::AllocationMap& map = server_.allocations();
99 for (TurnServer::AllocationMap::const_iterator it = map.begin(); 99 for (TurnServer::AllocationMap::const_iterator it = map.begin();
100 it != map.end(); ++it) { 100 it != map.end(); ++it) {
101 if (src == it->first.src()) { 101 if (src == it->first.src()) {
102 return it->second.get(); 102 return it->second.get();
103 } 103 }
104 } 104 }
105 return NULL; 105 return NULL;
106 } 106 }
107 107
108 private: 108 private:
109 // For this test server, succeed if the password is the same as the username. 109 // For this test server, succeed if the password is the same as the username.
110 // Obviously, do not use this in a production environment. 110 // Obviously, do not use this in a production environment.
111 virtual bool GetKey(const std::string& username, const std::string& realm, 111 virtual bool GetKey(const std::string& username, const std::string& realm,
112 std::string* key) { 112 std::string* key) {
113 return ComputeStunCredentialHash(username, realm, username, key); 113 return ComputeStunCredentialHash(username, realm, username, key);
114 } 114 }
115 115
116 TurnServer server_; 116 TurnServer server_;
117 rtc::Thread* thread_;
117 }; 118 };
118 119
119 } // namespace cricket 120 } // namespace cricket
120 121
121 #endif // WEBRTC_P2P_BASE_TESTTURNSERVER_H_ 122 #endif // WEBRTC_P2P_BASE_TESTTURNSERVER_H_
OLDNEW
« no previous file with comments | « webrtc/base/fakenetwork.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698