logowanie informacji ogolnych o symulacji
This commit is contained in:
7
Log.cpp
7
Log.cpp
@@ -70,8 +70,11 @@ void Log::print(string msg)
|
||||
if(has_colors())
|
||||
attron(COLOR_PAIR(this->getColor()));
|
||||
|
||||
printw("%s:%s%s", this->getObjectName()->c_str(), this->getDelimiter().c_str(), msg.c_str());
|
||||
|
||||
//printw("%s:%s%s", this->getObjectName()->c_str(), this->getDelimiter().c_str(), msg.c_str());
|
||||
printw("%s:%s", this->getObjectName()->c_str(), this->getDelimiter().c_str());
|
||||
attron(A_BOLD);
|
||||
printw("%s", msg.c_str());
|
||||
attroff(A_BOLD);
|
||||
if(has_colors())
|
||||
attroff(COLOR_PAIR(this->getColor()));
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ P2PServer::P2PServer()
|
||||
this->peerIp = "";
|
||||
this->seedPort = 0;
|
||||
this->peerPort = 0;
|
||||
this->sim = NULL;
|
||||
}
|
||||
|
||||
P2PServer::P2PServer(string hostname, string ip, string mask) : Node(hostname, ip, mask)
|
||||
@@ -21,6 +22,7 @@ P2PServer::P2PServer(string hostname, string ip, string mask) : Node(hostname,
|
||||
this->peerIp = "";
|
||||
this->seedPort = 0;
|
||||
this->peerPort = 0;
|
||||
this->sim = NULL;
|
||||
}
|
||||
|
||||
P2PServer::~P2PServer()
|
||||
@@ -62,6 +64,8 @@ void P2PServer::onRecv()
|
||||
pp.setSrcPort(p.getDstPort());
|
||||
ss.str("");
|
||||
|
||||
if (this->sim)
|
||||
this->sim->print("Sending to seed information about peer IP and port");
|
||||
ss << "Sending \"" << pp.getMsg() << "\" to " << pp.getDstIp() << ":" << pp.getDstPort();
|
||||
this->print(ss.str());
|
||||
this->send(pp);
|
||||
@@ -77,3 +81,13 @@ void P2PServer::onRecv()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Simulation* P2PServer::getSim()
|
||||
{
|
||||
return sim;
|
||||
}
|
||||
|
||||
void P2PServer::setSim(Simulation* sim)
|
||||
{
|
||||
this->sim = sim;
|
||||
}
|
||||
|
||||
@@ -10,17 +10,22 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "Node.h"
|
||||
#include "Simulation.h"
|
||||
|
||||
class P2PServer : public Node
|
||||
{
|
||||
string seedIp, peerIp;
|
||||
int seedPort, peerPort;
|
||||
Simulation *sim;
|
||||
|
||||
public:
|
||||
P2PServer();
|
||||
P2PServer(string hostname, string ip, string mask);
|
||||
virtual ~P2PServer();
|
||||
|
||||
virtual void onRecv();
|
||||
const Simulation* getSim();
|
||||
void setSim(Simulation* sim);
|
||||
};
|
||||
|
||||
#endif /* P2PSERVER_H_ */
|
||||
|
||||
15
Peer.cpp
15
Peer.cpp
@@ -13,6 +13,7 @@ Peer::Peer()
|
||||
this->srcPort = 0;
|
||||
this->remotePort = 0;
|
||||
this->sender = false;
|
||||
this->sim = NULL;
|
||||
}
|
||||
|
||||
Peer::Peer(string hostname, string ip, string mask, string gatewayIp) : Node(hostname, ip, mask, gatewayIp)
|
||||
@@ -21,6 +22,7 @@ Peer::Peer(string hostname, string ip, string mask, string gatewayIp) : Node(hos
|
||||
this->srcPort = 0;
|
||||
this->remotePort = 0;
|
||||
this->sender = false;
|
||||
this->sim = NULL;
|
||||
}
|
||||
|
||||
void Peer::onRecv()
|
||||
@@ -102,6 +104,8 @@ void Peer::sendData()
|
||||
p.setMsg(ss.str());
|
||||
ss.str("");
|
||||
|
||||
if (this->sim)
|
||||
this->sim->print("Sending a data to peer");
|
||||
ss << "Sending \"" << p.getMsg() << "\" to " << p.getDstIp() << ":" << p.getDstPort();
|
||||
this->print(ss.str());
|
||||
this->send(p);
|
||||
@@ -128,10 +132,19 @@ void Peer::sendAck(string dstIp, int dstPort)
|
||||
p.setMsg(ss.str());
|
||||
ss.str("");
|
||||
|
||||
if (this->sim)
|
||||
this->sim->print("Sending an acknowledgement to seed");
|
||||
ss << "Sending \"" << p.getMsg() << "\" to " << p.getDstIp() << ":" << p.getDstPort();
|
||||
this->print(ss.str());
|
||||
this->send(p);
|
||||
}
|
||||
|
||||
const Simulation* Peer::getSim()
|
||||
{
|
||||
return sim;
|
||||
}
|
||||
|
||||
|
||||
void Peer::setSim(Simulation* sim)
|
||||
{
|
||||
this->sim = sim;
|
||||
}
|
||||
|
||||
4
Peer.h
4
Peer.h
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "Node.h"
|
||||
#include "Simulation.h"
|
||||
|
||||
class Peer : public Node
|
||||
{
|
||||
@@ -18,6 +19,7 @@ class Peer : public Node
|
||||
string remoteIp;
|
||||
int remotePort;
|
||||
int partId;
|
||||
Simulation *sim;
|
||||
|
||||
public:
|
||||
Peer();
|
||||
@@ -28,6 +30,8 @@ public:
|
||||
void connectToServer(string serverIp, int serverPort);
|
||||
bool isSender() const;
|
||||
void setSender(bool sender);
|
||||
const Simulation* getSim();
|
||||
void setSim(Simulation* sim);
|
||||
|
||||
protected:
|
||||
void sendData();
|
||||
|
||||
@@ -176,8 +176,10 @@ 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");
|
||||
@@ -203,6 +205,7 @@ void Simulation::p2pSimulation()
|
||||
|
||||
this->print("Creating P2P server");
|
||||
P2PServer server("Server", "80.80.90.91", "255.255.255.255");
|
||||
server.setSim(this);
|
||||
server.setLogParams(2, YELLOW, "\t\t");
|
||||
server.print("IP 80.80.90.91/32");
|
||||
sleep(1);
|
||||
@@ -230,6 +233,7 @@ void Simulation::p2pSimulation()
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user