129 lines
5.0 KiB
C++
129 lines
5.0 KiB
C++
/*
|
|
* File: UnicastTransfer.h
|
|
* Author: jgaebler
|
|
*
|
|
* Created on October 25, 2012, 2:30 PM
|
|
*/
|
|
#pragma once
|
|
|
|
#ifndef UNICASTTRANSFER_H
|
|
#define UNICASTTRANSFER_H
|
|
|
|
#include "common/Defines.h"
|
|
#include "common/MoversightService.h"
|
|
|
|
#include "common/transport/MessageReference.h"
|
|
#include "UnicastMessageList.h"
|
|
#include "MessagReferenceCircularBuffer.h"
|
|
#include "timer/UnicastMessageRetransmitTimerQueue.h"
|
|
|
|
namespace ubeeme {
|
|
namespace moversight {
|
|
|
|
class Moversight;
|
|
class Dispatcher;
|
|
class UnicastMessage;
|
|
class UnicastMessageConfirm;
|
|
class UnicastMessageRetransmitTimer;
|
|
|
|
/**
|
|
* @class UnicastTransfer
|
|
* @author Jan Gäbler, Robert Noack
|
|
* @brief This service provides simple a unicast message transfer service for moversight.
|
|
* @ingroup Moversight
|
|
*
|
|
* This service provides a generic interface for reliable and unreliable message delivery
|
|
* from the local peer to any other network entity, such as other peers within the current
|
|
* group identified by an unique peer ID or external hosts only specified through their
|
|
* transport address.
|
|
* Whether a message is delivered reliable or unreliable is specified by a simple flag
|
|
* contained in the chosen method call. Messages sent without this flag either do not
|
|
* require an explicit confirmation PDU or confirmations are handled by the upper layer.
|
|
* Instead, if an explicit confirmation PDU is required, a single corresponding
|
|
* retransmission timer is created and set which will trigger the retransmission of PDU
|
|
* several times if necessary without the knowledge of any upper layer.
|
|
* The upper layer service will be informed when the transmission was either successful
|
|
* or unsuccessful. This is accomplished with direct event delivery offered by the dispatcher
|
|
* as part of the event system.
|
|
*
|
|
* Note that the reliable delivery is not necessary when confirmations are provided by
|
|
* a different mechanism in upper layer services, e.g. LT and GT exchange.
|
|
*
|
|
* Roadmap
|
|
* * override sendX methods from MoversightService
|
|
* * add awareness for messages containing the reliable flag
|
|
* * cleanup retransmission timer and message queue implementations
|
|
* * make the service store messages that are to be retransmitted
|
|
*/
|
|
class UnicastTransfer : public MoversightService {
|
|
public:
|
|
|
|
UnicastTransfer( Dispatcher & dis);
|
|
virtual ~UnicastTransfer();
|
|
|
|
virtual void initialise();
|
|
virtual void finalise();
|
|
|
|
UnicastTransfer & operator=(const UnicastTransfer & other);
|
|
|
|
// handle an incoming UTMessage
|
|
void handleMessage( UnicastMessage & pdu);
|
|
// handle an incoming UTMessageConfirm
|
|
void handleMessage( UnicastMessageConfirm & pdu);
|
|
|
|
// send a MoversightMessage to PeerID
|
|
virtual MessageReference send( UnicastMessage & msg, const PeerID & destination);
|
|
// send a MoversightMessage to TransportAddress
|
|
virtual MessageReference send( UnicastMessage & msg, const TransportAddress & destination);
|
|
|
|
// handle retransmission timeout
|
|
void handleTimeout(UnicastMessageRetransmitTimer * timer);
|
|
|
|
// handle group join
|
|
virtual void handleEvent( const JoinGroupDoneEvent& e);
|
|
|
|
// send a message (un)reliable to a certain transport address
|
|
void send( const MoversightMessage& pdu, const TransportAddress& dest, const bool reliable);
|
|
|
|
private:
|
|
// send a confirmation
|
|
void confirmReceivedMessage(UnicastMessage & pdu);
|
|
|
|
// deliver the message to the upper layer
|
|
void deliverMessage(UnicastMessage & msg);
|
|
|
|
// create and start a new retransmission timer
|
|
void createAndStartTimer(MessageReference & mRef);
|
|
|
|
// stop and delete an existing retransmission timer
|
|
void stopAndDeleteTimer(MessageReference const & mRef);
|
|
|
|
// store the message for retransmission
|
|
void storeMessage(UnicastMessage & msg);
|
|
|
|
// remove the message from the retransmission queue
|
|
void deleteMessage(MessageReference const & mRef);
|
|
|
|
private:
|
|
// create a new message reference
|
|
MessageReference createMesssageReference();
|
|
|
|
// the current message reference. might change when joining a group.
|
|
MessageReference currentMessageReference;
|
|
|
|
// messages stored for retransmission
|
|
UnicastMessageList retransmitMessageQueue;
|
|
|
|
// started timer. those correspond directly to stored messages
|
|
UnicastMessageRetransmitTimerQueue retransmitTimerQueue;
|
|
|
|
// ?? not in use :P
|
|
MessageReferenceCircularBuffer lastSeenMessageReferences;
|
|
|
|
};
|
|
}
|
|
}
|
|
|
|
#endif /* UNICASTTRANSFER_H */
|
|
|