This commit is contained in:
parent
36b156e5de
commit
38ae9f71b3
6 changed files with 74 additions and 34 deletions
|
@ -8,8 +8,9 @@ using namespace std;
|
||||||
|
|
||||||
Config::Config(int argc, char **argv) {
|
Config::Config(int argc, char **argv) {
|
||||||
_port = -1;
|
_port = -1;
|
||||||
|
_index = -1;
|
||||||
_mode = Protocol::TYPE_UNKNOWN;
|
_mode = Protocol::TYPE_UNKNOWN;
|
||||||
|
|
||||||
int groupPort;
|
int groupPort;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -22,13 +23,14 @@ Config::Config(int argc, char **argv) {
|
||||||
|
|
||||||
{"group", required_argument, 0, 'g'},
|
{"group", required_argument, 0, 'g'},
|
||||||
{"port", required_argument, 0, 'p'},
|
{"port", required_argument, 0, 'p'},
|
||||||
|
{"index", required_argument, 0, 'i'},
|
||||||
|
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
|
||||||
int c = getopt_long(argc, argv, "TACg:p:",
|
int c = getopt_long(argc, argv, "TACg:p:i:",
|
||||||
long_options, &option_index);
|
long_options, &option_index);
|
||||||
|
|
||||||
/* detect the end of options */
|
/* detect the end of options */
|
||||||
|
@ -55,6 +57,15 @@ Config::Config(int argc, char **argv) {
|
||||||
_mode = Protocol::TYPE_TEST;
|
_mode = Protocol::TYPE_TEST;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'i':
|
||||||
|
{
|
||||||
|
stringstream s;
|
||||||
|
printf("Index -> %s\n",optarg);
|
||||||
|
|
||||||
|
s << string(optarg);
|
||||||
|
s >> _index;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
{
|
{
|
||||||
stringstream s;
|
stringstream s;
|
||||||
|
@ -111,6 +122,11 @@ bool Config::isValid() {
|
||||||
}
|
}
|
||||||
valid++;
|
valid++;
|
||||||
|
|
||||||
|
if (_index > 0) {
|
||||||
|
score++;
|
||||||
|
}
|
||||||
|
valid++;
|
||||||
|
|
||||||
return (valid == score);
|
return (valid == score);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +138,10 @@ Protocol::Type Config::getMode(){
|
||||||
return _mode;
|
return _mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
short Config::getIndex(){
|
||||||
|
return _index;
|
||||||
|
}
|
||||||
|
|
||||||
int Config::getPort(){
|
int Config::getPort(){
|
||||||
return _port;
|
return _port;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ class Config {
|
||||||
std::list<HostId> _group_hosts;
|
std::list<HostId> _group_hosts;
|
||||||
int _port;
|
int _port;
|
||||||
Protocol::Type _mode;
|
Protocol::Type _mode;
|
||||||
|
short _index;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ class Config {
|
||||||
bool isValid();
|
bool isValid();
|
||||||
std::list<HostId> getGroupHosts();
|
std::list<HostId> getGroupHosts();
|
||||||
int getPort();
|
int getPort();
|
||||||
|
short getIndex();
|
||||||
Protocol::Type getMode();
|
Protocol::Type getMode();
|
||||||
};
|
};
|
||||||
#endif // _GYR_CONFIG_H
|
#endif // _GYR_CONFIG_H
|
||||||
|
|
|
@ -26,11 +26,11 @@ int main(int argc, char ** argv){
|
||||||
if (config.isValid()){
|
if (config.isValid()){
|
||||||
Glib::thread_init();
|
Glib::thread_init();
|
||||||
|
|
||||||
Group grp(config.getGroupHosts());
|
Group grp(config.getGroupHosts(), config.getIndex());
|
||||||
Clock * clk;
|
Clock * clk;
|
||||||
|
|
||||||
//FIXME non-dynamic port !
|
//FIXME non-dynamic port !
|
||||||
int portHigh = 2310;
|
int portHigh = 2710;
|
||||||
|
|
||||||
switch(config.getMode()){
|
switch(config.getMode()){
|
||||||
case Protocol::TYPE_TEST:
|
case Protocol::TYPE_TEST:
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
Group::Group(std::list<HostId> group){
|
Group::Group(std::list<HostId> group, short index){
|
||||||
_hosts = group;
|
_hosts = group;
|
||||||
_socket_desc = socket(AF_INET, SOCK_DGRAM, 0);
|
_socket_desc = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
_index = index;
|
||||||
|
|
||||||
/* et l'autre variante : AF_UNIX */
|
/* et l'autre variante : AF_UNIX */
|
||||||
if (_socket_desc < 0){
|
if (_socket_desc < 0){
|
||||||
|
@ -79,8 +80,11 @@ void Group::broadcast(Message & msg){
|
||||||
printf("Group::broadcast -- exit\n");
|
printf("Group::broadcast -- exit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
short Group::getIndex(){
|
||||||
|
return _index;
|
||||||
|
}
|
||||||
|
|
||||||
void Group::sendto(Message &msg, int index){
|
void Group::sendto(Message &msg, short index){
|
||||||
sockaddr_in * addr = _addrs[index];
|
sockaddr_in * addr = _addrs[index];
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
|
|
|
@ -27,13 +27,16 @@ class Group {
|
||||||
std::list<HostId> _hosts;
|
std::list<HostId> _hosts;
|
||||||
std::vector<sockaddr_in *> _addrs;
|
std::vector<sockaddr_in *> _addrs;
|
||||||
int _socket_desc;
|
int _socket_desc;
|
||||||
|
short _index;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
public:
|
public:
|
||||||
Group(std::list<HostId> group);
|
Group(std::list<HostId> group, short myindex);
|
||||||
|
|
||||||
void sendto(Message &msg, int index);
|
void sendto(Message &msg, short index);
|
||||||
void broadcast(Message &msg);
|
void broadcast(Message &msg);
|
||||||
|
short getIndex();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -72,7 +72,7 @@ void LowReceiver::run(){
|
||||||
strncpy(str, mesg->getData(), mesg->getDataSize());
|
strncpy(str, mesg->getData(), mesg->getDataSize());
|
||||||
str[mesg->getDataSize()] = '\0';
|
str[mesg->getDataSize()] = '\0';
|
||||||
printf("LowReceiver::run -- READ '%s'\n", str);
|
printf("LowReceiver::run -- READ '%s'\n", str);
|
||||||
|
|
||||||
this->manage(mesg);
|
this->manage(mesg);
|
||||||
|
|
||||||
delete(mesg);
|
delete(mesg);
|
||||||
|
@ -86,17 +86,17 @@ void LowReceiver::manage(Message * mesg){
|
||||||
switch(mesg->getType()){
|
switch(mesg->getType()){
|
||||||
case Protocol::TYPE_TEST :
|
case Protocol::TYPE_TEST :
|
||||||
{
|
{
|
||||||
printf("LowReceiver::manage -- NOT IMPLEMENTED\n");
|
printf("LowReceiver::manage -- NOT IMPLEMENTED\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Protocol::TYPE_ABCAST :
|
case Protocol::TYPE_ABCAST :
|
||||||
{
|
{
|
||||||
this->manage_abcast(mesg);
|
this->manage_abcast(mesg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Protocol::TYPE_CBCAST :
|
case Protocol::TYPE_CBCAST :
|
||||||
{
|
{
|
||||||
this->manage_cbcast(mesg);
|
this->manage_cbcast(mesg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -109,34 +109,45 @@ void LowReceiver::manage_abcast(Message * mesg) {
|
||||||
static std::list<MessageCellAb *> fifo;
|
static std::list<MessageCellAb *> fifo;
|
||||||
std::list<MessageCellAb *>::iterator iter;
|
std::list<MessageCellAb *>::iterator iter;
|
||||||
printf("LowReceiver::manage_abcast -- init\n");
|
printf("LowReceiver::manage_abcast -- init\n");
|
||||||
|
|
||||||
// FIXME: on suppose ne pas etre l'emetteur
|
|
||||||
// identifiant = horloge + id_site_emeteur
|
// identifiant = horloge + id_site_emeteur
|
||||||
bool firstSeenMessage = true;
|
bool firstSeenMessage = true;
|
||||||
for (iter = fifo.begin(); iter != fifo.end(); iter++){
|
bool iAmTheEmitter = false;
|
||||||
MessageCellAb * cur = *iter;
|
|
||||||
if (cur->message == mesg) {
|
if (mesg->getStamp().getIndex() == _group.getIndex()){
|
||||||
printf("LowReceiver::manage_abcast -- message seen\n");
|
iAmTheEmitter = true;
|
||||||
firstSeenMessage = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstSeenMessage){
|
if (iAmTheEmitter){
|
||||||
// si le message est vu pour la premiere fois:
|
printf("LowReceiver::manage_abcast - Received my own message \n");
|
||||||
// - on l'ajoute dans la liste d'attente
|
//FIXME: faire la gestion du abcast/send ici, c'est plus simple que
|
||||||
MessageCellAb * cell = new MessageCellAb();
|
//de partager une variable+mutex avec le sender
|
||||||
cell->message = new Message(*mesg); //FIXME: make a copy;
|
|
||||||
cell->type = MessageCellAb::TYPE_TEMPORARY;
|
|
||||||
// - on retourne une estampille(reception) a l'emeteur
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// sinon
|
for (iter = fifo.begin(); iter != fifo.end(); iter++){
|
||||||
// - l'estampille du message est mise a jour
|
MessageCellAb * cur = *iter;
|
||||||
TimeStamp * stamp = new TimeStamp (Protocol::TYPE_ABCAST, cell->message->getData(), cell->message->getDataSize());
|
if (cur->message == mesg) {
|
||||||
|
printf("LowReceiver::manage_abcast -- message seen\n");
|
||||||
|
firstSeenMessage = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// - le message est marqué comme final
|
if (firstSeenMessage){
|
||||||
// - on défile les estampille finale la
|
// 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); //FIXME: make a copy;
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue