Index: source/ariba/overlay/modules/chord/Chord.cpp
===================================================================
--- source/ariba/overlay/modules/chord/Chord.cpp	(revision 3696)
+++ source/ariba/overlay/modules/chord/Chord.cpp	(revision 3699)
@@ -49,6 +49,6 @@
 
 typedef chord_routing_table::item route_item;
-use_logging_cpp( Chord )
-;
+
+use_logging_cpp( Chord );
 
 Chord::Chord(BaseOverlay& _baseoverlay, const NodeID& _nodeid,
@@ -95,5 +95,4 @@
 	cmsg.encapsulate(&dmsg);
 	msg.encapsulate(&cmsg);
-	logging_debug("" << (int)cmsg.getType());
 	this->onMessage(&msg, NodeID::UNSPECIFIED, LinkID::UNSPECIFIED);
 }
@@ -150,5 +149,7 @@
 	OverlayInterface::NodeList nodelist;
 	for (size_t i = 0; i < table->size(); i++)
-		if ((*table)[i]->ref_count != 0) nodelist.push_back((*table)[i]->id);
+		if ((*table)[i]->ref_count != 0
+				&& !(*table)[i]->info.isUnspecified())
+			nodelist.push_back((*table)[i]->id);
 	return nodelist;
 }
@@ -161,16 +162,19 @@
 	route_item* item = table->insert(remote);
 
+
+	// item added to routing table?
+	if (item != NULL) { // yes-> add to routing table
+		logging_info("new routing neighbor: " << remote.toString()
+				<< " with link " << lnk.toString());
+		item->info = lnk;
+	} else { // no-> add orphan entry to routing table
+		logging_info("new orphan: " << remote.toString()
+				<< " with link " << lnk.toString());
+		table->insert_orphan(remote)->info = lnk;
+	}
+
 	if (!bootstrapLink.isUnspecified() && lnk == bootstrapLink) {
 		send_discovery_to(nodeid);
 		bootstrapLink = LinkID::UNSPECIFIED;
-	}
-
-	// item added to routing table?
-	if (item != NULL) { // yes-> add to routing table
-		logging_debug("new routing neighbor: " << remote.toString() );
-		item->info = lnk;
-	} else { // no-> add orphan entry to routing table
-		logging_debug("new orphan: " << remote.toString() );
-		table->insert_orphan(remote)->info = lnk;
 	}
 }
@@ -312,5 +316,10 @@
 		// leave
 	case M::leave: {
-		baseoverlay.dropLink(link);
+		if (link!=LinkID::UNSPECIFIED) {
+			route_item* item = table->get(remote);
+			if (item!=NULL) item->info = LinkID::UNSPECIFIED;
+			table->remove(remote);
+			baseoverlay.dropLink(link);
+		}
 		break;
 	}
@@ -319,21 +328,33 @@
 
 void Chord::eventFunction() {
+	if (!LinkID::UNSPECIFIED.isUnspecified())
+		logging_error("LinkID::UNSPECIFIED not unspecified!!!!");
 	stabilize_counter++;
 	if (stabilize_counter == 3) {
+		size_t numNeighbors = 0;
+		for (size_t i = 0; i < table->size(); i++) {
+			route_item* it = (*table)[i];
+			if (it->ref_count != 0 && !it->info.isUnspecified()) numNeighbors++;
+		}
+		logging_info("Running stabilization: #links="
+				<< table->size() << " #neighbors=" << numNeighbors );
 		stabilize_counter = 0;
 		stabilize_finger = ((stabilize_finger+1) % table->get_finger_table_size() );
-		logging_debug("sending discovery message to my neighbors");
-		send_discovery_to(nodeid);
-		send_discovery_to(
-			table->get_finger_table(stabilize_finger).get_compare().get_center()
-		);
+		logging_debug("Sending discovery message to my neighbors and fingers");
+		NodeID disc1 = nodeid;
+		NodeID disc2 =
+			table->get_finger_table(stabilize_finger).get_compare().get_center();
+		send_discovery_to(disc1);
+		if (disc1 != disc2) send_discovery_to(disc2);
 		orphan_removal_counter++;
 		if (orphan_removal_counter == 2) {
+			logging_info("Running orphan removal");
 			orphan_removal_counter = 0;
 			for (size_t i = 0; i < table->size(); i++) {
 				route_item* it = (*table)[i];
 				if (it->ref_count == 0 && !it->info.isUnspecified()) {
+					logging_info("Dropping orphaned link " << it->info.toString() << " to " << it->id.toString());
 					baseoverlay.dropLink(it->info);
-					logging_debug("dropping orphaned link " << it->info.toString() << " to " << it->id.toString());
+					it->info = LinkID::UNSPECIFIED;
 				}
 			}
@@ -341,7 +362,9 @@
 	}
 	logging_debug("--- chord routing information ----------------------------------");
-	logging_debug("predecessor: " << (table->get_predesessor()==NULL? "<none>" : table->get_predesessor()->toString()) );
+	logging_debug("predecessor: " << (table->get_predesessor()==NULL? "<none>" :
+		table->get_predesessor()->toString()) );
 	logging_debug("node_id    : " << nodeid.toString() );
-	logging_debug("successor  : " << (table->get_successor()==NULL? "<none>" : table->get_successor()->toString()));
+	logging_debug("successor  : " << (table->get_successor()==NULL? "<none>" :
+		table->get_successor()->toString()));
 	logging_debug("----------------------------------------------------------------");
 }
