/** * @file Peer.h * * Created on: 17.01.2017 * @author Piotr Dergun */ #ifndef PEER_H_ #define PEER_H_ #include "common.h" #include "Node.h" #include "Simulation.h" class Peer : public Node { /** flaga definiująca czy węzeł jest seedem (true) */ bool sender; /** źródłowy port węzła */ int srcPort; /** adres IP drugiej strony */ string remoteIp; /** port drugiej strony */ int remotePort; /** numer części danych pobrany/odebrany */ int partId; /** wskaźnik do obiektu symulacji w celu pisania w jego logu */ Simulation *sim; public: Peer(); Peer(string hostname, string ip, string mask, string gatewayIp); virtual ~Peer() {}; /** * wykonuje i rozdziela akcje seeda/peera jeżeli węzeł otrzyma pakiet */ virtual void onRecv(); /** * wykonuje połączenie z serwerem p2p w celu otrzymania informacji * o drugiej stronie lub wysyłając żądanie pobrania pliku * @param serverIp adres IP serwera * @param serverPort port serwera */ void connectToServer(string serverIp, int serverPort); /* mutuatory */ bool isSender() const; void setSender(bool sender); const Simulation* getSim(); void setSim(Simulation* sim); protected: /** * wysyła dane do peera, jeżeli obiekt jest nadawcą (seedem) */ void sendData(); /** * wysyła odpowiedź o odebraniu danych, jeżeli obiekt jest odbiorcą (peerem) * @param dstIp port docelowy seeda * @param dstPort port docelowy seeda */ void sendAck(string dstIp, int dstPort); }; #endif /* PEER_H_ */