This commit is contained in:
glenux 2006-03-01 21:40:44 +00:00
parent edf061cbca
commit c0bad9b9bc
13 changed files with 60 additions and 22 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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,

View file

@ -15,9 +15,8 @@ Group::Group(std::list<HostId> 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<HostId> 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<HostId> 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");

View file

@ -3,6 +3,7 @@
#include <string>
#include <list>
#include <exception>
#include <sys/types.h>
#include <sys/socket.h>
@ -14,6 +15,9 @@
#include "message.h"
class eGroupNotConstructed : std::exception { };
class eGroupUnableToSend : std::exception { };
class HostId {
public:
std::string host;

View file

@ -7,7 +7,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
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(){

View file

@ -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

View file

@ -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++){

View file

@ -55,7 +55,7 @@ Message::Message(void * data, int len) {
}
Message::Message(Protocol::Type type, TimeStamp &timestamp, char * mesg, short mesg_size) :
Message::Message(Protocol::Type type, TimeStamp &timestamp, char * mesg, unsigned short mesg_size) :
_type(type)
{
_data = new char[mesg_size];

View file

@ -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);

View file

@ -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;
}

View file

@ -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;

View file

@ -11,7 +11,7 @@ class TimeStamp : public std::vector<short int> {
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();