Ignore:
Timestamp:
Aug 11, 2009, 8:39:47 AM (15 years ago)
Author:
Christoph Mayer
Message:

watchdog bootstrapping und kleine relay fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/overlay/OverlayBootstrap.cpp

    r5412 r5838  
    5050                spovnetid( SpoVNetID::UNSPECIFIED ),
    5151                nodeid( NodeID::UNSPECIFIED ),
    52                 overlay( NULL ){
     52                overlay( NULL ),
     53                watchtimer(this) {
     54
     55        srand(time(NULL));
    5356}
    5457
     
    6669        manager.registerModule( BootstrapManager::BootstrapTypePeriodicBroadcast );
    6770        manager.registerModule( BootstrapManager::BootstrapTypeBluetoothSdp );
     71
     72        watchtimer.startWatchdog();
    6873}
    6974
     
    7883        manager.unregisterModule( BootstrapManager::BootstrapTypePeriodicBroadcast );
    7984        manager.unregisterModule( BootstrapManager::BootstrapTypeBluetoothSdp );
     85
     86        watchtimer.stopWatchdog();
    8087}
    8188
     
    144151}
    145152
     153void OverlayBootstrap::recordJoin(const EndpointDescriptor& _ep){
     154        boost::mutex::scoped_lock lock(lastJoinesMutex);
     155
     156        EventData data;
     157        data.spovnetid = spovnetid;
     158        data.nodeid = nodeid;
     159        data.endpoint = _ep;
     160
     161        lastJoines.push_front(JoinData(data));
     162}
     163
     164void OverlayBootstrap::checkOverlayStatus(){
     165
     166        // if we have no overlay neighbors, try to bootstrap using
     167        // bootstrap information that we already used
     168
     169        {       //limit history to 10 endpoints
     170                boost::mutex::scoped_lock lock(lastJoinesMutex);
     171                while(lastJoines.size() > 10)
     172                        lastJoines.pop_back();
     173        }
     174
     175        // we have overlay neighbors -> ok
     176        if(overlay->getOverlayNeighbors().size() > 0) return;
     177
     178        // no overlay neighbors -> try out already
     179        // successfully used bootstrap nodes
     180        JoinData data;
     181        {
     182                boost::mutex::scoped_lock lock(lastJoinesMutex);
     183                JoinStack::iterator i = lastJoines.begin();
     184                if(i == lastJoines.end()) return;
     185
     186                // use last used element and then put it into back
     187                JoinData data = *i;
     188                lastJoines.pop_front();
     189                lastJoines.push_back(data);
     190        }
     191
     192        logging_info("no overlay connections detected, " <<
     193                                        "trying to join using old bootstrap information");
     194
     195        // try to join using this node, if the join is successfull
     196        // the endpoint will again be inserted using recordJoin
     197        overlay->joinSpoVNet( spovnetid, data.data.endpoint );
     198}
     199
     200OverlayBootstrap::WatchdogTimer::WatchdogTimer(OverlayBootstrap* _obj) : obj(_obj) {
     201}
     202
     203void OverlayBootstrap::WatchdogTimer::startWatchdog(){
     204        Timer::setInterval(2000);
     205        Timer::start();
     206}
     207
     208void OverlayBootstrap::WatchdogTimer::stopWatchdog(){
     209        Timer::stop();
     210}
     211
     212void OverlayBootstrap::WatchdogTimer::eventFunction(){
     213        if(obj == NULL) return;
     214        obj->checkOverlayStatus();
     215}
     216
    146217}} // namespace ariba, overlay
Note: See TracChangeset for help on using the changeset viewer.