108 lines
3.6 KiB
C++
108 lines
3.6 KiB
C++
/*
|
|
* File: PeerIDToTaMap.h
|
|
*
|
|
* Author: gschneid
|
|
*
|
|
* Created on September 18, 2012, 2:12 PM
|
|
*/
|
|
#pragma once
|
|
|
|
#ifndef PEERIDTOTAMAP_H
|
|
#define PEERIDTOTAMAP_H
|
|
|
|
#include "common/Exception.h"
|
|
#include "common/transport/TransportAddress.h"
|
|
#include "common/container/PairQueue.h"
|
|
#include "common/container/PeerIDList.h"
|
|
|
|
#include <serializable.h>
|
|
|
|
namespace ubeeme {
|
|
namespace moversight {
|
|
|
|
/**
|
|
* @class PeerIDToTaMap
|
|
* @brief Provides a queue to store elements of the kind <PeerID, TransportAddress> to save
|
|
* the needed pairs for the shortened roster to oversend when a rejoin is started.
|
|
* @author Grit Schneider
|
|
* @ingroup Moversight
|
|
*/
|
|
class PeerIDToTaMap : public PairQueue<PeerID, TransportAddress>, public Serializable {
|
|
public:
|
|
|
|
/**
|
|
* @brief Adds the given object with the correct key to the queue.
|
|
* @throws LogicException - because its not possible to get the needed information to add
|
|
* both parameters out of one of them.
|
|
*/
|
|
void add(TransportAddress /* ta */) {
|
|
throw LogicException("Not working here - 2 parameters(peerID and Transportaddress) needed to add an entry!");
|
|
}//End
|
|
|
|
/**
|
|
* @brief Adds the given key and value to the queue.
|
|
* @param pID The key to add - here its the PeerID.
|
|
* @param ta The value to add with its key - here its the transportaddress which has maybe changed.
|
|
*/
|
|
void add(PeerID pID, TransportAddress ta) {
|
|
PairQueue<PeerID, TransportAddress>::add(pID, ta);
|
|
}
|
|
|
|
/**
|
|
* @brief Getting only the peerIDList, not the whole map.
|
|
* @return PeerIDlist.
|
|
*/
|
|
PeerIDList getPeerIDList() {
|
|
PeerIDList pIdList;
|
|
for (size_t i = 0; i < size(); i++) {
|
|
pIdList.add(getKey(i));
|
|
}
|
|
return pIdList;
|
|
}
|
|
|
|
/**
|
|
* @brief Getting only all the transportaddresses.
|
|
* @return List of TransportAddresses.
|
|
*/
|
|
List<TransportAddress> getTransportAddressList() {
|
|
List<TransportAddress> taList;
|
|
for (size_t i = 0; i < size(); i++) {
|
|
taList.add(get(i));
|
|
}
|
|
return taList;
|
|
}
|
|
|
|
/**
|
|
* @brief Setting the archive for serialization issues.
|
|
* @param archive - the archive to add it into.
|
|
*/
|
|
void set(Archive &archive){
|
|
if (archive.isReading()) {
|
|
std::vector<PeerID> tempPeerIDList;
|
|
std::vector<TransportAddress> tempTaList;
|
|
archive(tempPeerIDList);
|
|
archive(tempTaList);
|
|
|
|
PeerIDList pIDList;
|
|
pIDList.add(tempPeerIDList);
|
|
|
|
List<TransportAddress> taList;
|
|
taList.add(tempTaList);
|
|
|
|
for (size_t i = 0;i< pIDList.size(); i++) {
|
|
add(pIDList.get(i), taList.get(i));
|
|
}
|
|
}//End if
|
|
else {
|
|
std::vector<PeerID> tempPeerIDList = getPeerIDList().getInternal();
|
|
archive(tempPeerIDList);
|
|
std::vector<TransportAddress> tempTaList = getTransportAddressList().getInternal();
|
|
archive(tempTaList);
|
|
}//end else
|
|
}
|
|
};
|
|
}
|
|
}
|
|
#endif /* REDUCEDROSTERQUEUE_H */
|
|
|