]> git.lizzy.rs Git - dragonfireclient.git/blob - src/network/peerhandler.h
Travis: Update clang from 4.0 to 5.0 (#6467)
[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         MIN_RTT,
29         MAX_RTT,
30         AVG_RTT,
31         MIN_JITTER,
32         MAX_JITTER,
33         AVG_JITTER
34 } rtt_stat_type;
35
36 class Peer;
37
38 class PeerHandler
39 {
40 public:
41         PeerHandler() = default;
42
43         virtual ~PeerHandler() = default;
44
45         /*
46                 This is called after the Peer has been inserted into the
47                 Connection's peer container.
48         */
49         virtual void peerAdded(Peer *peer) = 0;
50
51         /*
52                 This is called before the Peer has been removed from the
53                 Connection's peer container.
54         */
55         virtual void deletingPeer(Peer *peer, bool timeout) = 0;
56 };
57
58 enum PeerChangeType : u8
59 {
60         PEER_ADDED,
61         PEER_REMOVED
62 };
63
64 struct PeerChange
65 {
66         PeerChange(PeerChangeType t, session_t _peer_id, bool _timeout) :
67                         type(t), peer_id(_peer_id), timeout(_timeout)
68         {
69         }
70         PeerChange() = delete;
71
72         PeerChangeType type;
73         session_t peer_id;
74         bool timeout;
75 };
76 }