Index: /source/ariba/Makefile.am
===================================================================
--- /source/ariba/Makefile.am	(revision 7727)
+++ /source/ariba/Makefile.am	(revision 7744)
@@ -415,4 +415,5 @@
   utility/types/Locator.cpp \
   utility/types/NodeID.cpp \
+  utility/types/PeerID.cpp \
   utility/types/OverlayParameterSet.cpp \
   utility/types/QoSParameterSet.cpp \
@@ -429,4 +430,5 @@
   utility/types/Locator.h \
   utility/types/NodeID.h \
+  utility/types/PeerID.h \
   utility/types/OverlayParameterSet.h \
   utility/types/QoSParameterSet.h \
Index: /source/ariba/communication/BaseCommunication.cpp
===================================================================
--- /source/ariba/communication/BaseCommunication.cpp	(revision 7727)
+++ /source/ariba/communication/BaseCommunication.cpp	(revision 7744)
@@ -38,5 +38,7 @@
 
 #include "BaseCommunication.h"
+
 #include "networkinfo/AddressDiscovery.h"
+#include "ariba/utility/types/PeerID.h"
 
 #ifdef UNDERLAY_OMNET
@@ -52,4 +54,6 @@
 namespace ariba {
 namespace communication {
+
+using ariba::utility::PeerID;
 
 use_logging_cpp(BaseCommunication);
@@ -100,4 +104,8 @@
 	currentSeqnum = 0;
 
+	// set local peer id
+	localDescriptor.getPeerId() = PeerID::random();
+	logging_info( "Using PeerID: " << localDescriptor.getPeerId() );
+
 	// creating transports
 	logging_info( "Creating transports ..." );
@@ -114,6 +122,9 @@
 
 	logging_info( "Searching for local locators ..." );
-	if(localDescriptor.getEndpoints().to_string().length() == 0)
-		AddressDiscovery::discover_endpoints( localDescriptor.getEndpoints() );
+	/**
+	 * DONT DO THAT: if(localDescriptor.getEndpoints().to_string().length() == 0)
+	 * since addresses are used to initialize transport addresses
+	 */
+	AddressDiscovery::discover_endpoints( localDescriptor.getEndpoints() );
 	logging_info( "Done. Local endpoints = " << localDescriptor.toString() );
 
@@ -177,4 +188,5 @@
 	AribaBaseMsg baseMsg( AribaBaseMsg::typeLinkRequest, linkid );
 	baseMsg.getLocalDescriptor() = localDescriptor;
+	baseMsg.getRemoteDescriptor().getPeerId() = descriptor.getPeerId();
 
 	// serialize and send message
@@ -338,4 +350,15 @@
 			logging_debug( "Received link open request" );
 
+			/// not the correct peer id-> skip request
+			if (!msg->getRemoteDescriptor().getPeerId().isUnspecified()
+				&& msg->getRemoteDescriptor().getPeerId() != localDescriptor.getPeerId()) {
+				logging_info("Received link request for "
+					<< msg->getRemoteDescriptor().getPeerId().toString()
+					<< "but i'm "
+					<< localDescriptor.getPeerId()
+					<< ": Ignoring!");
+				break;
+			}
+
 			/// only answer the first request
 			if (!queryRemoteLink(msg->getLocalLink()).isUnspecified()) {
Index: /source/ariba/communication/EndpointDescriptor.h
===================================================================
--- /source/ariba/communication/EndpointDescriptor.h	(revision 7727)
+++ /source/ariba/communication/EndpointDescriptor.h	(revision 7744)
@@ -43,4 +43,5 @@
 #include <set>
 #include "ariba/utility/serialization.h"
+#include "ariba/utility/types/PeerID.h"
 #include "ariba/utility/addressing/endpoint_set.hpp"
 
@@ -51,4 +52,5 @@
 using namespace std;
 using namespace ariba::addressing;
+using ariba::utility::PeerID;
 
 class EndpointDescriptor: public VSerializeable { VSERIALIZEABLE
@@ -120,6 +122,17 @@
 	}
 
+	/// returns a reference to the peer id
+	PeerID& getPeerId() {
+		return peerId;
+	}
+
+
+	/// returns a reference to the constant peer id
+	const PeerID& getPeerId() const {
+		return peerId;
+	}
 private:
 	endpoint_set endpoints;
+	PeerID peerId;
 };
 
@@ -127,5 +140,9 @@
 
 sznBeginDefault( ariba::communication::EndpointDescriptor, X ){
-	// serialize endpoints
+
+	// serialize peer id
+	X && &peerId;
+
+	// serialize end-points
 	uint16_t len = endpoints.to_bytes_size();
 	X && len;
Index: /source/ariba/communication/networkinfo/AddressDiscovery.cpp
===================================================================
--- /source/ariba/communication/networkinfo/AddressDiscovery.cpp	(revision 7727)
+++ /source/ariba/communication/networkinfo/AddressDiscovery.cpp	(revision 7744)
@@ -107,4 +107,8 @@
 		if (addr==NULL) continue;
 
+		// ignore tun devices
+		string device = string(i->ifa_name);
+		if(device.find_first_of("tun") == 0) continue;
+
 		if (addr->sa_family == AF_INET) {
 			// look for ipv4
Index: /source/ariba/overlay/BaseOverlay.cpp
===================================================================
--- /source/ariba/overlay/BaseOverlay.cpp	(revision 7727)
+++ /source/ariba/overlay/BaseOverlay.cpp	(revision 7744)
@@ -135,5 +135,5 @@
 		for (vector<ValueEntry>::iterator i = values.begin();
 				i != values.end(); i++ )
-			if (i->is_ttl_elapsed()) i = values.erase(i);
+			if (i->is_ttl_elapsed()) i = values.erase(i)-1;
 	}
 };
@@ -214,5 +214,5 @@
 			// found? yes-> delete entry
 			if ( equals(entry.key, key) ) {
-				i = entries.erase(i);
+				i = entries.erase(i)-1;
 				return true;
 			}
@@ -233,5 +233,5 @@
 					// value found? yes-> delete
 					if (equals(j->get_value(), value)) {
-						j = entry.values.erase(j);
+						j = entry.values.erase(j)-1;
 						return true;
 					}
@@ -252,8 +252,8 @@
 				// value found? yes-> delete
 				if (j->is_ttl_elapsed())
-					j = entry.values.erase(j);
+					j = entry.values.erase(j)-1;
 			}
 
-			if (entry.values.size()==0) i = entries.erase(i);
+			if (entry.values.size()==0) i = entries.erase(i)-1;
 		}
 	}
@@ -1911,9 +1911,13 @@
 			"in the overlay from service " + service.toString() );
 
+	if(message == NULL) return;
+	message->setReleasePayload(false);
+
 	OverlayInterface::NodeList nodes = overlayInterface->getKnownNodes(true);
-	OverlayInterface::NodeList::iterator i = nodes.begin();
-	for(; i != nodes.end(); i++ ) {
-		if( *i == nodeId) continue; // don't send to ourselfs
-		sendMessage( message, *i, service );
+	for(size_t i=0; i<nodes.size(); i++){
+		NodeID& id = nodes.at(i);
+		if(id == this->nodeId) continue; // don't send to ourselfs
+		if(i+1 == nodes.size()) message->setReleasePayload(true); // release payload on last send
+		sendMessage( message, id, service );
 	}
 }
Index: /source/ariba/overlay/modules/chord/Chord.cpp
===================================================================
--- /source/ariba/overlay/modules/chord/Chord.cpp	(revision 7727)
+++ /source/ariba/overlay/modules/chord/Chord.cpp	(revision 7744)
@@ -250,8 +250,15 @@
 		logging_info("new routing neighbor: " << remote.toString()
 				<< " with link " << lnk.toString());
-		// replace with new link
-		if (item->info!=lnk && item->info.isUnspecified()==false)
-			baseoverlay.dropLink(item->info);
-		item->info = lnk;
+
+		// replace with new link if link is "better"
+		if (item->info!=lnk && item->info.isUnspecified()==false) {
+			if (baseoverlay.compare( item->info, lnk ) == 1) {
+				logging_info("Replacing link due to concurrent link establishment.");
+				baseoverlay.dropLink(item->info);
+				item->info = lnk;
+			}
+		} else {
+			item->info = lnk;
+		}
 
 		// discover neighbors of new overlay neighbor
Index: /source/ariba/utility/types/PeerID.cpp
===================================================================
--- /source/ariba/utility/types/PeerID.cpp	(revision 7744)
+++ /source/ariba/utility/types/PeerID.cpp	(revision 7744)
@@ -0,0 +1,55 @@
+// [License]
+// The Ariba-Underlay Copyright
+//
+// Copyright (c) 2008-2009, Institute of Telematics, UniversitÃ€t Karlsruhe (TH)
+//
+// Institute of Telematics
+// UniversitÃ€t Karlsruhe (TH)
+// Zirkel 2, 76128 Karlsruhe
+// Germany
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// The views and conclusions contained in the software and documentation
+// are those of the authors and should not be interpreted as representing
+// official policies, either expressed or implied, of the Institute of
+// Telematics.
+// [License]
+
+#include "PeerID.h"
+
+namespace ariba {
+namespace utility {
+
+const PeerID PeerID::UNSPECIFIED;
+
+PeerID::PeerID() {
+}
+
+PeerID::PeerID(const Identifier& identifier) : Identifier(identifier){
+}
+
+PeerID::~PeerID() {
+}
+
+}} // namespace ariba, common
Index: /source/ariba/utility/types/PeerID.h
===================================================================
--- /source/ariba/utility/types/PeerID.h	(revision 7744)
+++ /source/ariba/utility/types/PeerID.h	(revision 7744)
@@ -0,0 +1,60 @@
+// [License]
+// The Ariba-Underlay Copyright
+//
+// Copyright (c) 2008-2009, Institute of Telematics, UniversitÃ€t Karlsruhe (TH)
+//
+// Institute of Telematics
+// UniversitÃ€t Karlsruhe (TH)
+// Zirkel 2, 76128 Karlsruhe
+// Germany
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// The views and conclusions contained in the software and documentation
+// are those of the authors and should not be interpreted as representing
+// official policies, either expressed or implied, of the Institute of
+// Telematics.
+// [License]
+
+#ifndef __PEERID_H
+#define __PEERID_H
+
+#include "ariba/utility/types/Identifier.h"
+
+namespace ariba {
+namespace utility {
+
+class PeerID : public Identifier {
+public:
+
+	static const PeerID UNSPECIFIED;
+
+	PeerID();
+	PeerID(const Identifier& identifier);
+	virtual ~PeerID();
+
+};
+
+}} // namespace ariba, common
+
+#endif // __PEERID_H
