czyszczenie kodu + udokumentowanie zgodnie z Doxyfile
This commit is contained in:
16
Log.cpp
16
Log.cpp
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Log.cpp
|
* @file Log.cpp
|
||||||
*
|
*
|
||||||
* Created on: 16.01.2017
|
* Created on: 16.01.2017
|
||||||
* Author: piotrek
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
@@ -121,9 +121,7 @@ void Log::printProgressBar(int lineNumber, int offset, string msg,
|
|||||||
cout << this->getObjectName()->c_str() << ": " << this->getDelimiter() << msg << endl;
|
cout << this->getObjectName()->c_str() << ": " << this->getDelimiter() << msg << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* metoda wypisuje log w wielu liniach od firstLineNumber do rows-2
|
|
||||||
*/
|
|
||||||
void Log::printLine(string msg, bool force)
|
void Log::printLine(string msg, bool force)
|
||||||
{
|
{
|
||||||
int cols, rows;
|
int cols, rows;
|
||||||
@@ -229,8 +227,8 @@ void Log::delay(int optional)
|
|||||||
if (t == 0)
|
if (t == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (t >= 10) // ns
|
if (t >= 10)
|
||||||
usleep(t);
|
usleep(t);
|
||||||
else
|
else
|
||||||
sleep(t); // s
|
sleep(t);
|
||||||
}
|
}
|
||||||
|
|||||||
49
Log.h
49
Log.h
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Log.h
|
* @file Log.h
|
||||||
*
|
*
|
||||||
* Created on: 16.01.2017
|
* Created on: 16.01.2017
|
||||||
* Author: piotrek
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LOG_H_
|
#ifndef LOG_H_
|
||||||
@@ -23,21 +23,58 @@ enum LOG_COLOR {
|
|||||||
|
|
||||||
class Log
|
class Log
|
||||||
{
|
{
|
||||||
|
/** nr linii na którym ma byc domyślnie zapisany komunikat */
|
||||||
int lineNumber;
|
int lineNumber;
|
||||||
|
/** kolor tekstu */
|
||||||
LOG_COLOR color;
|
LOG_COLOR color;
|
||||||
|
/** znaki specjalne pomiędzy nazwą zdarzenia, a komunikatem; zwykle tabulatory */
|
||||||
string delimiter;
|
string delimiter;
|
||||||
|
/** wskaźnik na element z nazwą - hostname etc. */
|
||||||
string *objectName;
|
string *objectName;
|
||||||
|
/** systemowy mutex blokujący pisanie przez inne wątki */
|
||||||
pthread_mutex_t *writeMutex;
|
pthread_mutex_t *writeMutex;
|
||||||
|
/** domyślny czas delay'a */
|
||||||
int delayVal;
|
int delayVal;
|
||||||
/* do obslugi wielolinijkowosci (na dole) */
|
/** numer linii, od której będą zaczynać się wieloliniowe komunikaty (do samego dołu) */
|
||||||
int firstLine;
|
int firstLine;
|
||||||
|
/** aktualny numer linii komunikatu wielolinijkowego */
|
||||||
int currentLine;
|
int currentLine;
|
||||||
public:
|
public:
|
||||||
Log();
|
Log();
|
||||||
|
/**
|
||||||
|
* wypisuje na ekran komunikat obiektu
|
||||||
|
* @param msg treść komunikatu
|
||||||
|
* @param force wymuszenie wyświetlenia jeżeli delay obiektu=0
|
||||||
|
* @param customLine określony nr linii, na którym ma być wyświetlony komunikat zamiast domyślnej linii
|
||||||
|
*/
|
||||||
void print(string msg, bool force=false, int customLine = -1);
|
void print(string msg, bool force=false, int customLine = -1);
|
||||||
|
/**
|
||||||
|
* wypisuje na ekran komunikat wielolinijkowy (linia po linii, aż do końca ekranu -2 linie)
|
||||||
|
* @param msg treść komunikatu
|
||||||
|
* @param force wymuszenie wyświetlania jeżeli delay obiektu=0
|
||||||
|
*/
|
||||||
void printLine(string msg, bool force=false);
|
void printLine(string msg, bool force=false);
|
||||||
|
/**
|
||||||
|
* tworzy efektowny progressbar wraz z wartością procentową na końcu linii
|
||||||
|
* @param lineNumber numer linii na którym ma być wyświetlony progress bar
|
||||||
|
* @param offset przesunięcie progressbaru w stosunku do nazwy
|
||||||
|
* @param msg nazwa progressbara
|
||||||
|
* @param percent procent określonego parametru, liczba wymierna z zakresu [0,1]
|
||||||
|
*/
|
||||||
void printProgressBar(int lineNumber, int offset, string msg, float percent);
|
void printProgressBar(int lineNumber, int offset, string msg, float percent);
|
||||||
|
/**
|
||||||
|
* zwraca mutex (Singleton) do blokowania pisania po konsoli
|
||||||
|
*/
|
||||||
|
static pthread_mutex_t * getMutex();
|
||||||
|
/**
|
||||||
|
* opóźnia wykonanie się poleceń o czas z delayVal lub customowy
|
||||||
|
* czas pomiędzy 0-9 uruchamia systemowe sleep()
|
||||||
|
* natomiast powyżej 9 funkcję usleep
|
||||||
|
* @param optional opcjonalny czas (1-9 sekundy, >=10 mikrosekundy)
|
||||||
|
*/
|
||||||
|
void delay(int optional=-1);
|
||||||
|
|
||||||
|
/* mutuatory */
|
||||||
LOG_COLOR getColor() const;
|
LOG_COLOR getColor() const;
|
||||||
void setColor(LOG_COLOR color);
|
void setColor(LOG_COLOR color);
|
||||||
const string& getDelimiter() const;
|
const string& getDelimiter() const;
|
||||||
@@ -45,8 +82,6 @@ public:
|
|||||||
int getLineNumber() const;
|
int getLineNumber() const;
|
||||||
void setLineNumber(int lineNumber);
|
void setLineNumber(int lineNumber);
|
||||||
void setLogParams(int lineNumber, LOG_COLOR color, string delimiter);
|
void setLogParams(int lineNumber, LOG_COLOR color, string delimiter);
|
||||||
static pthread_mutex_t * getMutex();
|
|
||||||
void delay(int optional=-1);
|
|
||||||
int getDelay() const;
|
int getDelay() const;
|
||||||
void setDelay(int delay);
|
void setDelay(int delay);
|
||||||
string* getObjectName() const;
|
string* getObjectName() const;
|
||||||
|
|||||||
17
Main.cpp
17
Main.cpp
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Main.cpp
|
* @file Main.cpp
|
||||||
*
|
*
|
||||||
* Created on: 07-01-2017
|
* Created on: 07-01-2017
|
||||||
* Author: Piotr Dergun
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@@ -10,6 +10,10 @@
|
|||||||
#include "NATRouter.h"
|
#include "NATRouter.h"
|
||||||
#include "Simulation.h"
|
#include "Simulation.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* zwraca na stderr informację o parametrach uruchomienia programu
|
||||||
|
* @param programName nazwa pliku wykonywalnego
|
||||||
|
*/
|
||||||
void usage(string programName)
|
void usage(string programName)
|
||||||
{
|
{
|
||||||
cerr << endl;
|
cerr << endl;
|
||||||
@@ -20,6 +24,11 @@ void usage(string programName)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* główna funkcja programu
|
||||||
|
* @param argc ilość argumentów
|
||||||
|
* @param argv tablica z argumentami
|
||||||
|
*/
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *endptr=NULL;
|
char *endptr=NULL;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* NATItem.cpp
|
* @file NATItem.cpp
|
||||||
*
|
*
|
||||||
* Created on: 10-01-2017
|
* Created on: 10-01-2017
|
||||||
* Author: Piotr Dergun
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "NATItem.h"
|
#include "NATItem.h"
|
||||||
|
|||||||
38
NATItem.h
38
NATItem.h
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* NATItem.h
|
* @file NATItem.h
|
||||||
*
|
*
|
||||||
* Created on: 10-01-2017
|
* Created on: 10-01-2017
|
||||||
* Author: Piotr Dergun
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NATITEM_H_
|
#ifndef NATITEM_H_
|
||||||
@@ -12,23 +12,41 @@
|
|||||||
|
|
||||||
class NATItem
|
class NATItem
|
||||||
{
|
{
|
||||||
string ip; // IP wewn. do którego ma trafić odpowiedź / z którego przyszło żądanie
|
/** IP węzła za NAT-em do którego ma trafić odpowiedź / z którego przyszło żądanie */
|
||||||
int port; // port komputera wewn. do którego ma trafić odpowiedź
|
string ip; //
|
||||||
unsigned long timeout; // czas (w sekundach) zajętości portu (0 - port wolny)
|
/** port węzła za NAT-em, do którego ma trafić odpowiedź */
|
||||||
|
int port;
|
||||||
|
/** czas, na jaki port w tablicy NAT pozostaje otwarty do ewentualnej odpowiedzi z zewnątrz */
|
||||||
|
unsigned long timeout;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NATItem();
|
NATItem();
|
||||||
|
/**
|
||||||
|
* sprawdza, czy port jest wolny (timeout == 0)
|
||||||
|
*/
|
||||||
bool isFree();
|
bool isFree();
|
||||||
|
/**
|
||||||
|
* zwiększa timeout o określoną wartość
|
||||||
|
* @param timeout dodawana wartość timeoutu
|
||||||
|
*/
|
||||||
void increaseTimeout(int timeout);
|
void increaseTimeout(int timeout);
|
||||||
|
/**
|
||||||
|
* ustawia timeout jako aktualny timestamp + określona wartość
|
||||||
|
* @param timeout czas timeoutu
|
||||||
|
*/
|
||||||
|
void setTimeout(int timeout);
|
||||||
|
/**
|
||||||
|
* ustawia timeout na 0 (zwalnia port w tablicy NAT)
|
||||||
|
*/
|
||||||
|
void free();
|
||||||
|
|
||||||
|
/* mutuatory */
|
||||||
const string& getIp() const;
|
const string& getIp() const;
|
||||||
void setIp(const string& ip);
|
void setIp(const string& ip);
|
||||||
int getPort() const;
|
int getPort() const;
|
||||||
void setPort(int port);
|
void setPort(int port);
|
||||||
unsigned long getTimeout() const;
|
unsigned long getTimeout() const;
|
||||||
void setTimeout(int timeout);
|
|
||||||
void free();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* NATITEM_H_ */
|
#endif /* NATITEM_H_ */
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* NATItem.cpp
|
* @file NATRouter.cpp
|
||||||
*
|
*
|
||||||
* Created on: 11-01-2017
|
* Created on: 11-01-2017
|
||||||
* Author: Piotr Dergun
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "NATRouter.h"
|
#include "NATRouter.h"
|
||||||
@@ -22,21 +22,25 @@ void NATRouter::initalizeNatTable()
|
|||||||
|
|
||||||
NATRouter::NATRouter()
|
NATRouter::NATRouter()
|
||||||
{
|
{
|
||||||
|
this->lastUsedPort = 0;
|
||||||
this->initalizeNatTable();
|
this->initalizeNatTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
NATRouter::NATRouter(string hostname) : Node(hostname)
|
NATRouter::NATRouter(string hostname) : Node(hostname)
|
||||||
{
|
{
|
||||||
|
this->lastUsedPort = 0;
|
||||||
this->initalizeNatTable();
|
this->initalizeNatTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
NATRouter::NATRouter(string hostname, string ip, string mask) : Node(hostname, ip, mask)
|
NATRouter::NATRouter(string hostname, string ip, string mask) : Node(hostname, ip, mask)
|
||||||
{
|
{
|
||||||
|
this->lastUsedPort = 0;
|
||||||
this->initalizeNatTable();
|
this->initalizeNatTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
NATRouter::NATRouter(string hostname, string ip, string mask, string gatewayIp) : Node(hostname, ip, mask, gatewayIp)
|
NATRouter::NATRouter(string hostname, string ip, string mask, string gatewayIp) : Node(hostname, ip, mask, gatewayIp)
|
||||||
{
|
{
|
||||||
|
this->lastUsedPort = 0;
|
||||||
this->initalizeNatTable();
|
this->initalizeNatTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +49,6 @@ int NATRouter::getFreePort()
|
|||||||
if (this->lastUsedPort == NAT_TABLE_LEN-1)
|
if (this->lastUsedPort == NAT_TABLE_LEN-1)
|
||||||
this->lastUsedPort = 0;
|
this->lastUsedPort = 0;
|
||||||
|
|
||||||
//if (this->natTable[this->lastUsedPort+1].isFree())
|
|
||||||
// return ++this->lastUsedPort;
|
|
||||||
for (int i = this->lastUsedPort+1; i<NAT_TABLE_LEN; ++i)
|
for (int i = this->lastUsedPort+1; i<NAT_TABLE_LEN; ++i)
|
||||||
if (this->natTable[i].isFree())
|
if (this->natTable[i].isFree())
|
||||||
{
|
{
|
||||||
@@ -60,11 +62,7 @@ int NATRouter::getFreePort()
|
|||||||
this->lastUsedPort = i;
|
this->lastUsedPort = i;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
for (int i=1; i<NAT_TABLE_LEN; ++i)
|
|
||||||
if (this->natTable[i].isFree())
|
|
||||||
return i;
|
|
||||||
*/
|
|
||||||
return -1; // nie ma żadnego wolnego portu
|
return -1; // nie ma żadnego wolnego portu
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,14 +140,6 @@ string NATRouter::getWanMask()
|
|||||||
return this->netWanConf.mask;
|
return this->netWanConf.mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* funkcja SNAT zapisuje w tablicy NAT
|
|
||||||
* numer portu zrodlowego komputera z LAN
|
|
||||||
* oraz jego IP i przeksztalca pakiet, zmieniajac
|
|
||||||
* zrodlowy IP na IP zewn. routera oraz wolny
|
|
||||||
* port z tablicy NAT. Jezeli portu nie ma to funkcja
|
|
||||||
* czeka, az sie zwolni
|
|
||||||
*/
|
|
||||||
void NATRouter::sNAT(Packet *packet)
|
void NATRouter::sNAT(Packet *packet)
|
||||||
{
|
{
|
||||||
int port;
|
int port;
|
||||||
@@ -162,7 +152,6 @@ void NATRouter::sNAT(Packet *packet)
|
|||||||
if (port == -1)
|
if (port == -1)
|
||||||
while ((port = this->getFreePort()) == -1)
|
while ((port = this->getFreePort()) == -1)
|
||||||
{
|
{
|
||||||
//TESTOWO
|
|
||||||
this->print("NAT table full, waiting 1s", true);
|
this->print("NAT table full, waiting 1s", true);
|
||||||
this->delay(1);
|
this->delay(1);
|
||||||
}
|
}
|
||||||
@@ -196,12 +185,6 @@ void NATRouter::sNAT(Packet *packet)
|
|||||||
natItem = NULL;
|
natItem = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* funkcja DNAT ma za zadanie znalezc w tablicy NAT
|
|
||||||
* port i adres IP wezla na ktory ma wrocic odpowiedz
|
|
||||||
* z sieci Internet (z zewnatrz), a takze przedluzyc
|
|
||||||
* czas zycia tego portu
|
|
||||||
*/
|
|
||||||
void NATRouter::dNAT(Packet* packet)
|
void NATRouter::dNAT(Packet* packet)
|
||||||
{
|
{
|
||||||
NATItem *natItem = &this->natTable[packet->getDstPort()];
|
NATItem *natItem = &this->natTable[packet->getDstPort()];
|
||||||
@@ -211,7 +194,6 @@ void NATRouter::dNAT(Packet* packet)
|
|||||||
|
|
||||||
packet->setDstIp(natItem->getIp()); // zamieniam IP lokalne na WAN'owe
|
packet->setDstIp(natItem->getIp()); // zamieniam IP lokalne na WAN'owe
|
||||||
packet->setDstPort(natItem->getPort()); // zamieniam port NAT na lokalny wezla
|
packet->setDstPort(natItem->getPort()); // zamieniam port NAT na lokalny wezla
|
||||||
//natItem->free(); // zwalniam port w routerze
|
|
||||||
natItem->increaseTimeout(5); // podbijam o kolejne 5 sekund skoro transmisja trwa
|
natItem->increaseTimeout(5); // podbijam o kolejne 5 sekund skoro transmisja trwa
|
||||||
|
|
||||||
this->print(ss.str());
|
this->print(ss.str());
|
||||||
@@ -231,18 +213,11 @@ string NATRouter::getWanNetwork()
|
|||||||
return this->netWanConf.network;
|
return this->netWanConf.network;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* funkcja szuka aktywnego zaalokowanego portu (aktywna
|
|
||||||
* transmisja) w tablicy NAT dla pary (srcIp:srcPort)
|
|
||||||
*/
|
|
||||||
int NATRouter::getAllocatedPort(string srcIp, int srcPort)
|
int NATRouter::getAllocatedPort(string srcIp, int srcPort)
|
||||||
{
|
{
|
||||||
map<string, int>::iterator it;
|
map<string, int>::iterator it;
|
||||||
int pos = -1;
|
int pos = -1;
|
||||||
/*for (int i=1; i<NAT_TABLE_LEN; ++i)
|
|
||||||
if (this->natTable[i].getIp() == srcIp && this->natTable[i].getPort() == srcPort)
|
|
||||||
return i;
|
|
||||||
*/
|
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss << srcIp << ":" << srcPort;
|
ss << srcIp << ":" << srcPort;
|
||||||
|
|
||||||
|
|||||||
58
NATRouter.h
58
NATRouter.h
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* NATRouter.h
|
* @file NATRouter.h
|
||||||
*
|
*
|
||||||
* Created on: 11-01-2017
|
* Created on: 11-01-2017
|
||||||
* Author: Piotr Dergun
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NATROUTER_H_
|
#ifndef NATROUTER_H_
|
||||||
@@ -14,15 +14,46 @@
|
|||||||
|
|
||||||
class NATRouter : public Node
|
class NATRouter : public Node
|
||||||
{
|
{
|
||||||
NATItem *natTable = NULL; // tablica z zaalokowanymi portami na zewnątrz
|
/** tablica z zaalokowanymi portami na zewnątrz (indeksy to numery portów po stronie WAN) */
|
||||||
map<string, int> natHelper; // mapa pomocnicza pozwalajaca szybko znalezc wpis
|
NATItem *natTable = NULL;
|
||||||
NetConf netWanConf; // konfiguracja sieciowa na zewnątrz
|
/**
|
||||||
|
* mapa do numerów portów, które wykorzystuje dana para zza NAT (IP, port)
|
||||||
|
* potrzebne do szybkiego przeszukiwania zaalokowanego portu w NAT
|
||||||
|
*/
|
||||||
|
map<string, int> natHelper;
|
||||||
|
/** konfiguracja interfejsu WAN routera */
|
||||||
|
NetConf netWanConf;
|
||||||
|
/** zachowuje ostatnio zaalokowany numer portu, aby zaalokować kolejny (o ile możliwe) */
|
||||||
|
int lastUsedPort;
|
||||||
|
/**
|
||||||
|
* inicjalizuje tablicę NAT
|
||||||
|
*/
|
||||||
void initalizeNatTable();
|
void initalizeNatTable();
|
||||||
|
/**
|
||||||
|
* zwraca pierwszy wolny numer portu w tablicy NAT
|
||||||
|
*/
|
||||||
int getFreePort();
|
int getFreePort();
|
||||||
int lastUsedPort = 0;
|
/**
|
||||||
|
* szuka aktywnego zaalokowanego portu (aktywna
|
||||||
|
* transmisja) w tablicy NAT dla pary (srcIp:srcPort)
|
||||||
|
*/
|
||||||
int getAllocatedPort(string srcIp, int srcPort);
|
int getAllocatedPort(string srcIp, int srcPort);
|
||||||
|
/**
|
||||||
|
* zapisuje w tablicy NAT numer portu źródłowego komputera z LAN oraz jego IP
|
||||||
|
* i przekształca pakiet, zmieniając zródłowy IP na IP zewnętrzny routera
|
||||||
|
* oraz wolny port z tablicy NAT. Jeżeli portu nie ma to funkcja czeka, aż sie zwolni
|
||||||
|
* @param packet wskaźnik do przetwarzanego pakietu
|
||||||
|
*/
|
||||||
void sNAT(Packet *packet);
|
void sNAT(Packet *packet);
|
||||||
|
/**
|
||||||
|
* ma za zadanie znaleźć w tablicy NAT port i adres IP węzła na który ma wrócić
|
||||||
|
* odpowiedź z sieci Internet (z zewnątrz), a także przedlużyć czas życia tego portu
|
||||||
|
* @param packet wskaźnik do przetwarzanego pakietu
|
||||||
|
*/
|
||||||
void dNAT(Packet *packet);
|
void dNAT(Packet *packet);
|
||||||
|
/**
|
||||||
|
* przelicza adres sieci dla połączenia WAN
|
||||||
|
*/
|
||||||
void setWanNetwork();
|
void setWanNetwork();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -31,16 +62,19 @@ public:
|
|||||||
NATRouter(string hostname, string ip, string mask);
|
NATRouter(string hostname, string ip, string mask);
|
||||||
NATRouter(string hostname, string ip, string mask, string gatewayIp);
|
NATRouter(string hostname, string ip, string mask, string gatewayIp);
|
||||||
~NATRouter();
|
~NATRouter();
|
||||||
|
/**
|
||||||
|
* obsługuje całą logikę routera/NAT/switcha w momencie nadejścia pakietu
|
||||||
|
*/
|
||||||
virtual void onRecv();
|
virtual void onRecv();
|
||||||
|
/**
|
||||||
|
* wyświetla statystyki zajętości tablicy NAT
|
||||||
|
*/
|
||||||
void freePorts();
|
void freePorts();
|
||||||
|
|
||||||
// settery
|
/* mutuatory */
|
||||||
void setWanIp(string wanIp);
|
void setWanIp(string wanIp);
|
||||||
void setWanMask(string wanMask);
|
void setWanMask(string wanMask);
|
||||||
void setWanGatewayIp(string wanGatewayIp);
|
void setWanGatewayIp(string wanGatewayIp);
|
||||||
|
|
||||||
// gettery
|
|
||||||
string getWanIp();
|
string getWanIp();
|
||||||
string getWanMask();
|
string getWanMask();
|
||||||
string getWanNetwork();
|
string getWanNetwork();
|
||||||
|
|||||||
37
Node.cpp
37
Node.cpp
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Node.cpp
|
* @file Node.cpp
|
||||||
*
|
*
|
||||||
* Created on: 10.01.2017
|
* Created on: 10.01.2017
|
||||||
* Author: piotrek
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
@@ -47,7 +47,6 @@ Node * Node::findConnection(string ip)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* funkcja pobiera i usuwa pakiet z bufora "karty sieciowej" */
|
|
||||||
Packet Node::recv()
|
Packet Node::recv()
|
||||||
{
|
{
|
||||||
Packet packet;
|
Packet packet;
|
||||||
@@ -120,13 +119,6 @@ Node::Node(string hostname, string ip, string mask, string gatewayIp) : Node(hos
|
|||||||
this->setGatewayIp(gatewayIp);
|
this->setGatewayIp(gatewayIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* funkcja symuluje typową sytuację: mamy kartę sieciową, a funkcja connectNode jest podłączeniem wtyczki
|
|
||||||
* z jednej strony
|
|
||||||
* @param firstConnected - oznacza, czy pierwsza strona jest podlaczona (jezeli nie to sprawdzamy
|
|
||||||
* czy polaczenie juz gdzies zostalo przypadkowo nawiazane, nawiazujemy polaczenie, a nastepnie
|
|
||||||
* przekazujemy sterowanie drugiemu wezlowi zeby zrobil to samo)
|
|
||||||
*/
|
|
||||||
bool Node::connectNode(Node *node, bool isExternal, bool firstConnected)
|
bool Node::connectNode(Node *node, bool isExternal, bool firstConnected)
|
||||||
{
|
{
|
||||||
if (node->getIp() == "0.0.0.0") // jezeli wezel nie ma skonfigurowanej sieci, nie mozna go przylaczyc
|
if (node->getIp() == "0.0.0.0") // jezeli wezel nie ma skonfigurowanej sieci, nie mozna go przylaczyc
|
||||||
@@ -135,24 +127,20 @@ bool Node::connectNode(Node *node, bool isExternal, bool firstConnected)
|
|||||||
if (!firstConnected)
|
if (!firstConnected)
|
||||||
{
|
{
|
||||||
map<Node*, bool>::iterator it = this->connectedNodes.begin();
|
map<Node*, bool>::iterator it = this->connectedNodes.begin();
|
||||||
for (; it != this->connectedNodes.end(); ++it) // sprawdzamy, czy połączenia już przypadkiem nie ma
|
for (; it != this->connectedNodes.end(); ++it) // sprawdzamy, czy połączenia już przypadkiem nie ma
|
||||||
{
|
{
|
||||||
if ((*it).first == node)
|
if ((*it).first == node)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->connectedNodes.insert(pair<Node*, bool>(node, isExternal));//this->connectedNodes.push_back(node); // podłączamy drugi węzeł
|
this->connectedNodes.insert(pair<Node*, bool>(node, isExternal)); // podłączamy drugi węzeł
|
||||||
|
|
||||||
if (!firstConnected)
|
if (!firstConnected)
|
||||||
node->connectNode(this, isExternal, true); // to samo w drugą stronę
|
node->connectNode(this, isExternal, true); // to samo w drugą stronę
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* funkcja wysyla, czyli przekazuje kopie pakietu kolejnemu wezlowi - docelowemu lub bramie domyslnej
|
|
||||||
* o ile jest skonfigurowana i istnieje do niej sciezka
|
|
||||||
*/
|
|
||||||
int Node::send(Packet packet, bool isRouter)
|
int Node::send(Packet packet, bool isRouter)
|
||||||
{
|
{
|
||||||
Node *node;
|
Node *node;
|
||||||
@@ -162,7 +150,7 @@ int Node::send(Packet packet, bool isRouter)
|
|||||||
node = this->findConnection(this->getGatewayIp());
|
node = this->findConnection(this->getGatewayIp());
|
||||||
|
|
||||||
if (!node)
|
if (!node)
|
||||||
return false; // nie ma zadnej trasy do wezla
|
return false; // nie ma żadnej trasy do węzła
|
||||||
|
|
||||||
if (packet.getDstPort() == 0)
|
if (packet.getDstPort() == 0)
|
||||||
return false; // wypada zdefiniowac nadawce oraz docelowy port...
|
return false; // wypada zdefiniowac nadawce oraz docelowy port...
|
||||||
@@ -181,10 +169,6 @@ int Node::send(Packet packet, bool isRouter)
|
|||||||
return packet.getSrcPort();
|
return packet.getSrcPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* funkcja jest modelem karty sieciowej - odbiera dane z sieci i umieszcza je
|
|
||||||
* w swoim buforze (czy tam systemie)
|
|
||||||
*/
|
|
||||||
void Node::putPacket(Packet packet)
|
void Node::putPacket(Packet packet)
|
||||||
{
|
{
|
||||||
this->rcvBuffer.push(packet);
|
this->rcvBuffer.push(packet);
|
||||||
@@ -238,9 +222,6 @@ string Node::calculateNetwork(string ip, string mask)
|
|||||||
return ipToString(stringToIp(ip) & stringToIp(mask));
|
return ipToString(stringToIp(ip) & stringToIp(mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* domyslnie onRecv w watku sciaga pakiet z kolejki (aby nie zjadalo pamieci RAM)
|
|
||||||
*/
|
|
||||||
void Node::onRecv()
|
void Node::onRecv()
|
||||||
{
|
{
|
||||||
while(true)
|
while(true)
|
||||||
@@ -259,7 +240,7 @@ string Node::getNetwork()
|
|||||||
return this->netConf.network;
|
return this->netConf.network;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::split(const std::string &s, char delim, vector<string> &elems)
|
void Node::split(const string &s, char delim, vector<string> &elems)
|
||||||
{
|
{
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss.str(s);
|
ss.str(s);
|
||||||
|
|||||||
86
Node.h
86
Node.h
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Node.h
|
* @file Node.h
|
||||||
*
|
*
|
||||||
* Created on: 10.01.2017
|
* Created on: 10.01.2017
|
||||||
* Author: piotrek
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NODE_H_
|
#ifndef NODE_H_
|
||||||
@@ -13,27 +13,70 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
/** adres IP */
|
||||||
string ip;
|
string ip;
|
||||||
|
/** maska podsieci */
|
||||||
string mask;
|
string mask;
|
||||||
|
/** adres sieci */
|
||||||
string network;
|
string network;
|
||||||
|
/** adres IP bramy domyślnej */
|
||||||
string gatewayIp;
|
string gatewayIp;
|
||||||
} NetConf;
|
} NetConf;
|
||||||
|
|
||||||
class Node : public Log
|
class Node : public Log
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
queue<Packet>rcvBuffer; // kolejka z pakietami do przetworzenia
|
/** kolejka z pakietami do przetworzenia */
|
||||||
map<Node*, bool> connectedNodes; // referencje do węzłów, z którymi jest podłączony
|
queue<Packet>rcvBuffer;
|
||||||
NetConf netConf; // konfiguracja sieciowa
|
/** referencje do węzłów, z którymi jest podłączony */
|
||||||
string hostname; // nazwa węzła
|
map<Node*, bool> connectedNodes;
|
||||||
|
/** konfiguracja karty sieciowej */
|
||||||
|
NetConf netConf;
|
||||||
|
/** nazwa węzła */
|
||||||
|
string hostname;
|
||||||
|
/**
|
||||||
|
* oblicza adres sieci, do której należy węzeł
|
||||||
|
*/
|
||||||
void setNetwork();
|
void setNetwork();
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* zwraca wskaźnik do węzła, z którym chcemy się połączyć,
|
||||||
|
* ew. do bramy, jeżeli nic nie znajdzie, a brama jest podłączona
|
||||||
|
* @param ip adres IP węzła docelowego
|
||||||
|
*/
|
||||||
Node * findConnection(string ip);
|
Node * findConnection(string ip);
|
||||||
|
/**
|
||||||
|
* pobiera i usuwa pakiet z bufora "karty sieciowej"
|
||||||
|
*/
|
||||||
Packet recv();
|
Packet recv();
|
||||||
|
/**
|
||||||
|
* przetwarza adres IP w postaci liczbowej na postać human-readable
|
||||||
|
* @param ip adres IP (liczba)
|
||||||
|
*/
|
||||||
string ipToString(unsigned int ip);
|
string ipToString(unsigned int ip);
|
||||||
|
/**
|
||||||
|
* przetwarza adres IP w postaci human-readable na postać liczbową
|
||||||
|
* @param ip adres IP (tekst)
|
||||||
|
*/
|
||||||
unsigned int stringToIp(string ip);
|
unsigned int stringToIp(string ip);
|
||||||
|
/**
|
||||||
|
* oblicza adres sieci dla zadanego adresu IP i maski
|
||||||
|
* @param ip adres IP
|
||||||
|
* @param mask maska podsieci
|
||||||
|
*/
|
||||||
string calculateNetwork(string ip, string mask);
|
string calculateNetwork(string ip, string mask);
|
||||||
|
/**
|
||||||
|
* dzieli string na części
|
||||||
|
* @param s referencja do stringu
|
||||||
|
* @param delim delimitator dzielący string na części
|
||||||
|
* @param elems referencja do wektora z podzielonymi elementami
|
||||||
|
*/
|
||||||
void split(const string &s, char delim, vector<string> &elems);
|
void split(const string &s, char delim, vector<string> &elems);
|
||||||
|
/**
|
||||||
|
* zwraca wektor z stringami, które powstały poprzez podzielenie stringa delimitatorem
|
||||||
|
* @s referencja do stringa, który ma zostać podzielony
|
||||||
|
* @delim delimitator
|
||||||
|
*/
|
||||||
vector<string> split(const string &s, char delim);
|
vector<string> split(const string &s, char delim);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -42,25 +85,42 @@ public:
|
|||||||
Node(string hostname, string ip, string mask);
|
Node(string hostname, string ip, string mask);
|
||||||
Node(string hostname, string ip, string mask, string gatewayIp);
|
Node(string hostname, string ip, string mask, string gatewayIp);
|
||||||
virtual ~Node();
|
virtual ~Node();
|
||||||
|
/**
|
||||||
|
* "łączy" węzły, czyli umieszcza dwustronną referencję do obiektów w mapie connectedNodes.
|
||||||
|
* Jest odwzorowaniem podłączenia wtyczki w dwóch urządzeniach sieciowych.
|
||||||
|
* @param node wskaźnik do węzła zdalnego
|
||||||
|
* @param isExternal flaga, czy połączenie jest po WAN
|
||||||
|
* @param firstConnected flaga czy pierwszy węzeł został dołączony (blokuje rekurencję metody)
|
||||||
|
*/
|
||||||
bool connectNode(Node *node, bool isExternal = false, bool firstConnected = false);
|
bool connectNode(Node *node, bool isExternal = false, bool firstConnected = false);
|
||||||
|
/**
|
||||||
|
* funkcja wysyła, czyli przekazuje kopię pakietu kolejnemu węzłowi
|
||||||
|
* @param packet pakiet do wysłania
|
||||||
|
* @param isRouter flaga jeżeli true to port źródłowy i IP źródłowy mają zostać zachowane (bez zmian)
|
||||||
|
*/
|
||||||
int send(Packet packet, bool isRouter = false);
|
int send(Packet packet, bool isRouter = false);
|
||||||
|
/**
|
||||||
|
* odbiera dane od węzła zdalnego i umieszcza je w buforze (kolejce) karty sieciowej
|
||||||
|
* @param packet pakiet
|
||||||
|
*/
|
||||||
void putPacket(Packet packet);
|
void putPacket(Packet packet);
|
||||||
|
|
||||||
// settery
|
/* mutuatory */
|
||||||
void setHostname(string hostname);
|
void setHostname(string hostname);
|
||||||
void setIp(string ip);
|
void setIp(string ip);
|
||||||
void setMask(string mask);
|
void setMask(string mask);
|
||||||
void setGatewayIp(string gatewayIp);
|
void setGatewayIp(string gatewayIp);
|
||||||
|
|
||||||
// gettery
|
|
||||||
string getHostname();
|
string getHostname();
|
||||||
string getIp();
|
string getIp();
|
||||||
string getMask();
|
string getMask();
|
||||||
string getNetwork();
|
string getNetwork();
|
||||||
string getGatewayIp();
|
string getGatewayIp();
|
||||||
|
|
||||||
virtual void onRecv(); // wirtualna metoda na odbiór i dalszą akcję
|
/*
|
||||||
|
* wirtualna metoda obsługi kolejki pakietów.
|
||||||
|
* Domyślnie wyłącznie ściąga pakiet z kolejki.
|
||||||
|
*/
|
||||||
|
virtual void onRecv();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* NODE_H_ */
|
#endif /* NODE_H_ */
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* P2PServer.cpp
|
* @file P2PServer.cpp
|
||||||
*
|
*
|
||||||
* Created on: 17.01.2017
|
* Created on: 17.01.2017
|
||||||
* Author: Piotr Dergun
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "P2PServer.h"
|
#include "P2PServer.h"
|
||||||
|
|||||||
24
P2PServer.h
24
P2PServer.h
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* P2PServer.h
|
* @file P2PServer.h
|
||||||
*
|
*
|
||||||
* Created on: 17.01.2017
|
* Created on: 17.01.2017
|
||||||
* Author: Piotr Dergun
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef P2PSERVER_H_
|
#ifndef P2PSERVER_H_
|
||||||
@@ -14,8 +14,14 @@
|
|||||||
|
|
||||||
class P2PServer : public Node
|
class P2PServer : public Node
|
||||||
{
|
{
|
||||||
string seedIp, peerIp;
|
/** adres IP seeda */
|
||||||
int seedPort, peerPort;
|
string seedIp;
|
||||||
|
/** adres IP peera */
|
||||||
|
string peerIp;
|
||||||
|
/** port seeda */
|
||||||
|
int seedPort;
|
||||||
|
/** port peera */
|
||||||
|
int peerPort;
|
||||||
Simulation *sim;
|
Simulation *sim;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -23,7 +29,13 @@ public:
|
|||||||
P2PServer(string hostname, string ip, string mask);
|
P2PServer(string hostname, string ip, string mask);
|
||||||
virtual ~P2PServer();
|
virtual ~P2PServer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* obsługuje przychodzące pakiety do serwera oraz zwraca do seeda
|
||||||
|
* informacje o adresie IP i otwartym porcie peera
|
||||||
|
*/
|
||||||
virtual void onRecv();
|
virtual void onRecv();
|
||||||
|
|
||||||
|
/* mutuatory */
|
||||||
const Simulation* getSim();
|
const Simulation* getSim();
|
||||||
void setSim(Simulation* sim);
|
void setSim(Simulation* sim);
|
||||||
};
|
};
|
||||||
|
|||||||
11
Packet.cpp
11
Packet.cpp
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Packet.cpp
|
* @file Packet.cpp
|
||||||
*
|
*
|
||||||
* Created on: 10-01-2017
|
* Created on: 10-01-2017
|
||||||
* Author: Piotr Dergun
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
@@ -12,7 +12,6 @@ Packet::Packet(string msg) : Packet()
|
|||||||
this->setMsg(msg);
|
this->setMsg(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
//settery
|
|
||||||
void Packet::setSrcIp(string srcIp)
|
void Packet::setSrcIp(string srcIp)
|
||||||
{
|
{
|
||||||
this->srcIp = srcIp;
|
this->srcIp = srcIp;
|
||||||
@@ -48,7 +47,7 @@ string Packet::getDstIp()
|
|||||||
return this->dstIp;
|
return this->dstIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Packet::Packet::getSrcPort()
|
int Packet::getSrcPort()
|
||||||
{
|
{
|
||||||
return this->srcPort;
|
return this->srcPort;
|
||||||
}
|
}
|
||||||
|
|||||||
17
Packet.h
17
Packet.h
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Packet.h
|
* @file Packet.h
|
||||||
*
|
*
|
||||||
* Created on: 10-01-2017
|
* Created on: 10-01-2017
|
||||||
* Author: Piotr Dergun
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PACKET_H_
|
#ifndef PACKET_H_
|
||||||
@@ -12,23 +12,26 @@
|
|||||||
|
|
||||||
class Packet
|
class Packet
|
||||||
{
|
{
|
||||||
|
/** adres IP źródłowy */
|
||||||
string srcIp;
|
string srcIp;
|
||||||
|
/** adres IP docelowy */
|
||||||
string dstIp;
|
string dstIp;
|
||||||
|
/** port źródłowy */
|
||||||
int srcPort;
|
int srcPort;
|
||||||
|
/** port docelowy */
|
||||||
int dstPort;
|
int dstPort;
|
||||||
|
/** treść pakietu - wiadomość, komunikat */
|
||||||
string msg;
|
string msg;
|
||||||
public:
|
public:
|
||||||
Packet() : srcIp("0.0.0.0"), dstIp("0.0.0.0"), srcPort(0), dstPort(0), msg("") {}
|
Packet() : srcIp("0.0.0.0"), dstIp("0.0.0.0"), srcPort(0), dstPort(0), msg("") {}
|
||||||
Packet(string msg);
|
Packet(string msg);
|
||||||
|
|
||||||
// settery
|
/* mutuatory */
|
||||||
void setSrcIp(string srcIp);
|
void setSrcIp(string srcIp);
|
||||||
void setDstIp(string dstIp);
|
void setDstIp(string dstIp);
|
||||||
void setSrcPort(int srcPort);
|
void setSrcPort(int srcPort);
|
||||||
void setDstPort(int dstPort);
|
void setDstPort(int dstPort);
|
||||||
void setMsg(string msg);
|
void setMsg(string msg);
|
||||||
|
|
||||||
// gettery
|
|
||||||
string getSrcIp();
|
string getSrcIp();
|
||||||
string getDstIp();
|
string getDstIp();
|
||||||
int getSrcPort();
|
int getSrcPort();
|
||||||
|
|||||||
8
Peer.cpp
8
Peer.cpp
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Peer.cpp
|
* @file Peer.cpp
|
||||||
*
|
*
|
||||||
* Created on: 17.01.2017
|
* Created on: 17.01.2017
|
||||||
* Author: piotrek
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
|
|||||||
33
Peer.h
33
Peer.h
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Peer.h
|
* @file Peer.h
|
||||||
*
|
*
|
||||||
* Created on: 17.01.2017
|
* Created on: 17.01.2017
|
||||||
* Author: piotrek
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PEER_H_
|
#ifndef PEER_H_
|
||||||
@@ -14,11 +14,17 @@
|
|||||||
|
|
||||||
class Peer : public Node
|
class Peer : public Node
|
||||||
{
|
{
|
||||||
|
/** flaga definiująca czy węzeł jest seedem (true) */
|
||||||
bool sender;
|
bool sender;
|
||||||
|
/** źródłowy port węzła */
|
||||||
int srcPort;
|
int srcPort;
|
||||||
|
/** adres IP drugiej strony */
|
||||||
string remoteIp;
|
string remoteIp;
|
||||||
|
/** port drugiej strony */
|
||||||
int remotePort;
|
int remotePort;
|
||||||
|
/** numer części danych pobrany/odebrany */
|
||||||
int partId;
|
int partId;
|
||||||
|
/** wskaźnik do obiektu symulacji w celu pisania w jego logu */
|
||||||
Simulation *sim;
|
Simulation *sim;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -26,15 +32,34 @@ public:
|
|||||||
Peer(string hostname, string ip, string mask, string gatewayIp);
|
Peer(string hostname, string ip, string mask, string gatewayIp);
|
||||||
virtual ~Peer() {};
|
virtual ~Peer() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wykonuje i rozdziela akcje seeda/peera jeżeli węzeł otrzyma pakiet
|
||||||
|
*/
|
||||||
virtual void onRecv();
|
virtual void onRecv();
|
||||||
|
/**
|
||||||
|
* wykonuje połączenie z serwerem p2p w celu otrzymania informacji
|
||||||
|
* o drugiej stronie lub wysyłając żądanie pobrania pliku
|
||||||
|
* @param serverIp adres IP serwera
|
||||||
|
* @param serverPort port serwera
|
||||||
|
*/
|
||||||
void connectToServer(string serverIp, int serverPort);
|
void connectToServer(string serverIp, int serverPort);
|
||||||
|
|
||||||
|
/* mutuatory */
|
||||||
bool isSender() const;
|
bool isSender() const;
|
||||||
void setSender(bool sender);
|
void setSender(bool sender);
|
||||||
const Simulation* getSim();
|
const Simulation* getSim();
|
||||||
void setSim(Simulation* sim);
|
void setSim(Simulation* sim);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* wysyła dane do peera, jeżeli obiekt jest nadawcą (seedem)
|
||||||
|
*/
|
||||||
void sendData();
|
void sendData();
|
||||||
|
/**
|
||||||
|
* wysyła odpowiedź o odebraniu danych, jeżeli obiekt jest odbiorcą (peerem)
|
||||||
|
* @param dstIp port docelowy seeda
|
||||||
|
* @param dstPort port docelowy seeda
|
||||||
|
*/
|
||||||
void sendAck(string dstIp, int dstPort);
|
void sendAck(string dstIp, int dstPort);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Simulation.cpp
|
* @file Simulation.cpp
|
||||||
*
|
*
|
||||||
* Created on: 16.01.2017
|
* Created on: 16.01.2017
|
||||||
* Author: piotrek
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Simulation.h"
|
#include "Simulation.h"
|
||||||
|
|||||||
46
Simulation.h
46
Simulation.h
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Simulation.h
|
* @file Simulation.h
|
||||||
*
|
*
|
||||||
* Created on: 16.01.2017
|
* Created on: 16.01.2017
|
||||||
* Author: piotrek
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SIMULATION_H_
|
#ifndef SIMULATION_H_
|
||||||
@@ -28,22 +28,56 @@ struct threadParams
|
|||||||
|
|
||||||
class Simulation : public Log
|
class Simulation : public Log
|
||||||
{
|
{
|
||||||
|
/** mapa z informacjami o wątkach */
|
||||||
map<string, struct threadParams> threads;
|
map<string, struct threadParams> threads;
|
||||||
int cols, rows;
|
/** ilość kolumn terminala */
|
||||||
|
int cols;
|
||||||
|
/** ilość wierszy terminala */
|
||||||
|
int rows;
|
||||||
|
/** nazwa obiektu, wymagana przez klasę Log */
|
||||||
string name;
|
string name;
|
||||||
|
/** timestamp w momencie uruchomienia symulacji */
|
||||||
unsigned long startTime;
|
unsigned long startTime;
|
||||||
public:
|
public:
|
||||||
Simulation();
|
Simulation();
|
||||||
~Simulation();
|
~Simulation();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tworzy wątek
|
||||||
|
* @param name nazwa wątku
|
||||||
|
* @param type typ wątku, do ustalania rzutowania i wywołania odpowiedniej metody
|
||||||
|
* @param context wskaźnik do obiektu, z którego będzie wywoływana odpowiednia metoda
|
||||||
|
*/
|
||||||
void createThread(string name, THREAD_TYPE type, void * context);
|
void createThread(string name, THREAD_TYPE type, void * context);
|
||||||
|
/**
|
||||||
|
* usuwa wątek
|
||||||
|
* @param name nazwa wątku
|
||||||
|
*/
|
||||||
void destroyThread(string name);
|
void destroyThread(string name);
|
||||||
|
/**
|
||||||
|
* wrapper, w który trzeba opakować metody do zastosowania w wątku
|
||||||
|
* @param context wskaźnik do obiektu, z którego będzie wywoływana odpowiednia metoda
|
||||||
|
*/
|
||||||
static void * threadWrapper(void * context);
|
static void * threadWrapper(void * context);
|
||||||
|
/**
|
||||||
|
* wykonuje się w wątku i dba o właściwe dane o rozmiarze okna
|
||||||
|
*/
|
||||||
void resizeWnd();
|
void resizeWnd();
|
||||||
|
/**
|
||||||
|
* wykonuje się w wątku i wyświetla aktualny czas symulacji
|
||||||
|
*/
|
||||||
void timer();
|
void timer();
|
||||||
|
/**
|
||||||
|
* uruchamia symulację typowego P2P - seed i peer łączy się z serwerem-trackerem
|
||||||
|
* a serwer odsyła informację zwrotną do seeda z informacją o adresie IP i porcie
|
||||||
|
* źródłowym peera
|
||||||
|
*/
|
||||||
void p2pSimulation();
|
void p2pSimulation();
|
||||||
|
/**
|
||||||
|
* uruchamia symulację przeciążenia NAT - sytuacji, w której wszystkie 65535 portów
|
||||||
|
* w tablicy NAT routera są zajęte i nie można dokonać SNAT+maskarady
|
||||||
|
* @param nNodes liczba klientów łączących się z serwerem
|
||||||
|
*/
|
||||||
void natOverflowSimulation(int nNodes);
|
void natOverflowSimulation(int nNodes);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
8
common.h
8
common.h
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* common.h
|
* @file common.h
|
||||||
*
|
*
|
||||||
* Created on: 10.01.2017
|
* Created on: 10.01.2017
|
||||||
* Author: Piotr Dergun
|
* @author Piotr Dergun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef COMMON_H_
|
#ifndef COMMON_H_
|
||||||
|
|||||||
2352
nat.doxyfile
Normal file
2352
nat.doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user