Network: fix a concurrency problem, by re-adding a copy in ConnectionCommand
[oweals/minetest.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 namespace con
23 {
24
25 typedef enum {
26         MIN_RTT,
27         MAX_RTT,
28         AVG_RTT,
29         MIN_JITTER,
30         MAX_JITTER,
31         AVG_JITTER
32 } rtt_stat_type;
33
34 class Peer;
35
36 class PeerHandler
37 {
38 public:
39         PeerHandler() = default;
40
41         virtual ~PeerHandler() = default;
42
43         /*
44                 This is called after the Peer has been inserted into the
45                 Connection's peer container.
46         */
47         virtual void peerAdded(Peer *peer) = 0;
48
49         /*
50                 This is called before the Peer has been removed from the
51                 Connection's peer container.
52         */
53         virtual void deletingPeer(Peer *peer, bool timeout) = 0;
54 };
55
56 enum PeerChangeType
57 {
58         PEER_ADDED,
59         PEER_REMOVED
60 };
61 struct PeerChange
62 {
63         PeerChange(PeerChangeType t, u16 _peer_id, bool _timeout)
64             : type(t), peer_id(_peer_id), timeout(_timeout)
65         {
66         }
67         PeerChange() = delete;
68
69         PeerChangeType type;
70         u16 peer_id;
71         bool timeout;
72 };
73 }