| 1 | // [Licence]
|
|---|
| 2 | // The Ariba-Underlay Copyright
|
|---|
| 3 | //
|
|---|
| 4 | // Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
|
|---|
| 5 | //
|
|---|
| 6 | // Institute of Telematics
|
|---|
| 7 | // UniversitÀt Karlsruhe (TH)
|
|---|
| 8 | // Zirkel 2, 76128 Karlsruhe
|
|---|
| 9 | // Germany
|
|---|
| 10 | //
|
|---|
| 11 | // Redistribution and use in source and binary forms, with or without
|
|---|
| 12 | // modification, are permitted provided that the following conditions are
|
|---|
| 13 | // met:
|
|---|
| 14 | //
|
|---|
| 15 | // 1. Redistributions of source code must retain the above copyright
|
|---|
| 16 | // notice, this list of conditions and the following disclaimer.
|
|---|
| 17 | // 2. Redistributions in binary form must reproduce the above copyright
|
|---|
| 18 | // notice, this list of conditions and the following disclaimer in the
|
|---|
| 19 | // documentation and/or other materials provided with the distribution.
|
|---|
| 20 | //
|
|---|
| 21 | // THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
|
|---|
| 22 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|---|
| 23 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|---|
| 24 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
|
|---|
| 25 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|---|
| 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|---|
| 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|---|
| 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|---|
| 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|---|
| 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|---|
| 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 32 | //
|
|---|
| 33 | // The views and conclusions contained in the software and documentation
|
|---|
| 34 | // are those of the authors and should not be interpreted as representing
|
|---|
| 35 | // official policies, either expressed or implied, of the Institute of
|
|---|
| 36 | // Telematics.
|
|---|
| 37 | // [Licence]
|
|---|
| 38 |
|
|---|
| 39 | #include "BaseOverlay.h"
|
|---|
| 40 |
|
|---|
| 41 | #include "ariba/utility/misc/OvlVis.h"
|
|---|
| 42 | using ariba::utility::OvlVis;
|
|---|
| 43 |
|
|---|
| 44 | namespace ariba {
|
|---|
| 45 | namespace overlay {
|
|---|
| 46 |
|
|---|
| 47 | use_logging_cpp(BaseOverlay);
|
|---|
| 48 |
|
|---|
| 49 | BaseOverlay::BaseOverlay( BaseCommunication& _basecomm, const NodeID& _nodeid )
|
|---|
| 50 | : bc( _basecomm ), nodeId( _nodeid ), spovnetId( SpoVNetID::UNSPECIFIED), overlayInterface( NULL ),
|
|---|
| 51 | initiatorLink( LinkID::UNSPECIFIED ), state( BaseOverlayStateInvalid ) {
|
|---|
| 52 |
|
|---|
| 53 | logging_info("creating base overlay");
|
|---|
| 54 |
|
|---|
| 55 | bc.registerMessageReceiver( this );
|
|---|
| 56 | bc.registerEventListener( this );
|
|---|
| 57 |
|
|---|
| 58 | ovl.visCreate( ovlId, nodeId, string(""), string("") );
|
|---|
| 59 | ovl.visChangeNodeColor(ovlId, nodeId, OvlVis::NODE_COLORS_GREY);
|
|---|
| 60 |
|
|---|
| 61 | // if (Identifier(Configuration::instance().read<unsigned long>("BASE_nodeid")) ==
|
|---|
| 62 | // Identifier(Configuration::instance().read<unsigned long>("SOURCE"))) {
|
|---|
| 63 | // ovl.visChangeNodeIcon(ovlId, nodeId, OvlVis::ICON_ID_CAMERA);
|
|---|
| 64 | // } else if (Identifier(Configuration::instance().read<unsigned long>("BASE_nodeid")) ==
|
|---|
| 65 | // Identifier(Configuration::instance().read<unsigned long>("MR_A"))) {
|
|---|
| 66 | // ovl.visChangeNodeIcon(ovlId, nodeId, OvlVis::ICON_ID_CHARACTER_A);
|
|---|
| 67 | // } else if (Identifier(Configuration::instance().read<unsigned long>("BASE_nodeid")) ==
|
|---|
| 68 | // Identifier(Configuration::instance().read<unsigned long>("MR_W"))) {
|
|---|
| 69 | // ovl.visChangeNodeIcon(ovlId, nodeId, OvlVis::ICON_ID_CHARACTER_W);
|
|---|
| 70 | // }
|
|---|
| 71 |
|
|---|
| 72 | // timer for auto link management
|
|---|
| 73 | Timer::setInterval( 5000 );
|
|---|
| 74 | Timer::start();
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | BaseOverlay::~BaseOverlay() {
|
|---|
| 78 |
|
|---|
| 79 | logging_info("deleting base overlay");
|
|---|
| 80 |
|
|---|
| 81 | Timer::stop();
|
|---|
| 82 | bc.unregisterMessageReceiver( this );
|
|---|
| 83 | bc.unregisterEventListener( this );
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | void BaseOverlay::joinSpoVNet(const SpoVNetID& id, const EndpointDescriptor& bootstrapEp){
|
|---|
| 87 |
|
|---|
| 88 | ovl.visShowNodeBubble ( ovlId, nodeId, "joining..." );
|
|---|
| 89 | logging_info( "starting to join spovnet " << id.toString() << "...");
|
|---|
| 90 |
|
|---|
| 91 | //
|
|---|
| 92 | // contact the spovnet initiator and request
|
|---|
| 93 | // to join. if the join is granted we will
|
|---|
| 94 | // receive further information on the structure
|
|---|
| 95 | // of the overlay that is used in the spovnet
|
|---|
| 96 | //
|
|---|
| 97 | // but first, we have to establish a link to the initiator...
|
|---|
| 98 | //
|
|---|
| 99 |
|
|---|
| 100 | spovnetId = id;
|
|---|
| 101 | state = BaseOverlayStateJoinInitiated;
|
|---|
| 102 |
|
|---|
| 103 | initiatorLink = bc.establishLink( bootstrapEp );
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | void BaseOverlay::leaveSpoVNet(){
|
|---|
| 107 |
|
|---|
| 108 | logging_info( "leaving spovnet " << spovnetId );
|
|---|
| 109 |
|
|---|
| 110 | // first, leave the overlay interface
|
|---|
| 111 | overlayInterface->leaveOverlay();
|
|---|
| 112 |
|
|---|
| 113 | if( state != BaseOverlayStateInitiator ){
|
|---|
| 114 |
|
|---|
| 115 | // then, leave the spovnet baseoverlay
|
|---|
| 116 | OverlayMsg overMsg( OverlayMsg::OverlayMessageTypeBye, nodeId );
|
|---|
| 117 | bc.sendMessage( initiatorLink, &overMsg );
|
|---|
| 118 |
|
|---|
| 119 | // drop the link and set to correct state
|
|---|
| 120 | bc.dropLink( initiatorLink );
|
|---|
| 121 | initiatorLink = LinkID::UNSPECIFIED;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | state = BaseOverlayStateInvalid;
|
|---|
| 125 | ovl.visShutdown( ovlId, nodeId, string("") );
|
|---|
| 126 |
|
|---|
| 127 | // inform all registered services of the event
|
|---|
| 128 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 129 | i->onOverlayDestroy( spovnetId );
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | void BaseOverlay::createSpoVNet(const SpoVNetID& id, const OverlayParameterSet& param, const SecurityParameterSet& sec, const QoSParameterSet& qos){
|
|---|
| 134 |
|
|---|
| 135 | //
|
|---|
| 136 | // set the state that we are an initiator,
|
|---|
| 137 | // this way incoming messages are handled correctly
|
|---|
| 138 | //
|
|---|
| 139 |
|
|---|
| 140 | logging_info("creating spovnet " + id.toString());
|
|---|
| 141 |
|
|---|
| 142 | spovnetId = id;
|
|---|
| 143 | state = BaseOverlayStateInitiator;
|
|---|
| 144 |
|
|---|
| 145 | overlayInterface = OverlayFactory::create( *this, param, nodeId, this );
|
|---|
| 146 | if( overlayInterface == NULL ){
|
|---|
| 147 | logging_fatal( "overlay structure not supported" );
|
|---|
| 148 | state = BaseOverlayStateInvalid;
|
|---|
| 149 | return;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | //
|
|---|
| 153 | // create the overlay
|
|---|
| 154 | //
|
|---|
| 155 |
|
|---|
| 156 | overlayInterface->createOverlay();
|
|---|
| 157 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 158 | i->onOverlayCreate( spovnetId );
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | //
|
|---|
| 162 | // bootstrap against ourselfs
|
|---|
| 163 | //
|
|---|
| 164 |
|
|---|
| 165 | overlayInterface->joinOverlay();
|
|---|
| 166 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 167 | i->onJoinSuccess( spovnetId );
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | ovl.visChangeNodeIcon ( ovlId, nodeId, OvlVis::ICON_ID_CAMERA );
|
|---|
| 171 | ovl.visChangeNodeColor( ovlId, nodeId, OvlVis::NODE_COLORS_GREEN);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | const EndpointDescriptor& BaseOverlay::getEndpointDescriptor(const LinkID& link) const {
|
|---|
| 175 |
|
|---|
| 176 | return bc.getEndpointDescriptor( link );
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | const EndpointDescriptor& BaseOverlay::getEndpointDescriptor(const NodeID& node) const {
|
|---|
| 180 |
|
|---|
| 181 | if( node == nodeId || node == NodeID::UNSPECIFIED )
|
|---|
| 182 | return bc.getEndpointDescriptor();
|
|---|
| 183 |
|
|---|
| 184 | if( overlayInterface == NULL ){
|
|---|
| 185 | logging_error( "overlay interface not set, cannot resolve endpoint" );
|
|---|
| 186 | return EndpointDescriptor::UNSPECIFIED;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | // TODO: if this is not a onehop overlay the operation will go asynchronously
|
|---|
| 190 | return overlayInterface->resolveNode( node );
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | const LinkID BaseOverlay::establishLink(const NodeID& node, const ServiceID& service){
|
|---|
| 194 |
|
|---|
| 195 | // TODO: if this is not a onehop overlay the operation will go asynchronously
|
|---|
| 196 | const EndpointDescriptor& endpoint = overlayInterface->resolveNode( node );
|
|---|
| 197 | if( endpoint == EndpointDescriptor::UNSPECIFIED ){
|
|---|
| 198 | logging_error( "could not resolve node to endpoint. unable to establish link" );
|
|---|
| 199 | return LinkID::UNSPECIFIED;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | logging_debug( "baseoverlay called to establish link between node " <<
|
|---|
| 203 | node.toString() << " on endpoint " << endpoint.toString() <<
|
|---|
| 204 | " for service " << service.toString() );
|
|---|
| 205 |
|
|---|
| 206 | return establishLink( endpoint, service );
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | const LinkID BaseOverlay::establishLink(const EndpointDescriptor& ep, const ServiceID& service){
|
|---|
| 210 |
|
|---|
| 211 | if( !listenerMux.contains( service ) ){
|
|---|
| 212 | logging_error( "no registered listener on serviceid " << service.toString() );
|
|---|
| 213 | return LinkID::UNSPECIFIED;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | ServiceInterface* receiver = listenerMux.get( service );
|
|---|
| 217 | const LinkID link = bc.establishLink( ep );
|
|---|
| 218 |
|
|---|
| 219 | LinkItem item (link, NodeID::UNSPECIFIED, service, receiver);
|
|---|
| 220 | linkMapping.insert( make_pair(link, item) );
|
|---|
| 221 |
|
|---|
| 222 | return link;
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | void BaseOverlay::dropLink(const LinkID& link){
|
|---|
| 226 |
|
|---|
| 227 | logging_debug( "baseoverlay dropping link " << link.toString() );
|
|---|
| 228 | LinkMapping::iterator i = linkMapping.find( link );
|
|---|
| 229 |
|
|---|
| 230 | if( i == linkMapping.end() ){
|
|---|
| 231 | logging_warn( "can't drop link, mapping unknown " << link.toString() );
|
|---|
| 232 | return;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | linkMapping.erase( i );
|
|---|
| 236 |
|
|---|
| 237 | LinkItem item = i->second;
|
|---|
| 238 | bc.dropLink( link );
|
|---|
| 239 |
|
|---|
| 240 | if( item.interface != NULL )
|
|---|
| 241 | item.interface->onLinkDown( spovnetId, nodeId, item.node );
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | seqnum_t BaseOverlay::sendMessage(const Message* message, const LinkID& link ){
|
|---|
| 245 |
|
|---|
| 246 | logging_debug( "baseoverlay is sending message on link " << link.toString() );
|
|---|
| 247 |
|
|---|
| 248 | LinkMapping::iterator i = linkMapping.find( link );
|
|---|
| 249 | if( i == linkMapping.end() ){
|
|---|
| 250 | logging_error( "could not send message. link not found " << link.toString() );
|
|---|
| 251 | return -1;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | OverlayMsg overmsg( OverlayMsg::OverlayMessageTypeData, i->second.service, nodeId );
|
|---|
| 255 | overmsg.encapsulate( const_cast<Message*>(message) );
|
|---|
| 256 |
|
|---|
| 257 | i->second.markused();
|
|---|
| 258 | return bc.sendMessage( link, &overmsg );
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | seqnum_t BaseOverlay::sendMessage(const Message* message, const NodeID& node, const ServiceID& service){
|
|---|
| 262 |
|
|---|
| 263 | LinkID link = LinkID::UNSPECIFIED;
|
|---|
| 264 |
|
|---|
| 265 | LinkMapping::iterator i = linkMapping.begin();
|
|---|
| 266 | LinkMapping::iterator iend = linkMapping.end();
|
|---|
| 267 |
|
|---|
| 268 | for( ; i != iend; i++ ){
|
|---|
| 269 | if( i->second.node == node && i->second.service == service ){
|
|---|
| 270 | link = i->second.link;
|
|---|
| 271 | break;
|
|---|
| 272 | }
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | if( link == LinkID::UNSPECIFIED ){
|
|---|
| 276 |
|
|---|
| 277 | logging_info( "no link could be found to send message to node " <<
|
|---|
| 278 | node.toString() << " for service " << service.toString() <<
|
|---|
| 279 | ". creating auto link ...");
|
|---|
| 280 |
|
|---|
| 281 | const LinkID link = establishLink( node, service );
|
|---|
| 282 | LinkMapping::iterator i = linkMapping.find( link );
|
|---|
| 283 |
|
|---|
| 284 | if( i == linkMapping.end() ){
|
|---|
| 285 | logging_error( "failed to establish auto link to node " << node.toString() <<
|
|---|
| 286 | " for service " << service.toString() );
|
|---|
| 287 | return -1;
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | i->second.autolink = true;
|
|---|
| 291 |
|
|---|
| 292 | } // if( link != LinkID::UNSPECIFIED )
|
|---|
| 293 |
|
|---|
| 294 | i->second.markused();
|
|---|
| 295 | return sendMessage( message, link );
|
|---|
| 296 | }
|
|---|
| 297 |
|
|---|
| 298 | bool BaseOverlay::bind(ServiceInterface* service, const ServiceID& sid) {
|
|---|
| 299 |
|
|---|
| 300 | logging_debug( "binding service " << service << " on serviceid " << sid.toString() );
|
|---|
| 301 |
|
|---|
| 302 | if( listenerMux.contains( sid ) ){
|
|---|
| 303 | logging_error( "some service already registered for service id " << sid.toString() );
|
|---|
| 304 | return false;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | listenerMux.registerItem( service, sid );
|
|---|
| 308 | return true;
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | ServiceInterface* BaseOverlay::unbind(const ServiceID& sid){
|
|---|
| 312 |
|
|---|
| 313 | logging_debug( "unbinding service from serviceid " << sid.toString() );
|
|---|
| 314 |
|
|---|
| 315 | if( !listenerMux.contains( sid ) ){
|
|---|
| 316 | logging_warn( "cannot unbind service. no service registered on service id " << sid.toString() );
|
|---|
| 317 | return NULL;
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | ServiceInterface* iface = listenerMux.get( sid );
|
|---|
| 321 | listenerMux.unregisterItem( sid );
|
|---|
| 322 |
|
|---|
| 323 | return NULL; //iface;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | void BaseOverlay::onLinkUp(const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote){
|
|---|
| 327 |
|
|---|
| 328 | logging_debug( "base overlay received linkup event " + id.toString() );
|
|---|
| 329 | // TODO: updateOvlVis( getNodeID(id) );
|
|---|
| 330 |
|
|---|
| 331 | //
|
|---|
| 332 | // if we get up a link while we are in the
|
|---|
| 333 | // join phase and this is the link that
|
|---|
| 334 | // we have initiated towards the spovnet owner
|
|---|
| 335 | // continue the join process by sending
|
|---|
| 336 | // a join request message through the link
|
|---|
| 337 | //
|
|---|
| 338 |
|
|---|
| 339 | if( state == BaseOverlayStateJoinInitiated && id == initiatorLink){
|
|---|
| 340 |
|
|---|
| 341 | logging_info( "join has been initiated by me and the link is now up. " <<
|
|---|
| 342 | "sending out join request for spovnet " <<
|
|---|
| 343 | spovnetId.toString() );
|
|---|
| 344 |
|
|---|
| 345 | OverlayMsg overMsg( OverlayMsg::OverlayMessageTypeJoinRequest, nodeId );
|
|---|
| 346 | JoinRequest joinmsg( spovnetId, nodeId );
|
|---|
| 347 | overMsg.encapsulate( &joinmsg );
|
|---|
| 348 |
|
|---|
| 349 | state = BaseOverlayStateJoinInitiated; // state remains in JoinInitiated
|
|---|
| 350 | bc.sendMessage( id, &overMsg );
|
|---|
| 351 |
|
|---|
| 352 | return;
|
|---|
| 353 |
|
|---|
| 354 | } // if( state == BaseOverlayStateJoinInitiated && id == initiatorLink)
|
|---|
| 355 |
|
|---|
| 356 | //
|
|---|
| 357 | // otherwise this is a link initiated by a service
|
|---|
| 358 | // then we exchange update messages to exchange the
|
|---|
| 359 | // service id and node id for the link. in this case
|
|---|
| 360 | // we should have a link mapping for this link. if
|
|---|
| 361 | // we have no link mapping this link was initiated by
|
|---|
| 362 | // the remote side.
|
|---|
| 363 | //
|
|---|
| 364 |
|
|---|
| 365 | LinkMapping::iterator i = linkMapping.find( id );
|
|---|
| 366 |
|
|---|
| 367 | if( i == linkMapping.end() ){
|
|---|
| 368 |
|
|---|
| 369 | LinkItem item (id, NodeID::UNSPECIFIED, ServiceID::UNSPECIFIED, NULL );
|
|---|
| 370 | linkMapping.insert( make_pair(id, item) );
|
|---|
| 371 |
|
|---|
| 372 | } else {
|
|---|
| 373 |
|
|---|
| 374 | logging_debug( "sending out OverlayMessageTypeUpdate" <<
|
|---|
| 375 | " for service " << i->second.service.toString() <<
|
|---|
| 376 | " with local node id " << nodeId.toString() <<
|
|---|
| 377 | " on link " << id.toString() );
|
|---|
| 378 |
|
|---|
| 379 | OverlayMsg overMsg(
|
|---|
| 380 | OverlayMsg::OverlayMessageTypeUpdate,
|
|---|
| 381 | i->second.service,
|
|---|
| 382 | nodeId
|
|---|
| 383 | );
|
|---|
| 384 |
|
|---|
| 385 | bc.sendMessage( id, &overMsg );
|
|---|
| 386 | i->second.markused();
|
|---|
| 387 |
|
|---|
| 388 | } // if( i == linkMapping.end() )
|
|---|
| 389 |
|
|---|
| 390 | // the link is only valid for the service when we receive
|
|---|
| 391 | // the OverlayMessageTypeUpdate from the remote node and
|
|---|
| 392 | // have the nodeid and serviceid for the link!
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | void BaseOverlay::onLinkDown(const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote){
|
|---|
| 396 |
|
|---|
| 397 | logging_debug( "link went down " << id.toString() );
|
|---|
| 398 |
|
|---|
| 399 | //
|
|---|
| 400 | // tell the service that the link went
|
|---|
| 401 | // down and remove the mapping
|
|---|
| 402 | //
|
|---|
| 403 |
|
|---|
| 404 | LinkMapping::iterator i = linkMapping.find( id );
|
|---|
| 405 | if( i == linkMapping.end() ) {
|
|---|
| 406 | // this can also be one of the baseoverlay links that
|
|---|
| 407 | // no mapping is stored for. therefore we issue no warning
|
|---|
| 408 | return;
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 411 | if( i->second.interface != NULL )
|
|---|
| 412 | i->second.interface->onLinkDown( id, nodeId, i->second.node );
|
|---|
| 413 |
|
|---|
| 414 | linkMapping.erase( i );
|
|---|
| 415 | }
|
|---|
| 416 |
|
|---|
| 417 | void BaseOverlay::onLinkChanged(const LinkID& id, const NetworkLocator* oldlocal, const NetworkLocator* newlocal, const NetworkLocator* oldremote, const NetworkLocator* newremote){
|
|---|
| 418 |
|
|---|
| 419 | logging_debug( "link changed " << id.toString() );
|
|---|
| 420 |
|
|---|
| 421 | //
|
|---|
| 422 | // tell the service that the link changed
|
|---|
| 423 | //
|
|---|
| 424 |
|
|---|
| 425 | LinkMapping::iterator i = linkMapping.find( id );
|
|---|
| 426 | if( i == linkMapping.end() ) return;
|
|---|
| 427 |
|
|---|
| 428 | if( i->second.interface != NULL )
|
|---|
| 429 | i->second.interface->onLinkChanged( id, nodeId, i->second.node );
|
|---|
| 430 |
|
|---|
| 431 | i->second.markused();
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | void BaseOverlay::onLinkFail(const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote){
|
|---|
| 435 |
|
|---|
| 436 | logging_debug( "link failed " << id.toString() );
|
|---|
| 437 |
|
|---|
| 438 | //
|
|---|
| 439 | // tell the service that the link failed
|
|---|
| 440 | //
|
|---|
| 441 |
|
|---|
| 442 | LinkMapping::iterator i = linkMapping.find( id );
|
|---|
| 443 | if( i == linkMapping.end() ) return;
|
|---|
| 444 |
|
|---|
| 445 | if( i->second.interface != NULL )
|
|---|
| 446 | i->second.interface->onLinkFail( id, nodeId, i->second.node );
|
|---|
| 447 |
|
|---|
| 448 | i->second.markused();
|
|---|
| 449 | }
|
|---|
| 450 |
|
|---|
| 451 | void BaseOverlay::onLinkQoSChanged(const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote, const QoSParameterSet& qos) {
|
|---|
| 452 |
|
|---|
| 453 | logging_debug( "link qos changed " << id.toString() );
|
|---|
| 454 |
|
|---|
| 455 | //
|
|---|
| 456 | // tell the service that the link qos has changed
|
|---|
| 457 | //
|
|---|
| 458 |
|
|---|
| 459 | LinkMapping::iterator i = linkMapping.find( id );
|
|---|
| 460 | if( i == linkMapping.end() ) return;
|
|---|
| 461 |
|
|---|
| 462 | if( i->second.interface != NULL )
|
|---|
| 463 | i->second.interface->onLinkQoSChanged( id, nodeId, i->second.node, qos );
|
|---|
| 464 |
|
|---|
| 465 | i->second.markused();
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | bool BaseOverlay::receiveMessage(const Message* message,
|
|---|
| 469 | const LinkID& link, const NodeID& /*the nodeid is invalid in this case! removed var to prevent errors*/ ){
|
|---|
| 470 |
|
|---|
| 471 | OverlayMsg* overlayMsg = ((Message*)message)->decapsulate<OverlayMsg>();
|
|---|
| 472 | if( overlayMsg == NULL ) return false;
|
|---|
| 473 |
|
|---|
| 474 | // mark the link as in action
|
|---|
| 475 | LinkMapping::iterator item = linkMapping.find( link );
|
|---|
| 476 | if( item != linkMapping.end() ) item->second.markused();
|
|---|
| 477 |
|
|---|
| 478 | //
|
|---|
| 479 | // handle user date that we forward to the
|
|---|
| 480 | // appropriate service using the service id
|
|---|
| 481 | // in the message. as we don't know the class
|
|---|
| 482 | // of message that the service handles, we
|
|---|
| 483 | // forward it as a pure Message*
|
|---|
| 484 | //
|
|---|
| 485 |
|
|---|
| 486 | if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeData) ) {
|
|---|
| 487 |
|
|---|
| 488 | logging_debug( "baseoverlay received message of type OverlayMessageTypeData" );
|
|---|
| 489 |
|
|---|
| 490 | const ServiceID& service = overlayMsg->getService();
|
|---|
| 491 | ServiceInterface* serviceListener = listenerMux.get( service );
|
|---|
| 492 |
|
|---|
| 493 | logging_debug( "received data for service " << service.toString() );
|
|---|
| 494 |
|
|---|
| 495 | if( serviceListener != NULL )
|
|---|
| 496 | serviceListener->receiveMessage( overlayMsg, link, overlayMsg->getSourceNode() );
|
|---|
| 497 |
|
|---|
| 498 | return true;
|
|---|
| 499 |
|
|---|
| 500 | } // if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeData) )
|
|---|
| 501 |
|
|---|
| 502 | //
|
|---|
| 503 | // handle spovnet instance join requests
|
|---|
| 504 | //
|
|---|
| 505 |
|
|---|
| 506 | else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeJoinRequest) &&
|
|---|
| 507 | state == BaseOverlayStateInitiator){
|
|---|
| 508 |
|
|---|
| 509 | logging_debug( "baseoverlay received message of type OverlayMessageTypeJoinRequest" );
|
|---|
| 510 |
|
|---|
| 511 | JoinRequest* joinReq = overlayMsg->decapsulate<JoinRequest>();
|
|---|
| 512 | logging_info( "received join request for spovnet " <<
|
|---|
| 513 | joinReq->getSpoVNetID().toString() );
|
|---|
| 514 |
|
|---|
| 515 | //
|
|---|
| 516 | // make sure that the node actually wants to join
|
|---|
| 517 | // the correct spovnet id that we administrate
|
|---|
| 518 | //
|
|---|
| 519 |
|
|---|
| 520 | if( joinReq->getSpoVNetID() != spovnetId ){
|
|---|
| 521 | logging_error( "received join request for spovnet we don't handle " <<
|
|---|
| 522 | joinReq->getSpoVNetID().toString() );
|
|---|
| 523 | return false;
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 526 | //
|
|---|
| 527 | // only if all services allow the node to join it is allowed
|
|---|
| 528 | // using the isJoinAllowed interface security policies can be
|
|---|
| 529 | // implemented by higher layer services
|
|---|
| 530 | //
|
|---|
| 531 |
|
|---|
| 532 | bool allow = true;
|
|---|
| 533 |
|
|---|
| 534 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 535 | allow &= i->isJoinAllowed( overlayMsg->getSourceNode(), spovnetId );
|
|---|
| 536 | }
|
|---|
| 537 |
|
|---|
| 538 | logging_info( "sending back join reply for spovnet " <<
|
|---|
| 539 | spovnetId.toString() << " to node " <<
|
|---|
| 540 | overlayMsg->getSourceNode().toString() <<
|
|---|
| 541 | ". result: " << (allow ? "allowed" : "denied") );
|
|---|
| 542 |
|
|---|
| 543 | joiningNodes.push_back( overlayMsg->getSourceNode() );
|
|---|
| 544 |
|
|---|
| 545 | //
|
|---|
| 546 | // send back our spovnetid, default overlay parameters,
|
|---|
| 547 | // join allow result, and ourself as the endpoint
|
|---|
| 548 | // to bootstrap the overlay against
|
|---|
| 549 | //
|
|---|
| 550 |
|
|---|
| 551 | OverlayMsg retmsg( OverlayMsg::OverlayMessageTypeJoinReply, nodeId );
|
|---|
| 552 | JoinReply replyMsg( spovnetId, OverlayParameterSet::DEFAULT,
|
|---|
| 553 | allow, getEndpointDescriptor() );
|
|---|
| 554 |
|
|---|
| 555 | retmsg.encapsulate(&replyMsg);
|
|---|
| 556 | bc.sendMessage( link, &retmsg );
|
|---|
| 557 |
|
|---|
| 558 | return true;
|
|---|
| 559 |
|
|---|
| 560 | } // else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeJoinRequest) && state == BaseOverlayStateInitiator)
|
|---|
| 561 |
|
|---|
| 562 | //
|
|---|
| 563 | // handle replies to spovnet instance join requests
|
|---|
| 564 | //
|
|---|
| 565 |
|
|---|
| 566 | else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeJoinReply) &&
|
|---|
| 567 | state == BaseOverlayStateJoinInitiated){
|
|---|
| 568 |
|
|---|
| 569 | logging_debug( "baseoverlay received message of type OverlayMessageTypeJoinReply" );
|
|---|
| 570 |
|
|---|
| 571 | JoinReply* replyMsg = overlayMsg->decapsulate<JoinReply>();
|
|---|
| 572 | logging_info( "received spovnet join reply" );
|
|---|
| 573 |
|
|---|
| 574 | //
|
|---|
| 575 | // make sure that we actually wanted to get
|
|---|
| 576 | // into the spovnet whose id is in the message
|
|---|
| 577 | //
|
|---|
| 578 |
|
|---|
| 579 | if( replyMsg->getSpoVNetID() != spovnetId ){
|
|---|
| 580 | logging_error( "received spovnet join reply for spovnet " <<
|
|---|
| 581 | replyMsg->getSpoVNetID().toString() <<
|
|---|
| 582 | " but we wanted to join spovnet " <<
|
|---|
| 583 | spovnetId.toString() );
|
|---|
| 584 |
|
|---|
| 585 | // state does not change here, maybe
|
|---|
| 586 | // the reply does come in later
|
|---|
| 587 | return false;
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 | //
|
|---|
| 591 | // if we did not get access to the spovnet
|
|---|
| 592 | // notify of the failure and
|
|---|
| 593 | // close the link to the initiator
|
|---|
| 594 | //
|
|---|
| 595 |
|
|---|
| 596 | if( ! replyMsg->getJoinAllowed() ){
|
|---|
| 597 |
|
|---|
| 598 | logging_warn( "our join request has been denied" );
|
|---|
| 599 |
|
|---|
| 600 | bc.dropLink( initiatorLink );
|
|---|
| 601 | initiatorLink = LinkID::UNSPECIFIED;
|
|---|
| 602 | state = BaseOverlayStateInvalid;
|
|---|
| 603 |
|
|---|
| 604 | // inform all registered services of the event
|
|---|
| 605 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 606 | i->onJoinFail( spovnetId );
|
|---|
| 607 | }
|
|---|
| 608 |
|
|---|
| 609 | return true;
|
|---|
| 610 | }
|
|---|
| 611 |
|
|---|
| 612 | logging_info( "join request has been accepted for spovnet " << spovnetId.toString() );
|
|---|
| 613 |
|
|---|
| 614 | //
|
|---|
| 615 | // if we did get access to the spovnet
|
|---|
| 616 | // we try to create the overlay structure
|
|---|
| 617 | // as given in the reply message
|
|---|
| 618 | //
|
|---|
| 619 |
|
|---|
| 620 | overlayInterface = OverlayFactory::create( *this, replyMsg->getParam(), nodeId, this );
|
|---|
| 621 |
|
|---|
| 622 | if( overlayInterface == NULL ){
|
|---|
| 623 | logging_error( "overlay structure not supported" );
|
|---|
| 624 |
|
|---|
| 625 | bc.dropLink( initiatorLink );
|
|---|
| 626 | initiatorLink = LinkID::UNSPECIFIED;
|
|---|
| 627 | state = BaseOverlayStateInvalid;
|
|---|
| 628 |
|
|---|
| 629 | // inform all registered services of the event
|
|---|
| 630 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 631 | i->onJoinFail( spovnetId );
|
|---|
| 632 | }
|
|---|
| 633 |
|
|---|
| 634 | return true;
|
|---|
| 635 | }
|
|---|
| 636 |
|
|---|
| 637 | //
|
|---|
| 638 | // now start the join process for the overlay.
|
|---|
| 639 | // the join process for the spovnet baseoverlay
|
|---|
| 640 | // is now complete. we use the endpoint for
|
|---|
| 641 | // overlay structure bootstrapping that the
|
|---|
| 642 | // initiator provided in his reply message
|
|---|
| 643 | //
|
|---|
| 644 |
|
|---|
| 645 | state = BaseOverlayStateCompleted;
|
|---|
| 646 | ovl.visChangeNodeColor( ovlId, nodeId, OvlVis::NODE_COLORS_GREEN);
|
|---|
| 647 |
|
|---|
| 648 | overlayInterface->createOverlay();
|
|---|
| 649 |
|
|---|
| 650 | // inform all registered services of the event
|
|---|
| 651 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 652 | i->onOverlayCreate( spovnetId );
|
|---|
| 653 | }
|
|---|
| 654 |
|
|---|
| 655 | overlayInterface->joinOverlay( replyMsg->getBootstrapEndpoint() );
|
|---|
| 656 |
|
|---|
| 657 | // inform all registered services of the event
|
|---|
| 658 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 659 | i->onJoinSuccess( spovnetId );
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | return true;
|
|---|
| 663 |
|
|---|
| 664 | } // else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeJoinReply) && state == BaseOverlayStateJoinInitiated)
|
|---|
| 665 |
|
|---|
| 666 |
|
|---|
| 667 | //
|
|---|
| 668 | // handle update messages for link establishment
|
|---|
| 669 | //
|
|---|
| 670 |
|
|---|
| 671 | else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeUpdate) ){
|
|---|
| 672 |
|
|---|
| 673 | logging_debug( "baseoverlay received message of type OverlayMessageTypeUpdate" );
|
|---|
| 674 |
|
|---|
| 675 | const NodeID& sourcenode = overlayMsg->getSourceNode();
|
|---|
| 676 | const ServiceID& service = overlayMsg->getService();
|
|---|
| 677 |
|
|---|
| 678 | //
|
|---|
| 679 | // we should have a linkmapping for the link, otherwise
|
|---|
| 680 | // we ignore update messages
|
|---|
| 681 | //
|
|---|
| 682 |
|
|---|
| 683 | LinkMapping::iterator i = linkMapping.find( link );
|
|---|
| 684 | if( i == linkMapping.end() ){
|
|---|
| 685 | logging_warn( "received overlay update message for link " <<
|
|---|
| 686 | link.toString() << " for which we have no mapping" );
|
|---|
| 687 | return false;
|
|---|
| 688 | }
|
|---|
| 689 |
|
|---|
| 690 | //
|
|---|
| 691 | // update our link mapping information for this link
|
|---|
| 692 | //
|
|---|
| 693 |
|
|---|
| 694 | bool changed = ( i->second.node != sourcenode ) || ( i->second.service != service );
|
|---|
| 695 |
|
|---|
| 696 | i->second.node = sourcenode;
|
|---|
| 697 | i->second.service = service;
|
|---|
| 698 |
|
|---|
| 699 | //
|
|---|
| 700 | // if our link information changed, we send out an update, too
|
|---|
| 701 | //
|
|---|
| 702 |
|
|---|
| 703 | if( changed ){
|
|---|
| 704 | OverlayMsg overMsg( OverlayMsg::OverlayMessageTypeUpdate, i->second.service, nodeId );
|
|---|
| 705 | bc.sendMessage( link, &overMsg );
|
|---|
| 706 | }
|
|---|
| 707 |
|
|---|
| 708 | //
|
|---|
| 709 | // set the correct listener service for the linkitem
|
|---|
| 710 | // now we can tell the registered service of the linkup event
|
|---|
| 711 | //
|
|---|
| 712 |
|
|---|
| 713 | if( !listenerMux.contains( service ) ){
|
|---|
| 714 | logging_warn( "linkup event for service that has not been registered" );
|
|---|
| 715 | return false;
|
|---|
| 716 | }
|
|---|
| 717 |
|
|---|
| 718 | ServiceInterface* iface = listenerMux.get( service );
|
|---|
| 719 | if( iface == NULL ){
|
|---|
| 720 | logging_warn( "linkup event for service that has been registered with a NULL interface" );
|
|---|
| 721 | return true;
|
|---|
| 722 | }
|
|---|
| 723 |
|
|---|
| 724 | i->second.interface = iface;
|
|---|
| 725 | iface->onLinkUp( link, nodeId, sourcenode );
|
|---|
| 726 | i->second.markused();
|
|---|
| 727 |
|
|---|
| 728 | return true ;
|
|---|
| 729 |
|
|---|
| 730 | } // else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeUpdate) )
|
|---|
| 731 |
|
|---|
| 732 | //
|
|---|
| 733 | // bye messages to say goodbye
|
|---|
| 734 | //
|
|---|
| 735 |
|
|---|
| 736 | else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeBye)){
|
|---|
| 737 |
|
|---|
| 738 | logging_debug( "baseoverlay received message of type OverlayMessageTypeBye" );
|
|---|
| 739 |
|
|---|
| 740 | logging_debug( "received bye message from " <<
|
|---|
| 741 | overlayMsg->getSourceNode().toString() );
|
|---|
| 742 |
|
|---|
| 743 | //
|
|---|
| 744 | // if we are the initiator and receive a bye from a node
|
|---|
| 745 | // the node just left. if we are a node and receive a bye
|
|---|
| 746 | // from the initiator, we have to close, too.
|
|---|
| 747 | //
|
|---|
| 748 |
|
|---|
| 749 | if( overlayMsg->getSourceNode() == spovnetInitiator ){
|
|---|
| 750 |
|
|---|
| 751 | bc.dropLink( initiatorLink );
|
|---|
| 752 | initiatorLink = LinkID::UNSPECIFIED;
|
|---|
| 753 | state = BaseOverlayStateInvalid;
|
|---|
| 754 |
|
|---|
| 755 | logging_fatal( "initiator ended spovnet" );
|
|---|
| 756 |
|
|---|
| 757 | // inform all registered services of the event
|
|---|
| 758 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 759 | i->onOverlayDestroy( spovnetId );
|
|---|
| 760 | }
|
|---|
| 761 |
|
|---|
| 762 | } else {
|
|---|
| 763 |
|
|---|
| 764 | // a node that said goodbye and we are the initiator
|
|---|
| 765 | // don't have to do much here, as the node also
|
|---|
| 766 | // will go out of the overlay structure
|
|---|
| 767 | logging_info( "node left " << overlayMsg->getSourceNode() );
|
|---|
| 768 |
|
|---|
| 769 | // inform all registered services of the event
|
|---|
| 770 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 771 | i->onNodeLeave( overlayMsg->getSourceNode(), spovnetId );
|
|---|
| 772 | }
|
|---|
| 773 | }
|
|---|
| 774 |
|
|---|
| 775 | return true;
|
|---|
| 776 |
|
|---|
| 777 | } // else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeBye))
|
|---|
| 778 |
|
|---|
| 779 | //
|
|---|
| 780 | // something wrong ...
|
|---|
| 781 | //
|
|---|
| 782 |
|
|---|
| 783 | else {
|
|---|
| 784 |
|
|---|
| 785 | logging_error( "received message in invalid state! don't know " <<
|
|---|
| 786 | "what to do with this message of type " <<
|
|---|
| 787 | overlayMsg->getType() );
|
|---|
| 788 | return false;
|
|---|
| 789 |
|
|---|
| 790 | } // else
|
|---|
| 791 |
|
|---|
| 792 | return false;
|
|---|
| 793 | }
|
|---|
| 794 |
|
|---|
| 795 | void BaseOverlay::broadcastMessage(Message* message, const ServiceID& service){
|
|---|
| 796 |
|
|---|
| 797 | logging_debug( "broadcasting message to all known nodes " <<
|
|---|
| 798 | "in the overlay from service " + service.toString() );
|
|---|
| 799 |
|
|---|
| 800 | OverlayInterface::NodeList nodes = overlayInterface->getKnownNodes();
|
|---|
| 801 |
|
|---|
| 802 | OverlayInterface::NodeList::iterator i = nodes.begin();
|
|---|
| 803 | OverlayInterface::NodeList::iterator iend = nodes.end();
|
|---|
| 804 |
|
|---|
| 805 | for( ; i != iend; i++ ){
|
|---|
| 806 | if( *i == nodeId) continue; // don't send to ourselfs
|
|---|
| 807 | sendMessage( message, *i, service ); // TODO: sollte auto links aufbauen fÃŒr sowas
|
|---|
| 808 | }
|
|---|
| 809 | }
|
|---|
| 810 |
|
|---|
| 811 | void BaseOverlay::updateOvlVis( const NodeID& n ) {
|
|---|
| 812 | NodeID node = n;
|
|---|
| 813 | /* void visShowNodeBubble (
|
|---|
| 814 | NETWORK_ID network,
|
|---|
| 815 | NodeID& node,
|
|---|
| 816 | string label
|
|---|
| 817 | );
|
|---|
| 818 | */
|
|---|
| 819 | using namespace std;
|
|---|
| 820 |
|
|---|
| 821 | if (node == nodeId || node.isUnspecified()) return;
|
|---|
| 822 |
|
|---|
| 823 | // min/max
|
|---|
| 824 | if ( node < min || min.isUnspecified() ) min = node;
|
|---|
| 825 | if ( node > max || max.isUnspecified() ) max = node;
|
|---|
| 826 |
|
|---|
| 827 | // successor
|
|---|
| 828 | if ( succ.isUnspecified() || (node > nodeId && (succ < nodeId || (node-nodeId) < (succ-nodeId))) ) {
|
|---|
| 829 | if (!succ.isUnspecified() && node != succ)
|
|---|
| 830 | ovl.visDisconnect(ovlId, nodeId, succ, string(""));
|
|---|
| 831 | succ = node;
|
|---|
| 832 | ovl.visConnect(ovlId, nodeId, succ, string(""));
|
|---|
| 833 | }
|
|---|
| 834 |
|
|---|
| 835 | // set successor (circle-wrap)
|
|---|
| 836 | if (succ.isUnspecified() && !min.isUnspecified()) {
|
|---|
| 837 | succ = min;
|
|---|
| 838 | ovl.visConnect(ovlId, nodeId, succ, string(""));
|
|---|
| 839 | }
|
|---|
| 840 | }
|
|---|
| 841 |
|
|---|
| 842 | const NodeID& BaseOverlay::getNodeID(const LinkID& lid) const {
|
|---|
| 843 |
|
|---|
| 844 | if( lid == LinkID::UNSPECIFIED ) return nodeId;
|
|---|
| 845 |
|
|---|
| 846 | LinkMapping::const_iterator i = linkMapping.find( lid );
|
|---|
| 847 | if( i == linkMapping.end() ) return NodeID::UNSPECIFIED;
|
|---|
| 848 | else return i->second.node;
|
|---|
| 849 | }
|
|---|
| 850 |
|
|---|
| 851 | void BaseOverlay::incomingRouteMessage(Message* msg){
|
|---|
| 852 | // gets handled as normal data message
|
|---|
| 853 | // TODO: passt das so?
|
|---|
| 854 | receiveMessage( msg, LinkID::UNSPECIFIED, NodeID::UNSPECIFIED );
|
|---|
| 855 | }
|
|---|
| 856 |
|
|---|
| 857 | void BaseOverlay::onNodeJoin(const NodeID& node){
|
|---|
| 858 |
|
|---|
| 859 | JoiningNodes::iterator i = std::find( joiningNodes.begin(), joiningNodes.end(), node );
|
|---|
| 860 | if( i == joiningNodes.end() ) return;
|
|---|
| 861 |
|
|---|
| 862 | logging_info( "node has successfully joined baseoverlay and overlay structure "
|
|---|
| 863 | << node.toString() );
|
|---|
| 864 |
|
|---|
| 865 | BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
|
|---|
| 866 | i->onNodeJoin( node, spovnetId );
|
|---|
| 867 | }
|
|---|
| 868 |
|
|---|
| 869 | joiningNodes.erase( i );
|
|---|
| 870 | }
|
|---|
| 871 |
|
|---|
| 872 | void BaseOverlay::eventFunction(){
|
|---|
| 873 |
|
|---|
| 874 | list<LinkID> oldlinks;
|
|---|
| 875 | time_t now = time(NULL);
|
|---|
| 876 |
|
|---|
| 877 | // first gather all the links from linkMapping that need droppin
|
|---|
| 878 | // don't directly drop, as the dropLink function affects the
|
|---|
| 879 | // linkMapping structure that we are traversing here.
|
|---|
| 880 | // drop links after a timeout of 30s
|
|---|
| 881 |
|
|---|
| 882 | // the macro gets confused if type is passed directly
|
|---|
| 883 | // because of the comma in the pair definition
|
|---|
| 884 | typedef pair<LinkID,LinkItem> pairitem;
|
|---|
| 885 |
|
|---|
| 886 | BOOST_FOREACH( pairitem item, linkMapping ){
|
|---|
| 887 | if( item.second.autolink && difftime(now, item.second.lastuse) > 30)
|
|---|
| 888 | oldlinks.push_back( item.first );
|
|---|
| 889 | }
|
|---|
| 890 |
|
|---|
| 891 | BOOST_FOREACH( const LinkID lnk, oldlinks ){
|
|---|
| 892 | dropLink( lnk );
|
|---|
| 893 | }
|
|---|
| 894 | }
|
|---|
| 895 |
|
|---|
| 896 | }} // namespace ariba, overlay
|
|---|