2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_
12 #define WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_
16 #include "webrtc/p2p/base/candidate.h"
17 #include "webrtc/p2p/base/rawtransport.h"
18 #include "webrtc/p2p/base/transportchannelimpl.h"
19 #include "webrtc/base/messagequeue.h"
21 #if defined(FEATURE_ENABLE_PSTN)
31 class PortAllocatorSession;
36 // Implements a channel that just sends bare packets once we have received the
37 // address of the other side. We pick a single address to send them based on
38 // a simple investigation of NAT type.
39 class RawTransportChannel : public TransportChannelImpl,
40 public rtc::MessageHandler {
42 RawTransportChannel(const std::string& content_name,
44 RawTransport* transport,
45 rtc::Thread *worker_thread,
46 PortAllocator *allocator);
47 virtual ~RawTransportChannel();
49 // Implementation of normal channel packet sending.
50 virtual int SendPacket(const char *data, size_t len,
51 const rtc::PacketOptions& options, int flags);
52 virtual int SetOption(rtc::Socket::Option opt, int value);
53 virtual int GetError();
55 // Implements TransportChannelImpl.
56 virtual Transport* GetTransport() { return raw_transport_; }
57 virtual void SetIceCredentials(const std::string& ice_ufrag,
58 const std::string& ice_pwd) {}
59 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
60 const std::string& ice_pwd) {}
62 // Creates an allocator session to start figuring out which type of
63 // port we should send to the other client. This will send
64 // SignalAvailableCandidate once we have decided.
65 virtual void Connect();
67 // Resets state back to unconnected.
70 // We don't actually worry about signaling since we can't send new candidates.
71 virtual void OnSignalingReady() {}
73 // Handles a message setting the remote address. We are writable once we
74 // have this since we now know where to send.
75 virtual void OnCandidate(const Candidate& candidate);
77 void OnRemoteAddress(const rtc::SocketAddress& remote_address);
79 // Below ICE specific virtual methods not implemented.
80 virtual IceRole GetIceRole() const { return ICEROLE_UNKNOWN; }
81 virtual void SetIceRole(IceRole role) {}
82 virtual void SetIceTiebreaker(uint64 tiebreaker) {}
84 virtual bool GetIceProtocolType(IceProtocolType* type) const { return false; }
85 virtual void SetIceProtocolType(IceProtocolType type) {}
87 virtual void SetIceUfrag(const std::string& ice_ufrag) {}
88 virtual void SetIcePwd(const std::string& ice_pwd) {}
89 virtual void SetRemoteIceMode(IceMode mode) {}
90 virtual size_t GetConnectionCount() const { return 1; }
92 virtual bool GetStats(ConnectionInfos* infos) {
97 virtual bool IsDtlsActive() const { return false; }
99 // Default implementation.
100 virtual bool GetSslRole(rtc::SSLRole* role) const {
104 virtual bool SetSslRole(rtc::SSLRole role) {
108 // Set up the ciphers to use for DTLS-SRTP.
109 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers) {
113 // Find out which DTLS-SRTP cipher was negotiated
114 virtual bool GetSrtpCipher(std::string* cipher) {
118 // Returns false because the channel is not DTLS.
119 virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const {
123 virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const {
127 // Allows key material to be extracted for external encryption.
128 virtual bool ExportKeyingMaterial(
129 const std::string& label,
130 const uint8* context,
138 virtual bool SetLocalIdentity(rtc::SSLIdentity* identity) {
142 // Set DTLS Remote fingerprint. Must be after local identity set.
143 virtual bool SetRemoteFingerprint(
144 const std::string& digest_alg,
151 RawTransport* raw_transport_;
152 rtc::Thread *worker_thread_;
153 PortAllocator* allocator_;
154 PortAllocatorSession* allocator_session_;
155 StunPort* stun_port_;
156 RelayPort* relay_port_;
157 PortInterface* port_;
159 rtc::SocketAddress remote_address_;
161 // Called when the allocator creates another port.
162 void OnPortReady(PortAllocatorSession* session, PortInterface* port);
164 // Called when one of the ports we are using has determined its address.
165 void OnCandidatesReady(PortAllocatorSession *session,
166 const std::vector<Candidate>& candidates);
168 // Called once we have chosen the port to use for communication with the
169 // other client. This will send its address and prepare the port for use.
170 void SetPort(PortInterface* port);
172 // Called once we have a port and a remote address. This will set mark the
173 // channel as writable and signal the route to the client.
176 // Called when we receive a packet from the other client.
177 void OnReadPacket(PortInterface* port, const char* data, size_t size,
178 const rtc::SocketAddress& addr);
180 // Handles a message to destroy unused ports.
181 virtual void OnMessage(rtc::Message *msg);
183 DISALLOW_EVIL_CONSTRUCTORS(RawTransportChannel);
186 } // namespace cricket
188 #endif // defined(FEATURE_ENABLE_PSTN)
189 #endif // WEBRTC_P2P_BASE_RAWTRANSPORTCHANNEL_H_