Browse Source

poprawki czasu symulacji P2P

master
Piotr Dergun 7 years ago
parent
commit
724cb01232
3 changed files with 27 additions and 27 deletions
  1. +1
    -1
      NATRouter.cpp
  2. +2
    -2
      P2PServer.cpp
  3. +24
    -24
      Simulation.cpp

+ 1
- 1
NATRouter.cpp View File

@ -155,7 +155,7 @@ void NATRouter::sNAT(Packet *packet)
natItem = &this->natTable[port];
natItem->setIp(packet->getSrcIp());
natItem->setPort(packet->getSrcPort());
natItem->setTimeout(/*5*/10);
natItem->setTimeout(/*5*/15);
stringstream ss;
ss << "SNAT " << packet->getSrcIp() << ":" << packet->getSrcPort() << " --> " << this->getWanIp() << ":" << port;

+ 2
- 2
P2PServer.cpp View File

@ -41,7 +41,7 @@ void P2PServer::onRecv()
{
ss << "onRecv() Received \"" << p.getMsg() << "\" from " << p.getSrcIp() << ":" << p.getSrcPort();
this->print(ss.str());
sleep(1);
sleep(2);
if (p.getMsg() == "getRemoteIPPort")
{
@ -69,7 +69,7 @@ void P2PServer::onRecv()
ss << "Sending \"" << pp.getMsg() << "\" to " << pp.getDstIp() << ":" << pp.getDstPort();
this->print(ss.str());
this->send(pp);
sleep(1);
sleep(3);
}
}
else

+ 24
- 24
Simulation.cpp View File

@ -174,15 +174,15 @@ void Simulation::timer()
void Simulation::p2pSimulation()
{
this->print("Creating P2P peers");
Peer peer1("Peer 1", "192.168.1.2", "255.255.255.0", "192.168.1.1");
peer1.setSender(true);
peer1.setSim(this);
peer1.setLogParams(0, GREEN, "\t\t");
Peer peer2("Peer 2", "10.0.0.2", "255.255.255.0", "10.0.0.1");
peer2.setSim(this);
peer2.setLogParams(4, CYAN, "\t\t");
peer1.print("IP 192.168.1.2/24, Gateway: 192.168.1.1");
peer2.print("IP 10.0.0.2/24, Gateway: 10.0.0.1");
Peer seed("Seed", "192.168.1.2", "255.255.255.0", "192.168.1.1");
seed.setSender(true);
seed.setSim(this);
seed.setLogParams(0, GREEN, "\t\t");
Peer peer("Peer", "10.0.0.2", "255.255.255.0", "10.0.0.1");
peer.setSim(this);
peer.setLogParams(4, CYAN, "\t\t");
seed.print("IP 192.168.1.2/24, Gateway: 192.168.1.1");
peer.print("IP 10.0.0.2/24, Gateway: 10.0.0.1");
sleep(1);
this->print("Creating NAT devices");
@ -210,35 +210,35 @@ void Simulation::p2pSimulation()
server.print("IP 80.80.90.91/32");
sleep(1);
this->print("Plugging Peer1 <---> Router 1");
r1.connectNode(&peer1);
sleep(1);
this->print("Plugging Peer2 <---> Router 2");
r2.connectNode(&peer2);
sleep(1);
this->print("Plugging Seed <---> Router 1");
r1.connectNode(&seed);
usleep(600000);
this->print("Plugging Peer <---> Router 2");
r2.connectNode(&peer);
usleep(600000);
this->print("Plugging Router 1 <---> Router 2");
r1.connectNode(&r2, true);
sleep(1);
usleep(600000);
this->print("Plugging Server <---> Router 1");
server.connectNode(&r1);
sleep(1);
usleep(600000);
this->print("Plugging Server <---> Router 2");
server.connectNode(&r2);
sleep(1);
usleep(600000);
this->print("Starting simulation...");
sleep(1);
this->print("Starting simulation...");
this->createThread("r1", NODE_RECV, &r1);
this->createThread("r2", NODE_RECV, &r2);
this->createThread("s1", NODE_RECV, &server);
this->print("Connecting peers to P2P server");
peer1.connectToServer("80.80.90.91", 6565);
peer2.connectToServer("80.80.90.91", 6565);
sleep(1);
this->createThread("p1", NODE_RECV, &peer1);
this->createThread("p2", NODE_RECV, &peer2);
seed.connectToServer("80.80.90.91", 6565);
peer.connectToServer("80.80.90.91", 6565);
sleep(3);
this->createThread("p1", NODE_RECV, &seed);
this->createThread("p2", NODE_RECV, &peer);

Loading…
Cancel
Save