summaryrefslogtreecommitdiff
path: root/Plugins/jingle/libjingle/talk/p2p/client/httpportallocator.h
blob: 96f3e722fdb4853e303d9c83841113ef2653f5bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef _HTTPPORTALLOCATOR_H_
#define _HTTPPORTALLOCATOR_H_

#include "talk/p2p/client/basicportallocator.h"

namespace talk_base {
  class SignalThread;
}

namespace cricket {

class HttpPortAllocator : public BasicPortAllocator {
public:
  HttpPortAllocator(talk_base::NetworkManager* network_manager, const std::string &user_agent);
  virtual ~HttpPortAllocator();

  virtual PortAllocatorSession *CreateSession(const std::string &name,
					      const std::string &session_type);
  void SetStunHosts(const std::vector<talk_base::SocketAddress> &hosts) {stun_hosts_ = hosts;}
  void SetRelayHosts(const std::vector<std::string> &hosts) {relay_hosts_ = hosts;}
  void SetRelayToken(const std::string &relay) {relay_token_ = relay;}
  std::string relay_token() const { return relay_token_; }
private:
  std::vector<talk_base::SocketAddress> stun_hosts_;
  std::vector<std::string> relay_hosts_;
  std::string relay_token_;
  std::string agent_;
};

class RequestData;

class HttpPortAllocatorSession : public BasicPortAllocatorSession {
 public:
  HttpPortAllocatorSession(HttpPortAllocator *allocator,
                           const std::string &name,
			   const std::string &session_type,
			   const std::vector<talk_base::SocketAddress> &stun_hosts,
			   const std::vector<std::string> &relay_hosts,
			   const std::string &relay,
			   const std::string &agent);
  ~HttpPortAllocatorSession() {};

protected:
  virtual void GetPortConfigurations();

private:
  std::vector<std::string> relay_hosts_;
  std::vector<talk_base::SocketAddress> stun_hosts_;
  std::string relay_token_;
  std::string agent_;

  void OnRequestDone(talk_base::SignalThread* request);
  HttpPortAllocator* http_allocator() {
    return static_cast<HttpPortAllocator*>(allocator());
  }
  int attempts_;
};

} // namespace cricket

#endif // _XMPPPORTALLOCATOR_H_