Index: source/ariba/overlay/BaseOverlay.h
===================================================================
--- source/ariba/overlay/BaseOverlay.h	(revision 10653)
+++ source/ariba/overlay/BaseOverlay.h	(revision 12060)
@@ -47,5 +47,12 @@
 #include <vector>
 #include <deque>
+#include <stdexcept>
 #include <boost/foreach.hpp>
+
+#ifdef ECLIPSE_PARSER
+    #define foreach(a, b) for(a : b)
+#else
+    #define foreach(a, b) BOOST_FOREACH(a, b)
+#endif
 
 #include "ariba/utility/messages.h"
@@ -64,4 +71,5 @@
 #include "ariba/overlay/modules/OverlayStructureEvents.h"
 #include "ariba/overlay/OverlayBootstrap.h"
+#include "ariba/overlay/SequenceNumber.h"
 
 // forward declarations
@@ -92,4 +100,7 @@
 using ariba::communication::BaseCommunication;
 using ariba::communication::CommunicationEvents;
+
+// transport
+//using ariba::transport::system_priority;
 
 // utilities
@@ -103,5 +114,4 @@
 using ariba::utility::Demultiplexer;
 using ariba::utility::MessageReceiver;
-using ariba::utility::MessageSender;
 using ariba::utility::seqnum_t;
 using ariba::utility::Timer;
@@ -110,5 +120,19 @@
 namespace overlay {
 
-using namespace ariba::addressing;
+
+
+class message_not_sent: public std::runtime_error
+{
+public:
+    /** Takes a character string describing the error.  */
+    explicit message_not_sent(const string& __arg)  :
+        std::runtime_error(__arg)
+    {
+    }
+    
+    virtual ~message_not_sent() throw() {}
+};
+
+
 
 class LinkDescriptor;
@@ -121,5 +145,5 @@
 		protected Timer {
 
-	friend class OneHop;
+//	friend class OneHop;  // DEPRECATED
 	friend class Chord;
 	friend class ariba::SideportListener;
@@ -128,5 +152,4 @@
 
 public:
-
 	/**
 	 * Constructs an empty non-functional base overlay instance
@@ -142,5 +165,5 @@
 	 * Starts the Base Overlay instance
 	 */
-	void start(BaseCommunication& _basecomm, const NodeID& _nodeid);
+	void start(BaseCommunication* _basecomm, const NodeID& _nodeid);
 
 	/**
@@ -161,5 +184,5 @@
 	 * Starts a link establishment procedure to the specfied node
 	 * for the service with id service
-	 *
+	 * 
 	 * @param node Destination node id
 	 * @param service Service to connect to
@@ -179,10 +202,20 @@
 	void dropLink( const LinkID& link );
 
+	
+	
+	/* +++++ Message sending +++++ */
+	
+	
 	/// sends a message over an existing link
-	seqnum_t sendMessage(const Message* message, const LinkID& link );
+	const SequenceNumber& sendMessage(reboost::message_t message,
+	        const LinkID& link,
+	        uint8_t priority ) throw(message_not_sent);
 
 	/// sends a message to a node and a specific service
-	seqnum_t sendMessage(const Message* message, const NodeID& remote,
-		const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID);
+    const SequenceNumber& sendMessage(reboost::message_t message,
+	        const NodeID& remote,
+	        uint8_t priority,
+	        const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID);
+
 
     /**
@@ -191,6 +224,6 @@
      *  @return NodeID of the (closest) destination node; 
      */
-	NodeID sendMessageCloserToNodeID(const Message* message, const NodeID& address,
-	        const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID);
+	NodeID sendMessageCloserToNodeID(reboost::message_t message, const NodeID& address,
+	        uint8_t priority, const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID);
 	
 	/**
@@ -198,6 +231,11 @@
 	 * Depending on the structure of the overlay, this can be very different.
 	 */
-	void broadcastMessage(Message* message, const ServiceID& service);
-
+	void broadcastMessage(reboost::message_t message, const ServiceID& service, uint8_t priority);
+
+	
+	/* +++++ [Message sending] +++++ */
+	
+	
+	
 	/**
 	 * Returns the end-point descriptor of a link.
@@ -294,44 +332,59 @@
 	 */
 	void leaveSpoVNet();
+	
+	
+	/* link status */
+	bool isLinkDirect(const ariba::LinkID& lnk) const;
+	int getHopCount(const ariba::LinkID& lnk) const;
+
+    bool isLinkVital(const LinkDescriptor* link) const;
+    bool isLinkDirectVital(const LinkDescriptor* link) const;
 
 protected:
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual void onLinkUp(const LinkID& id, const address_v* local,
-		const address_v* remote);
-
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual void onLinkDown(const LinkID& id, const address_v* local,
-		const address_v* remote);
-
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual void onLinkChanged(const LinkID& id,
-		const address_v* oldlocal, const address_v* newlocal,
-		const address_v* oldremote, const address_v* newremote);
-
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual void onLinkFail(const LinkID& id, const address_v* local,
-		const address_v* remote);
-
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual void onLinkQoSChanged(const LinkID& id,
-		const address_v* local, const address_v* remote,
-		const QoSParameterSet& qos);
-
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual bool onLinkRequest(const LinkID& id, const address_v* local,
-		const address_v* remote);
-
+
+    /**
+     * @see ariba::communication::CommunicationEvents.h
+     */
+    virtual bool onLinkRequest(const LinkID& id,
+            const addressing2::EndpointPtr local,
+            const addressing2::EndpointPtr remote);
+
+    /**
+     * @see ariba::communication::CommunicationEvents.h
+     */
+    virtual void onLinkUp(const LinkID& id,
+            const addressing2::EndpointPtr local, const addressing2::EndpointPtr remote);
+
+    /**
+     * @see ariba::communication::CommunicationEvents.h
+     */
+    virtual void onLinkDown(const LinkID& id,
+            const addressing2::EndpointPtr local, const addressing2::EndpointPtr remote);
+
+    /**
+     * @see ariba::communication::CommunicationEvents.h
+     */
+    virtual void onLinkChanged(const LinkID& id,
+        const addressing2::EndpointPtr oldlocal,  const addressing2::EndpointPtr newlocal,
+        const addressing2::EndpointPtr oldremote, const addressing2::EndpointPtr newremote);
+
+    /**
+     * @see ariba::communication::CommunicationEvents.h
+     * 
+     * NOTE: Just calls onLinkDown (at the moment..)
+     */
+    virtual void onLinkFail(const LinkID& id,
+            const addressing2::EndpointPtr local, const addressing2::EndpointPtr remote);
+
+    /**
+     * @see ariba::communication::CommunicationEvents.h
+     */
+//    virtual void onLinkQoSChanged(const LinkID& id,
+//            const addressing2::EndpointPtr local, const addressing2::EndpointPtr remote,
+//            const QoSParameterSet& qos);
+
+	
+	
+	
 	/**
 	 * Processes a received message from BaseCommunication
@@ -340,6 +393,8 @@
 	 * the node the message came from!
 	 */
-	virtual bool receiveMessage( const Message* message, const LinkID& link,
-		const NodeID& );
+	virtual bool receiveMessage( reboost::shared_buffer_t message,
+	        const LinkID& link,
+	        const NodeID&,
+	        bool bypass_overlay );
 
 	/**
@@ -359,4 +414,12 @@
 	std::string getLinkHTMLInfo();
 
+
+private:
+	/// NOTE: "id" is an Overlay-LinkID
+	void __onLinkEstablishmentFailed(const LinkID& id);
+	
+	/// called from typeLinkClose-handler
+    void __removeDroppedLink(const LinkID& link);
+	
 private:
 	/// is the base overlay started yet
@@ -396,21 +459,26 @@
 
 	/// demultiplexes a incoming message with link descriptor
-	bool handleMessage( const Message* message, LinkDescriptor* ld,
+	bool handleMessage( reboost::shared_buffer_t message, LinkDescriptor* ld,
 		const LinkID bcLink = LinkID::UNSPECIFIED );
 
 	// handle data and signalling messages
-	bool handleData( OverlayMsg* msg, LinkDescriptor* ld );
+	bool handleData( reboost::shared_buffer_t message, OverlayMsg* msg, LinkDescriptor* ld );
+	bool handleLostMessage( reboost::shared_buffer_t message, OverlayMsg* msg );
 	bool handleSignaling( OverlayMsg* msg, LinkDescriptor* ld );
 
 	// handle join request / reply messages
-	bool handleJoinRequest( OverlayMsg* msg, const LinkID& bcLink );
-	bool handleJoinReply( OverlayMsg* msg, const LinkID& bcLink );
+	bool handleJoinRequest( reboost::shared_buffer_t message, const NodeID& source, const LinkID& bcLink );
+	bool handleJoinReply( reboost::shared_buffer_t message, const LinkID& bcLink );
 
 	// handle link messages
 	bool handleLinkRequest( OverlayMsg* msg, LinkDescriptor* ld );
-	bool handleLinkReply( OverlayMsg* msg, LinkDescriptor* ld );
+	bool handleLinkReply( OverlayMsg* msg, reboost::shared_buffer_t sub_message, LinkDescriptor* ld );
 	bool handleLinkUpdate( OverlayMsg* msg, LinkDescriptor* ld );
 	bool handleLinkDirect( OverlayMsg* msg, LinkDescriptor* ld );
 	bool handleLinkAlive( OverlayMsg* msg, LinkDescriptor* ld );
+    
+    // ping-pong over overlaypath/routing
+    bool handlePing( OverlayMsg* overlayMsg, LinkDescriptor* ld );
+    bool handlePong( OverlayMsg* overlayMsg, LinkDescriptor* ld );
 
 
@@ -478,24 +546,40 @@
 	// internal message delivery -----------------------------------------------
 
+    // Convert OverlayMessage into new format and give it down to BaseCommunication
+    seqnum_t send_overlaymessage_down( OverlayMsg* message, const LinkID& bc_link, uint8_t priority );
+
+    
 	/// routes a message to its destination node
-	void route( OverlayMsg* message );
-
+	void route( OverlayMsg* message, const NodeID& last_hop = NodeID::UNSPECIFIED );
+	
 	/// sends a raw message to another node, delivers it to the base overlay class
-	seqnum_t send( OverlayMsg* message, const NodeID& destination );
+	/// may throw "message_not_sent"-exception
+	seqnum_t send( OverlayMsg* message,
+                   const NodeID& destination,
+                   uint8_t priority,
+                const NodeID& last_hop = NodeID::UNSPECIFIED )
+    throw(message_not_sent);
 
 	/// send a raw message using a link descriptor, delivers it to the base overlay class
-	seqnum_t send( OverlayMsg* message, LinkDescriptor* ld,
-		bool ignore_down = false );
+	seqnum_t send( OverlayMsg* message,
+	        LinkDescriptor* ld,
+	        uint8_t priority ) throw(message_not_sent);
 
 	/// send a message using a node id using overlay routing
 	/// sets necessary fields in the overlay message!
-	seqnum_t send_node( OverlayMsg* message, const NodeID& remote,
-		const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID);
+	/// may throw "message_not_sent"-exception
+	seqnum_t send_node( OverlayMsg* message, const NodeID& remote, uint8_t priority,
+		const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID) throw(message_not_sent);
 
 	/// send a message using a node id using overlay routing using a link
 	/// sets necessary fields in the overlay message!
-	seqnum_t send_link( OverlayMsg* message, const LinkID& link,
-		bool ignore_down = false );
-
+	void send_link( OverlayMsg* message,
+	        const LinkID& link,
+	        uint8_t priority ) throw(message_not_sent);
+
+	
+	/// sends a notification to a sender from whom we just dropped a message
+	void report_lost_message( const OverlayMsg* message );
+	
 	// misc --------------------------------------------------------------------
 
