Changeset 4866 for source/ariba
- Timestamp:
- Jul 13, 2009, 9:42:32 AM (15 years ago)
- Location:
- source/ariba
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/overlay/OverlayBootstrap.cpp
r4850 r4866 44 44 45 45 use_logging_cpp(OverlayBootstrap); 46 SystemEventType OverlayBootstrapMethodType("OverlayBootstrapMethodType"); 46 47 47 48 OverlayBootstrap::OverlayBootstrap() … … 61 62 62 63 manager.registerCallback( this ); 63 manager.register AllModules();64 manager.registerModule( BootstrapManager::BootstrapTypePeriodicBroadcast ); 64 65 } 65 66 void OverlayBootstrap::stop(){ … … 69 70 70 71 manager.unregisterCallback( this ); 71 manager.unregisterAllModules(); 72 manager.unregisterModule( BootstrapManager::BootstrapTypePeriodicBroadcast ); 73 } 74 75 void OverlayBootstrap::handleSystemEvent(const SystemEvent& event){ 76 77 78 EventData* data = event.getData<EventData>(); 79 80 // announcement for our spovnet 81 logging_info( "found bootstrap node for our SpoVNetID " << data->spovnetid.toString() 82 << " on NodeID " << data->nodeid.toString() << " with endpoint " << data->endpoint.toString() ); 83 84 85 // TODO: do stuff on overlay 86 87 88 delete data; 72 89 } 73 90 … … 95 112 if( nid == this->nodeid ) return; 96 113 97 // announcement for our spovnet 98 logging_info( "found bootstrap node for our SpoVNetID " << sid.toString() 99 << " on NodeID " << nid << " with endpoint " << ep.toString() ); 114 // 115 // send out the bootstrap information as 116 // event to synchronize into the system queue 117 // 118 119 EventData* data = new EventData(); 120 data->spovnetid = sid; 121 data->nodeid = nid; 122 data->endpoint = ep; 123 124 SystemQueue::instance().scheduleEvent( 125 SystemEvent( this, OverlayBootstrapMethodType, data), 0 ); 100 126 } 101 127 -
source/ariba/overlay/OverlayBootstrap.h
r4836 r4866 47 47 #include "ariba/utility/bootstrap/BootstrapInformationCallback.h" 48 48 #include "ariba/communication/EndpointDescriptor.h" 49 #include "ariba/utility/system/SystemEventListener.h" 50 #include "ariba/utility/system/SystemQueue.h" 51 #include "ariba/utility/system/SystemEvent.h" 52 #include "ariba/utility/system/SystemEventType.h" 49 53 50 54 using std::string; … … 55 59 using ariba::utility::BootstrapInformationCallback; 56 60 using ariba::communication::EndpointDescriptor; 61 using ariba::utility::SystemEventType; 62 using ariba::utility::SystemEvent; 63 using ariba::utility::SystemQueue; 64 using ariba::utility::SystemEventListener; 57 65 58 66 namespace ariba { … … 61 69 class BaseOverlay; 62 70 63 class OverlayBootstrap : public BootstrapInformationCallback {71 class OverlayBootstrap : public BootstrapInformationCallback, public SystemEventListener { 64 72 use_logging_h(OverlayBootstrap); 65 73 public: … … 74 82 75 83 protected: 84 virtual void handleSystemEvent(const SystemEvent& event); 76 85 virtual void onBootstrapServiceFound(string name, string info1, string info2, string info); 77 86 78 87 private: 88 typedef struct _EventData { 89 SpoVNetID spovnetid; 90 NodeID nodeid; 91 EndpointDescriptor endpoint; 92 } EventData; 93 79 94 BootstrapManager& manager; 80 95 SpoVNetID spovnetid; -
source/ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.cpp
r4853 r4866 59 59 use_logging_cpp(PeriodicBroadcast); 60 60 const long PeriodicBroadcast::timerinterval = 1000; 61 const long PeriodicBroadcast::servicetimeout = 3000; 61 62 const unsigned int PeriodicBroadcast::serverport_v4 = 5634; 62 63 const unsigned int PeriodicBroadcast::serverport_v6 = 5636; … … 130 131 void PeriodicBroadcast::updateRemoteServices(){ 131 132 133 // cleanup the services that timed out 134 // so they are seen of as new after timeout 135 { 136 boost::mutex::scoped_lock lock( remoteServicesMutex ); 137 bool deleted; 138 139 do { 140 deleted = false; 141 142 ServiceList::iterator i = remoteServices.begin(); 143 ServiceList::iterator iend = remoteServices.end(); 144 145 for( ; i != iend; i++ ){ 146 147 if( time(NULL) > (i->second.lastseen + servicetimeout) ){ 148 remoteServices.erase( i ); 149 deleted = true; 150 break; 151 } 152 } 153 154 }while(deleted); 155 } 156 157 // check if we received new services: 158 // check remoteServices against newRemoteServices 159 { 160 boost::mutex::scoped_lock lock( newRemoteServicesMutex ); 161 typedef std::pair<string,Service> mapitem; 162 163 BOOST_FOREACH( mapitem item, newRemoteServices ){ 164 165 string name = item.first; 166 Service service = item.second; 167 168 ServiceList::iterator i = remoteServices.find( name ); 169 if( i != remoteServices.end() ) { 170 // update the item lastseen time 171 i->second.lastseen = service.lastseen; 172 continue; 173 } 174 175 { 176 // insert the new item as new, lastseen has been set in the 177 // receive function, as this timer only runs in intervals 178 boost::mutex::scoped_lock lock2( remoteServicesMutex ); 179 remoteServices.insert( std::make_pair(name, service) ); 180 } 181 182 callback->onBootstrapServiceFound(name, service.info1, service.info2, service.info3); 183 } 184 185 // we have checked and transfered all new items 186 newRemoteServices.clear(); 187 } 132 188 } 133 189 -
source/ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.h
r4853 r4866 44 44 #include <map> 45 45 #include <string> 46 #include <ctime> 46 47 #include <iostream> 47 48 #include <boost/asio.hpp> … … 56 57 using std::map; 57 58 using std::string; 59 using std::cout; 58 60 using boost::asio::ip::udp; 59 61 … … 83 85 void updateRemoteServices(); 84 86 85 static const long timerinterval; 87 static const long timerinterval; // used to send out updates on our services and check for new services 88 static const long servicetimeout; // timeout after that a service is dead when we did not receive updates 86 89 static const unsigned int serverport_v4; 87 90 static const unsigned int serverport_v6; … … 92 95 string info2; 93 96 string info3; 97 time_t lastseen; 98 99 _Service() 100 : name(""), info1(""), info2(""), info3(""), lastseen(0){ 101 } 94 102 } Service; 95 103 … … 133 141 Data data = data_serialize( msg, DEFAULT_V ); 134 142 uint8_t* pnt = data.getBuffer(); 135 size_t len = data.getLength() ;143 size_t len = data.getLength() / 8; 136 144 boost::system::error_code ignored_error; 145 146 cout << "-----------> sending out " << data << std::endl; 137 147 138 148 { … … 172 182 data_deserialize( msg, data ); 173 183 184 cout << "-----------> received " << data << std::endl; 185 174 186 { // insert new found service 175 187 boost::mutex::scoped_lock( *servicesmutex ); … … 182 194 s.info2 = msg.getInfo2(); 183 195 s.info3 = msg.getInfo3(); 196 s.lastseen = time(NULL); 184 197 services->insert( std::make_pair(msg.getName(), s) ); 185 198 }
Note:
See TracChangeset
for help on using the changeset viewer.