debian: fix build-deps for focal
[amule.git] / src / kademlia / net / PacketTracking.h
blob07c13f220f14d9d153e1a7f2dcd396e5eee599da
1 // -*- C++ -*-
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2008-2011 Dévai Tamás ( gonosztopi@amule.org )
5 // Copyright (c) 2008-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
7 //
8 // Any parts of this program derived from the xMule, lMule or eMule project,
9 // or contributed by third-party developers are copyrighted by their
10 // respective authors.
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #ifndef KADEMLIA_NET_PACKETTRACKING_H
28 #define KADEMLIA_NET_PACKETTRACKING_H
30 #include <map>
31 #include <list>
32 #include "../utils/UInt128.h"
33 #include "../../Types.h"
35 namespace Kademlia
38 struct TrackPackets_Struct {
39 uint32_t ip;
40 uint32_t inserted;
41 uint8_t opcode;
44 struct TrackChallenge_Struct {
45 uint32_t ip;
46 uint32_t inserted;
47 uint8_t opcode;
48 CUInt128 contactID;
49 CUInt128 challenge;
52 struct TrackPacketsIn_Struct {
53 struct TrackedRequestIn_Struct {
54 uint32_t m_count;
55 uint32_t m_firstAdded;
56 uint8_t m_opcode;
57 bool m_dbgLogged;
60 TrackPacketsIn_Struct()
62 m_lastExpire = 0;
63 m_ip = 0;
66 uint32_t m_ip;
67 uint32_t m_lastExpire;
68 typedef std::list<TrackedRequestIn_Struct> TrackedRequestList;
69 TrackedRequestList m_trackedRequests;
72 class CPacketTracking
74 public:
75 CPacketTracking() throw() { lastTrackInCleanup = 0; }
76 virtual ~CPacketTracking();
78 protected:
79 void AddTrackedOutPacket(uint32_t ip, uint8_t opcode);
80 bool IsOnOutTrackList(uint32_t ip, uint8_t opcode, bool dontRemove = false);
81 bool InTrackListIsAllowedPacket(uint32_t ip, uint8_t opcode, bool validReceiverkey);
82 void InTrackListCleanup();
83 void AddLegacyChallenge(const CUInt128& contactID, const CUInt128& challengeID, uint32_t ip, uint8_t opcode);
84 bool IsLegacyChallenge(const CUInt128& challengeID, uint32_t ip, uint8_t opcode, CUInt128& contactID);
85 bool HasActiveLegacyChallenge(uint32_t ip) const;
87 private:
88 static bool IsTrackedOutListRequestPacket(uint8_t opcode) throw();
89 typedef std::list<TrackPackets_Struct> TrackedPacketList;
90 typedef std::list<TrackChallenge_Struct> TrackChallengeList;
91 typedef std::map<uint32_t, TrackPacketsIn_Struct*> TrackedPacketInMap;
92 TrackedPacketList listTrackedRequests;
93 TrackChallengeList listChallengeRequests;
94 TrackedPacketInMap m_mapTrackPacketsIn;
95 uint32_t lastTrackInCleanup;
98 } // namespace Kademlia
100 #endif /* KADEMLIA_NET_PACKETTRACKING_H */