peerhandler.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. {
  22. MIN_RTT,
  23. MAX_RTT,
  24. AVG_RTT,
  25. MIN_JITTER,
  26. MAX_JITTER,
  27. AVG_JITTER
  28. } rtt_stat_type;
  29. class Peer;
  30. class PeerHandler
  31. {
  32. public:
  33. PeerHandler() = default;
  34. virtual ~PeerHandler() = default;
  35. /*
  36. This is called after the Peer has been inserted into the
  37. Connection's peer container.
  38. */
  39. virtual void peerAdded(Peer *peer) = 0;
  40. /*
  41. This is called before the Peer has been removed from the
  42. Connection's peer container.
  43. */
  44. virtual void deletingPeer(Peer *peer, bool timeout) = 0;
  45. };
  46. enum PeerChangeType : u8
  47. {
  48. PEER_ADDED,
  49. PEER_REMOVED
  50. };
  51. struct PeerChange
  52. {
  53. PeerChange(PeerChangeType t, session_t _peer_id, bool _timeout) :
  54. type(t), peer_id(_peer_id), timeout(_timeout)
  55. {
  56. }
  57. PeerChange() = delete;
  58. PeerChangeType type;
  59. session_t peer_id;
  60. bool timeout;
  61. };
  62. }