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