This commit is contained in:
parent
5be15863d3
commit
28a4348365
4 changed files with 48 additions and 20 deletions
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
#include "macros.h"
|
||||||
#include "clock_cb.h"
|
#include "clock_cb.h"
|
||||||
|
|
||||||
ClockCb::ClockCb(size_t size, size_t index){
|
ClockCb::ClockCb(size_t size, size_t index){
|
||||||
|
@ -49,6 +50,8 @@ bool ClockCb::adjust(TimeStamp ts){
|
||||||
// si les deux conditions sont respectées, on met à jour l'horloge...
|
// si les deux conditions sont respectées, on met à jour l'horloge...
|
||||||
_ticks[emit_idx] = _ticks[emit_idx] + 1;
|
_ticks[emit_idx] = _ticks[emit_idx] + 1;
|
||||||
printf("ClockCb::adjust -- time update _ticks[%d] = %d\n", emit_idx, _ticks[emit_idx]);
|
printf("ClockCb::adjust -- time update _ticks[%d] = %d\n", emit_idx, _ticks[emit_idx]);
|
||||||
|
} else {
|
||||||
|
printf("ClockCb::adding -- %scannot adjust%s ... \n", COLOR_RED, COLOR_NORMAL);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
20
src/group.cc
20
src/group.cc
|
@ -72,10 +72,27 @@ void Group::broadcast(Message & msg){
|
||||||
printf("Group::broadcast -- enter\n");
|
printf("Group::broadcast -- enter\n");
|
||||||
std::vector<sockaddr_in *>::iterator saIter;
|
std::vector<sockaddr_in *>::iterator saIter;
|
||||||
|
|
||||||
|
std::list<int> raList;
|
||||||
|
// choisir aléatoirement l'ordre des sites recepteurs
|
||||||
for (int index = 0; index < _addrs.size(); index++){
|
for (int index = 0; index < _addrs.size(); index++){
|
||||||
this->sendto(msg, index);
|
raList.push_back(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while(raList.size() > 0){
|
||||||
|
int r=rand() % raList.size();
|
||||||
|
|
||||||
|
std::list<int>::iterator it;
|
||||||
|
it = raList.begin();
|
||||||
|
for (int i=0; i<r; i++){
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Sending to %d\n", *it);
|
||||||
|
this->sendto(msg, *it);
|
||||||
|
|
||||||
|
raList.remove(*it);
|
||||||
|
}
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
printf("Group::broadcast -- exit\n");
|
printf("Group::broadcast -- exit\n");
|
||||||
}
|
}
|
||||||
|
@ -98,6 +115,7 @@ void Group::sendto(Message &msg, short index){
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
printf("Group::sendto -- got mesg\n");
|
printf("Group::sendto -- got mesg\n");
|
||||||
|
|
||||||
|
sleep(1); //FIXME: de-activate
|
||||||
if ((en = ::sendto(_socket_desc,
|
if ((en = ::sendto(_socket_desc,
|
||||||
message,
|
message,
|
||||||
message_len,
|
message_len,
|
||||||
|
|
|
@ -13,21 +13,23 @@ LowSender::LowSender(Group &grp, Clock &clk, Protocol::Type type) : _group(grp),
|
||||||
void LowSender::run(){
|
void LowSender::run(){
|
||||||
// thread part
|
// thread part
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
for (int delay = 10; delay >= 0; delay-- ){
|
||||||
|
printf("\rLowSender::run -- Waiting %d seconds... ", delay);
|
||||||
|
fflush(stdout);
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
while(1){
|
while(1){
|
||||||
sleep(3);
|
sleep(1);
|
||||||
if (rand() % 3 == 0) {
|
printf("LowSender::run -- Broadcasting '%s'\n", MESSAGE);
|
||||||
printf("LowSender::run -- Broadcasting '%s'\n", MESSAGE);
|
TimeStamp ts = _clock.inc();
|
||||||
TimeStamp ts = _clock.inc();
|
pDEBUG("Timestamp done\n");
|
||||||
pDEBUG("Timestamp done\n");
|
|
||||||
|
|
||||||
Message msg(_type, ts, MESSAGE, strlen(MESSAGE));
|
Message msg(_type, ts, MESSAGE, strlen(MESSAGE));
|
||||||
pDEBUG("Mesg done and ready to send\n");
|
pDEBUG("Mesg done and ready to send\n");
|
||||||
|
|
||||||
_group.broadcast(msg);
|
_group.broadcast(msg);
|
||||||
pDEBUG("Mesg sent\n");
|
pDEBUG("Mesg sent\n");
|
||||||
} else {
|
|
||||||
pDEBUG("Not sending\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include "macros.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
|
||||||
#define DEBUG_INPUT 1
|
#define DEBUG_INPUT 0
|
||||||
#define DEBUG_OUTPUT 1
|
#define DEBUG_OUTPUT 0
|
||||||
|
|
||||||
|
#define DEBUG (DEBUG_INPUT || DEBUG_OUTPUT)
|
||||||
|
|
||||||
Message::Message(const Message & original){
|
Message::Message(const Message & original){
|
||||||
printf("Message::Message -- copy\n");
|
printf("Message::Message -- copy\n");
|
||||||
|
@ -138,18 +141,20 @@ char * Message::getRaw(){
|
||||||
char * result = new char[_size];
|
char * result = new char[_size];
|
||||||
memcpy(result, _raw, _size);
|
memcpy(result, _raw, _size);
|
||||||
|
|
||||||
printf("Message::getRaw -- hex: \n");
|
if (DEBUG){
|
||||||
for (int i=0; i < _size; i++){
|
pDEBUG("hex: \n");
|
||||||
printf("%#x ", result[i]);
|
for (int i=0; i < _size; i++){
|
||||||
|
printf("%#x ", result[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t Message::getRawSize(){
|
size_t Message::getRawSize(){
|
||||||
printf("Message::getRawSize -- %d\n",_size);
|
pDEBUG("%d\n",_size);
|
||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue