Index: source/ariba/overlay/BaseOverlay.cpp
===================================================================
--- source/ariba/overlay/BaseOverlay.cpp	(revision 3705)
+++ source/ariba/overlay/BaseOverlay.cpp	(revision 3712)
@@ -270,4 +270,5 @@
 	LinkMapping::iterator i = linkMapping.find( link );
 
+	// find the link item to drop
 	if( i == linkMapping.end() ){
 		logging_warn( "can't drop link, mapping unknown " << link.toString() );
@@ -275,9 +276,20 @@
 	}
 
+	LinkItem item = i->second;
+
+	// delete all queued messages
+	if( item.waitingmsg.size() > 0 ){
+
+		logging_warn( "dropping link " << link.toString() <<
+			" that has " << item.waitingmsg.size() << " waiting messages" );
+
+		item.deleteWaiting();
+	}
+
+	// erase the mapping and drop the link
 	linkMapping.erase( i );
-
-	LinkItem item = i->second;
 	bc->dropLink( link );
 
+	// tell sideports and listeners of the drop
 	item.interface->onLinkDown( link, item.node );
 	sideport->onLinkDown(link, this->nodeId, item.node, this->spovnetId );
@@ -287,4 +299,8 @@
 
 	logging_debug( "baseoverlay is sending data message on link " << link.toString() );
+
+	//
+	// get the mapping for this link
+	//
 
 	LinkMapping::iterator i = linkMapping.find( link );
@@ -294,9 +310,29 @@
 	}
 
-	OverlayMsg overmsg(
-		OverlayMsg::OverlayMessageTypeData,	i->second.service, nodeId );
+	i->second.markused();
+
+	//
+	// check if the link is up yet, if its an autlink queue message
+	//
+
+	if( !i->second.linkup ){
+
+		if( i->second.autolink ){
+			logging_info( "auto link " << link.toString() << " is not up yet, queueing message" );
+			i->second.waitingmsg.push_back( new Message(*message) );
+		} else {
+			logging_error("link " << link.toString() << " is not up yet, dropping message" );
+		}
+
+		return -1;
+	}
+
+	//
+	// send the message through the basecomm
+	//
+
+	OverlayMsg overmsg( OverlayMsg::OverlayMessageTypeData,	i->second.service, nodeId );
 	overmsg.encapsulate( const_cast<Message*>(message) );
 
-	i->second.markused();
 	return bc->sendMessage( link, &overmsg );
 }
@@ -308,4 +344,8 @@
 	LinkMapping::iterator i = linkMapping.begin();
 	LinkMapping::iterator iend = linkMapping.end();
+
+	//
+	// see if we find a link for this node and service destination
+	//
 
 	for( ; i != iend; i++ ){
@@ -316,4 +356,8 @@
 	}
 
+	//
+	// if we found no link, create an auto link
+	//
+
 	if( link == LinkID::UNSPECIFIED ){
 
@@ -322,6 +366,10 @@
 				". creating auto link ...");
 
+		// call basecomm to create a link
 		link = establishLink( node, service );
+
+		// this will call onlinkup on us, if everything worked we now have a mapping
 		LinkMapping::iterator i = linkMapping.find( link );
+		i->second.autolink = true;
 
 		if( i == linkMapping.end() || link == LinkID::UNSPECIFIED ){
@@ -330,6 +378,4 @@
 			return -1;
 		}
-
-		i->second.autolink = true;
 
 		logging_debug( "establishing autolink in progress to node "
@@ -531,4 +577,13 @@
 	sideport->onLinkDown( id, this->nodeId, i->second.node, this->spovnetId );
 
+	// delete all queued messages
+	if( i->second.waitingmsg.size() > 0 ){
+
+		logging_warn( "dropping link " << id.toString() <<
+			" that has " << i->second.waitingmsg.size() << " waiting messages" );
+
+		i->second.deleteWaiting();
+	}
+
 	linkMapping.erase( i );
 }
@@ -788,7 +843,5 @@
 
 		// update our link mapping information for this link
-		bool changed =
-			( i->second.node != sourcenode ) ||
-			( i->second.service != service );
+		bool changed = ( i->second.node != sourcenode ) || ( i->second.service != service );
 		i->second.node = sourcenode;
 		i->second.service = service;
@@ -818,14 +871,5 @@
 
 		// ask the service whether it wants to accept this link
-		if( iface->onLinkRequest(sourcenode) ){
-
-			logging_debug("link " << link.toString() <<
-					" has been accepted by service " << service.toString());
-
-			// call the notification functions
-			iface->onLinkUp( link, sourcenode );
-			sideport->onLinkUp( link, nodeId, sourcenode, this->spovnetId );
-
-		} else {
+		if( !iface->onLinkRequest(sourcenode) ){
 
 			logging_debug("link " << link.toString() <<
@@ -836,5 +880,30 @@
 			// drop the link
 			dropLink( link );
-		}
+
+			return true;
+		}
+
+		//
+		// link has been accepted, link is now up, send messages out first
+		//
+
+		i->second.linkup = true;
+		logging_debug("link " << link.toString() <<
+						" has been accepted by service " << service.toString() << " and is now up");
+
+		if( i->second.waitingmsg.size() > 0 ){
+			logging_info( "sending out queued messages on link " << link.toString() );
+
+			BOOST_FOREACH( Message* msg, i->second.waitingmsg ){
+				sendMessage( msg, link );
+				delete msg;
+			}
+
+			i->second.waitingmsg.clear();
+		}
+
+		// call the notification functions
+		iface->onLinkUp( link, sourcenode );
+		sideport->onLinkUp( link, nodeId, sourcenode, this->spovnetId );
 
 		return true;
