peerhandler.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "networkprotocol.h"
  18. namespace con
  19. {
  20. typedef enum {
  21. MIN_RTT,
  22. MAX_RTT,
  23. AVG_RTT,
  24. MIN_JITTER,
  25. MAX_JITTER,
  26. AVG_JITTER
  27. } rtt_stat_type;
  28. class Peer;
  29. class PeerHandler
  30. {
  31. public:
  32. PeerHandler() = default;
  33. virtual ~PeerHandler() = default;
  34. /*
  35. This is called after the Peer has been inserted into the
  36. Connection's peer container.
  37. */
  38. virtual void peerAdded(Peer *peer) = 0;
  39. /*
  40. This is called before the Peer has been removed from the
  41. Connection's peer container.
  42. */
  43. virtual void deletingPeer(Peer *peer, bool timeout) = 0;
  44. };
  45. enum PeerChangeType : u8
  46. {
  47. PEER_ADDED,
  48. PEER_REMOVED
  49. };
  50. struct PeerChange
  51. {
  52. PeerChange(PeerChangeType t, session_t _peer_id, bool _timeout) :
  53. type(t), peer_id(_peer_id), timeout(_timeout)
  54. {
  55. }
  56. PeerChange() = delete;
  57. PeerChangeType type;
  58. session_t peer_id;
  59. bool timeout;
  60. };
  61. }