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