~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/p2p/base/stunport.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_STUNPORT_H_
 
29
#define TALK_P2P_BASE_STUNPORT_H_
 
30
 
 
31
#include <string>
 
32
 
 
33
#include "talk/base/asyncpacketsocket.h"
 
34
#include "talk/p2p/base/udpport.h"
 
35
#include "talk/p2p/base/stunrequest.h"
 
36
 
 
37
namespace talk_base {
 
38
class AsyncResolver;
 
39
class SignalThread;
 
40
}
 
41
 
 
42
namespace cricket {
 
43
 
 
44
extern const char STUN_PORT_TYPE[];
 
45
 
 
46
// Communicates using the address on the outside of a NAT.
 
47
class StunPort : public Port {
 
48
 public:
 
49
  static StunPort* Create(talk_base::Thread* thread,
 
50
                          talk_base::PacketSocketFactory* factory,
 
51
                          talk_base::Network* network,
 
52
                          const talk_base::IPAddress& ip,
 
53
                          int min_port, int max_port,
 
54
                          const talk_base::SocketAddress& server_addr) {
 
55
    StunPort* port = new StunPort(thread, factory, network,
 
56
                                  ip, min_port, max_port, server_addr);
 
57
    if (!port->Init()) {
 
58
      delete port;
 
59
      port = NULL;
 
60
    }
 
61
    return port;
 
62
  }
 
63
  virtual ~StunPort();
 
64
 
 
65
  talk_base::SocketAddress GetLocalAddress() const {
 
66
    return socket_->GetLocalAddress();
 
67
  }
 
68
 
 
69
  const talk_base::SocketAddress& server_addr() const { return server_addr_; }
 
70
  void set_server_addr(const talk_base::SocketAddress& addr) {
 
71
    server_addr_ = addr;
 
72
  }
 
73
 
 
74
  const talk_base::SocketAddress& server_addr2() const { return server_addr2_; }
 
75
  void set_server_addr2(const talk_base::SocketAddress& addr) {
 
76
    server_addr2_ = addr;
 
77
  }
 
78
 
 
79
  virtual void PrepareAddress();
 
80
 
 
81
  // This will contact the secondary server and signal another candidate
 
82
  // address for this port (which may be the same as the first address).
 
83
  void PrepareSecondaryAddress();
 
84
 
 
85
  virtual Connection* CreateConnection(const Candidate& address,
 
86
                                       CandidateOrigin origin);
 
87
  virtual int SetOption(talk_base::Socket::Option opt, int value);
 
88
  virtual int GetError();
 
89
 
 
90
 protected:
 
91
  StunPort(talk_base::Thread* thread, talk_base::PacketSocketFactory* factory,
 
92
           talk_base::Network* network, const talk_base::IPAddress& ip,
 
93
           int min_port, int max_port,
 
94
           const talk_base::SocketAddress& server_addr);
 
95
  bool Init();
 
96
 
 
97
  virtual int SendTo(const void* data, size_t size,
 
98
                     const talk_base::SocketAddress& addr, bool payload);
 
99
 
 
100
  void OnReadPacket(talk_base::AsyncPacketSocket* socket,
 
101
                    const char* data, size_t size,
 
102
                    const talk_base::SocketAddress& remote_addr);
 
103
 
 
104
 private:
 
105
  // DNS resolution of the STUN server.
 
106
  void ResolveStunAddress();
 
107
  void OnResolveResult(talk_base::SignalThread* thread);
 
108
  // Sends STUN requests to the server.
 
109
  void OnSendPacket(const void* data, size_t size, StunRequest* req);
 
110
 
 
111
  talk_base::SocketAddress server_addr_;
 
112
  talk_base::SocketAddress server_addr2_;
 
113
  StunRequestManager requests_;
 
114
  talk_base::AsyncPacketSocket* socket_;
 
115
  int error_;
 
116
  talk_base::AsyncResolver* resolver_;
 
117
 
 
118
  friend class StunPortBindingRequest;
 
119
};
 
120
 
 
121
}  // namespace cricket
 
122
 
 
123
#endif  // TALK_P2P_BASE_STUNPORT_H_