This commit is contained in:
parent
30614ad733
commit
3b58b086d3
13 changed files with 29 additions and 79 deletions
1
src/TODO
1
src/TODO
|
@ -1,2 +1,3 @@
|
||||||
dans la RFC, indiquer si le temps commence à 0 ou à 1
|
dans la RFC, indiquer si le temps commence à 0 ou à 1
|
||||||
indiquer si l'index de la machine commence à 0 ou à 1
|
indiquer si l'index de la machine commence à 0 ou à 1
|
||||||
|
envoyer les messages au highreceiver
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Clock {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual TimeStamp inc() = 0;
|
virtual TimeStamp inc() = 0;
|
||||||
virtual void adjust(TimeStamp timestamp) = 0;
|
virtual bool adjust(TimeStamp timestamp) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,6 +20,6 @@ TimeStamp ClockAb::inc(){
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClockAb::adjust(TimeStamp ts){
|
bool ClockAb::adjust(TimeStamp ts){
|
||||||
printf("ClockAb::adjust -- NOT IMPLEMENTED\n");
|
printf("ClockAb::adjust -- NOT IMPLEMENTED\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ class ClockAb : public Clock {
|
||||||
ClockAb(size_t index);
|
ClockAb(size_t index);
|
||||||
|
|
||||||
virtual TimeStamp inc();
|
virtual TimeStamp inc();
|
||||||
virtual void adjust(TimeStamp stamp);
|
virtual bool adjust(TimeStamp stamp);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,7 +18,14 @@ ClockCb::ClockCb(size_t size, size_t index){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClockCb::adjust(TimeStamp ts){
|
bool ClockCb::adjust(TimeStamp ts){
|
||||||
|
bool result = false;
|
||||||
|
// lock jusqu'a la fin de la fonction
|
||||||
|
Glib::Mutex::Lock lock(_mutex);
|
||||||
|
// si les conditions sont remplies, alors on peut modifier l'horloge
|
||||||
|
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeStamp ClockCb::inc(){
|
TimeStamp ClockCb::inc(){
|
||||||
|
|
|
@ -13,7 +13,7 @@ class ClockCb : public Clock {
|
||||||
ClockCb(size_t size, size_t index);
|
ClockCb(size_t size, size_t index);
|
||||||
|
|
||||||
virtual TimeStamp inc();
|
virtual TimeStamp inc();
|
||||||
virtual void adjust(TimeStamp stamp);
|
virtual bool adjust(TimeStamp stamp);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,6 +10,6 @@ TimeStamp ClockTest::inc(){
|
||||||
//prin
|
//prin
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClockTest::adjust(TimeStamp ts){
|
bool ClockTest::adjust(TimeStamp ts){
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class ClockTest : public Clock {
|
||||||
public:
|
public:
|
||||||
ClockTest(); //int truc, int truc);
|
ClockTest(); //int truc, int truc);
|
||||||
virtual TimeStamp inc();
|
virtual TimeStamp inc();
|
||||||
virtual void adjust(TimeStamp stamp);
|
virtual bool adjust(TimeStamp stamp);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -122,7 +122,7 @@ bool Config::isValid() {
|
||||||
}
|
}
|
||||||
valid++;
|
valid++;
|
||||||
|
|
||||||
if (_index > 0) {
|
if (_index >= 0) {
|
||||||
score++;
|
score++;
|
||||||
}
|
}
|
||||||
valid++;
|
valid++;
|
||||||
|
|
|
@ -30,7 +30,7 @@ int main(int argc, char ** argv){
|
||||||
Clock * clk;
|
Clock * clk;
|
||||||
|
|
||||||
short portHigh = -1;
|
short portHigh = -1;
|
||||||
HighReceiver high_receiver;
|
HighReceiver high_receiver(config.getPort()+1);
|
||||||
portHigh = high_receiver.getPort();
|
portHigh = high_receiver.getPort();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,12 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
HighReceiver::HighReceiver(){
|
HighReceiver::HighReceiver(short low_port){
|
||||||
|
|
||||||
printf("LowReceiver::LowReceiver --");
|
printf("LowReceiver::LowReceiver --");
|
||||||
|
|
||||||
|
_port = low_port + 1;
|
||||||
|
|
||||||
_socket_desc = socket(AF_INET, SOCK_DGRAM, 0);
|
_socket_desc = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
|
||||||
/* et l'autre variante : AF_UNIX */
|
/* et l'autre variante : AF_UNIX */
|
||||||
|
@ -29,7 +31,7 @@ HighReceiver::HighReceiver(){
|
||||||
// port_high = interne
|
// port_high = interne
|
||||||
bzero(_socket_addr,sizeof(sockaddr_in));
|
bzero(_socket_addr,sizeof(sockaddr_in));
|
||||||
_socket_addr->sin_family = AF_INET;
|
_socket_addr->sin_family = AF_INET;
|
||||||
_socket_addr->sin_port = 0; //FIXME random port ?
|
_socket_addr->sin_port = htons(_port);
|
||||||
_socket_addr->sin_addr.s_addr = htonl(INADDR_ANY);
|
_socket_addr->sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
|
||||||
// chopper une socket
|
// chopper une socket
|
||||||
|
@ -39,7 +41,6 @@ HighReceiver::HighReceiver(){
|
||||||
fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__);
|
fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
//FIXME: initialiser le port
|
|
||||||
}
|
}
|
||||||
|
|
||||||
short HighReceiver::getPort(){
|
short HighReceiver::getPort(){
|
||||||
|
|
|
@ -9,7 +9,7 @@ class HighReceiver {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
public:
|
public:
|
||||||
HighReceiver();
|
HighReceiver(short low_port);
|
||||||
~HighReceiver();
|
~HighReceiver();
|
||||||
|
|
||||||
void run(); // thread part
|
void run(); // thread part
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
|
|
||||||
void LowReceiver::manage_cbcast(Message * mesg) {
|
void LowReceiver::manage_cbcast(Message * mesg) {
|
||||||
static std::list<MessageCellCb *> fifo_get;
|
static std::list<MessageCellCb *> fifo_undelivered;
|
||||||
static std::list<MessageCellCb *> fifo_send;
|
//static std::list<MessageCellCb *> fifo_send;
|
||||||
|
|
||||||
std::list<MessageCellCb *>::iterator iter;
|
std::list<MessageCellCb *>::iterator iter;
|
||||||
printf("LowReceiver::manage_cbcast -- init\n");
|
printf("LowReceiver::manage_cbcast -- init\n");
|
||||||
|
@ -19,76 +19,17 @@ void LowReceiver::manage_cbcast(Message * mesg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iAmTheEmitter){
|
if (iAmTheEmitter){
|
||||||
printf("LowReceiver::manage_cbcast - Received my own message \n");
|
printf("LowReceiver::manage_cbcast - Received my own message -- delivering automatically\n");
|
||||||
//on faire la gestion du cbcast/send ici, c'est plus simple que
|
//on faire la gestion du cbcast/send ici, c'est plus simple que
|
||||||
//de partager une variable+mutex avec le sender
|
//de partager une variable+mutex avec le sender
|
||||||
|
|
||||||
//FIXME: chercher si l'on a déja recu ce message
|
|
||||||
MessageCellCb * 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
|
|
||||||
MessageCellCb * 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 MessageCellCb();
|
|
||||||
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 {
|
} else {
|
||||||
printf("LowReceiver::manage_cbcast - Received a message from a friend\n");
|
printf("LowReceiver::manage_cbcast - Received a message from a friend\n");
|
||||||
for (iter = fifo_get.begin(); iter != fifo_get.end(); iter++){
|
// FIXME: si l'horloge est ajustable
|
||||||
MessageCellCb * cur = *iter;
|
// (donc les contraintes TS_m[j] = TS_m[j]+1 && ... ),
|
||||||
if (cur->message == mesg) {
|
// alors on délivre directement
|
||||||
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
|
|
||||||
MessageCellCb * cell = new MessageCellCb();
|
|
||||||
cell->message = new Message(*mesg);
|
|
||||||
cell->type = MessageCellCb::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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue