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)
51
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 &name,
60
const std::string &content_type,
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
virtual int SetOption(talk_base::Socket::Option opt, int value);
69
virtual int GetError();
71
// Returns the raw transport that created this channel.
72
virtual Transport* GetTransport() { return raw_transport_; }
74
// Creates an allocator session to start figuring out which type of
75
// port we should send to the other client. This will send
76
// SignalAvailableCandidate once we have decided.
77
virtual void Connect();
79
// Resets state back to unconnected.
82
// We don't actually worry about signaling since we can't send new candidates.
83
virtual void OnSignalingReady() {}
85
// Handles a message setting the remote address. We are writable once we
86
// have this since we now know where to send.
87
virtual void OnCandidate(const Candidate& candidate);
89
void OnRemoteAddress(const talk_base::SocketAddress& remote_address);
93
RawTransport* raw_transport_;
94
talk_base::Thread *worker_thread_;
95
PortAllocator* allocator_;
96
PortAllocatorSession* allocator_session_;
98
RelayPort* relay_port_;
101
talk_base::SocketAddress remote_address_;
103
// Called when the allocator creates another port.
104
void OnPortReady(PortAllocatorSession* session, Port* port);
106
// Called when one of the ports we are using has determined its address.
107
void OnCandidatesReady(PortAllocatorSession *session,
108
const std::vector<Candidate>& candidates);
110
// Called once we have chosen the port to use for communication with the
111
// other client. This will send its address and prepare the port for use.
112
void SetPort(Port* port);
114
// Called once we have a port and a remote address. This will set mark the
115
// channel as writable and signal the route to the client.
118
// Called when we receive a packet from the other client.
119
void OnReadPacket(Port* port, const char* data, size_t size,
120
const talk_base::SocketAddress& addr);
122
// Handles a message to destroy unused ports.
123
virtual void OnMessage(talk_base::Message *msg);
125
DISALLOW_EVIL_CONSTRUCTORS(RawTransportChannel);
128
} // namespace cricket
130
#endif // defined(FEATURE_ENABLE_PSTN)
131
#endif // TALK_P2P_BASE_RAWTRANSPORTCHANNEL_H_