| OLD | NEW |
| 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 19 matching lines...) Expand all Loading... |
| 30 virtual ~NATInternalSocketFactory() {} | 30 virtual ~NATInternalSocketFactory() {} |
| 31 virtual AsyncSocket* CreateInternalSocket(int family, int type, | 31 virtual AsyncSocket* CreateInternalSocket(int family, int type, |
| 32 const SocketAddress& local_addr, SocketAddress* nat_addr) = 0; | 32 const SocketAddress& local_addr, SocketAddress* nat_addr) = 0; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 // Creates sockets that will send all traffic through a NAT, using an existing | 35 // Creates sockets that will send all traffic through a NAT, using an existing |
| 36 // NATServer instance running at nat_addr. The actual data is sent using sockets | 36 // NATServer instance running at nat_addr. The actual data is sent using sockets |
| 37 // from a socket factory, given to the constructor. | 37 // from a socket factory, given to the constructor. |
| 38 class NATSocketFactory : public SocketFactory, public NATInternalSocketFactory { | 38 class NATSocketFactory : public SocketFactory, public NATInternalSocketFactory { |
| 39 public: | 39 public: |
| 40 NATSocketFactory(SocketFactory* factory, const SocketAddress& nat_addr); | 40 NATSocketFactory(SocketFactory* factory, const SocketAddress& nat_udp_addr, |
| 41 const SocketAddress& nat_tcp_addr); |
| 41 | 42 |
| 42 // SocketFactory implementation | 43 // SocketFactory implementation |
| 43 Socket* CreateSocket(int type) override; | 44 Socket* CreateSocket(int type) override; |
| 44 Socket* CreateSocket(int family, int type) override; | 45 Socket* CreateSocket(int family, int type) override; |
| 45 AsyncSocket* CreateAsyncSocket(int type) override; | 46 AsyncSocket* CreateAsyncSocket(int type) override; |
| 46 AsyncSocket* CreateAsyncSocket(int family, int type) override; | 47 AsyncSocket* CreateAsyncSocket(int family, int type) override; |
| 47 | 48 |
| 48 // NATInternalSocketFactory implementation | 49 // NATInternalSocketFactory implementation |
| 49 AsyncSocket* CreateInternalSocket(int family, | 50 AsyncSocket* CreateInternalSocket(int family, |
| 50 int type, | 51 int type, |
| 51 const SocketAddress& local_addr, | 52 const SocketAddress& local_addr, |
| 52 SocketAddress* nat_addr) override; | 53 SocketAddress* nat_addr) override; |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 SocketFactory* factory_; | 56 SocketFactory* factory_; |
| 56 SocketAddress nat_addr_; | 57 SocketAddress nat_udp_addr_; |
| 58 SocketAddress nat_tcp_addr_; |
| 57 DISALLOW_COPY_AND_ASSIGN(NATSocketFactory); | 59 DISALLOW_COPY_AND_ASSIGN(NATSocketFactory); |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 // Creates sockets that will send traffic through a NAT depending on what | 62 // Creates sockets that will send traffic through a NAT depending on what |
| 61 // address they bind to. This can be used to simulate a client on a NAT sending | 63 // address they bind to. This can be used to simulate a client on a NAT sending |
| 62 // to a client that is not behind a NAT. | 64 // to a client that is not behind a NAT. |
| 63 // Note that the internal addresses of clients must be unique. This is because | 65 // Note that the internal addresses of clients must be unique. This is because |
| 64 // there is only one socketserver per thread, and the Bind() address is used to | 66 // there is only one socketserver per thread, and the Bind() address is used to |
| 65 // figure out which NAT (if any) the socket should talk to. | 67 // figure out which NAT (if any) the socket should talk to. |
| 66 // | 68 // |
| (...skipping 20 matching lines...) Expand all Loading... |
| 87 | 89 |
| 88 // a specific NAT | 90 // a specific NAT |
| 89 class Translator { | 91 class Translator { |
| 90 public: | 92 public: |
| 91 Translator(NATSocketServer* server, NATType type, | 93 Translator(NATSocketServer* server, NATType type, |
| 92 const SocketAddress& int_addr, SocketFactory* ext_factory, | 94 const SocketAddress& int_addr, SocketFactory* ext_factory, |
| 93 const SocketAddress& ext_addr); | 95 const SocketAddress& ext_addr); |
| 94 ~Translator(); | 96 ~Translator(); |
| 95 | 97 |
| 96 SocketFactory* internal_factory() { return internal_factory_.get(); } | 98 SocketFactory* internal_factory() { return internal_factory_.get(); } |
| 97 SocketAddress internal_address() const { | 99 SocketAddress internal_udp_address() const { |
| 98 return nat_server_->internal_address(); | 100 return nat_server_->internal_udp_address(); |
| 99 } | 101 } |
| 100 SocketAddress internal_tcp_address() const { | 102 SocketAddress internal_tcp_address() const { |
| 101 return SocketAddress(); // nat_server_->internal_tcp_address(); | 103 return SocketAddress(); // nat_server_->internal_tcp_address(); |
| 102 } | 104 } |
| 103 | 105 |
| 104 Translator* GetTranslator(const SocketAddress& ext_ip); | 106 Translator* GetTranslator(const SocketAddress& ext_ip); |
| 105 Translator* AddTranslator(const SocketAddress& ext_ip, | 107 Translator* AddTranslator(const SocketAddress& ext_ip, |
| 106 const SocketAddress& int_ip, NATType type); | 108 const SocketAddress& int_ip, NATType type); |
| 107 void RemoveTranslator(const SocketAddress& ext_ip); | 109 void RemoveTranslator(const SocketAddress& ext_ip); |
| 108 | 110 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 }; | 157 }; |
| 156 | 158 |
| 157 // Free-standing NAT helper functions. | 159 // Free-standing NAT helper functions. |
| 158 size_t PackAddressForNAT(char* buf, size_t buf_size, | 160 size_t PackAddressForNAT(char* buf, size_t buf_size, |
| 159 const SocketAddress& remote_addr); | 161 const SocketAddress& remote_addr); |
| 160 size_t UnpackAddressFromNAT(const char* buf, size_t buf_size, | 162 size_t UnpackAddressFromNAT(const char* buf, size_t buf_size, |
| 161 SocketAddress* remote_addr); | 163 SocketAddress* remote_addr); |
| 162 } // namespace rtc | 164 } // namespace rtc |
| 163 | 165 |
| 164 #endif // WEBRTC_BASE_NATSOCKETFACTORY_H_ | 166 #endif // WEBRTC_BASE_NATSOCKETFACTORY_H_ |
| OLD | NEW |