This commit is contained in:
glenux 2006-03-04 14:31:32 +00:00
parent 749807ec3f
commit f922c0b92e
2 changed files with 100 additions and 0 deletions

View file

@ -79,3 +79,8 @@ Message_data :
~~~~~~~~~~~~~~
array of unsigned shorts (16 bits * Message_size)
Notes:
~~~~~~
Timestamps start at time = 0
Site indexes start at index = 1

95
src/lowreceiver_cb.cc Normal file
View file

@ -0,0 +1,95 @@
#include "lowreceiver.h"
#include "messagecell_ab.h"
void LowReceiver::manage_cbcast(Message * mesg) {
static std::list<MessageCellAb *> fifo_get;
static std::list<MessageCellAb *> fifo_send;
std::list<MessageCellAb *>::iterator iter;
printf("LowReceiver::manage_cbcast -- init\n");
// identifiant = horloge + id_site_emeteur
bool iAmTheEmitter = false;
bool firstSeenMessage = true;
if (mesg->getStamp().getIndex() == _group.getIndex()){
iAmTheEmitter = true;
}
if (iAmTheEmitter){
printf("LowReceiver::manage_cbcast - Received my own message \n");
//on faire la gestion du cbcast/send ici, c'est plus simple que
//de partager une variable+mutex avec le sender
//FIXME: chercher si l'on a déja recu ce message
MessageCellAb * cell = NULL;
for (iter = fifo_send.begin(); iter != fifo_send.end(); iter++){
//on fait pointer cell sur la cellule si égale a l'id du message
//courant
MessageCellAb * cur = *iter;
if (cur->message == mesg){
printf("LowReceiver::manage_cbcast -- message seen\n");
firstSeenMessage = false;
cell = cur;
break;
}
}
if (firstSeenMessage){
//sinon on le crée
printf("LowReceiver::manage_cbcast -- message is first\n");
cell = new MessageCellAb();
cell->message = new Message(*mesg);
//et on l'ajoute au fifo
fifo_send.push_back(cell);
}
//FIXME: comparer le timestamp max a ceux que l'on recoit
cell->count += 1;
if (cell->count == _group.getCount()){
// broadcaster le nouveau timestamp du message
//
// le message a broadcaster est exactement le message max
// reçu... mais bon... on le reconstruit quand m^eme
// IMPROVE
TimeStamp st = cell->message->getStamp();
Message * nMsg = new Message(Protocol::TYPE_ABCAST,
st,
cell->maximum->getRaw(),
cell->maximum->getRawSize());
_group.broadcast(*nMsg);
}
} else {
printf("LowReceiver::manage_cbcast - Received a message from a friend\n");
for (iter = fifo_get.begin(); iter != fifo_get.end(); iter++){
MessageCellAb * cur = *iter;
if (cur->message == mesg) {
printf("LowReceiver::manage_cbcast -- message seen\n");
firstSeenMessage = false;
break;
}
}
if (firstSeenMessage){
printf("LowReceiver::manage_cbcast -- message is first\n");
// si le message est vu pour la premiere fois:
// - on l'ajoute dans la liste d'attente
MessageCellAb * cell = new MessageCellAb();
cell->message = new Message(*mesg);
cell->type = MessageCellAb::TYPE_TEMPORARY;
// - on retourne une estampille(reception) a l'emeteur
} else {
// sinon
// - l'estampille du message est mise a jour
TimeStamp * stamp = new TimeStamp (Protocol::TYPE_ABCAST, mesg->getData(), mesg->getDataSize());
// - le message est marqué comme final
// - on défile les estampille finale la
}
}
}