forked from irwir/eMule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientList.h
159 lines (138 loc) · 5.51 KB
/
ClientList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//this file is part of eMule
//Copyright (C)2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#include "DeadSourceList.h"
class CClientReqSocket;
class CUpDownClient;
namespace Kademlia{
class CContact;
class CUInt128;
};
typedef CTypedPtrList<CPtrList, CUpDownClient*> CUpDownClientPtrList;
#define NUM_CLIENTLIST_STATS 19
#define BAN_CLEANUP_TIME 1200000 // 20 min
//------------CDeletedClient Class----------------------
// this class / list is a bit overkill, but currently needed to avoid any exploit possibtility
// it will keep track of certain clients attributes for 2 hours, while the CUpDownClient object might be deleted already
// currently: IP, Port, UserHash
struct PORTANDHASH{
uint16 nPort;
void* pHash;
};
struct IPANDTICS{
uint32 dwIP;
uint32 dwInserted;
};
struct CONNECTINGCLIENT{
CUpDownClient* pClient;
uint32 dwInserted;
};
class CDeletedClient{
public:
CDeletedClient(const CUpDownClient* pClient);
CArray<PORTANDHASH> m_ItemsList;
uint32 m_dwInserted;
uint32 m_cBadRequest;
};
enum buddyState
{
Disconnected,
Connecting,
Connected
};
// ----------------------CClientList Class---------------
class CClientList
{
friend class CClientListCtrl;
public:
CClientList();
~CClientList();
// Clients
void AddClient(CUpDownClient* toadd,bool bSkipDupTest = false);
void RemoveClient(CUpDownClient* toremove, LPCTSTR pszReason = NULL);
void GetStatistics(uint32& totalclient, int stats[NUM_CLIENTLIST_STATS],
CMap<uint32, uint32, uint32, uint32>& clientVersionEDonkey,
CMap<uint32, uint32, uint32, uint32>& clientVersionEDonkeyHybrid,
CMap<uint32, uint32, uint32, uint32>& clientVersionEMule,
CMap<uint32, uint32, uint32, uint32>& clientVersionAMule);
uint32 GetClientCount() { return list.GetCount();}
void DeleteAll();
bool AttachToAlreadyKnown(CUpDownClient** client, CClientReqSocket* sender);
CUpDownClient* FindClientByIP(uint32 clientip, UINT port) const;
CUpDownClient* FindClientByUserHash(const uchar* clienthash, uint32 dwIP = 0, uint16 nTCPPort = 0) const;
CUpDownClient* FindClientByIP(uint32 clientip) const;
CUpDownClient* FindClientByIP_UDP(uint32 clientip, UINT nUDPport) const;
CUpDownClient* FindClientByServerID(uint32 uServerIP, uint32 uUserID) const;
CUpDownClient* FindClientByUserID_KadPort(uint32 clientID,uint16 kadPort) const;
CUpDownClient* FindClientByIP_KadPort(uint32 ip, uint16 port) const;
// Banned clients
void AddBannedClient(uint32 dwIP);
bool IsBannedClient(uint32 dwIP) const;
void RemoveBannedClient(uint32 dwIP);
UINT GetBannedCount() const { return m_bannedList.GetCount(); }
void RemoveAllBannedClients();
// Tracked clients
void AddTrackClient(CUpDownClient* toadd);
bool ComparePriorUserhash(uint32 dwIP, uint16 nPort, void* pNewHash);
UINT GetClientsFromIP(uint32 dwIP) const;
void TrackBadRequest(const CUpDownClient* upcClient, int nIncreaseCounter);
uint32 GetBadRequests(const CUpDownClient* upcClient) const;
UINT GetTrackedCount() const { return m_trackedClientsList.GetCount(); }
void RemoveAllTrackedClients();
// Kad client list, buddy handling
bool RequestTCP(Kademlia::CContact* contact, uint8 byConnectOptions);
void RequestBuddy(Kademlia::CContact* contact, uint8 byConnectOptions);
bool IncomingBuddy(Kademlia::CContact* contact, Kademlia::CUInt128* buddyID);
void RemoveFromKadList(CUpDownClient* torem);
void AddToKadList(CUpDownClient* toadd);
bool DoRequestFirewallCheckUDP(const Kademlia::CContact& contact);
//bool DebugDoRequestFirewallCheckUDP(uint32 ip, uint16 port);
uint8 GetBuddyStatus() { return m_nBuddyStatus; }
CUpDownClient* GetBuddy() { return m_pBuddy; }
void AddKadFirewallRequest(uint32 dwIP);
bool IsKadFirewallCheckIP(uint32 dwIP) const;
// Direct Callback List
void AddTrackCallbackRequests(uint32 dwIP);
bool AllowCalbackRequest(uint32 dwIP) const;
// Connecting Clients
void AddConnectingClient(CUpDownClient* pToAdd);
void RemoveConnectingClient(CUpDownClient* pToRemove);
void Process();
bool IsValidClient(CUpDownClient* tocheck) const;
void Debug_SocketDeleted(CClientReqSocket* deleted) const;
// ZZ:UploadSpeedSense -->
bool GiveClientsForTraceRoute();
// ZZ:UploadSpeedSense <--
void ProcessA4AFClients() const; // ZZ:DownloadManager
CDeadSourceList m_globDeadSourceList;
protected:
void CleanUpClientList();
void ProcessConnectingClientsList();
private:
CUpDownClientPtrList list;
CUpDownClientPtrList m_KadList;
CMap<uint32, uint32, uint32, uint32> m_bannedList;
CMap<uint32, uint32, CDeletedClient*, CDeletedClient*> m_trackedClientsList;
uint32 m_dwLastBannCleanUp;
uint32 m_dwLastTrackedCleanUp;
uint32 m_dwLastClientCleanUp;
CUpDownClient* m_pBuddy;
uint8 m_nBuddyStatus;
CList<IPANDTICS> listFirewallCheckRequests;
CList<IPANDTICS> listDirectCallbackRequests;
CList<CONNECTINGCLIENT> m_liConnectingClients;
};