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