This commit is contained in:
parent
edf061cbca
commit
c0bad9b9bc
13 changed files with 60 additions and 22 deletions
|
@ -2,6 +2,16 @@
|
||||||
RFC : Multi-BroadCast Protocol (MBCP)
|
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 :
|
Datagrams :
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -68,4 +78,4 @@ Message_size : unsigned short (16 bits)
|
||||||
Message_data :
|
Message_data :
|
||||||
~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~
|
||||||
array of unsigned shorts (16 bits * Message_size)
|
array of unsigned shorts (16 bits * Message_size)
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ Config::Config(int argc, char **argv) {
|
||||||
{
|
{
|
||||||
HostId g_host;
|
HostId g_host;
|
||||||
string optstr(optarg);
|
string optstr(optarg);
|
||||||
stringstream s_host, s_port;
|
///stringstream s_host, s_port;
|
||||||
|
|
||||||
int idx = optstr.find(":");
|
int idx = optstr.find(":");
|
||||||
if (idx > 0){
|
if (idx > 0){
|
||||||
|
@ -87,8 +87,8 @@ Config::Config(int argc, char **argv) {
|
||||||
|
|
||||||
// on oblige la forme XXXXXX:YY
|
// on oblige la forme XXXXXX:YY
|
||||||
|
|
||||||
s_host << optstr.substr(0,idx);
|
g_host.host = optstr.substr(0,idx);
|
||||||
s_host >> (g_host.host);
|
//s_host >> (g_host.host);
|
||||||
|
|
||||||
s_port << optstr.substr(idx+1, optstr.size()-idx-1);
|
s_port << optstr.substr(idx+1, optstr.size()-idx-1);
|
||||||
s_port >> (g_host.port);
|
s_port >> (g_host.port);
|
||||||
|
|
|
@ -29,8 +29,10 @@ int main(int argc, char ** argv){
|
||||||
Group grp(config.getGroupHosts(), config.getIndex());
|
Group grp(config.getGroupHosts(), config.getIndex());
|
||||||
Clock * clk;
|
Clock * clk;
|
||||||
|
|
||||||
//FIXME non-dynamic port !
|
short portHigh = -1;
|
||||||
int portHigh = 2710;
|
HighReceiver high_receiver;
|
||||||
|
portHigh = high_receiver.getPort();
|
||||||
|
|
||||||
|
|
||||||
switch(config.getMode()){
|
switch(config.getMode()){
|
||||||
case Protocol::TYPE_TEST:
|
case Protocol::TYPE_TEST:
|
||||||
|
@ -56,7 +58,6 @@ int main(int argc, char ** argv){
|
||||||
exit(-1);
|
exit(-1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
HighReceiver high_receiver(portHigh);
|
|
||||||
|
|
||||||
LowReceiver low_receiver(config.getPort(),
|
LowReceiver low_receiver(config.getPort(),
|
||||||
portHigh,
|
portHigh,
|
||||||
|
|
12
src/group.cc
12
src/group.cc
|
@ -15,9 +15,8 @@ Group::Group(std::list<HostId> group, short index){
|
||||||
/* error */
|
/* error */
|
||||||
perror("Creation de la socket impossible");
|
perror("Creation de la socket impossible");
|
||||||
fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__);
|
fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__);
|
||||||
// FIXME: throw something
|
|
||||||
exit(-1);
|
|
||||||
|
|
||||||
|
throw new eGroupNotConstructed();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr_in * myaddr = new sockaddr_in;
|
struct sockaddr_in * myaddr = new sockaddr_in;
|
||||||
|
@ -31,7 +30,8 @@ Group::Group(std::list<HostId> group, short index){
|
||||||
//FIXME : throw something
|
//FIXME : throw something
|
||||||
perror("Attachement de la socket impossible");
|
perror("Attachement de la socket impossible");
|
||||||
fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__);
|
fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__);
|
||||||
exit(-1);
|
|
||||||
|
throw new eGroupNotConstructed();
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME: définir une liste avec les structures...
|
//FIXME: définir une liste avec les structures...
|
||||||
|
@ -54,8 +54,8 @@ Group::Group(std::list<HostId> group, short index){
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Erreur client : echec gethostbyname sur %s\n",
|
"Erreur client : echec gethostbyname sur %s\n",
|
||||||
hid.host.c_str()) ;
|
hid.host.c_str()) ;
|
||||||
//FIXME: throw something
|
|
||||||
exit(-1);
|
throw new eGroupNotConstructed();
|
||||||
}
|
}
|
||||||
|
|
||||||
addr->sin_family = AF_INET;
|
addr->sin_family = AF_INET;
|
||||||
|
@ -107,7 +107,7 @@ void Group::sendto(Message &msg, short index){
|
||||||
|
|
||||||
perror("sendto failed\n");
|
perror("sendto failed\n");
|
||||||
/* error */
|
/* error */
|
||||||
exit(-2);
|
throw new eGroupUnableToSend();
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
printf("Group::sendto -- done\n");
|
printf("Group::sendto -- done\n");
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
@ -14,6 +15,9 @@
|
||||||
|
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
|
||||||
|
class eGroupNotConstructed : std::exception { };
|
||||||
|
class eGroupUnableToSend : std::exception { };
|
||||||
|
|
||||||
class HostId {
|
class HostId {
|
||||||
public:
|
public:
|
||||||
std::string host;
|
std::string host;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
HighReceiver::HighReceiver(short int portHigh){
|
HighReceiver::HighReceiver(){
|
||||||
|
|
||||||
printf("LowReceiver::LowReceiver --");
|
printf("LowReceiver::LowReceiver --");
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ HighReceiver::HighReceiver(short int portHigh){
|
||||||
// port_high = interne
|
// port_high = interne
|
||||||
bzero(_socket_addr,sizeof(sockaddr_in));
|
bzero(_socket_addr,sizeof(sockaddr_in));
|
||||||
_socket_addr->sin_family = AF_INET;
|
_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);
|
_socket_addr->sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
|
||||||
// chopper une socket
|
// chopper une socket
|
||||||
|
@ -39,6 +39,11 @@ HighReceiver::HighReceiver(short int portHigh){
|
||||||
fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__);
|
fprintf(stderr,"BOUM at %s:%d",__FILE__,__LINE__);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
//FIXME: initialiser le port
|
||||||
|
}
|
||||||
|
|
||||||
|
short HighReceiver::getPort(){
|
||||||
|
return _port;
|
||||||
}
|
}
|
||||||
|
|
||||||
HighReceiver::~HighReceiver(){
|
HighReceiver::~HighReceiver(){
|
||||||
|
|
|
@ -5,13 +5,16 @@ class HighReceiver {
|
||||||
private:
|
private:
|
||||||
int _socket_desc;
|
int _socket_desc;
|
||||||
struct sockaddr_in * _socket_addr;
|
struct sockaddr_in * _socket_addr;
|
||||||
|
int _port;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
public:
|
public:
|
||||||
HighReceiver(short int portHigh);
|
HighReceiver();
|
||||||
~HighReceiver();
|
~HighReceiver();
|
||||||
|
|
||||||
void run(); // thread part
|
void run(); // thread part
|
||||||
|
|
||||||
|
short getPort(); // seq part
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _GYR_HIGH_RECEIVER_H
|
#endif // _GYR_HIGH_RECEIVER_H
|
||||||
|
|
|
@ -39,14 +39,27 @@ void LowReceiver::manage_abcast(Message * mesg) {
|
||||||
//sinon on le crée
|
//sinon on le crée
|
||||||
printf("LowReceiver::manage_abcast -- message is first\n");
|
printf("LowReceiver::manage_abcast -- message is first\n");
|
||||||
cell = new MessageCellAb();
|
cell = new MessageCellAb();
|
||||||
|
cell->message = new Message(*mesg);
|
||||||
//et on l'ajoute au fifo
|
//et on l'ajoute au fifo
|
||||||
fifo_send.push_back(cell);
|
fifo_send.push_back(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell->message = new Message(*mesg);
|
|
||||||
//FIXME: comparer le timestamp max a ceux que l'on recoit
|
//FIXME: comparer le timestamp max a ceux que l'on recoit
|
||||||
cell->count += 1;
|
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 {
|
} else {
|
||||||
printf("LowReceiver::manage_abcast - Received a message from a friend\n");
|
printf("LowReceiver::manage_abcast - Received a message from a friend\n");
|
||||||
for (iter = fifo_get.begin(); iter != fifo_get.end(); iter++){
|
for (iter = fifo_get.begin(); iter != fifo_get.end(); iter++){
|
||||||
|
|
|
@ -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)
|
_type(type)
|
||||||
{
|
{
|
||||||
_data = new char[mesg_size];
|
_data = new char[mesg_size];
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Message {
|
||||||
protected:
|
protected:
|
||||||
public:
|
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(void * data, int len);
|
||||||
Message(const Message & mesg);
|
Message(const Message & mesg);
|
||||||
|
|
||||||
|
|
|
@ -5,4 +5,6 @@ MessageCellAb::MessageCellAb(){
|
||||||
printf("MessageCellAb::MessageCellAb -- constructor\n");
|
printf("MessageCellAb::MessageCellAb -- constructor\n");
|
||||||
this->message = NULL;
|
this->message = NULL;
|
||||||
this->type = MessageCellAb::TYPE_UNDEF;
|
this->type = MessageCellAb::TYPE_UNDEF;
|
||||||
|
this->count = 0;
|
||||||
|
this->maximum = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ TimeStamp::TimeStamp(Protocol::Type type, short index){
|
||||||
_type = type;
|
_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;
|
int pos_idx = 0;
|
||||||
short stamp_len = -1;
|
short stamp_len = -1;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ class TimeStamp : public std::vector<short int> {
|
||||||
Protocol::Type _type;
|
Protocol::Type _type;
|
||||||
public:
|
public:
|
||||||
TimeStamp(Protocol::Type t, short idx);
|
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();
|
char * getRaw();
|
||||||
unsigned short getRawSize();
|
unsigned short getRawSize();
|
||||||
|
|
Loading…
Add table
Reference in a new issue