1/* 2 * libjingle 3 * Copyright 2004--2005, 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_TRANSPORTCHANNELPROXY_H_ 29#define TALK_P2P_BASE_TRANSPORTCHANNELPROXY_H_ 30 31#include <string> 32#include <utility> 33#include <vector> 34 35#include "talk/p2p/base/transportchannel.h" 36#include "webrtc/base/messagehandler.h" 37 38namespace rtc { 39class Thread; 40} 41 42namespace cricket { 43 44class TransportChannelImpl; 45 46// Proxies calls between the client and the transport channel implementation. 47// This is needed because clients are allowed to create channels before the 48// network negotiation is complete. Hence, we create a proxy up front, and 49// when negotiation completes, connect the proxy to the implementaiton. 50class TransportChannelProxy : public TransportChannel, 51 public rtc::MessageHandler { 52 public: 53 TransportChannelProxy(const std::string& content_name, 54 const std::string& name, 55 int component); 56 virtual ~TransportChannelProxy(); 57 58 const std::string& name() const { return name_; } 59 TransportChannelImpl* impl() { return impl_; } 60 61 // Sets the implementation to which we will proxy. 62 void SetImplementation(TransportChannelImpl* impl); 63 64 // Implementation of the TransportChannel interface. These simply forward to 65 // the implementation. 66 virtual int SendPacket(const char* data, size_t len, 67 const rtc::PacketOptions& options, 68 int flags); 69 virtual int SetOption(rtc::Socket::Option opt, int value); 70 virtual int GetError(); 71 virtual IceRole GetIceRole() const; 72 virtual bool GetStats(ConnectionInfos* infos); 73 virtual bool IsDtlsActive() const; 74 virtual bool GetSslRole(rtc::SSLRole* role) const; 75 virtual bool SetSslRole(rtc::SSLRole role); 76 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers); 77 virtual bool GetSrtpCipher(std::string* cipher); 78 virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const; 79 virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const; 80 virtual bool ExportKeyingMaterial(const std::string& label, 81 const uint8* context, 82 size_t context_len, 83 bool use_context, 84 uint8* result, 85 size_t result_len); 86 87 private: 88 // Catch signals from the implementation channel. These just forward to the 89 // client (after updating our state to match). 90 void OnReadableState(TransportChannel* channel); 91 void OnWritableState(TransportChannel* channel); 92 void OnReadPacket(TransportChannel* channel, const char* data, size_t size, 93 const rtc::PacketTime& packet_time, int flags); 94 void OnReadyToSend(TransportChannel* channel); 95 void OnRouteChange(TransportChannel* channel, const Candidate& candidate); 96 97 void OnMessage(rtc::Message* message); 98 99 typedef std::pair<rtc::Socket::Option, int> OptionPair; 100 typedef std::vector<OptionPair> OptionList; 101 std::string name_; 102 rtc::Thread* worker_thread_; 103 TransportChannelImpl* impl_; 104 OptionList pending_options_; 105 std::vector<std::string> pending_srtp_ciphers_; 106 107 DISALLOW_EVIL_CONSTRUCTORS(TransportChannelProxy); 108}; 109 110} // namespace cricket 111 112#endif // TALK_P2P_BASE_TRANSPORTCHANNELPROXY_H_ 113