Line data Source code
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 : 15 365 : XmppChannelConfig::XmppChannelConfig(bool isClient) : 16 365 : ToAddr(""), FromAddr(""), NodeAddr(""), logUVE(false), auth_enabled(false), 17 365 : path_to_server_cert(""), path_to_server_priv_key(""), path_to_ca_cert(""), 18 365 : tcp_hold_time(XmppChannelConfig::kTcpHoldTime), gr_helper_disable(false), 19 730 : xmpp_hold_time(90), dscp_value(0), isClient_(isClient) { 20 365 : } 21 : 22 0 : int XmppChannelConfig::CompareTo(const XmppChannelConfig &rhs) const { 23 : int res; 24 : 25 0 : if (endpoint < rhs.endpoint) return -1; 26 0 : if (endpoint > rhs.endpoint) return 1; 27 0 : res = name.compare(rhs.name); 28 0 : if (res) return res; 29 : 30 0 : return 0; 31 : } 32 : 33 102 : void XmppConfigManager::PeerConfigDiff(PeerDiffObserver obs) const { 34 : const XmppConfigData::XmppChannelConfigMap &n_current = 35 102 : current_->neighbors(); 36 102 : if (future_.get() == NULL) { 37 0 : return; 38 : } 39 102 : const XmppConfigData::XmppChannelConfigMap &n_future = future_->neighbors(); 40 : 41 : XmppConfigData::XmppChannelConfigMap::const_iterator icurr = 42 102 : n_current.begin(); 43 : XmppConfigData::XmppChannelConfigMap::const_iterator inext = 44 102 : n_future.begin(); 45 : 46 102 : while (icurr != n_current.end() && inext != n_future.end()) { 47 0 : if (icurr->first < inext->first) { 48 0 : obs(DF_DELETE, icurr->second, NULL); 49 0 : ++icurr; 50 0 : } else if (icurr->first > inext->first) { 51 0 : obs(DF_ADD, NULL, inext->second); 52 0 : ++inext; 53 : } else { 54 0 : int cmp = icurr->second->CompareTo(*inext->second); 55 0 : if (cmp != 0) { 56 0 : obs(DF_CHANGE, icurr->second, inext->second); 57 : } 58 0 : ++icurr; 59 0 : ++inext; 60 : } 61 : } 62 111 : for (; icurr != n_current.end(); ++icurr) { 63 9 : obs(DF_DELETE, icurr->second, NULL); 64 : } 65 195 : for (; inext != n_future.end(); ++inext) { 66 93 : obs(DF_ADD, NULL, inext->second); 67 : } 68 : } 69 : 70 102 : void XmppConfigManager::SetFuture(const XmppConfigData *future) { 71 102 : future_.reset(future); 72 102 : } 73 : 74 102 : void XmppConfigManager::AcceptFuture() { 75 102 : current_.reset(future_.release()); 76 102 : } 77 : 78 0 : void XmppConfigManager::Terminate() { 79 0 : current_.reset(); 80 0 : future_.reset(); 81 0 : } 82 : 83 138 : XmppConfigManager::XmppConfigManager() : current_(new XmppConfigData()) { 84 138 : }