Ignore:
Timestamp:
Feb 18, 2009, 11:39:30 AM (15 years ago)
Author:
mies
Message:

implemented bootstrap info parser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/AribaModule.cpp

    r2434 r2452  
    4545// ariba includes
    4646#include "ariba/utility/misc/Helper.h"
     47#include "ariba/utility/misc/StringFormat.h"
    4748
    4849// hack includes
     
    5354using namespace ariba::utility::Helper;
    5455using ariba::interface::UnderlayAbstraction;
     56using ariba::communication::EndpointDescriptor;
    5557
    5658namespace ariba {
     59
     60AribaModule::BootstrapNode::~BootstrapNode() {
     61        if (desc!=NULL) delete desc;
     62}
    5763
    5864AribaModule::AribaModule() {
     
    6975}
    7076
    71 
    7277string 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();
    7489}
    7590
    7691void 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
     111void AribaModule::addBootstrapNode(const Name& spovnet,
    88112                communication::EndpointDescriptor* desc) {
    89113
     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;
    90138}
    91139
    92140const 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 ) {
    98145                                if( node.desc != NULL ) return node.desc;
    99146                        }
    100147                }
    101148        }
    102 
    103149        return NULL;
    104150}
     
    150196                *loc = communication::IPv4Locator::fromString(value);
    151197                ip_addr = loc;
    152         } else if (key == "tcp.port") tcp_port = stoi(value);
     198        }
     199        else if (key == "tcp.port") tcp_port = stoi(value);
    153200        else if (key == "udp.port") udp_port = stoi(value);
    154201        else if (key == "bootstrap.hints") addBootstrapHints(value);
Note: See TracChangeset for help on using the changeset viewer.