henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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 | |
| 28 | #include "talk/p2p/base/portproxy.h" |
| 29 | |
| 30 | namespace cricket { |
| 31 | |
| 32 | void PortProxy::set_impl(PortInterface* port) { |
| 33 | impl_ = port; |
| 34 | impl_->SignalUnknownAddress.connect( |
| 35 | this, &PortProxy::OnUnknownAddress); |
| 36 | impl_->SignalDestroyed.connect(this, &PortProxy::OnPortDestroyed); |
| 37 | impl_->SignalRoleConflict.connect(this, &PortProxy::OnRoleConflict); |
| 38 | } |
| 39 | |
| 40 | const std::string& PortProxy::Type() const { |
| 41 | ASSERT(impl_ != NULL); |
| 42 | return impl_->Type(); |
| 43 | } |
| 44 | |
| 45 | talk_base::Network* PortProxy::Network() const { |
| 46 | ASSERT(impl_ != NULL); |
| 47 | return impl_->Network(); |
| 48 | } |
| 49 | |
| 50 | void PortProxy::SetIceProtocolType(IceProtocolType protocol) { |
| 51 | ASSERT(impl_ != NULL); |
| 52 | impl_->SetIceProtocolType(protocol); |
| 53 | } |
| 54 | |
| 55 | IceProtocolType PortProxy::IceProtocol() const { |
| 56 | ASSERT(impl_ != NULL); |
| 57 | return impl_->IceProtocol(); |
| 58 | } |
| 59 | |
| 60 | // Methods to set/get ICE role and tiebreaker values. |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame^] | 61 | void PortProxy::SetIceRole(IceRole role) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | ASSERT(impl_ != NULL); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame^] | 63 | impl_->SetIceRole(role); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | } |
| 65 | |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame^] | 66 | IceRole PortProxy::GetIceRole() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | ASSERT(impl_ != NULL); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame^] | 68 | return impl_->GetIceRole(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 69 | } |
| 70 | |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame^] | 71 | void PortProxy::SetIceTiebreaker(uint64 tiebreaker) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | ASSERT(impl_ != NULL); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame^] | 73 | impl_->SetIceTiebreaker(tiebreaker); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | } |
| 75 | |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame^] | 76 | uint64 PortProxy::IceTiebreaker() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 77 | ASSERT(impl_ != NULL); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame^] | 78 | return impl_->IceTiebreaker(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | bool PortProxy::SharedSocket() const { |
| 82 | ASSERT(impl_ != NULL); |
| 83 | return impl_->SharedSocket(); |
| 84 | } |
| 85 | |
| 86 | void PortProxy::PrepareAddress() { |
| 87 | ASSERT(impl_ != NULL); |
| 88 | impl_->PrepareAddress(); |
| 89 | } |
| 90 | |
| 91 | Connection* PortProxy::CreateConnection(const Candidate& remote_candidate, |
| 92 | CandidateOrigin origin) { |
| 93 | ASSERT(impl_ != NULL); |
| 94 | return impl_->CreateConnection(remote_candidate, origin); |
| 95 | } |
| 96 | |
| 97 | int PortProxy::SendTo(const void* data, |
| 98 | size_t size, |
| 99 | const talk_base::SocketAddress& addr, |
| 100 | bool payload) { |
| 101 | ASSERT(impl_ != NULL); |
| 102 | return impl_->SendTo(data, size, addr, payload); |
| 103 | } |
| 104 | |
| 105 | int PortProxy::SetOption(talk_base::Socket::Option opt, |
| 106 | int value) { |
| 107 | ASSERT(impl_ != NULL); |
| 108 | return impl_->SetOption(opt, value); |
| 109 | } |
| 110 | |
| 111 | int PortProxy::GetOption(talk_base::Socket::Option opt, |
| 112 | int* value) { |
| 113 | ASSERT(impl_ != NULL); |
| 114 | return impl_->GetOption(opt, value); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | int PortProxy::GetError() { |
| 119 | ASSERT(impl_ != NULL); |
| 120 | return impl_->GetError(); |
| 121 | } |
| 122 | |
| 123 | const std::vector<Candidate>& PortProxy::Candidates() const { |
| 124 | ASSERT(impl_ != NULL); |
| 125 | return impl_->Candidates(); |
| 126 | } |
| 127 | |
| 128 | void PortProxy::SendBindingResponse( |
| 129 | StunMessage* request, const talk_base::SocketAddress& addr) { |
| 130 | ASSERT(impl_ != NULL); |
| 131 | impl_->SendBindingResponse(request, addr); |
| 132 | } |
| 133 | |
| 134 | Connection* PortProxy::GetConnection( |
| 135 | const talk_base::SocketAddress& remote_addr) { |
| 136 | ASSERT(impl_ != NULL); |
| 137 | return impl_->GetConnection(remote_addr); |
| 138 | } |
| 139 | |
| 140 | void PortProxy::SendBindingErrorResponse( |
| 141 | StunMessage* request, const talk_base::SocketAddress& addr, |
| 142 | int error_code, const std::string& reason) { |
| 143 | ASSERT(impl_ != NULL); |
| 144 | impl_->SendBindingErrorResponse(request, addr, error_code, reason); |
| 145 | } |
| 146 | |
| 147 | void PortProxy::EnablePortPackets() { |
| 148 | ASSERT(impl_ != NULL); |
| 149 | impl_->EnablePortPackets(); |
| 150 | } |
| 151 | |
| 152 | std::string PortProxy::ToString() const { |
| 153 | ASSERT(impl_ != NULL); |
| 154 | return impl_->ToString(); |
| 155 | } |
| 156 | |
| 157 | void PortProxy::OnUnknownAddress( |
| 158 | PortInterface *port, |
| 159 | const talk_base::SocketAddress &addr, |
| 160 | ProtocolType proto, |
| 161 | IceMessage *stun_msg, |
| 162 | const std::string &remote_username, |
| 163 | bool port_muxed) { |
| 164 | ASSERT(port == impl_); |
| 165 | ASSERT(!port_muxed); |
| 166 | SignalUnknownAddress(this, addr, proto, stun_msg, remote_username, true); |
| 167 | } |
| 168 | |
| 169 | void PortProxy::OnRoleConflict(PortInterface* port) { |
| 170 | ASSERT(port == impl_); |
| 171 | SignalRoleConflict(this); |
| 172 | } |
| 173 | |
| 174 | void PortProxy::OnPortDestroyed(PortInterface* port) { |
| 175 | ASSERT(port == impl_); |
| 176 | // |port| will be destroyed in PortAllocatorSessionMuxer. |
| 177 | SignalDestroyed(this); |
| 178 | } |
| 179 | |
| 180 | } // namespace cricket |