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#ifndef TALK_P2P_BASE_PORTPROXY_H_ 29#define TALK_P2P_BASE_PORTPROXY_H_ 30 31#include "talk/base/sigslot.h" 32#include "talk/p2p/base/portinterface.h" 33 34namespace talk_base { 35class Network; 36} 37 38namespace cricket { 39 40class PortProxy : public PortInterface, public sigslot::has_slots<> { 41 public: 42 PortProxy() {} 43 virtual ~PortProxy() {} 44 45 PortInterface* impl() { return impl_; } 46 void set_impl(PortInterface* port); 47 48 virtual const std::string& Type() const; 49 virtual talk_base::Network* Network() const; 50 51 virtual void SetIceProtocolType(IceProtocolType protocol); 52 virtual IceProtocolType IceProtocol() const; 53 54 // Methods to set/get ICE role and tiebreaker values. 55 virtual void SetIceRole(IceRole role); 56 virtual IceRole GetIceRole() const; 57 58 virtual void SetIceTiebreaker(uint64 tiebreaker); 59 virtual uint64 IceTiebreaker() const; 60 61 virtual bool SharedSocket() const; 62 63 // Forwards call to the actual Port. 64 virtual void PrepareAddress(); 65 virtual Connection* CreateConnection(const Candidate& remote_candidate, 66 CandidateOrigin origin); 67 virtual Connection* GetConnection( 68 const talk_base::SocketAddress& remote_addr); 69 70 virtual int SendTo(const void* data, size_t size, 71 const talk_base::SocketAddress& addr, bool payload); 72 virtual int SetOption(talk_base::Socket::Option opt, int value); 73 virtual int GetOption(talk_base::Socket::Option opt, int* value); 74 virtual int GetError(); 75 76 virtual const std::vector<Candidate>& Candidates() const; 77 78 virtual void SendBindingResponse(StunMessage* request, 79 const talk_base::SocketAddress& addr); 80 virtual void SendBindingErrorResponse( 81 StunMessage* request, const talk_base::SocketAddress& addr, 82 int error_code, const std::string& reason); 83 84 virtual void EnablePortPackets(); 85 virtual std::string ToString() const; 86 87 private: 88 void OnUnknownAddress(PortInterface *port, 89 const talk_base::SocketAddress &addr, 90 ProtocolType proto, 91 IceMessage *stun_msg, 92 const std::string &remote_username, 93 bool port_muxed); 94 void OnRoleConflict(PortInterface* port); 95 void OnPortDestroyed(PortInterface* port); 96 97 PortInterface* impl_; 98}; 99 100} // namespace cricket 101 102#endif // TALK_P2P_BASE_PORTPROXY_H_ 103