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