|
@ -9,9 +9,12 @@ |
|
|
#include "Node.h"
|
|
|
#include "Node.h"
|
|
|
#include "NATRouter.h"
|
|
|
#include "NATRouter.h"
|
|
|
#include "Peer.h"
|
|
|
#include "Peer.h"
|
|
|
|
|
|
#include "P2PServer.h"
|
|
|
|
|
|
|
|
|
Simulation::Simulation() |
|
|
Simulation::Simulation() |
|
|
{ |
|
|
{ |
|
|
|
|
|
srand(time(NULL)); |
|
|
|
|
|
|
|
|
this->rows = 0; |
|
|
this->rows = 0; |
|
|
this->cols = 0; |
|
|
this->cols = 0; |
|
|
#ifndef DEBUG
|
|
|
#ifndef DEBUG
|
|
@ -145,11 +148,14 @@ void Simulation::resizeWnd() |
|
|
|
|
|
|
|
|
void Simulation::timer() |
|
|
void Simulation::timer() |
|
|
{ |
|
|
{ |
|
|
|
|
|
#ifndef DEBUG
|
|
|
char str[10]; |
|
|
char str[10]; |
|
|
int h,m, s; |
|
|
int h,m, s; |
|
|
unsigned long timeElapsed; |
|
|
unsigned long timeElapsed; |
|
|
|
|
|
#endif
|
|
|
while(true) |
|
|
while(true) |
|
|
{ |
|
|
{ |
|
|
|
|
|
#ifndef DEBUG
|
|
|
refresh(); |
|
|
refresh(); |
|
|
timeElapsed = time(NULL) - this->startTime; |
|
|
timeElapsed = time(NULL) - this->startTime; |
|
|
h = timeElapsed / 3600; |
|
|
h = timeElapsed / 3600; |
|
@ -159,6 +165,7 @@ void Simulation::timer() |
|
|
sprintf(str, "%02d:%02d:%02d", h, m, s); |
|
|
sprintf(str, "%02d:%02d:%02d", h, m, s); |
|
|
move(0, this->cols-strlen(str)); |
|
|
move(0, this->cols-strlen(str)); |
|
|
printw(str); |
|
|
printw(str); |
|
|
|
|
|
#endif
|
|
|
usleep(100000); // 100 ms
|
|
|
usleep(100000); // 100 ms
|
|
|
//sleep(1);
|
|
|
//sleep(1);
|
|
|
} |
|
|
} |
|
@ -168,6 +175,7 @@ void Simulation::p2pSimulation() |
|
|
{ |
|
|
{ |
|
|
this->print("Creating P2P peers"); |
|
|
this->print("Creating P2P peers"); |
|
|
Peer peer1("Peer 1", "192.168.1.2", "255.255.255.0", "192.168.1.1"); |
|
|
Peer peer1("Peer 1", "192.168.1.2", "255.255.255.0", "192.168.1.1"); |
|
|
|
|
|
peer1.setSender(true); |
|
|
peer1.setLogParams(0, GREEN, "\t\t"); |
|
|
peer1.setLogParams(0, GREEN, "\t\t"); |
|
|
Peer peer2("Peer 2", "10.0.0.2", "255.255.255.0", "10.0.0.1"); |
|
|
Peer peer2("Peer 2", "10.0.0.2", "255.255.255.0", "10.0.0.1"); |
|
|
peer2.setLogParams(4, CYAN, "\t\t"); |
|
|
peer2.setLogParams(4, CYAN, "\t\t"); |
|
@ -194,7 +202,7 @@ void Simulation::p2pSimulation() |
|
|
sleep(1); |
|
|
sleep(1); |
|
|
|
|
|
|
|
|
this->print("Creating P2P server"); |
|
|
this->print("Creating P2P server"); |
|
|
Node server("Server", "80.80.90.91", "255.255.255.255"); |
|
|
|
|
|
|
|
|
P2PServer server("Server", "80.80.90.91", "255.255.255.255"); |
|
|
server.setLogParams(2, YELLOW, "\t\t"); |
|
|
server.setLogParams(2, YELLOW, "\t\t"); |
|
|
server.print("IP 80.80.90.91/32"); |
|
|
server.print("IP 80.80.90.91/32"); |
|
|
sleep(1); |
|
|
sleep(1); |
|
@ -221,11 +229,13 @@ void Simulation::p2pSimulation() |
|
|
this->createThread("r1", NODE_RECV, &r1); |
|
|
this->createThread("r1", NODE_RECV, &r1); |
|
|
this->createThread("r2", NODE_RECV, &r2); |
|
|
this->createThread("r2", NODE_RECV, &r2); |
|
|
this->createThread("s1", NODE_RECV, &server); |
|
|
this->createThread("s1", NODE_RECV, &server); |
|
|
this->createThread("p2", NODE_RECV, &peer2); |
|
|
|
|
|
|
|
|
|
|
|
peer1.connectToServer("80.80.90.91", 6565); |
|
|
peer1.connectToServer("80.80.90.91", 6565); |
|
|
|
|
|
peer2.connectToServer("80.80.90.91", 6565); |
|
|
sleep(1); |
|
|
sleep(1); |
|
|
this->createThread("p1", NODE_RECV, &peer1); |
|
|
this->createThread("p1", NODE_RECV, &peer1); |
|
|
|
|
|
this->createThread("p2", NODE_RECV, &peer2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(1); |
|
|
while(1); |
|
|