150 lines
4.5 KiB
C++
150 lines
4.5 KiB
C++
|
|
#include "SplitAnnounce.h"
|
|
|
|
#include "Dispatcher.h"
|
|
#include "common/validator/MessageValidator.h"
|
|
#include "fd/NetworkFailureDetector.h"
|
|
|
|
namespace ubeeme {
|
|
namespace moversight {
|
|
|
|
/**
|
|
* @brief Default Constructor
|
|
*/
|
|
SplitAnnounce::SplitAnnounce() : MulticastMessage("SPA", SPA), options(0) {
|
|
}
|
|
|
|
/**
|
|
* @brief Copy Constructor
|
|
* @param other The instance to copy
|
|
*/
|
|
SplitAnnounce::SplitAnnounce(const SplitAnnounce &other) : MulticastMessage(other) {
|
|
operator =(other);
|
|
}
|
|
|
|
/**
|
|
* @brief Assignment operator
|
|
* @param other The instance to assign.
|
|
* @return A reference to the local instance.
|
|
*/
|
|
SplitAnnounce &
|
|
SplitAnnounce::operator=(const SplitAnnounce & other) {
|
|
|
|
if (this == &other) return *this;
|
|
MulticastMessage::operator=(other);
|
|
|
|
options = other.options;
|
|
|
|
splitPeers.clear();
|
|
splitPeers.add( other.splitPeers);
|
|
|
|
return *this;
|
|
}
|
|
|
|
/**
|
|
* @brief Destructor
|
|
*/
|
|
SplitAnnounce::~SplitAnnounce() {
|
|
}
|
|
|
|
/**
|
|
* @brief Duplicate method. Creates a copy of the current message.
|
|
* @return The copy of the current instance.
|
|
*/
|
|
SplitAnnounce *
|
|
SplitAnnounce::dup() const {
|
|
return new SplitAnnounce(*this);
|
|
}
|
|
|
|
/**
|
|
* @brief Handles this message. To handle a message, it has first successfully validated.
|
|
* @param dis A reference to the dispatcher, used to forward this message to the handling modules.
|
|
*/
|
|
void
|
|
SplitAnnounce::handleReceive(Dispatcher & dis) {
|
|
//validate the message
|
|
if (dis.getMessageValidator()->isValid(*this)) {
|
|
//notify the NFD about ongoing traffic
|
|
dis.getNetworkFailureDetector().handleMessage(this);
|
|
//handle the message
|
|
dis.getMessageTransfer().handleMessage(this);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Handles the message delivering. To deliver a message, the message to each module which is interested in this message.
|
|
* @param dis A reference to the dispatcher, used to forward this message to the handling modules.
|
|
* @param missedPeers A list of peers, which have missed this message, as they are pending.
|
|
* @throw FlushModeException If while a flush an other split occurs
|
|
*/
|
|
void
|
|
SplitAnnounce::handleDeliver(Dispatcher & dis, const PeerIDList & missedPeers) {
|
|
//store the message for re-synchronization
|
|
dis.getMobilitySupport().storeMessage(*this);
|
|
//process the message
|
|
dis.getSplitService().handleSplitAnnounceMessage(*this, missedPeers);
|
|
}
|
|
|
|
/**
|
|
* @brief Gets the split options
|
|
* @return returns the split options
|
|
*/
|
|
unsigned char
|
|
SplitAnnounce::getOptions() const {
|
|
return options;
|
|
}
|
|
|
|
/**
|
|
* @brief Sets the split options
|
|
* @param options The split options to be set
|
|
*/
|
|
void
|
|
SplitAnnounce::setOptions(unsigned char options) {
|
|
this->options = options;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Gets the PeerIDList of the peers wanting to split.
|
|
* @return the PeerIDList of the splitting peers.
|
|
*/
|
|
const PeerIDList &
|
|
SplitAnnounce::getSplitPeers() const {
|
|
return splitPeers;
|
|
}
|
|
|
|
/**
|
|
* @brief Sets the PeerIDList of the splitting peers.
|
|
* @param splitPeers The list of the peerIDs of the splitting peers
|
|
*/
|
|
void
|
|
SplitAnnounce::setSplitPeers(const PeerIDList& splitPeers) {
|
|
this->splitPeers = splitPeers;
|
|
}
|
|
|
|
/**
|
|
* @brief Archive method.
|
|
* @param archive The archive to which the attributes are to add
|
|
*/
|
|
void
|
|
SplitAnnounce::set(Archive & archive) {
|
|
MulticastMessage::set(archive);
|
|
|
|
archive( const_cast<PeerIDList&>( getSplitPeers()));
|
|
|
|
if( archive.isReading()) {
|
|
char options;
|
|
archive( (int8&) options);
|
|
setOptions(options);
|
|
}//End if
|
|
else{
|
|
char options(getOptions());
|
|
archive((int8 &)options);
|
|
}//End else
|
|
|
|
archive(splitPeers);
|
|
|
|
}
|
|
}
|
|
}
|