nat overflow working 100%
This commit is contained in:
41
Log.cpp
41
Log.cpp
@@ -13,7 +13,8 @@ Log::Log()
|
||||
this->delimiter = "";
|
||||
this->lineNumber = 0;
|
||||
this->objectName = NULL;
|
||||
|
||||
this->currentLine = 0;
|
||||
this->firstLine = 0;
|
||||
this->writeMutex = Log::getMutex();
|
||||
this->setDelay(1);
|
||||
}
|
||||
@@ -120,13 +121,44 @@ void Log::printProgressBar(int lineNumber, int offset, string msg,
|
||||
cout << this->getObjectName()->c_str() << ": " << this->getDelimiter() << msg << endl;
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* metoda wypisuje log w wielu liniach od firstLineNumber do rows-2
|
||||
*/
|
||||
void Log::printLine(string msg, bool force)
|
||||
{
|
||||
int cols, rows;
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
|
||||
if (this->currentLine > rows-3)
|
||||
this->currentLine = this->firstLine;
|
||||
|
||||
this->print(msg, force, this->currentLine);
|
||||
|
||||
pthread_mutex_lock(this->writeMutex);
|
||||
move(this->currentLine+1, 0);
|
||||
clrtoeol();
|
||||
move(0,0);
|
||||
pthread_mutex_unlock(this->writeMutex);
|
||||
++this->currentLine;
|
||||
}
|
||||
|
||||
int Log::getFirstLine() const
|
||||
{
|
||||
return firstLine;
|
||||
}
|
||||
|
||||
void Log::setFirstLine(int firstLine)
|
||||
{
|
||||
this->firstLine = firstLine;
|
||||
this->currentLine = firstLine;
|
||||
}
|
||||
|
||||
void Log::setObjectName(string* objectName)
|
||||
{
|
||||
this->objectName = objectName;
|
||||
}
|
||||
|
||||
void Log::print(string msg, bool force)
|
||||
void Log::print(string msg, bool force, int customLine)
|
||||
{
|
||||
#ifndef DEBUG
|
||||
if (this->getObjectName() == NULL)
|
||||
@@ -136,7 +168,10 @@ void Log::print(string msg, bool force)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(this->writeMutex);
|
||||
move(this->getLineNumber(), 0);
|
||||
if (customLine > -1)
|
||||
move(customLine, 0);
|
||||
else
|
||||
move(this->getLineNumber(), 0);
|
||||
clrtoeol();
|
||||
|
||||
if(has_colors())
|
||||
|
||||
9
Log.h
9
Log.h
@@ -29,10 +29,13 @@ class Log
|
||||
string *objectName;
|
||||
pthread_mutex_t *writeMutex;
|
||||
int delayVal;
|
||||
|
||||
/* do obslugi wielolinijkowosci (na dole) */
|
||||
int firstLine;
|
||||
int currentLine;
|
||||
public:
|
||||
Log();
|
||||
void print(string msg, bool force=false);
|
||||
void print(string msg, bool force=false, int customLine = -1);
|
||||
void printLine(string msg, bool force=false);
|
||||
void printProgressBar(int lineNumber, int offset, string msg, float percent);
|
||||
|
||||
LOG_COLOR getColor() const;
|
||||
@@ -48,6 +51,8 @@ public:
|
||||
void setDelay(int delay);
|
||||
string* getObjectName() const;
|
||||
void setObjectName(string* objectName);
|
||||
int getFirstLine() const;
|
||||
void setFirstLine(int firstLine);
|
||||
};
|
||||
|
||||
#endif /* LOG_H_ */
|
||||
|
||||
4
Main.cpp
4
Main.cpp
@@ -40,9 +40,9 @@ int main(int argc, char *argv[])
|
||||
usage(argv[0]);
|
||||
|
||||
nodesCount = strtol(argv[2], &endptr, 10);
|
||||
if (nodesCount < 1 || nodesCount > 255)
|
||||
if (nodesCount < 1 || nodesCount > 253)
|
||||
{
|
||||
cerr << "Invalid number of nodes format [1,255]" << endl;
|
||||
cerr << "Invalid number of nodes format [1,253]" << endl;
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -251,8 +251,9 @@ void Simulation::p2pSimulation()
|
||||
|
||||
void Simulation::natOverflowSimulation(int nNodes)
|
||||
{
|
||||
int i = 0;//, srcPort;
|
||||
int i = 0, srcPort;
|
||||
stringstream ss;
|
||||
string hostname;
|
||||
|
||||
this->print("Creating server");
|
||||
Node server("Server", "93.92.91.90", "255.255.255.255");
|
||||
@@ -275,10 +276,8 @@ void Simulation::natOverflowSimulation(int nNodes)
|
||||
|
||||
this->print("Creating and setting clients");
|
||||
Node *client = new Node[nNodes];
|
||||
int *currentSrcPort = new int[nNodes];
|
||||
for (i = 0; i < nNodes; ++i)
|
||||
{
|
||||
currentSrcPort[i] = 1;
|
||||
client[i].setLogParams(2, CYAN, "\t");
|
||||
ss.str("");
|
||||
ss << "Client " << (i + 1);
|
||||
@@ -318,16 +317,22 @@ void Simulation::natOverflowSimulation(int nNodes)
|
||||
p.setDstPort(80);
|
||||
i=0;
|
||||
|
||||
Log clientLog;
|
||||
clientLog.setLogParams(5, MAGENTA, "\t");
|
||||
clientLog.setFirstLine(6);
|
||||
clientLog.setObjectName(&hostname);
|
||||
|
||||
while(true)
|
||||
{
|
||||
i = (nNodes>1) ? rand()%nNodes : 0;
|
||||
if (currentSrcPort[i] == 65535)
|
||||
currentSrcPort[i] = 1;
|
||||
ss.str("");
|
||||
|
||||
//p.setSrcPort(currentSrcPort[i]++);
|
||||
p.setSrcPort(0);
|
||||
client[i].send(p);
|
||||
//p.setSrcPort(0);
|
||||
srcPort = client[i].send(p);
|
||||
hostname = client[i].getHostname();
|
||||
|
||||
ss << "Sent " << client[i].getIp() << ":" << srcPort << " to 93.92.91.90:80";
|
||||
clientLog.printLine(ss.str());
|
||||
this->delay(150);
|
||||
//usleep(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user