Index: source/ariba/overlay/BaseOverlay.h
===================================================================
--- source/ariba/overlay/BaseOverlay.h	(revision 3374)
+++ source/ariba/overlay/BaseOverlay.h	(revision 3690)
@@ -1,3 +1,3 @@
-// [Licence]
+// [License]
 // The Ariba-Underlay Copyright
 //
@@ -35,5 +35,5 @@
 // official policies, either expressed or implied, of the Institute of
 // Telematics.
-// [Licence]
+// [License]
 
 #ifndef BASEOVERLAY_H_
@@ -62,16 +62,13 @@
 #include "ariba/overlay/modules/OverlayFactory.h"
 #include "ariba/overlay/modules/OverlayStructureEvents.h"
-#include "ariba/overlay/messages/OverlayMsg.h"
-#include "ariba/overlay/messages/JoinRequest.h"
-#include "ariba/overlay/messages/JoinReply.h"
-
-// forward declerations
+
+// forward declarations
 namespace ariba {
-	class NodeListener;
-	class CommunicationListener;
-	class SideportListener;
-	namespace utility {
-		class OvlVis;
-	}
+class NodeListener;
+class CommunicationListener;
+class SideportListener;
+namespace utility {
+class OvlVis;
+}
 }
 
@@ -87,15 +84,10 @@
 using ariba::CommunicationListener;
 
+// communication
 using ariba::communication::EndpointDescriptor;
 using ariba::communication::BaseCommunication;
 using ariba::communication::CommunicationEvents;
 
-using ariba::overlay::OverlayMsg;
-using ariba::overlay::JoinRequest;
-using ariba::overlay::JoinReply;
-using ariba::overlay::OverlayInterface;
-using ariba::overlay::OverlayFactory;
-using ariba::overlay::OverlayStructureEvents;
-
+// utilities
 using ariba::utility::NodeID;
 using ariba::utility::SpoVNetID;
@@ -118,12 +110,15 @@
 namespace overlay {
 
-class BaseOverlay :
-	public MessageReceiver,
-	public CommunicationEvents,
-	public OverlayStructureEvents,
-	protected Timer {
+class BaseOverlay: public MessageReceiver, public CommunicationEvents,
+	public OverlayStructureEvents, protected Timer {
+
+private:
+	friend class OneHop;
+	friend class Chord;
 
 	use_logging_h( BaseOverlay );
+
 public:
+
 	/**
 	 * Constructs an empty non-functional base overlay instance
@@ -139,5 +134,5 @@
 	 * Starts the Base Overlay instance
 	 */
-	void start( BaseCommunication& _basecomm, const NodeID& _nodeid );
+	void start(BaseCommunication& _basecomm, const NodeID& _nodeid);
 
 	/**
@@ -152,27 +147,27 @@
 	 * @param node Destination node id
 	 * @param service Service to connect to
-	 */
-	const LinkID establishLink( const NodeID& node, const ServiceID& service );
+	 * @param linkid Link identifier to be used with this link
+	 */
+	const LinkID establishLink(const NodeID& node, const ServiceID& service,
+			const LinkID& linkid = LinkID::UNSPECIFIED);
 
 	/**
 	 * Starts a link establishment procedure to the specified
+	 *
 	 * endpoint and to the specified service
 	 */
-	const LinkID establishLink( const EndpointDescriptor& ep, const ServiceID& service );
-
-	/**
-	 * TODO
-	 */
-	void  dropLink( const LinkID& link );
-
-	/**
-	 * TODO
-	 */
-	seqnum_t sendMessage( const Message* message, const LinkID& link );
-
-	/**
-	 * TODO
-	 */
-	seqnum_t sendMessage( const Message* message, const NodeID& node, const ServiceID& service );
+	const LinkID establishLink(const EndpointDescriptor& ep,
+			const ServiceID& service, const LinkID& linkid =
+					LinkID::UNSPECIFIED);
+
+	/// drops a link
+	void dropLink(const LinkID& link);
+
+	/// sends a message over an existing link
+	seqnum_t sendMessage(const Message* message, const LinkID& link);
+
+	/// sends a message to a node and a specific service
+	seqnum_t sendMessage(const Message* message, const NodeID& node,
+			const ServiceID& service);
 
 	/**
@@ -180,10 +175,5 @@
 	 * Depending on the structure of the overlay, this can be very different.
 	 */
-	void broadcastMessage( Message* message, const ServiceID& service );
-
-	/**
-	 * Get a list of overlay neighboring nodes.
-	 */
-	vector<NodeID> getOverlayNeighbors() const;
+	void broadcastMessage(Message* message, const ServiceID& service);
 
 	/**
@@ -193,39 +183,40 @@
 	 * @return The end-point descriptor of the link's end-point
 	 */
-	const EndpointDescriptor& getEndpointDescriptor( const LinkID& link = LinkID::UNSPECIFIED ) const;
-
-	/**
-	 * TODO
-	 */
-	const EndpointDescriptor& getEndpointDescriptor( const NodeID& node ) const;
-
-	/**
-	 * TODO
-	 */
+	const EndpointDescriptor& getEndpointDescriptor(const LinkID& link =
+			LinkID::UNSPECIFIED) const;
+
+	/**
+	 * Get a list of overlay neighbors.
+	 *
+	 * @return A list of overlay neighbors.
+	 */
+	vector<NodeID> getOverlayNeighbors() const;
+
+	/**
+	 * Returns a end-endpoint descriptor of a overlay neighbor.
+	 * If the node is not known -- an unspecified endpoint descriptor is
+	 * returned.
+	 *
+	 * @param node The node identifer of a overlay neighbor.
+	 * @return The end-point descriptor of the node or unspecified.
+	 */
+	const EndpointDescriptor& getEndpointDescriptor(const NodeID& node) const;
+
+	// TODO: Doc
 	bool bind(CommunicationListener* listener, const ServiceID& sid);
 
-	/**
-	 * TODO
-	 */
+	// TODO: Doc
 	bool unbind(CommunicationListener* listener, const ServiceID& sid);
 
-	/**
-	 * TODO
-	 */
+	// TODO: Doc
 	bool bind(NodeListener* listener);
 
-	/**
-	 * TODO
-	 */
+	// TODO: Doc
 	bool unbind(NodeListener* listener);
 
-	/**
-	 * TODO
-	 */
+	// TODO: Doc
 	bool registerSidePort(SideportListener* _sideport);
 
-	/**
-	 * TODO
-	 */
+	// TODO: Doc
 	bool unregisterSidePort(SideportListener* _sideport);
 
@@ -236,5 +227,5 @@
 	 * @return The NodeID of the link
 	 */
-	const NodeID& getNodeID( const LinkID& lid = LinkID::UNSPECIFIED ) const ;
+	const NodeID& getNodeID(const LinkID& lid = LinkID::UNSPECIFIED) const;
 
 	/**
@@ -245,23 +236,27 @@
 	 * @return a vector that contains all the link ids requested
 	 */
-	vector<LinkID> getLinkIDs( const NodeID& nid = NodeID::UNSPECIFIED ) const;
-
-	/**
-	 * TODO
-	 */
-	void joinSpoVNet( const SpoVNetID& id, const EndpointDescriptor& bootstrapEp );
-
-	/**
-	 * TODO
-	 */
-	void createSpoVNet(
-		const SpoVNetID& id,
-		const OverlayParameterSet& param = OverlayParameterSet::DEFAULT,
-		const SecurityParameterSet& sec  = SecurityParameterSet::DEFAULT,
-		const QoSParameterSet& qos = QoSParameterSet::DEFAULT
-	);
-
-	/**
-	 * TODO
+	vector<LinkID> getLinkIDs(const NodeID& nid = NodeID::UNSPECIFIED) const;
+
+	/**
+	 * Join a existing sponaneous virtual network (spovnet).
+	 *
+	 * @param id A spovnet identifier
+	 * @param boot A bootstrap node
+	 */
+	void joinSpoVNet(const SpoVNetID& id, const EndpointDescriptor& boot );
+
+	/**
+	 * Initiates a new spontaneous virtual network.
+	 * This makes this BaseOverlay to the SpoVNet-Initiator.
+	 *
+	 * @param id The spovnet identifier
+	 */
+	void createSpoVNet(const SpoVNetID& id, const OverlayParameterSet& param =
+			OverlayParameterSet::DEFAULT, const SecurityParameterSet& sec =
+			SecurityParameterSet::DEFAULT, const QoSParameterSet& qos =
+			QoSParameterSet::DEFAULT);
+
+	/**
+	 * Let the node leave the SpoVNet.
 	 */
 	void leaveSpoVNet();
@@ -272,57 +267,69 @@
 	 * @see ariba::communication::CommunicationEvents.h
 	 */
-	virtual void onLinkUp( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
-
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual void onLinkDown( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
-
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual void onLinkChanged( const LinkID& id, const NetworkLocator* oldlocal, const NetworkLocator* newlocal, const NetworkLocator* oldremote, const NetworkLocator* newremote );
-
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual void onLinkFail( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
-
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual void onLinkQoSChanged( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote, const QoSParameterSet& qos );
-
-	/**
-	 * @see ariba::communication::CommunicationEvents.h
-	 */
-	virtual bool onLinkRequest( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
+	virtual void onLinkUp(const LinkID& id, const NetworkLocator* local,
+			const NetworkLocator* remote);
+
+	/**
+	 * @see ariba::communication::CommunicationEvents.h
+	 */
+	virtual void onLinkDown(const LinkID& id, const NetworkLocator* local,
+			const NetworkLocator* remote);
+
+	/**
+	 * @see ariba::communication::CommunicationEvents.h
+	 */
+	virtual void onLinkChanged(const LinkID& id,
+			const NetworkLocator* oldlocal, const NetworkLocator* newlocal,
+			const NetworkLocator* oldremote, const NetworkLocator* newremote);
+
+	/**
+	 * @see ariba::communication::CommunicationEvents.h
+	 */
+	virtual void onLinkFail(const LinkID& id, const NetworkLocator* local,
+			const NetworkLocator* remote);
+
+	/**
+	 * @see ariba::communication::CommunicationEvents.h
+	 */
+	virtual void onLinkQoSChanged(const LinkID& id,
+			const NetworkLocator* local, const NetworkLocator* remote,
+			const QoSParameterSet& qos);
+
+	/**
+	 * @see ariba::communication::CommunicationEvents.h
+	 */
+	virtual bool onLinkRequest(const LinkID& id, const NetworkLocator* local,
+			const NetworkLocator* remote);
 
 	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	/**
+	 * Processes a received message.
+	 *
+	 * Beware: nodeid is not valid in this case! (since this class implements
+	 * nodeid's in the first place *g*)
+	 */
+	virtual bool receiveMessage(
+		const Message* message, const LinkID& link,	const NodeID&);
+
 	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-	/**
-	 * TODO
-	 */
-	virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& ); // nodeid is not valid in this case!
-
-	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-	/**
-	 * see OverlayStructureEvents.h, called from specific OverlayInterface class
-	 */
-	virtual void incomingRouteMessage( Message* msg );
-
-	/**
-	 * see OverlayStructureEvents.h, called from specific OverlayInterface class
-	 */
-	virtual void onNodeJoin( const NodeID& node );
-
-
-	/**
-	 * TODO, for timer events
+
+	/**
+	 * This method is called, when a routed message arrives from the
+	 * overlay.
+	 *
+	 * @see OverlayStructureEvents.h
+	 */
+	virtual void incomingRouteMessage(Message* msg);
+
+	/**
+	 * This method is called, when a new node joined the network
+	 *
+	 * @see OverlayStructureEvents.h
+	 */
+	virtual void onNodeJoin(const NodeID& node);
+
+	/**
+	 * Timer Event method
 	 */
 	virtual void eventFunction();
@@ -382,8 +389,8 @@
 	 */
 	typedef enum _BaseOverlayState {
-		BaseOverlayStateInvalid        = 0,
-		BaseOverlayStateInitiator      = 1,
-		BaseOverlayStateJoinInitiated  = 2,
-		BaseOverlayStateCompleted      = 3,
+		BaseOverlayStateInvalid = 0,
+		BaseOverlayStateInitiator = 1,
+		BaseOverlayStateJoinInitiated = 2,
+		BaseOverlayStateCompleted = 3,
 	} BaseOverlayState;
 
@@ -403,5 +410,5 @@
 	NodeID min, max;
 	NodeID succ, pred;
-	void updateOvlVis( const NodeID& node );
+	void updateOvlVis(const NodeID& node);
 
 	/**
@@ -412,14 +419,15 @@
 		static const LinkItem UNSPECIFIED;
 
-		LinkItem()
-			: link(LinkID::UNSPECIFIED), node(NodeID::UNSPECIFIED),
-				service(ServiceID::UNSPECIFIED), interface(&CommunicationListener::DEFAULT),
-				autolink(false), lastuse(0){
+		LinkItem() :
+			link(LinkID::UNSPECIFIED), node(NodeID::UNSPECIFIED), service(
+					ServiceID::UNSPECIFIED), interface(
+					&CommunicationListener::DEFAULT), autolink(false), lastuse(
+					0) {
 		}
 
-		LinkItem( const LinkID& _link, const NodeID& _node,
-				const ServiceID& _service, CommunicationListener* _interface )
-			: link( _link ), node( _node ), service( _service ), interface( _interface ),
-				autolink( false ), lastuse( time(NULL) ) {
+		LinkItem(const LinkID& _link, const NodeID& _node,
+				const ServiceID& _service, CommunicationListener* _interface) :
+			link(_link), node(_node), service(_service), interface(_interface),
+					autolink(false), lastuse(time(NULL)) {
 
 			assert( _interface != NULL );
@@ -434,6 +442,5 @@
 
 		// information needed for auto links
-
-		void markused(){
+		void markused() {
 			lastuse = time(NULL);
 		}
@@ -444,7 +451,10 @@
 
 	typedef map<const LinkID, LinkItem> LinkMapping;
-	typedef pair<const LinkID,LinkItem> LinkPair;
+	typedef pair<const LinkID, LinkItem> LinkPair;
 	LinkMapping linkMapping;
 
+	// map of a link request map a nonce to a LinkID
+	typedef map<const uint32_t, LinkID> PendingLinkMap;
+	PendingLinkMap pendingLinks;
 
 	/**
@@ -457,5 +467,6 @@
 };
 
-}} // namespace ariba, overlay
+}
+} // namespace ariba, overlay
 
 #endif /*BASEOVERLAY_H_*/
