3 * Copyright 2004--2005, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
28 #ifndef TALK_P2P_BASE_RAWTRANSPORTCHANNEL_H_
29 #define TALK_P2P_BASE_RAWTRANSPORTCHANNEL_H_
33 #include "talk/base/messagequeue.h"
34 #include "talk/p2p/base/transportchannelimpl.h"
35 #include "talk/p2p/base/rawtransport.h"
36 #include "talk/p2p/base/candidate.h"
38 #if defined(FEATURE_ENABLE_PSTN)
48 class PortAllocatorSession;
53 // Implements a channel that just sends bare packets once we have received the
54 // address of the other side. We pick a single address to send them based on
55 // a simple investigation of NAT type.
56 class RawTransportChannel : public TransportChannelImpl,
57 public talk_base::MessageHandler {
59 RawTransportChannel(const std::string& content_name,
61 RawTransport* transport,
62 talk_base::Thread *worker_thread,
63 PortAllocator *allocator);
64 virtual ~RawTransportChannel();
66 // Implementation of normal channel packet sending.
67 virtual int SendPacket(const char *data, size_t len,
68 talk_base::DiffServCodePoint dscp, int flags);
69 virtual int SetOption(talk_base::Socket::Option opt, int value);
70 virtual int GetError();
72 // Implements TransportChannelImpl.
73 virtual Transport* GetTransport() { return raw_transport_; }
74 virtual void SetIceCredentials(const std::string& ice_ufrag,
75 const std::string& ice_pwd) {}
76 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
77 const std::string& ice_pwd) {}
79 // Creates an allocator session to start figuring out which type of
80 // port we should send to the other client. This will send
81 // SignalAvailableCandidate once we have decided.
82 virtual void Connect();
84 // Resets state back to unconnected.
87 // We don't actually worry about signaling since we can't send new candidates.
88 virtual void OnSignalingReady() {}
90 // Handles a message setting the remote address. We are writable once we
91 // have this since we now know where to send.
92 virtual void OnCandidate(const Candidate& candidate);
94 void OnRemoteAddress(const talk_base::SocketAddress& remote_address);
96 // Below ICE specific virtual methods not implemented.
97 virtual IceRole GetIceRole() const { return ICEROLE_UNKNOWN; }
98 virtual void SetIceRole(IceRole role) {}
99 virtual void SetIceTiebreaker(uint64 tiebreaker) {}
100 virtual void SetIceProtocolType(IceProtocolType type) {}
101 virtual void SetIceUfrag(const std::string& ice_ufrag) {}
102 virtual void SetIcePwd(const std::string& ice_pwd) {}
103 virtual void SetRemoteIceMode(IceMode mode) {}
105 virtual bool GetStats(ConnectionInfos* infos) {
110 virtual bool IsDtlsActive() const { return false; }
112 // Default implementation.
113 virtual bool GetSslRole(talk_base::SSLRole* role) const {
117 virtual bool SetSslRole(talk_base::SSLRole role) {
121 // Set up the ciphers to use for DTLS-SRTP.
122 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers) {
126 // Find out which DTLS-SRTP cipher was negotiated
127 virtual bool GetSrtpCipher(std::string* cipher) {
131 // Returns false because the channel is not DTLS.
132 virtual bool GetLocalIdentity(talk_base::SSLIdentity** identity) const {
136 virtual bool GetRemoteCertificate(talk_base::SSLCertificate** cert) const {
140 // Allows key material to be extracted for external encryption.
141 virtual bool ExportKeyingMaterial(
142 const std::string& label,
143 const uint8* context,
151 virtual bool SetLocalIdentity(talk_base::SSLIdentity* identity) {
155 // Set DTLS Remote fingerprint. Must be after local identity set.
156 virtual bool SetRemoteFingerprint(
157 const std::string& digest_alg,
164 RawTransport* raw_transport_;
165 talk_base::Thread *worker_thread_;
166 PortAllocator* allocator_;
167 PortAllocatorSession* allocator_session_;
168 StunPort* stun_port_;
169 RelayPort* relay_port_;
170 PortInterface* port_;
172 talk_base::SocketAddress remote_address_;
174 // Called when the allocator creates another port.
175 void OnPortReady(PortAllocatorSession* session, PortInterface* port);
177 // Called when one of the ports we are using has determined its address.
178 void OnCandidatesReady(PortAllocatorSession *session,
179 const std::vector<Candidate>& candidates);
181 // Called once we have chosen the port to use for communication with the
182 // other client. This will send its address and prepare the port for use.
183 void SetPort(PortInterface* port);
185 // Called once we have a port and a remote address. This will set mark the
186 // channel as writable and signal the route to the client.
189 // Called when we receive a packet from the other client.
190 void OnReadPacket(PortInterface* port, const char* data, size_t size,
191 const talk_base::SocketAddress& addr);
193 // Handles a message to destroy unused ports.
194 virtual void OnMessage(talk_base::Message *msg);
196 DISALLOW_EVIL_CONSTRUCTORS(RawTransportChannel);
199 } // namespace cricket
201 #endif // defined(FEATURE_ENABLE_PSTN)
202 #endif // TALK_P2P_BASE_RAWTRANSPORTCHANNEL_H_