OpenSDN source code
xmpp_config.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include "xmpp/xmpp_config.h"
7 
8 #include "base/logging.h"
9 #include <boost/algorithm/string.hpp>
10 
11 using namespace boost::asio::ip;
12 using namespace boost::property_tree;
13 using namespace std;
14 
16  ToAddr(""), FromAddr(""), NodeAddr(""), logUVE(false), auth_enabled(false),
17  path_to_server_cert(""), path_to_server_priv_key(""), path_to_ca_cert(""),
18  tcp_hold_time(XmppChannelConfig::kTcpHoldTime), gr_helper_disable(false),
19  xmpp_hold_time(90), dscp_value(0), isClient_(isClient) {
20 }
21 
23  int res;
24 
25  if (endpoint < rhs.endpoint) return -1;
26  if (endpoint > rhs.endpoint) return 1;
27  res = name.compare(rhs.name);
28  if (res) return res;
29 
30  return 0;
31 }
32 
34  const XmppConfigData::XmppChannelConfigMap &n_current =
35  current_->neighbors();
36  if (future_.get() == NULL) {
37  return;
38  }
39  const XmppConfigData::XmppChannelConfigMap &n_future = future_->neighbors();
40 
41  XmppConfigData::XmppChannelConfigMap::const_iterator icurr =
42  n_current.begin();
43  XmppConfigData::XmppChannelConfigMap::const_iterator inext =
44  n_future.begin();
45 
46  while (icurr != n_current.end() && inext != n_future.end()) {
47  if (icurr->first < inext->first) {
48  obs(DF_DELETE, icurr->second, NULL);
49  ++icurr;
50  } else if (icurr->first > inext->first) {
51  obs(DF_ADD, NULL, inext->second);
52  ++inext;
53  } else {
54  int cmp = icurr->second->CompareTo(*inext->second);
55  if (cmp != 0) {
56  obs(DF_CHANGE, icurr->second, inext->second);
57  }
58  ++icurr;
59  ++inext;
60  }
61  }
62  for (; icurr != n_current.end(); ++icurr) {
63  obs(DF_DELETE, icurr->second, NULL);
64  }
65  for (; inext != n_future.end(); ++inext) {
66  obs(DF_ADD, NULL, inext->second);
67  }
68 }
69 
71  future_.reset(future);
72 }
73 
75  current_.reset(future_.release());
76 }
77 
79  current_.reset();
80  future_.reset();
81 }
82 
84 }
int CompareTo(const XmppChannelConfig &rhs) const
Definition: xmpp_config.cc:22
std::string name
Definition: xmpp_config.h:24
boost::asio::ip::tcp::endpoint endpoint
Definition: xmpp_config.h:25
XmppChannelConfig(bool isClient=false)
Definition: xmpp_config.cc:15
boost::ptr_map< boost::asio::ip::tcp::endpoint, XmppChannelConfig > XmppChannelConfigMap
Definition: xmpp_config.h:52
boost::function< void(DiffType, const XmppChannelConfig *, const XmppChannelConfig *)> PeerDiffObserver
Definition: xmpp_config.h:88
std::unique_ptr< const XmppConfigData > future_
Definition: xmpp_config.h:106
void PeerConfigDiff(PeerDiffObserver obs) const
Definition: xmpp_config.cc:33
void SetFuture(const XmppConfigData *future)
Definition: xmpp_config.cc:70
std::unique_ptr< const XmppConfigData > current_
Definition: xmpp_config.h:105