You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2004--2011, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "talk/p2p/base/portproxy.h"
  28. namespace cricket {
  29. void PortProxy::set_impl(PortInterface* port) {
  30. impl_ = port;
  31. impl_->SignalUnknownAddress.connect(
  32. this, &PortProxy::OnUnknownAddress);
  33. impl_->SignalDestroyed.connect(this, &PortProxy::OnPortDestroyed);
  34. }
  35. const std::string& PortProxy::Type() const {
  36. ASSERT(impl_ != NULL);
  37. return impl_->Type();
  38. }
  39. talk_base::Network* PortProxy::Network() const {
  40. ASSERT(impl_ != NULL);
  41. return impl_->Network();
  42. }
  43. void PortProxy::SetIceProtocolType(IceProtocolType protocol) {
  44. ASSERT(impl_ != NULL);
  45. impl_->SetIceProtocolType(protocol);
  46. }
  47. IceProtocolType PortProxy::IceProtocol() const {
  48. ASSERT(impl_ != NULL);
  49. return impl_->IceProtocol();
  50. }
  51. // Methods to set/get ICE role and tiebreaker values.
  52. void PortProxy::SetRole(TransportRole role) {
  53. ASSERT(impl_ != NULL);
  54. impl_->SetRole(role);
  55. }
  56. TransportRole PortProxy::Role() const {
  57. ASSERT(impl_ != NULL);
  58. return impl_->Role();
  59. }
  60. void PortProxy::SetTiebreaker(uint64 tiebreaker) {
  61. ASSERT(impl_ != NULL);
  62. impl_->SetTiebreaker(tiebreaker);
  63. }
  64. uint64 PortProxy::Tiebreaker() const {
  65. ASSERT(impl_ != NULL);
  66. return impl_->Tiebreaker();
  67. }
  68. bool PortProxy::SharedSocket() const {
  69. ASSERT(impl_ != NULL);
  70. return impl_->SharedSocket();
  71. }
  72. void PortProxy::PrepareAddress() {
  73. ASSERT(impl_ != NULL);
  74. impl_->PrepareAddress();
  75. }
  76. Connection* PortProxy::CreateConnection(const Candidate& remote_candidate,
  77. CandidateOrigin origin) {
  78. ASSERT(impl_ != NULL);
  79. return impl_->CreateConnection(remote_candidate, origin);
  80. }
  81. int PortProxy::SendTo(const void* data,
  82. size_t size,
  83. const talk_base::SocketAddress& addr,
  84. bool payload) {
  85. ASSERT(impl_ != NULL);
  86. return impl_->SendTo(data, size, addr, payload);
  87. }
  88. int PortProxy::SetOption(talk_base::Socket::Option opt,
  89. int value) {
  90. ASSERT(impl_ != NULL);
  91. return impl_->SetOption(opt, value);
  92. }
  93. int PortProxy::GetOption(talk_base::Socket::Option opt,
  94. int* value) {
  95. ASSERT(impl_ != NULL);
  96. return impl_->GetOption(opt, value);
  97. }
  98. int PortProxy::GetError() {
  99. ASSERT(impl_ != NULL);
  100. return impl_->GetError();
  101. }
  102. const std::vector<Candidate>& PortProxy::Candidates() const {
  103. ASSERT(impl_ != NULL);
  104. return impl_->Candidates();
  105. }
  106. void PortProxy::SendBindingResponse(
  107. StunMessage* request, const talk_base::SocketAddress& addr) {
  108. ASSERT(impl_ != NULL);
  109. impl_->SendBindingResponse(request, addr);
  110. }
  111. Connection* PortProxy::GetConnection(
  112. const talk_base::SocketAddress& remote_addr) {
  113. ASSERT(impl_ != NULL);
  114. return impl_->GetConnection(remote_addr);
  115. }
  116. void PortProxy::SendBindingErrorResponse(
  117. StunMessage* request, const talk_base::SocketAddress& addr,
  118. int error_code, const std::string& reason) {
  119. ASSERT(impl_ != NULL);
  120. impl_->SendBindingErrorResponse(request, addr, error_code, reason);
  121. }
  122. void PortProxy::EnablePortPackets() {
  123. ASSERT(impl_ != NULL);
  124. impl_->EnablePortPackets();
  125. }
  126. std::string PortProxy::ToString() const {
  127. ASSERT(impl_ != NULL);
  128. return impl_->ToString();
  129. }
  130. void PortProxy::OnUnknownAddress(
  131. PortInterface *port,
  132. const talk_base::SocketAddress &addr,
  133. ProtocolType proto,
  134. IceMessage *stun_msg,
  135. const std::string &remote_username,
  136. bool port_muxed) {
  137. ASSERT(port == impl_);
  138. ASSERT(!port_muxed);
  139. SignalUnknownAddress(this, addr, proto, stun_msg, remote_username, true);
  140. }
  141. void PortProxy::OnPortDestroyed(PortInterface* port) {
  142. ASSERT(port == impl_);
  143. // |port| will be destroyed in PortAllocatorSessionMuxer.
  144. SignalDestroyed(this);
  145. }
  146. } // namespace cricket