Symulacja NAT na przedmiot Symulacje Komputerowe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.5 KiB

  1. /**
  2. * @file Peer.h
  3. *
  4. * Created on: 17.01.2017
  5. * @author Piotr Dergun
  6. */
  7. #ifndef PEER_H_
  8. #define PEER_H_
  9. #include "common.h"
  10. #include "Node.h"
  11. #include "Simulation.h"
  12. class Peer : public Node
  13. {
  14. /** flaga definiująca czy węzeł jest seedem (true) */
  15. bool sender;
  16. /** źródłowy port węzła */
  17. int srcPort;
  18. /** adres IP drugiej strony */
  19. string remoteIp;
  20. /** port drugiej strony */
  21. int remotePort;
  22. /** numer części danych pobrany/odebrany */
  23. int partId;
  24. /** wskaźnik do obiektu symulacji w celu pisania w jego logu */
  25. Simulation *sim;
  26. public:
  27. Peer();
  28. Peer(string hostname, string ip, string mask, string gatewayIp);
  29. virtual ~Peer() {};
  30. /**
  31. * wykonuje i rozdziela akcje seeda/peera jeżeli węzeł otrzyma pakiet
  32. */
  33. virtual void onRecv();
  34. /**
  35. * wykonuje połączenie z serwerem p2p w celu otrzymania informacji
  36. * o drugiej stronie lub wysyłając żądanie pobrania pliku
  37. * @param serverIp adres IP serwera
  38. * @param serverPort port serwera
  39. */
  40. void connectToServer(string serverIp, int serverPort);
  41. /* mutuatory */
  42. bool isSender() const;
  43. void setSender(bool sender);
  44. const Simulation* getSim();
  45. void setSim(Simulation* sim);
  46. protected:
  47. /**
  48. * wysyła dane do peera, jeżeli obiekt jest nadawcą (seedem)
  49. */
  50. void sendData();
  51. /**
  52. * wysyła odpowiedź o odebraniu danych, jeżeli obiekt jest odbiorcą (peerem)
  53. * @param dstIp port docelowy seeda
  54. * @param dstPort port docelowy seeda
  55. */
  56. void sendAck(string dstIp, int dstPort);
  57. };
  58. #endif /* PEER_H_ */