From c0bad9b9bcc5067db73a360f73b6cb252c09e8e3 Mon Sep 17 00:00:00 2001 From: glenux Date: Wed, 1 Mar 2006 21:40:44 +0000 Subject: [PATCH] --- doc/my-rfc.txt | 12 +++++++++++- src/config.cc | 6 +++--- src/dabroadcast.cc | 7 ++++--- src/group.cc | 12 ++++++------ src/group.h | 4 ++++ src/highreceiver.cc | 9 +++++++-- src/highreceiver.h | 5 ++++- src/lowreceiver_ab.cc | 17 +++++++++++++++-- src/message.cc | 2 +- src/message.h | 2 +- src/messagecell_ab.cc | 2 ++ src/timestamp.cc | 2 +- src/timestamp.h | 2 +- 13 files changed, 60 insertions(+), 22 deletions(-) diff --git a/doc/my-rfc.txt b/doc/my-rfc.txt index 563ec3e..511b0ea 100644 --- a/doc/my-rfc.txt +++ b/doc/my-rfc.txt @@ -2,6 +2,16 @@ RFC : Multi-BroadCast Protocol (MBCP) ------------------------------------- +In the case of TEST : + nothing to say... + +In the case of ABCAST : + the first datagram (from emiter) contains the real message + the second datagram (from sites) contains the type/timestamp of the first datagram and + the new timestamp in the message part + the last datagram (from emiter) contains the type/timestamp of the first datagram and + the final official timestamp in the message part + Datagrams : ~~~~~~~~~~~ @@ -68,4 +78,4 @@ Message_size : unsigned short (16 bits) Message_data : ~~~~~~~~~~~~~~ array of unsigned shorts (16 bits * Message_size) - + diff --git a/src/config.cc b/src/config.cc index 165f1b3..8162f7d 100644 --- a/src/config.cc +++ b/src/config.cc @@ -79,7 +79,7 @@ Config::Config(int argc, char **argv) { { HostId g_host; string optstr(optarg); - stringstream s_host, s_port; + ///stringstream s_host, s_port; int idx = optstr.find(":"); if (idx > 0){ @@ -87,8 +87,8 @@ Config::Config(int argc, char **argv) { // on oblige la forme XXXXXX:YY - s_host << optstr.substr(0,idx); - s_host >> (g_host.host); + g_host.host = optstr.substr(0,idx); + //s_host >> (g_host.host); s_port << optstr.substr(idx+1, optstr.size()-idx-1); s_port >> (g_host.port); diff --git a/src/dabroadcast.cc b/src/dabroadcast.cc index def024f..d018005 100644 --- a/src/dabroadcast.cc +++ b/src/dabroadcast.cc @@ -29,8 +29,10 @@ int main(int argc, char ** argv){ Group grp(config.getGroupHosts(), config.getIndex()); Clock * clk; - //FIXME non-dynamic port ! - int portHigh = 2710; + short portHigh = -1; + HighReceiver high_receiver; + portHigh = high_receiver.getPort(); + switch(config.getMode()){ case Protocol::TYPE_TEST: @@ -56,7 +58,6 @@ int main(int argc, char ** argv){ exit(-1); break; } - HighReceiver high_receiver(portHigh); LowReceiver low_receiver(config.getPort(), portHigh, diff --git a/src/group.cc b/src/group.cc index 712710f..fecec1f 100644 --- a/src/group.cc +++ b/src/group.cc @@ -15,9 +15,8 @@ Group::Group(std::list group, short index){ /* error */ perror("Creation de la socket impossible"); fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__); - // FIXME: throw something - exit(-1); + throw new eGroupNotConstructed(); } struct sockaddr_in * myaddr = new sockaddr_in; @@ -31,7 +30,8 @@ Group::Group(std::list group, short index){ //FIXME : throw something perror("Attachement de la socket impossible"); fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__); - exit(-1); + + throw new eGroupNotConstructed(); } //FIXME: définir une liste avec les structures... @@ -54,8 +54,8 @@ Group::Group(std::list group, short index){ fprintf(stderr, "Erreur client : echec gethostbyname sur %s\n", hid.host.c_str()) ; - //FIXME: throw something - exit(-1); + + throw new eGroupNotConstructed(); } addr->sin_family = AF_INET; @@ -107,7 +107,7 @@ void Group::sendto(Message &msg, short index){ perror("sendto failed\n"); /* error */ - exit(-2); + throw new eGroupUnableToSend(); } else { if (DEBUG) printf("Group::sendto -- done\n"); diff --git a/src/group.h b/src/group.h index 3936bd1..1f14036 100644 --- a/src/group.h +++ b/src/group.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -14,6 +15,9 @@ #include "message.h" +class eGroupNotConstructed : std::exception { }; +class eGroupUnableToSend : std::exception { }; + class HostId { public: std::string host; diff --git a/src/highreceiver.cc b/src/highreceiver.cc index 3ce9e13..b315611 100644 --- a/src/highreceiver.cc +++ b/src/highreceiver.cc @@ -7,7 +7,7 @@ #include #include -HighReceiver::HighReceiver(short int portHigh){ +HighReceiver::HighReceiver(){ printf("LowReceiver::LowReceiver --"); @@ -29,7 +29,7 @@ HighReceiver::HighReceiver(short int portHigh){ // port_high = interne bzero(_socket_addr,sizeof(sockaddr_in)); _socket_addr->sin_family = AF_INET; - _socket_addr->sin_port = htons(portHigh); + _socket_addr->sin_port = 0; //FIXME random port ? _socket_addr->sin_addr.s_addr = htonl(INADDR_ANY); // chopper une socket @@ -39,6 +39,11 @@ HighReceiver::HighReceiver(short int portHigh){ fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__); exit(-1); } + //FIXME: initialiser le port +} + +short HighReceiver::getPort(){ + return _port; } HighReceiver::~HighReceiver(){ diff --git a/src/highreceiver.h b/src/highreceiver.h index f8a0913..e634365 100644 --- a/src/highreceiver.h +++ b/src/highreceiver.h @@ -5,13 +5,16 @@ class HighReceiver { private: int _socket_desc; struct sockaddr_in * _socket_addr; + int _port; protected: public: - HighReceiver(short int portHigh); + HighReceiver(); ~HighReceiver(); void run(); // thread part + + short getPort(); // seq part }; #endif // _GYR_HIGH_RECEIVER_H diff --git a/src/lowreceiver_ab.cc b/src/lowreceiver_ab.cc index 87d8216..6563d7c 100644 --- a/src/lowreceiver_ab.cc +++ b/src/lowreceiver_ab.cc @@ -39,14 +39,27 @@ void LowReceiver::manage_abcast(Message * mesg) { //sinon on le crée printf("LowReceiver::manage_abcast -- message is first\n"); cell = new MessageCellAb(); + cell->message = new Message(*mesg); //et on l'ajoute au fifo fifo_send.push_back(cell); } - cell->message = new Message(*mesg); //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_abcast - Received a message from a friend\n"); for (iter = fifo_get.begin(); iter != fifo_get.end(); iter++){ diff --git a/src/message.cc b/src/message.cc index 5111dd2..7d1bc59 100644 --- a/src/message.cc +++ b/src/message.cc @@ -55,7 +55,7 @@ Message::Message(void * data, int len) { } -Message::Message(Protocol::Type type, TimeStamp ×tamp, char * mesg, short mesg_size) : +Message::Message(Protocol::Type type, TimeStamp ×tamp, char * mesg, unsigned short mesg_size) : _type(type) { _data = new char[mesg_size]; diff --git a/src/message.h b/src/message.h index ca560b2..bad6454 100644 --- a/src/message.h +++ b/src/message.h @@ -19,7 +19,7 @@ class Message { protected: public: - Message(Protocol::Type type, TimeStamp &ts, char * data, short data_size); + Message(Protocol::Type type, TimeStamp &ts, char * data, unsigned short data_size); Message(void * data, int len); Message(const Message & mesg); diff --git a/src/messagecell_ab.cc b/src/messagecell_ab.cc index 21a53c5..59721bd 100644 --- a/src/messagecell_ab.cc +++ b/src/messagecell_ab.cc @@ -5,4 +5,6 @@ MessageCellAb::MessageCellAb(){ printf("MessageCellAb::MessageCellAb -- constructor\n"); this->message = NULL; this->type = MessageCellAb::TYPE_UNDEF; + this->count = 0; + this->maximum = NULL; } diff --git a/src/timestamp.cc b/src/timestamp.cc index fe58fe9..e9943de 100644 --- a/src/timestamp.cc +++ b/src/timestamp.cc @@ -10,7 +10,7 @@ TimeStamp::TimeStamp(Protocol::Type type, short index){ _type = type; } -TimeStamp::TimeStamp(Protocol::Type type, char * raw, short raw_size){ +TimeStamp::TimeStamp(Protocol::Type type, char * raw, unsigned short raw_size){ int pos_idx = 0; short stamp_len = -1; diff --git a/src/timestamp.h b/src/timestamp.h index 37ffb27..0300604 100644 --- a/src/timestamp.h +++ b/src/timestamp.h @@ -11,7 +11,7 @@ class TimeStamp : public std::vector { Protocol::Type _type; public: TimeStamp(Protocol::Type t, short idx); - TimeStamp::TimeStamp(Protocol::Type type, char * raw, short raw_size); + TimeStamp::TimeStamp(Protocol::Type type, char * raw, unsigned short raw_size); char * getRaw(); unsigned short getRawSize();