Changeset 2452 for source/ariba/AribaModule.cpp
- Timestamp:
- Feb 18, 2009, 11:39:30 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/AribaModule.cpp
r2434 r2452 45 45 // ariba includes 46 46 #include "ariba/utility/misc/Helper.h" 47 #include "ariba/utility/misc/StringFormat.h" 47 48 48 49 // hack includes … … 53 54 using namespace ariba::utility::Helper; 54 55 using ariba::interface::UnderlayAbstraction; 56 using ariba::communication::EndpointDescriptor; 55 57 56 58 namespace ariba { 59 60 AribaModule::BootstrapNode::~BootstrapNode() { 61 if (desc!=NULL) delete desc; 62 } 57 63 58 64 AribaModule::AribaModule() { … … 69 75 } 70 76 71 72 77 string AribaModule::getBootstrapHints(const Name& spoVNetName) const { 73 78 std::ostringstream o; 79 BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) { 80 o << info.spovnetName.toString() << "{"; 81 int i=0; 82 BOOST_FOREACH( const BootstrapNode& node, info.nodes ) { 83 if (i!=0) o << ","; 84 if( node.desc != NULL ) o << node.desc->toString(); 85 i++; 86 } 87 } 88 return o.str(); 74 89 } 75 90 76 91 void AribaModule::addBootstrapHints(string boot_info) { 77 string str = boot_info; 78 static ::boost::regex boot_expr("<([^>:]+)[:]?([0-9]+)?>([^<]+)(.*)"); 79 ::boost::smatch what; 80 while (::boost::regex_match(str, what, boot_expr)) { 81 std::cout << what[1].str() << ":" << what[2].str() << "=" << what[3] 82 << std::endl; 83 str = what[4].str(); 84 } 85 } 86 87 void AribaModule::addBootstrapNode(const Name& spovnet, const Name& node, 92 using namespace boost::xpressive; 93 using namespace ariba::utility::string_format; 94 using namespace ariba::utility::Helper; 95 using namespace std; 96 97 smatch match; 98 if (regex_search(boot_info, match, robjects)) { 99 regex_nav nav = match; 100 for (int i = 0; i < nav.size(); i++) { 101 string type = nav[i][robject_id].str(); 102 string data = nav[i][robject_data].str(); 103 data = data.substr(1, data.size() - 2); 104 Name name = type; 105 EndpointDescriptor* desc = EndpointDescriptor::fromString(data); 106 addBootstrapNode(name, desc); 107 } 108 } 109 } 110 111 void AribaModule::addBootstrapNode(const Name& spovnet, 88 112 communication::EndpointDescriptor* desc) { 89 113 114 // set bootstrap node 115 BootstrapNode node; 116 node.timestamp = 0; 117 node.desc = desc; 118 bool added = false; 119 120 // add node to existing bootstrap list 121 BOOST_FOREACH( BootstrapInfo& info, bootstrapNodes ){ 122 if (info.spovnetName == spovnet) { 123 info.nodes.push_back(node); 124 added = true; 125 break; 126 } 127 } 128 129 // create new entry 130 if (!added) { 131 BootstrapInfo info; 132 info.spovnetName = spovnet; 133 info.nodes.push_back(node); 134 bootstrapNodes.push_back(info); 135 } 136 137 std::cout << "added bootstrap info: " << getBootstrapHints() << std::endl; 90 138 } 91 139 92 140 const communication::EndpointDescriptor* AribaModule::getBootstrapNode( 93 const Name& spovnet) { 94 95 BOOST_FOREACH( BootstrapInfo info, bootstrapNodes ){ 96 if( info.spovnetName == spovnet ){ 97 BOOST_FOREACH( BootstrapNode node, info.desc ){ 141 const Name& spovnet) const { 142 BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) { 143 if( info.spovnetName == spovnet ) { 144 BOOST_FOREACH( const BootstrapNode& node, info.nodes ) { 98 145 if( node.desc != NULL ) return node.desc; 99 146 } 100 147 } 101 148 } 102 103 149 return NULL; 104 150 } … … 150 196 *loc = communication::IPv4Locator::fromString(value); 151 197 ip_addr = loc; 152 } else if (key == "tcp.port") tcp_port = stoi(value); 198 } 199 else if (key == "tcp.port") tcp_port = stoi(value); 153 200 else if (key == "udp.port") udp_port = stoi(value); 154 201 else if (key == "bootstrap.hints") addBootstrapHints(value);
Note:
See TracChangeset
for help on using the changeset viewer.