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_TRANSPORTCHANNEL_H_
29 #define TALK_P2P_BASE_TRANSPORTCHANNEL_H_
34 #include "talk/p2p/base/candidate.h"
35 #include "talk/p2p/base/transport.h"
36 #include "talk/p2p/base/transportdescription.h"
37 #include "webrtc/base/asyncpacketsocket.h"
38 #include "webrtc/base/basictypes.h"
39 #include "webrtc/base/dscp.h"
40 #include "webrtc/base/sigslot.h"
41 #include "webrtc/base/socket.h"
42 #include "webrtc/base/sslidentity.h"
43 #include "webrtc/base/sslstreamadapter.h"
49 // Flags for SendPacket/SignalReadPacket.
51 PF_NORMAL = 0x00, // A normal packet.
52 PF_SRTP_BYPASS = 0x01, // An encrypted SRTP packet; bypass any additional
53 // crypto provided by the transport (e.g. DTLS)
56 // A TransportChannel represents one logical stream of packets that are sent
57 // between the two sides of a session.
58 class TransportChannel : public sigslot::has_slots<> {
60 explicit TransportChannel(const std::string& content_name, int component)
61 : content_name_(content_name),
62 component_(component),
63 readable_(false), writable_(false) {}
64 virtual ~TransportChannel() {}
66 // TODO(mallinath) - Remove this API, as it's no longer useful.
67 // Returns the session id of this channel.
68 virtual const std::string SessionId() const { return std::string(); }
70 const std::string& content_name() const { return content_name_; }
71 int component() const { return component_; }
73 // Returns the readable and states of this channel. Each time one of these
74 // states changes, a signal is raised. These states are aggregated by the
76 bool readable() const { return readable_; }
77 bool writable() const { return writable_; }
78 sigslot::signal1<TransportChannel*> SignalReadableState;
79 sigslot::signal1<TransportChannel*> SignalWritableState;
80 // Emitted when the TransportChannel's ability to send has changed.
81 sigslot::signal1<TransportChannel*> SignalReadyToSend;
83 // Attempts to send the given packet. The return value is < 0 on failure.
84 // TODO: Remove the default argument once channel code is updated.
85 virtual int SendPacket(const char* data, size_t len,
86 const rtc::PacketOptions& options,
89 // Sets a socket option on this channel. Note that not all options are
90 // supported by all transport types.
91 virtual int SetOption(rtc::Socket::Option opt, int value) = 0;
93 // Returns the most recent error that occurred on this channel.
94 virtual int GetError() = 0;
96 // Returns the current stats for this connection.
97 virtual bool GetStats(ConnectionInfos* infos) = 0;
100 virtual bool IsDtlsActive() const = 0;
102 // Default implementation.
103 virtual bool GetSslRole(rtc::SSLRole* role) const = 0;
105 // Sets up the ciphers to use for DTLS-SRTP.
106 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers) = 0;
108 // Finds out which DTLS-SRTP cipher was negotiated
109 virtual bool GetSrtpCipher(std::string* cipher) = 0;
111 // Gets a copy of the local SSL identity, owned by the caller.
112 virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const = 0;
114 // Gets a copy of the remote side's SSL certificate, owned by the caller.
115 virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const = 0;
117 // Allows key material to be extracted for external encryption.
118 virtual bool ExportKeyingMaterial(const std::string& label,
119 const uint8* context,
123 size_t result_len) = 0;
125 // Signalled each time a packet is received on this channel.
126 sigslot::signal5<TransportChannel*, const char*,
127 size_t, const rtc::PacketTime&, int> SignalReadPacket;
129 // This signal occurs when there is a change in the way that packets are
130 // being routed, i.e. to a different remote location. The candidate
131 // indicates where and how we are currently sending media.
132 sigslot::signal2<TransportChannel*, const Candidate&> SignalRouteChange;
134 // Invoked when the channel is being destroyed.
135 sigslot::signal1<TransportChannel*> SignalDestroyed;
137 // Debugging description of this transport channel.
138 std::string ToString() const;
141 // Sets the readable state, signaling if necessary.
142 void set_readable(bool readable);
144 // Sets the writable state, signaling if necessary.
145 void set_writable(bool writable);
149 // Used mostly for debugging.
150 std::string content_name_;
155 DISALLOW_EVIL_CONSTRUCTORS(TransportChannel);
158 } // namespace cricket
160 #endif // TALK_P2P_BASE_TRANSPORTCHANNEL_H_