blob: 2c6119aa5d3fee6b50b19749a9a2d58406601999 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
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
30namespace cricket {
31
32void 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
40const std::string& PortProxy::Type() const {
41 ASSERT(impl_ != NULL);
42 return impl_->Type();
43}
44
45talk_base::Network* PortProxy::Network() const {
46 ASSERT(impl_ != NULL);
47 return impl_->Network();
48}
49
50void PortProxy::SetIceProtocolType(IceProtocolType protocol) {
51 ASSERT(impl_ != NULL);
52 impl_->SetIceProtocolType(protocol);
53}
54
55IceProtocolType 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.orga5506692013-08-12 21:18:15 +000061void PortProxy::SetIceRole(IceRole role) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062 ASSERT(impl_ != NULL);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +000063 impl_->SetIceRole(role);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064}
65
mallinath@webrtc.orga5506692013-08-12 21:18:15 +000066IceRole PortProxy::GetIceRole() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067 ASSERT(impl_ != NULL);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +000068 return impl_->GetIceRole();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069}
70
mallinath@webrtc.orga5506692013-08-12 21:18:15 +000071void PortProxy::SetIceTiebreaker(uint64 tiebreaker) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 ASSERT(impl_ != NULL);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +000073 impl_->SetIceTiebreaker(tiebreaker);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074}
75
mallinath@webrtc.orga5506692013-08-12 21:18:15 +000076uint64 PortProxy::IceTiebreaker() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077 ASSERT(impl_ != NULL);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +000078 return impl_->IceTiebreaker();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079}
80
81bool PortProxy::SharedSocket() const {
82 ASSERT(impl_ != NULL);
83 return impl_->SharedSocket();
84}
85
86void PortProxy::PrepareAddress() {
87 ASSERT(impl_ != NULL);
88 impl_->PrepareAddress();
89}
90
91Connection* PortProxy::CreateConnection(const Candidate& remote_candidate,
92 CandidateOrigin origin) {
93 ASSERT(impl_ != NULL);
94 return impl_->CreateConnection(remote_candidate, origin);
95}
96
97int 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
105int PortProxy::SetOption(talk_base::Socket::Option opt,
106 int value) {
107 ASSERT(impl_ != NULL);
108 return impl_->SetOption(opt, value);
109}
110
111int PortProxy::GetOption(talk_base::Socket::Option opt,
112 int* value) {
113 ASSERT(impl_ != NULL);
114 return impl_->GetOption(opt, value);
115}
116
117
118int PortProxy::GetError() {
119 ASSERT(impl_ != NULL);
120 return impl_->GetError();
121}
122
123const std::vector<Candidate>& PortProxy::Candidates() const {
124 ASSERT(impl_ != NULL);
125 return impl_->Candidates();
126}
127
128void PortProxy::SendBindingResponse(
129 StunMessage* request, const talk_base::SocketAddress& addr) {
130 ASSERT(impl_ != NULL);
131 impl_->SendBindingResponse(request, addr);
132}
133
134Connection* PortProxy::GetConnection(
135 const talk_base::SocketAddress& remote_addr) {
136 ASSERT(impl_ != NULL);
137 return impl_->GetConnection(remote_addr);
138}
139
140void 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
147void PortProxy::EnablePortPackets() {
148 ASSERT(impl_ != NULL);
149 impl_->EnablePortPackets();
150}
151
152std::string PortProxy::ToString() const {
153 ASSERT(impl_ != NULL);
154 return impl_->ToString();
155}
156
157void 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
169void PortProxy::OnRoleConflict(PortInterface* port) {
170 ASSERT(port == impl_);
171 SignalRoleConflict(this);
172}
173
174void PortProxy::OnPortDestroyed(PortInterface* port) {
175 ASSERT(port == impl_);
176 // |port| will be destroyed in PortAllocatorSessionMuxer.
177 SignalDestroyed(this);
178}
179
180} // namespace cricket