/
xmpp_config.h
104 lines (80 loc) · 2.52 KB
/
xmpp_config.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef __XMPP_CONFIG_H__
#define __XMPP_CONFIG_H__
#include <boost/asio/ip/tcp.hpp>
#include <boost/function.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/ptr_container/ptr_map.hpp>
#include "base/util.h"
// Internal representation of Peer configuration
class XmppChannelConfig {
public:
explicit XmppChannelConfig(bool isClient = false);
std::string ToAddr;
std::string FromAddr;
std::string NodeAddr; // pubsub node
std::string name;
boost::asio::ip::tcp::endpoint endpoint;
boost::asio::ip::tcp::endpoint local_endpoint;
bool logUVE;
bool auth_enabled;
std::string path_to_server_cert;
std::string path_to_pvt_key;
int tcp_hold_time;
int CompareTo(const XmppChannelConfig &rhs) const;
static int const default_client_port = 5269;
static int const default_server_port = 5222;
static int const kTcpHoldTime = 30; //in secs
bool ClientOnly() const { return isClient_; }
private:
bool isClient_;
};
class XmppConfigData {
public:
typedef boost::ptr_map<boost::asio::ip::tcp::endpoint, XmppChannelConfig>
XmppChannelConfigMap;
XmppConfigData() {
}
void AddXmppChannelConfig(XmppChannelConfig *channel) {
neighbors_.insert(channel->endpoint, channel);
}
XmppChannelConfig &GetXmppChannelConfig(const boost::asio::ip::tcp::endpoint ep) {
return neighbors_[ep];
}
const XmppChannelConfigMap &neighbors() const { return neighbors_; }
void Clear() {
neighbors_.clear();
}
private:
XmppChannelConfigMap neighbors_;
DISALLOW_COPY_AND_ASSIGN(XmppConfigData);
};
class XmppConfigManager {
public:
enum DiffType {
DF_NONE,
DF_ADD,
DF_CHANGE,
DF_DELETE
};
XmppConfigManager();
typedef boost::function<void(DiffType, const XmppChannelConfig *,
const XmppChannelConfig *)> PeerDiffObserver;
// stage 1: build the future internal representation
bool ParseConfig(const std::string &config, XmppConfigData *);
// stage 2: generate a delta
void PeerConfigDiff(PeerDiffObserver obs) const;
// stage 3: commit
void AcceptFuture();
// testing API -- begin --
void SetFuture(const XmppConfigData *future);
// testing API -- end --
void Terminate();
private:
std::auto_ptr<const XmppConfigData> current_;
std::auto_ptr<const XmppConfigData> future_;
DISALLOW_COPY_AND_ASSIGN(XmppConfigManager);
};
#endif