diff --git a/Log.cpp b/Log.cpp index 882d5d1..4cc8c6f 100644 --- a/Log.cpp +++ b/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())); diff --git a/P2PServer.cpp b/P2PServer.cpp index 0577065..e882ef3 100644 --- a/P2PServer.cpp +++ b/P2PServer.cpp @@ -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; +} diff --git a/P2PServer.h b/P2PServer.h index cdd760a..ebab016 100644 --- a/P2PServer.h +++ b/P2PServer.h @@ -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_ */ diff --git a/Peer.cpp b/Peer.cpp index 496e08a..0fc6360 100644 --- a/Peer.cpp +++ b/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; +} diff --git a/Peer.h b/Peer.h index 4410aa3..8dbe723 100644 --- a/Peer.h +++ b/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(); diff --git a/Simulation.cpp b/Simulation.cpp index d484c87..63a93ed 100644 --- a/Simulation.cpp +++ b/Simulation.cpp @@ -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);