Index: source/ariba/overlay/BaseOverlay.cpp
===================================================================
--- source/ariba/overlay/BaseOverlay.cpp	(revision 2473)
+++ source/ariba/overlay/BaseOverlay.cpp	(revision 2483)
@@ -69,4 +69,8 @@
 // 		ovl.visChangeNodeIcon(ovlId, nodeId, OvlVis::ICON_ID_CHARACTER_W);
 // 	}
+
+	// timer for auto link management
+	Timer::setInterval( 5000 );
+	Timer::start();
 }
 
@@ -75,4 +79,5 @@
 	logging_info("deleting base overlay");
 
+	Timer::stop();
 	bc.unregisterMessageReceiver( this );
 	bc.unregisterEventListener( this );
@@ -147,17 +152,22 @@
 	//
 	// create the overlay
-	// and bootstrap against ourselfs
 	//
 
 	overlayInterface->createOverlay();
+	BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+		i->onOverlayCreate( spovnetId );
+	}
+
+	//
+	// bootstrap against ourselfs
+	//
+
 	overlayInterface->joinOverlay();
+	BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+		i->onJoinSuccess( spovnetId );
+	}
 
 	ovl.visChangeNodeIcon ( ovlId, nodeId, OvlVis::ICON_ID_CAMERA );
 	ovl.visChangeNodeColor( ovlId, nodeId, OvlVis::NODE_COLORS_GREEN);
-
-	// inform all registered services of the event
-	BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
-		i->onOverlayCreate( spovnetId );
-	}
 }
 
@@ -245,4 +255,5 @@
 	overmsg.encapsulate( const_cast<Message*>(message) );
 
+	i->second.markused();
 	return bc.sendMessage( link, &overmsg );
 }
@@ -263,9 +274,23 @@
 
 	if( link == LinkID::UNSPECIFIED ){
-		logging_error( "no link could be found to send message to node " <<
-				node.toString() << " for service " << service.toString() );
-		return -1;
-	}
-
+
+		logging_info( "no link could be found to send message to node " <<
+				node.toString() << " for service " << service.toString() <<
+				". creating auto link ...");
+		
+		const LinkID link = establishLink( node, service );
+		LinkMapping::iterator i = linkMapping.find( link );
+
+		if( i == linkMapping.end() ){
+			logging_error( "failed to establish auto link to node " << node.toString() <<
+					" for service " << service.toString() );
+			return -1;
+		}
+
+		i->second.autolink = true;
+
+	} // if( link != LinkID::UNSPECIFIED )
+
+	i->second.markused();
 	return sendMessage( message, link );
 }
@@ -352,6 +377,12 @@
 				" on link " << id.toString() );
 
-		OverlayMsg overMsg( OverlayMsg::OverlayMessageTypeUpdate, i->second.service, nodeId );
+		OverlayMsg overMsg( 
+			OverlayMsg::OverlayMessageTypeUpdate, 
+			i->second.service, 
+			nodeId 
+			);
+
 		bc.sendMessage( id, &overMsg );
+		i->second.markused();
 
 	} // if( i == linkMapping.end() )
@@ -397,4 +428,6 @@
 	if( i->second.interface != NULL )
 		i->second.interface->onLinkChanged( id, nodeId, i->second.node );
+
+	i->second.markused();
 }
 
@@ -412,4 +445,6 @@
 	if( i->second.interface != NULL )
 		i->second.interface->onLinkFail( id, nodeId, i->second.node );
+
+	i->second.markused();
 }
 
@@ -427,4 +462,6 @@
 	if( i->second.interface != NULL )
 		i->second.interface->onLinkQoSChanged( id, nodeId, i->second.node, qos );
+
+	i->second.markused();
 }
 
@@ -434,4 +471,8 @@
 	OverlayMsg* overlayMsg = ((Message*)message)->decapsulate<OverlayMsg>();
 	if( overlayMsg == NULL ) return false;
+
+	// mark the link as in action
+	LinkMapping::iterator item = linkMapping.find( link );
+	if( item != linkMapping.end() ) item->second.markused();
 
 	//
@@ -683,4 +724,5 @@
 		i->second.interface = iface;
 		iface->onLinkUp( link, nodeId, sourcenode );
+		i->second.markused();
 
 		return true ;
@@ -828,3 +870,27 @@
 }
 
+void BaseOverlay::eventFunction(){
+
+	list<LinkID> oldlinks;
+	time_t now = time(NULL);
+
+	// first gather all the links from linkMapping that need droppin
+	// don't directly drop, as the dropLink function affects the
+	// linkMapping structure that we are traversing here.
+	// drop links after a timeout of 30s
+
+	// the macro gets confused if type is passed directly
+	// because of the comma in the pair definition
+	typedef pair<LinkID,LinkItem> pairitem; 
+
+	BOOST_FOREACH( pairitem item, linkMapping ){
+		if( item.second.autolink && difftime(now, item.second.lastuse) > 30)
+			oldlinks.push_back( item.first );
+	}
+
+	BOOST_FOREACH( const LinkID lnk, oldlinks ){
+		dropLink( lnk );
+	}
+}
+
 }} // namespace ariba, overlay
